-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftRight.lean
theorem denote_blastShiftRight (aig : AIG α) (target : ArbitraryShiftTarget aig w0)
    (lhs : BitVec w0) (rhs : BitVec target.n) (assign : α → Bool)
    (hleft : ∀ (idx : Nat) (hidx : idx < w0), ⟦aig, target.target.get idx hidx, assign⟧ = lhs.getLsbD idx)
    (hright : ∀ (idx : Nat) (hidx : idx < target.n), ⟦aig, target.distance.get idx hidx, assign⟧ = rhs.getLsbD idx) :
    ∀ (idx : Nat) (hidx : idx < w0),
        ⟦
          (blastShiftRight aig target).aig,
          (blastShiftRight aig target).vec.get idx hidx,
          assign
        ⟧
          =
        (lhs >>> rhs).getLsbD idx

Proof state:
case mk.isFalse.hacc
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx : Nat
hidx : idx < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
h✝ : ¬n = 0
hres :
  blastShiftRight.go (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).aig
      (distance.cast ⋯) 0 (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).vec =
    res
⊢ ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign,
        { aig := (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).aig,
          ref :=
            (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).vec.get idx hidx }⟧ =
      (lhs.ushiftRightRec rhs 0).getLsbD idx

Tactic:
intro idx hidx

Result:
case mk.isFalse.hacc
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx✝ : Nat
hidx✝ : idx✝ < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
h✝ : ¬n = 0
hres :
  blastShiftRight.go (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).aig
      (distance.cast ⋯) 0 (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).vec =
    res
idx : Nat
hidx : idx < w0
⊢ ⟦assign,
      { aig := (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).aig,
        ref :=
          (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).vec.get idx hidx }⟧ =
    (lhs.ushiftRightRec rhs 0).getLsbD idx

Proof state:
case mk.isTrue
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx : Nat
hidx : idx < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
h✝ : n = 0
hres : { aig := aig, vec := target } = res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx }⟧ =
    (lhs.ushiftRightRec rhs ({ n := n, target := target, distance := distance }.n - 1)).getLsbD idx

Tactic:
next hzero =>
dsimp only
subst hzero
rw [← hres]
simp [hleft, BitVec.and_twoPow]

Result:
no goals

Proof state:
case mk
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx : Nat
hidx : idx < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
hres : blastShiftRight aig { n := n, target := target, distance := distance } = res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx }⟧ =
    (lhs.ushiftRightRec rhs ({ n := n, target := target, distance := distance }.n - 1)).getLsbD idx

Tactic:
unfold blastShiftRight at hres

Result:
case mk
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx : Nat
hidx : idx < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
hres :
  (match { n := n, target := target, distance := distance } with
    | { n := n, target := input, distance := distance } =>
      if n = 0 then { aig := aig, vec := input }
      else
        let res := blastShiftRight.twoPowShift aig { n := n, lhs := input, rhs := distance, pow := 0 };
        let aig_1 := res.aig;
        let acc := res.vec;
        let_fun this := ⋯;
        let distance := distance.cast this;
        blastShiftRight.go aig_1 distance 0 acc) =
    res
⊢ ⟦assign, { aig := res.aig, ref := res.vec.get idx hidx }⟧ =
    (lhs.ushiftRightRec rhs ({ n := n, target := target, distance := distance }.n - 1)).getLsbD idx

Proof state:
case mk.isFalse.hacc.hleft
α : Type
inst✝¹ : Hashable α
inst✝ : DecidableEq α
w0 : Nat
aig : AIG α
lhs : BitVec w0
assign : α → Bool
idx✝ : Nat
hidx✝ : idx✝ < w0
res : RefVecEntry α w0
n : Nat
target : aig.RefVec w0
distance : aig.RefVec n
rhs : BitVec { n := n, target := target, distance := distance }.n
hleft :
  ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.target.get idx hidx }⟧ =
      lhs.getLsbD idx
hright :
  ∀ (idx : Nat) (hidx : idx < { n := n, target := target, distance := distance }.n),
    ⟦assign, { aig := aig, ref := { n := n, target := target, distance := distance }.distance.get idx hidx }⟧ =
      rhs.getLsbD idx
h✝ : ¬n = 0
hres :
  blastShiftRight.go (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).aig
      (distance.cast ⋯) 0 (blastShiftRight.twoPowShift aig { n := n, lhs := target, rhs := distance, pow := 0 }).vec =
    res
idx : Nat
hidx : idx < w0
⊢ ∀ (idx : Nat) (hidx : idx < w0),
    ⟦assign, { aig := aig, ref := { n := n, lhs := target, rhs := distance, pow := 0 }.lhs.get idx hidx }⟧ =
      lhs.getLsbD idx

Tactic:
simp [hleft]

Result:
no goals