-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Expr.lean
theorem go_denote_eq (aig : AIG BVBit) (expr : BVExpr w) (assign : Assignment) :
    ∀ (idx : Nat) (hidx : idx < w),
        ⟦(go aig expr).val.aig, (go aig expr).val.vec.get idx hidx, assign.toAIGAssignment⟧
          =
        (expr.eval assign).getLsbD idx

Proof state:
case signExtend.inl
w : Nat
assign : Assignment
originalWidth v : Nat
inner : BVExpr originalWidth
ih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < originalWidth),
    ⟦assign.toAIGAssignment, { aig := (go aig inner).val.aig, ref := (go aig inner).val.vec.get idx hidx }⟧ =
      (eval assign inner).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < v
res : RefVecEntry BVBit v
hgo : blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec } = res
this : 0 ≤ originalWidth
heq : 0 = originalWidth
⊢ ⟦assign.toAIGAssignment,
      { aig := (blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec }).aig,
        ref :=
          (blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec }).vec.get idx
            hidx }⟧ =
    (eval assign (signExtend v inner)).getLsbD idx

Tactic:
simp only [eval_signExtend]

Result:
case signExtend.inl
w : Nat
assign : Assignment
originalWidth v : Nat
inner : BVExpr originalWidth
ih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < originalWidth),
    ⟦assign.toAIGAssignment, { aig := (go aig inner).val.aig, ref := (go aig inner).val.vec.get idx hidx }⟧ =
      (eval assign inner).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < v
res : RefVecEntry BVBit v
hgo : blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec } = res
this : 0 ≤ originalWidth
heq : 0 = originalWidth
⊢ ⟦assign.toAIGAssignment,
      { aig := (blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec }).aig,
        ref :=
          (blastZeroExtend (go aig inner).1.aig { w := originalWidth, vec := (go aig inner).1.vec }).vec.get idx
            hidx }⟧ =
    (BitVec.signExtend v (eval assign inner)).getLsbD idx

Proof state:
case un.shiftLeftConst
w : Nat
assign : Assignment
w✝ : Nat
expr : BVExpr w✝
ih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < w✝),
    ⟦assign.toAIGAssignment, { aig := (go aig expr).val.aig, ref := (go aig expr).val.vec.get idx hidx }⟧ =
      (eval assign expr).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < w✝
n✝ : Nat
⊢ ⟦assign.toAIGAssignment,
      { aig := (go aig (un (BVUnOp.shiftLeftConst n✝) expr)).val.aig,
        ref := (go aig (un (BVUnOp.shiftLeftConst n✝) expr)).val.vec.get idx hidx }⟧ =
    (eval assign (un (BVUnOp.shiftLeftConst n✝) expr)).getLsbD idx

Tactic:
simp [go, ih, hidx]

Result:
no goals

Proof state:
case signExtend.inl
w : Nat
assign : Assignment
v : Nat
aig : AIG BVBit
idx : Nat
hidx : idx < v
res : RefVecEntry BVBit v
inner : BVExpr 0
ih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < 0),
    ⟦assign.toAIGAssignment, { aig := (go aig inner).val.aig, ref := (go aig inner).val.vec.get idx hidx }⟧ =
      (eval assign inner).getLsbD idx
hgo : blastZeroExtend (go aig inner).1.aig { w := 0, vec := (go aig inner).1.vec } = res
this : 0 ≤ 0
⊢ (eval assign inner).msb = false

Tactic:
rw [BitVec.msb_zero_length]

Result:
no goals

Proof state:
case shiftLeft
w : Nat
assign : Assignment
m✝ n✝ : Nat
lhs : BVExpr m✝
rhs : BVExpr n✝
lih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < m✝),
    ⟦assign.toAIGAssignment, { aig := (go aig lhs).val.aig, ref := (go aig lhs).val.vec.get idx hidx }⟧ =
      (eval assign lhs).getLsbD idx
rih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < n✝),
    ⟦assign.toAIGAssignment, { aig := (go aig rhs).val.aig, ref := (go aig rhs).val.vec.get idx hidx }⟧ =
      (eval assign rhs).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < m✝
⊢ ⟦assign.toAIGAssignment,
      {
        aig :=
          (blastShiftLeft (go (go aig lhs).1.aig rhs).1.aig
              { n := n✝, target := (go aig lhs).1.vec.cast ⋯, distance := (go (go aig lhs).1.aig rhs).1.vec }).aig,
        ref :=
          (blastShiftLeft (go (go aig lhs).1.aig rhs).1.aig
                  { n := n✝, target := (go aig lhs).1.vec.cast ⋯,
                    distance := (go (go aig lhs).1.aig rhs).1.vec }).vec.get
            idx hidx }⟧ =
    (eval assign lhs <<< eval assign rhs).getLsbD idx

