-- Mathlib/.lake/packages/lean4/src/lean/Std/Sat/AIG/RefVecOperator/Zip.lean
theorem zip.go_le_size {aig : AIG α} (idx : Nat) (hidx) (s : RefVec aig idx)
    (lhs rhs : RefVec aig len)
    (f : (aig : AIG α) → BinaryInput aig → Entrypoint α) [LawfulOperator α BinaryInput f]
    [chainable : LawfulZipOperator α f] :
    aig.decls.size ≤ (go aig idx s hidx lhs rhs f).1.decls.size

Proof state:
case isFalse
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : ¬idx < len
⊢ aig.decls.size ≤
    (let_fun this := ⋯;
          { aig := aig, vec := this ▸ s }).aig.decls.size

Tactic:
simp

Result:
no goals

Proof state:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤ (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).aig.decls.size

Tactic:
apply LawfulOperator.le_size

Result:
no goals

Proof state:
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ ?m.23617 ≤
    (go (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).aig (idx + 1)
            ((s.cast ⋯).push (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯)
            f).aig.decls.size

Tactic:
apply zip.go_le_size

Result:
no goals

Proof state:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤
    (go (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).aig (idx + 1)
            ((s.cast ⋯).push (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯)
            f).aig.decls.size

Tactic:
refine Nat.le_trans ?_ (by apply zip.go_le_size)

Result:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤ (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).aig.decls.size

Proof state:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤
    (let res := f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ };
          let aig_1 := res.aig;
          let newRef := res.ref;
          let_fun this := ⋯;
          let s := s.cast this;
          let s := s.push newRef;
          go aig_1 (idx + 1) s ⋯ (lhs.cast this) (rhs.cast this) f).aig.decls.size

Tactic:
dsimp only

Result:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤
    (go (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).aig (idx + 1)
            ((s.cast ⋯).push (f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ }).ref) ⋯ (lhs.cast ⋯) (rhs.cast ⋯)
            f).aig.decls.size

Proof state:
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
⊢ aig.decls.size ≤ (go aig idx s hidx lhs rhs f).aig.decls.size

Tactic:
unfold go

Result:
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
⊢ aig.decls.size ≤
    (if hidx : idx < len then
            let res := f aig { lhs := lhs.get idx hidx, rhs := rhs.get idx hidx };
            let aig_1 := res.aig;
            let newRef := res.ref;
            let_fun this := ⋯;
            let s := s.cast this;
            let s := s.push newRef;
            go aig_1 (idx + 1) s ⋯ (lhs.cast this) (rhs.cast this) f
          else
            let_fun this := ⋯;
            { aig := aig, vec := this ▸ s }).aig.decls.size

Proof state:
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
⊢ aig.decls.size ≤
    (if hidx : idx < len then
            let res := f aig { lhs := lhs.get idx hidx, rhs := rhs.get idx hidx };
            let aig_1 := res.aig;
            let newRef := res.ref;
            let_fun this := ⋯;
            let s := s.cast this;
            let s := s.push newRef;
            go aig_1 (idx + 1) s ⋯ (lhs.cast this) (rhs.cast this) f
          else
            let_fun this := ⋯;
            { aig := aig, vec := this ▸ s }).aig.decls.size

Tactic:
split

Result:
case isTrue
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : idx < len
⊢ aig.decls.size ≤
    (let res := f aig { lhs := lhs.get idx h✝, rhs := rhs.get idx h✝ };
          let aig_1 := res.aig;
          let newRef := res.ref;
          let_fun this := ⋯;
          let s := s.cast this;
          let s := s.push newRef;
          go aig_1 (idx + 1) s ⋯ (lhs.cast this) (rhs.cast this) f).aig.decls.size

case isFalse
α : Type
inst✝² : Hashable α
inst✝¹ : DecidableEq α
len : Nat
aig : AIG α
idx : Nat
hidx : idx ≤ len
s : aig.RefVec idx
lhs rhs : aig.RefVec len
f : (aig : AIG α) → aig.BinaryInput → Entrypoint α
inst✝ : LawfulOperator α BinaryInput f
chainable : LawfulZipOperator α f
h✝ : ¬idx < len
⊢ aig.decls.size ≤
    (let_fun this := ⋯;
          { aig := aig, vec := this ▸ s }).aig.decls.size