Theorem: List.reverse_take
File: Mathlib/Data/List/Basic.lean

tactic: induction' xs with xs_hd xs_tl xs_ih generalizing n <;>
  simp only [reverse_cons, drop, reverse_nil, zero_tsub, length, take_nil]
state_before: ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h : n ≤ length xs
⊢ take n (reverse xs) = reverse (drop (length xs - n) xs)

tactic: cases' h.lt_or_eq_dec with h' h'
state_before: case cons
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
⊢ take n (reverse xs_tl ++ [xs_hd]) = reverse (drop (length xs_tl + 1 - n) (xs_hd :: xs_tl))

tactic: replace h' := le_of_succ_le_succ h'
state_before: case cons.inl
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n < length (xs_hd :: xs_tl)
⊢ take n (reverse xs_tl ++ [xs_hd]) = reverse (drop (length xs_tl + 1 - n) (xs_hd :: xs_tl))

tactic: rw [take_append_of_le_length, xs_ih _ h']
state_before: case cons.inl
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n ≤ length xs_tl
⊢ take n (reverse xs_tl ++ [xs_hd]) = reverse (drop (length xs_tl + 1 - n) (xs_hd :: xs_tl))

tactic: rw [show xs_tl.length + 1 - n = succ (xs_tl.length - n) from _, drop]
state_before: case cons.inl
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n ≤ length xs_tl
⊢ reverse (drop (length xs_tl - n) xs_tl) = reverse (drop (length xs_tl + 1 - n) (xs_hd :: xs_tl))

case cons.inl
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n ≤ length xs_tl
⊢ n ≤ length (reverse xs_tl)

tactic: rwa [succ_eq_add_one, ← @tsub_add_eq_add_tsub]
state_before: ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n ≤ length xs_tl
⊢ length xs_tl + 1 - n = succ (length xs_tl - n)

tactic: rwa [length_reverse]
state_before: case cons.inl
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n ≤ length xs_tl
⊢ n ≤ length (reverse xs_tl)

tactic: subst h'
state_before: case cons.inr
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n✝ : ℕ
h✝ : n✝ ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
n : ℕ
h : n ≤ length (xs_hd :: xs_tl)
h' : n = length (xs_hd :: xs_tl)
⊢ take n (reverse xs_tl ++ [xs_hd]) = reverse (drop (length xs_tl + 1 - n) (xs_hd :: xs_tl))

tactic: rw [length, tsub_self, drop]
state_before: case cons.inr
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h✝ : n ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
h : length (xs_hd :: xs_tl) ≤ length (xs_hd :: xs_tl)
⊢ take (length (xs_hd :: xs_tl)) (reverse xs_tl ++ [xs_hd]) =
    reverse (drop (length xs_tl + 1 - length (xs_hd :: xs_tl)) (xs_hd :: xs_tl))

tactic: suffices xs_tl.length + 1 = (xs_tl.reverse ++ [xs_hd]).length by
  rw [this, take_length, reverse_cons]
state_before: case cons.inr
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h✝ : n ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
h : length (xs_hd :: xs_tl) ≤ length (xs_hd :: xs_tl)
⊢ take (length xs_tl + 1) (reverse xs_tl ++ [xs_hd]) = reverse (xs_hd :: xs_tl)

tactic: rw [length_append, length_reverse]
state_before: case cons.inr
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h✝ : n ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
h : length (xs_hd :: xs_tl) ≤ length (xs_hd :: xs_tl)
⊢ length xs_tl + 1 = length (reverse xs_tl ++ [xs_hd])

tactic: rfl
state_before: case cons.inr
ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h✝ : n ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
h : length (xs_hd :: xs_tl) ≤ length (xs_hd :: xs_tl)
⊢ length xs_tl + 1 = length xs_tl + length [xs_hd]

tactic: rw [this, take_length, reverse_cons]
state_before: ι : Type ?u.221288
α✝ : Type u
β : Type v
γ : Type w
δ : Type x
l₁ l₂ : List α✝
α : Type u_1
xs : List α
n : ℕ
h✝ : n ≤ length xs
xs_hd : α
xs_tl : List α
xs_ih : ∀ (n : ℕ), n ≤ length xs_tl → take n (reverse xs_tl) = reverse (drop (length xs_tl - n) xs_tl)
h : length (xs_hd :: xs_tl) ≤ length (xs_hd :: xs_tl)
this : length xs_tl + 1 = length (reverse xs_tl ++ [xs_hd])
⊢ take (length xs_tl + 1) (reverse xs_tl ++ [xs_hd]) = reverse (xs_hd :: xs_tl)