Tactic:
apply denote_blastShiftLeft

Result:
case shiftLeft.hleft
w : Nat
assign : Assignment
m✝ n✝ : Nat
lhs : BVExpr m✝
rhs : BVExpr n✝
lih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < m✝),
    ⟦assign.toAIGAssignment, { aig := (go aig lhs).val.aig, ref := (go aig lhs).val.vec.get idx hidx }⟧ =
      (eval assign lhs).getLsbD idx
rih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < n✝),
    ⟦assign.toAIGAssignment, { aig := (go aig rhs).val.aig, ref := (go aig rhs).val.vec.get idx hidx }⟧ =
      (eval assign rhs).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < m✝
⊢ ∀ (idx : Nat) (hidx : idx < m✝),
    ⟦assign.toAIGAssignment,
        { aig := (go (go aig lhs).1.aig rhs).1.aig,
          ref :=
            { n := n✝, target := (go aig lhs).1.vec.cast ⋯, distance := (go (go aig lhs).1.aig rhs).1.vec }.target.get
              idx hidx }⟧ =
      (eval assign lhs).getLsbD idx

case shiftLeft.hright
w : Nat
assign : Assignment
m✝ n✝ : Nat
lhs : BVExpr m✝
rhs : BVExpr n✝
lih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < m✝),
    ⟦assign.toAIGAssignment, { aig := (go aig lhs).val.aig, ref := (go aig lhs).val.vec.get idx hidx }⟧ =
      (eval assign lhs).getLsbD idx
rih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < n✝),
    ⟦assign.toAIGAssignment, { aig := (go aig rhs).val.aig, ref := (go aig rhs).val.vec.get idx hidx }⟧ =
      (eval assign rhs).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < m✝
⊢ ∀ (idx : Nat)
    (hidx : idx < { n := n✝, target := (go aig lhs).1.vec.cast ⋯, distance := (go (go aig lhs).1.aig rhs).1.vec }.n),
    ⟦assign.toAIGAssignment,
        { aig := (go (go aig lhs).1.aig rhs).1.aig,
          ref :=
            { n := n✝, target := (go aig lhs).1.vec.cast ⋯, distance := (go (go aig lhs).1.aig rhs).1.vec }.distance.get
              idx hidx }⟧ =
      (eval assign rhs).getLsbD idx

Proof state:
case bin.xor
w : Nat
assign : Assignment
w✝ : Nat
lhs rhs : BVExpr w✝
lih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < w✝),
    ⟦assign.toAIGAssignment, { aig := (go aig lhs).val.aig, ref := (go aig lhs).val.vec.get idx hidx }⟧ =
      (eval assign lhs).getLsbD idx
rih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < w✝),
    ⟦assign.toAIGAssignment, { aig := (go aig rhs).val.aig, ref := (go aig rhs).val.vec.get idx hidx }⟧ =
      (eval assign rhs).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < w✝
⊢ (⟦assign.toAIGAssignment,
        { aig := (bitblast (bitblast aig lhs).aig rhs).aig, ref := ((bitblast aig lhs).vec.get idx hidx).cast ⋯ }⟧ ^^
      (eval assign rhs).getLsbD idx) =
    ((eval assign lhs).getLsbD idx ^^ (eval assign rhs).getLsbD idx)

Tactic:
rw [AIG.LawfulVecOperator.denote_input_vec (f := bitblast)]

Result:
case bin.xor
w : Nat
assign : Assignment
w✝ : Nat
lhs rhs : BVExpr w✝
lih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < w✝),
    ⟦assign.toAIGAssignment, { aig := (go aig lhs).val.aig, ref := (go aig lhs).val.vec.get idx hidx }⟧ =
      (eval assign lhs).getLsbD idx
rih :
  ∀ (aig : AIG BVBit) (idx : Nat) (hidx : idx < w✝),
    ⟦assign.toAIGAssignment, { aig := (go aig rhs).val.aig, ref := (go aig rhs).val.vec.get idx hidx }⟧ =
      (eval assign rhs).getLsbD idx
aig : AIG BVBit
idx : Nat
hidx : idx < w✝
⊢ (⟦assign.toAIGAssignment, { aig := (bitblast aig lhs).aig, ref := (bitblast aig lhs).vec.get idx hidx }⟧ ^^
      (eval assign rhs).getLsbD idx) =
    ((eval assign lhs).getLsbD idx ^^ (eval assign rhs).getLsbD idx)