-- Mathlib/.lake/packages/lean4/src/lean/Std/Tactic/BVDecide/LRAT/Internal/Formula/Lemmas.lean
theorem insert_iff {n : Nat} (f : DefaultFormula n) (c1 : DefaultClause n) (c2 : DefaultClause n) :
    c2 ∈ toList (insert f c1) ↔ c2 = c1 ∨ c2 ∈ toList f

Proof state:
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
⊢ (some c2 ∈ (f.insert c1).clauses.toList ∨
      (∃ a,
          (a, false) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, true) = c2) ∨
        ∃ a,
          (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2) ↔
    c2 = c1 ∨
      some c2 ∈ f.clauses.toList ∨
        (∃ a,
            (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨
              (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2) ∨
          ∃ a,
            (a, false) ∈ f.ratUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.ratUnits.toList ∧ unit (a, true) = c2

Tactic:
by_cases c2 = c1

Result:
case pos
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
h✝ : c2 = c1
⊢ (some c2 ∈ (f.insert c1).clauses.toList ∨
      (∃ a,
          (a, false) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, true) = c2) ∨
        ∃ a,
          (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2) ↔
    c2 = c1 ∨
      some c2 ∈ f.clauses.toList ∨
        (∃ a,
            (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨
              (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2) ∨
          ∃ a,
            (a, false) ∈ f.ratUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.ratUnits.toList ∧ unit (a, true) = c2

case neg
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
h✝ : ¬c2 = c1
⊢ (some c2 ∈ (f.insert c1).clauses.toList ∨
      (∃ a,
          (a, false) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, true) = c2) ∨
        ∃ a,
          (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
            (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2) ↔
    c2 = c1 ∨
      some c2 ∈ f.clauses.toList ∨
        (∃ a,
            (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨
              (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2) ∨
          ∃ a,
            (a, false) ∈ f.ratUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.ratUnits.toList ∧ unit (a, true) = c2

Proof state:
case mpr.inr.inr.inl
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : ∃ a, (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2
⊢ some c2 ∈ (f.insert c1).clauses.toList ∨
    (∃ a,
        (a, false) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, false) = c2 ∨
          (a, true) ∈ (f.insert c1).rupUnits.toList ∧ unit (a, true) = c2) ∨
      ∃ a,
        (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
          (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2

Tactic:
rw [rupUnits_insert]

Result:
case mpr.inr.inr.inl
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : ∃ a, (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2
⊢ some c2 ∈ (f.insert c1).clauses.toList ∨
    (∃ a, (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2) ∨
      ∃ a,
        (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
          (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2

Proof state:
case mpr.inr.inr.inl
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : ∃ a, (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2
⊢ some c2 ∈ (f.insert c1).clauses.toList ∨
    (∃ a, (a, false) ∈ f.rupUnits.toList ∧ unit (a, false) = c2 ∨ (a, true) ∈ f.rupUnits.toList ∧ unit (a, true) = c2) ∨
      ∃ a,
        (a, false) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, false) = c2 ∨
          (a, true) ∈ (f.insert c1).ratUnits.toList ∧ unit (a, true) = c2

Tactic:
exact Or.inr <| Or.inl h

Result:
no goals

Proof state:
case mp.h.inl.h
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ (f.insert c1).clauses.toList
⊢ some c2 ∈ f.clauses.toList

Tactic:
simp only [insert] at h

Result:
case mp.h.inl.h
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h :
  some c2 ∈
    (match c1.isUnit with
        | none =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments }
        | some (l, true) =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments.modify l.val addPosAssignment }
        | some (l, false) =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments.modify l.val addNegAssignment }).clauses.toList
⊢ some c2 ∈ f.clauses.toList

Proof state:
case mpr.inr.inl.h
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ f.clauses.toList
⊢ some c2 ∈ (f.insert c1).clauses.toList

Tactic:
simp only [insert]

Result:
case mpr.inr.inl.h
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ f.clauses.toList
⊢ some c2 ∈
    (match c1.isUnit with
        | none =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments }
        | some (l, true) =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments.modify l.val addPosAssignment }
        | some (l, false) =>
          { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
            assignments := f.assignments.modify l.val addNegAssignment }).clauses.toList

Proof state:
case mpr.inr.inl.h.h_1
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ f.clauses.toList
x✝ : Option (Literal (PosFin n))
heq✝ : c1.isUnit = none
⊢ some c2 ∈
    { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
          assignments := f.assignments }.clauses.toList

case mpr.inr.inl.h.h_2
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ f.clauses.toList
x✝ : Option (Literal (PosFin n))
l✝ : PosFin n
heq✝ : c1.isUnit = some (l✝, true)
⊢ some c2 ∈
    { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
          assignments := f.assignments.modify l✝.val addPosAssignment }.clauses.toList

case mpr.inr.inl.h.h_3
n : Nat
f : DefaultFormula n
c1 c2 : DefaultClause n
c2_ne_c1 : ¬c2 = c1
h : some c2 ∈ f.clauses.toList
x✝ : Option (Literal (PosFin n))
l✝ : PosFin n
heq✝ : c1.isUnit = some (l✝, false)
⊢ some c2 ∈
    { clauses := f.clauses.push (some c1), rupUnits := f.rupUnits, ratUnits := f.ratUnits,
          assignments := f.assignments.modify l✝.val addNegAssignment }.clauses.toList

Tactic:
all_goals
  simp only [Array.push_toList, List.mem_append, List.mem_singleton, Option.some.injEq]
  exact Or.inl h

Result:
no goals