-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddSound.lean
theorem safe_insert_of_performRatCheck_fold_success {n : Nat} (f : DefaultFormula n)
    (f_readyForRatAdd : ReadyForRatAdd f) (c : DefaultClause n) (pivot : Literal (PosFin n))
    (rupHints : Array Nat) (ratHints : Array (Nat × Array Nat))
    (pivot_in_c : pivot ∈ Clause.toList c)
    (ratHintsExhaustive_eq_true : ratHintsExhaustive f pivot ratHints = true)
    (performRatCheck_fold_success :
      (Array.foldl
        (fun x ratHint => if x.2 = true then performRatCheck x.1 (Literal.negate pivot) ratHint else (x.1, false))
        ((performRupCheck (insertRupUnits f (negate c)).1 rupHints).1, true) ratHints 0 (Array.size ratHints)).2 = true) :
    Equisat (PosFin n) f (insert f c)

Proof state:
case intro.inl
n : Nat
f : DefaultFormula n
f_readyForRatAdd : f.ReadyForRatAdd
c : DefaultClause n
pivot : Literal (PosFin n)
rupHints : Array Nat
ratHints : Array (Nat × Array Nat)
pivot_in_c : Limplies (PosFin n) pivot c
ratHintsExhaustive_eq_true : f.ratHintsExhaustive pivot ratHints = true
performRatCheck_fold_success :
  (Array.foldl (fun x ratHint => if x.snd = true then x.fst.performRatCheck pivot.negate ratHint else (x.fst, false))
        (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst, true) ratHints).snd =
    true
p : PosFin n → Bool
pf : p ⊨ f
p' : PosFin n → Bool := fun a => if a = pivot.fst then pivot.snd else p a
p'_entails_c : p' ⊨ c
c' : DefaultClause n
p'_not_entails_c' : ¬(p' ⊨ c')
c'_in_f : c' ∈ f.toList
pc' : p ⊨ c'
negPivot_in_c' : pivot.negate ∈ Clause.toList c'
i : Fin ratHints.size
hc' : f.clauses[ratHints[i].fst]! = some c'
h_performRupCheck_res :
  ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.ratUnits = #[] ∧
    ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.assignments.size = n
performRatCheck_success :
  (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.performRatCheck pivot.negate ratHints[i]).snd = true
performRupCheck_res_satisfies_AssignmentsInvariant :
  ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.AssignmentsInvariant
h :
  ∀ (c_1 : DefaultClause n),
    f.clauses[ratHints[↑i].fst]! = some c_1 →
      Limplies (PosFin n) ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst (c_1.delete pivot.negate)
c'' : DefaultClause n
hc'' : c'' ∈ (f.insertRupUnits c.negate).fst.toList
c''_in_negc : c'' ∈ List.map Clause.unit c.negate
pc : ∀ (x : PosFin n), ((x, false) ∈ c.clause → ¬p x = false) ∧ ((x, true) ∈ c.clause → ¬p x = true)
⊢ ∃ a, (a, false) ∈ Clause.toList c'' ∧ p a = false ∨ (a, true) ∈ Clause.toList c'' ∧ p a = true

Tactic:
simp only [negate, Literal.negate, List.map_map, List.mem_map, Function.comp_apply, Prod.exists,
  Bool.exists_bool, Bool.not_false, Bool.not_true] at c''_in_negc

Result:
case intro.inl
n : Nat
f : DefaultFormula n
f_readyForRatAdd : f.ReadyForRatAdd
c : DefaultClause n
pivot : Literal (PosFin n)
rupHints : Array Nat
ratHints : Array (Nat × Array Nat)
pivot_in_c : Limplies (PosFin n) pivot c
ratHintsExhaustive_eq_true : f.ratHintsExhaustive pivot ratHints = true
performRatCheck_fold_success :
  (Array.foldl (fun x ratHint => if x.snd = true then x.fst.performRatCheck pivot.negate ratHint else (x.fst, false))
        (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst, true) ratHints).snd =
    true
