-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddResult.lean
theorem derivedLitsInvariant_confirmRupHint {n : Nat} (f : DefaultFormula n) (f_assignments_size : f.assignments.size = n)
    (rupHints : Array Nat) (i : Fin rupHints.size)
    (acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool)
    (ih : ∃ hsize : acc.1.size = n, DerivedLitsInvariant f f_assignments_size acc.1 hsize acc.2.1) :
    let rupHint_res := (confirmRupHint f.clauses) acc rupHints[i]
    ∃ hsize : rupHint_res.1.size = n, DerivedLitsInvariant f f_assignments_size rupHint_res.1 hsize rupHint_res.2.1

Proof state:
case intro.isFalse.inr.inr.intro.inl
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
h✝ : ¬(acc.2.2.snd || acc.2.2.fst) = true
c : DefaultClause n
rupHint_clause_eq_c : f.clauses[rupHints[↑i]]? = some (some c)
hencounteredBoth : c.reduce acc.fst = ReduceResult.encounteredBoth
⊢ f.DerivedLitsInvariant f_assignments_size
    (match c.reduce acc.fst with
      | ReduceResult.encounteredBoth => (acc.fst, acc.2.fst, true, false)
      | ReduceResult.reducedToEmpty => (acc.fst, acc.2.fst, true, false)
      | ReduceResult.reducedToUnit (l, b) =>
        if hasAssignment b acc.fst[l.val]! = true then (acc.fst, acc.2.fst, false, false)
        else (acc.fst.modify l.val (addAssignment b), (l, b) :: acc.2.fst, false, false)
      | ReduceResult.reducedToNonunit => (acc.fst, acc.2.fst, false, true)).fst
    ⋯
    (match c.reduce acc.fst with
        | ReduceResult.encounteredBoth => (acc.fst, acc.2.fst, true, false)
        | ReduceResult.reducedToEmpty => (acc.fst, acc.2.fst, true, false)
        | ReduceResult.reducedToUnit (l, b) =>
          if hasAssignment b acc.fst[l.val]! = true then (acc.fst, acc.2.fst, false, false)
          else (acc.fst.modify l.val (addAssignment b), (l, b) :: acc.2.fst, false, false)
        | ReduceResult.reducedToNonunit => (acc.fst, acc.2.fst, false, true)).snd.fst

Tactic:
simp only [hencounteredBoth]

Result:
case intro.isFalse.inr.inr.intro.inl
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
h✝ : ¬(acc.2.2.snd || acc.2.2.fst) = true
c : DefaultClause n
rupHint_clause_eq_c : f.clauses[rupHints[↑i]]? = some (some c)
hencounteredBoth : c.reduce acc.fst = ReduceResult.encounteredBoth
⊢ f.DerivedLitsInvariant f_assignments_size acc.fst ⋯ acc.2.fst

Proof state:
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
h✝ : ¬(acc.2.2.snd || acc.2.2.fst) = true
c : DefaultClause n
rupHint_clause_eq_c : f.clauses[rupHints[↑i]]? = some (some c)
⊢ ReduceResult.reducedToNonunit = ReduceResult.encounteredBoth ∨
    ReduceResult.reducedToNonunit = ReduceResult.reducedToEmpty ∨
      (∃ l, ReduceResult.reducedToNonunit = ReduceResult.reducedToUnit l) ∨
        ReduceResult.reducedToNonunit = ReduceResult.reducedToNonunit

Tactic:
exact (Or.inr ∘ Or.inr ∘ Or.inr) rfl

Result:
no goals

Proof state:
case intro
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
⊢ f.DerivedLitsInvariant f_assignments_size (confirmRupHint f.clauses acc rupHints[i]).fst hsize'
    (confirmRupHint f.clauses acc rupHints[i]).snd.fst

Tactic:
simp only [confirmRupHint, Fin.getElem_fin]

Result:
case intro
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
⊢ f.DerivedLitsInvariant f_assignments_size
    (if (acc.2.2.snd || acc.2.2.fst) = true then (acc.fst, acc.2.fst, acc.2.2.fst, acc.2.2.snd)
      else
        match f.clauses[rupHints[↑i]]? with
        | some (some c) =>
          match c.reduce acc.fst with
          | ReduceResult.encounteredBoth => (acc.fst, acc.2.fst, true, false)
          | ReduceResult.reducedToEmpty => (acc.fst, acc.2.fst, true, false)
          | ReduceResult.reducedToUnit (l, b) =>
            if hasAssignment b acc.fst[l.val]! = true then (acc.fst, acc.2.fst, false, false)
            else (acc.fst.modify l.val (addAssignment b), (l, b) :: acc.2.fst, false, false)
          | ReduceResult.reducedToNonunit => (acc.fst, acc.2.fst, false, true)
        | some none => (acc.fst, acc.2.fst, false, true)
        | none => (acc.fst, acc.2.fst, false, true)).fst
    ⋯
    (if (acc.2.2.snd || acc.2.2.fst) = true then (acc.fst, acc.2.fst, acc.2.2.fst, acc.2.2.snd)
        else
          match f.clauses[rupHints[↑i]]? with
          | some (some c) =>
            match c.reduce acc.fst with
            | ReduceResult.encounteredBoth => (acc.fst, acc.2.fst, true, false)
            | ReduceResult.reducedToEmpty => (acc.fst, acc.2.fst, true, false)
            | ReduceResult.reducedToUnit (l, b) =>
              if hasAssignment b acc.fst[l.val]! = true then (acc.fst, acc.2.fst, false, false)
              else (acc.fst.modify l.val (addAssignment b), (l, b) :: acc.2.fst, false, false)
            | ReduceResult.reducedToNonunit => (acc.fst, acc.2.fst, false, true)
          | some none => (acc.fst, acc.2.fst, false, true)
          | none => (acc.fst, acc.2.fst, false, true)).snd.fst

Proof state:
n : Nat
f : DefaultFormula n
f_assignments_size : f.assignments.size = n
rupHints : Array Nat
i : Fin rupHints.size
acc : Array Assignment × CNF.Clause (PosFin n) × Bool × Bool
hsize : acc.fst.size = n
ih : f.DerivedLitsInvariant f_assignments_size acc.fst hsize acc.snd.fst
hsize' : (confirmRupHint f.clauses acc rupHints[i]).fst.size = n
h✝ : ¬(acc.2.2.snd || acc.2.2.fst) = true
c : DefaultClause n
rupHint_clause_eq_c : f.clauses[rupHints[↑i]]? = some (some c)
⊢ c.reduce acc.fst = ReduceResult.encounteredBoth ∨
    c.reduce acc.fst = ReduceResult.reducedToEmpty ∨
      (∃ l, c.reduce acc.fst = ReduceResult.reducedToUnit l) ∨ c.reduce acc.fst = ReduceResult.reducedToNonunit

Tactic:
match reduce c acc.fst with
| ReduceResult.encounteredBoth => exact Or.inl rfl
| ReduceResult.reducedToEmpty => exact (Or.inr ∘ Or.inl) rfl
| ReduceResult.reducedToUnit l => exact (Or.inr ∘ Or.inr ∘ Or.inl ∘ Exists.intro l) rfl
| ReduceResult.reducedToNonunit => exact (Or.inr ∘ Or.inr ∘ Or.inr) rfl

Result:
no goals