Theorem: List.merge_loop
File: .lake/packages/batteries/Batteries/Data/List/Lemmas.lean

tactic: rw [merge]
state_before: α : Type u_1
s : α → α → Bool
l r t : List α
⊢ merge.loop s l r t = t.reverseAux (merge s l r)
state_after: α : Type u_1
s : α → α → Bool
l r t : List α
⊢ merge.loop s l r t = t.reverseAux (merge.loop s l r [])

tactic: generalize hn : l.length + r.length = n
state_before: α : Type u_1
s : α → α → Bool
l r t : List α
⊢ merge.loop s l r t = t.reverseAux (merge.loop s l r [])
state_after: α : Type u_1
s : α → α → Bool
l r t : List α
n : Nat
hn : l.length + r.length = n
⊢ merge.loop s l r t = t.reverseAux (merge.loop s l r [])

tactic: rw [eq_nil_of_length_eq_zero (Nat.eq_zero_of_add_eq_zero_left hn)]
state_before: case zero
α : Type u_1
s : α → α → Bool
l r t : List α
hn : l.length + r.length = 0
⊢ merge.loop s l r t = t.reverseAux (merge.loop s l r [])
state_after: case zero
α : Type u_1
s : α → α → Bool
l r t : List α
hn : l.length + r.length = 0
⊢ merge.loop s l [] t = t.reverseAux (merge.loop s l [] [])

tactic: rw [eq_nil_of_length_eq_zero (Nat.eq_zero_of_add_eq_zero_right hn)]
state_before: case zero
α : Type u_1
s : α → α → Bool
l r t : List α
hn : l.length + r.length = 0
⊢ merge.loop s l [] t = t.reverseAux (merge.loop s l [] [])
state_after: case zero
α : Type u_1
s : α → α → Bool
l r t : List α
hn : l.length + r.length = 0
⊢ merge.loop s [] [] t = t.reverseAux (merge.loop s [] [] [])

tactic: simp only [merge.loop, reverseAux]
state_before: case zero
α : Type u_1
s : α → α → Bool
l r t : List α
hn : l.length + r.length = 0
⊢ merge.loop s [] [] t = t.reverseAux (merge.loop s [] [] [])
state_after: no goals

tactic: simp only [merge_loop_nil_left]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l r✝ t r : List α
hn : [].length + r.length = n + 1
⊢ merge.loop s [] r t = t.reverseAux (merge.loop s [] r [])
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l r✝ t r : List α
hn : [].length + r.length = n + 1
⊢ t.reverseAux r = t.reverseAux ([].reverseAux r)

tactic: rfl
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l r✝ t r : List α
hn : [].length + r.length = n + 1
⊢ t.reverseAux r = t.reverseAux ([].reverseAux r)
state_after: no goals

tactic: simp only [merge_loop_nil_right]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r t l : List α
hn : l.length + [].length = n + 1
⊢ merge.loop s l [] t = t.reverseAux (merge.loop s l [] [])
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r t l : List α
hn : l.length + [].length = n + 1
⊢ t.reverseAux l = t.reverseAux ([].reverseAux l)

tactic: rfl
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r t l : List α
hn : l.length + [].length = n + 1
⊢ t.reverseAux l = t.reverseAux ([].reverseAux l)
state_after: no goals

tactic: simp only [merge.loop, cond]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
⊢ merge.loop s (a :: l) (b :: r) t = t.reverseAux (merge.loop s (a :: l) (b :: r) [])
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
⊢ (match s a b with
    | true => merge.loop s l (b :: r) (a :: t)
    | false => merge.loop s (a :: l) r (b :: t)) =
    t.reverseAux
      (match s a b with
      | true => merge.loop s l (b :: r) [a]
      | false => merge.loop s (a :: l) r [b])

tactic: split
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
⊢ (match s a b with
    | true => merge.loop s l (b :: r) (a :: t)
    | false => merge.loop s (a :: l) r (b :: t)) =
    t.reverseAux
      (match s a b with
      | true => merge.loop s l (b :: r) [a]
      | false => merge.loop s (a :: l) r [b])
state_after: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ merge.loop s l (b :: r) (a :: t) = t.reverseAux (merge.loop s l (b :: r) [a])