p : PosFin n → Bool
pf : p ⊨ f
p' : PosFin n → Bool := fun a => if a = pivot.fst then pivot.snd else p a
p'_entails_c : p' ⊨ c
c' : DefaultClause n
p'_not_entails_c' : ¬(p' ⊨ c')
c'_in_f : c' ∈ f.toList
pc' : p ⊨ c'
negPivot_in_c' : pivot.negate ∈ Clause.toList c'
i : Fin ratHints.size
hc' : f.clauses[ratHints[i].fst]! = some c'
h_performRupCheck_res :
  ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.ratUnits = #[] ∧
    ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.assignments.size = n
performRatCheck_success :
  (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.performRatCheck pivot.negate ratHints[i]).snd = true
performRupCheck_res_satisfies_AssignmentsInvariant :
  ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst.AssignmentsInvariant
h :
  ∀ (c_1 : DefaultClause n),
    f.clauses[ratHints[↑i].fst]! = some c_1 →
      Limplies (PosFin n) ((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst (c_1.delete pivot.negate)
c'' : DefaultClause n
hc'' : c'' ∈ (f.insertRupUnits c.negate).fst.toList
pc : ∀ (x : PosFin n), ((x, false) ∈ c.clause → ¬p x = false) ∧ ((x, true) ∈ c.clause → ¬p x = true)
c''_in_negc :
  ∃ a, (a, false) ∈ c.clause ∧ Clause.unit (a, true) = c'' ∨ (a, true) ∈ c.clause ∧ Clause.unit (a, false) = c''
⊢ ∃ a, (a, false) ∈ Clause.toList c'' ∧ p a = false ∨ (a, true) ∈ Clause.toList c'' ∧ p a = true

Proof state:
case neg.intro.intro.inl
n : Nat
f : DefaultFormula n
f_readyForRatAdd : f.ReadyForRatAdd
c : DefaultClause n
pivot : Literal (PosFin n)
rupHints : Array Nat
ratHints : Array (Nat × Array Nat)
pivot_in_c : Limplies (PosFin n) pivot c
ratHintsExhaustive_eq_true : f.ratHintsExhaustive pivot ratHints = true
performRatCheck_fold_success :
  (Array.foldl (fun x ratHint => if x.snd = true then x.fst.performRatCheck pivot.negate ratHint else (x.fst, false))
        (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst, true) ratHints).snd =
    true
p : PosFin n → Bool
pf : p ⊨ f
pc : ¬(p ⊨ c)
p' : PosFin n → Bool := fun a => if a = pivot.fst then pivot.snd else p a
p'_entails_c : p' ⊨ c
c' : DefaultClause n
p'_not_entails_c' : ¬(p' ⊨ c')
c'_eq_c : c' = c
⊢ False

Tactic:
rw [← c'_eq_c] at p'_entails_c

Result:
case neg.intro.intro.inl
n : Nat
f : DefaultFormula n
f_readyForRatAdd : f.ReadyForRatAdd
c : DefaultClause n
pivot : Literal (PosFin n)
rupHints : Array Nat
ratHints : Array (Nat × Array Nat)
pivot_in_c : Limplies (PosFin n) pivot c
ratHintsExhaustive_eq_true : f.ratHintsExhaustive pivot ratHints = true
performRatCheck_fold_success :
  (Array.foldl (fun x ratHint => if x.snd = true then x.fst.performRatCheck pivot.negate ratHint else (x.fst, false))
        (((f.insertRupUnits c.negate).fst.performRupCheck rupHints).fst, true) ratHints).snd =
    true
p : PosFin n → Bool
pf : p ⊨ f
pc : ¬(p ⊨ c)
p' : PosFin n → Bool := fun a => if a = pivot.fst then pivot.snd else p a
c' : DefaultClause n
p'_entails_c : p' ⊨ c'
p'_not_entails_c' : ¬(p' ⊨ c')
c'_eq_c : c' = c
⊢ False