case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ merge.loop s (a :: l) r (b :: t) = t.reverseAux (merge.loop s (a :: l) r [b])

tactic: have hn : l.length + (b :: r).length = n := by
  apply Nat.add_right_cancel (m:=1)
  rw [←hn]; simp only [length_cons, Nat.add_succ, Nat.succ_add]
state_before: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ merge.loop s l (b :: r) (a :: t) = t.reverseAux (merge.loop s l (b :: r) [a])
state_after: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
hn : l.length + (b :: r).length = n
⊢ merge.loop s l (b :: r) (a :: t) = t.reverseAux (merge.loop s l (b :: r) [a])

tactic: rw [ih _ _ (a::t) hn, ih _ _ [] hn, ih _ _ [a] hn]
state_before: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
hn : l.length + (b :: r).length = n
⊢ merge.loop s l (b :: r) (a :: t) = t.reverseAux (merge.loop s l (b :: r) [a])
state_after: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
hn : l.length + (b :: r).length = n
⊢ (a :: t).reverseAux ([].reverseAux (merge.loop s l (b :: r) [])) =
    t.reverseAux ([a].reverseAux (merge.loop s l (b :: r) []))

tactic: rfl
state_before: case h_1
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
hn : l.length + (b :: r).length = n
⊢ (a :: t).reverseAux ([].reverseAux (merge.loop s l (b :: r) [])) =
    t.reverseAux ([a].reverseAux (merge.loop s l (b :: r) []))
state_after: no goals

tactic: apply Nat.add_right_cancel (m:=1)
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ l.length + (b :: r).length = n
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ l.length + (b :: r).length + 1 = n + 1

tactic: rw [←hn]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ l.length + (b :: r).length + 1 = n + 1
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ l.length + (b :: r).length + 1 = (a :: l).length + (b :: r).length

tactic: simp only [length_cons, Nat.add_succ, Nat.succ_add]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = true
⊢ l.length + (b :: r).length + 1 = (a :: l).length + (b :: r).length
state_after: no goals

tactic: have hn : (a::l).length + r.length = n := by
  apply Nat.add_right_cancel (m:=1)
  rw [←hn]; simp only [length_cons, Nat.add_succ, Nat.succ_add]
state_before: case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ merge.loop s (a :: l) r (b :: t) = t.reverseAux (merge.loop s (a :: l) r [b])
state_after: case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
hn : (a :: l).length + r.length = n
⊢ merge.loop s (a :: l) r (b :: t) = t.reverseAux (merge.loop s (a :: l) r [b])

tactic: rw [ih _ _ (b::t) hn, ih _ _ [] hn, ih _ _ [b] hn]
state_before: case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
hn : (a :: l).length + r.length = n
⊢ merge.loop s (a :: l) r (b :: t) = t.reverseAux (merge.loop s (a :: l) r [b])
state_after: case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
hn : (a :: l).length + r.length = n
⊢ (b :: t).reverseAux ([].reverseAux (merge.loop s (a :: l) r [])) =
    t.reverseAux ([b].reverseAux (merge.loop s (a :: l) r []))

tactic: rfl
state_before: case h_2
α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn✝ : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
hn : (a :: l).length + r.length = n
⊢ (b :: t).reverseAux ([].reverseAux (merge.loop s (a :: l) r [])) =
    t.reverseAux ([b].reverseAux (merge.loop s (a :: l) r []))
state_after: no goals

tactic: apply Nat.add_right_cancel (m:=1)
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ (a :: l).length + r.length = n
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ (a :: l).length + r.length + 1 = n + 1

tactic: rw [←hn]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ (a :: l).length + r.length + 1 = n + 1
state_after: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ (a :: l).length + r.length + 1 = (a :: l).length + (b :: r).length

tactic: simp only [length_cons, Nat.add_succ, Nat.succ_add]
state_before: α : Type u_1
s : α → α → Bool
n : Nat
ih : ∀ (l r t : List α), l.length + r.length = n → merge.loop s l r t = t.reverseAux (merge.loop s l r [])
l✝ r✝ t : List α
a : α
l : List α
b : α
r : List α
hn : (a :: l).length + (b :: r).length = n + 1
c✝ : Bool
heq✝ : s a b = false
⊢ (a :: l).length + r.length + 1 = (a :: l).length + (b :: r).length
state_after: no goals