Theorem: List.permutations_perm_permutations'
File: Mathlib/Data/List/Perm.lean

tactic: obtain ⟨n, h⟩ : ∃ n, length ts < n := ⟨_, Nat.lt_succ_self _⟩
state_before: α : Type uu
β : Type vv
l₁ l₂ ts : List α
⊢ permutations ts ~ permutations' ts

tactic: induction' n with n IH generalizing ts
state_before: case intro
α : Type uu
β : Type vv
l₁ l₂ ts : List α
n : ℕ
h : length ts < n
⊢ permutations ts ~ permutations' ts

tactic: refine' List.reverseRecOn ts (fun _ => _) (fun ts t _ h => _) h
state_before: case intro.succ
α : Type uu
β : Type vv
l₁ l₂ ts✝ : List α
n✝ : ℕ
h✝ : length ts✝ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts : List α
h : length ts < succ n
⊢ permutations ts ~ permutations' ts

tactic: rw [← concat_eq_append, length_concat, Nat.succ_lt_succ_iff] at h
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length (ts ++ [t]) < succ n
⊢ permutations (ts ++ [t]) ~ permutations' (ts ++ [t])

tactic: have IH₂ := (IH ts.reverse (by rwa [length_reverse])).trans (reverse_perm _).permutations'
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
⊢ permutations (ts ++ [t]) ~ permutations' (ts ++ [t])

tactic: simp only [permutations_append, foldr_permutationsAux2, permutationsAux_nil,
  permutationsAux_cons, append_nil]
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ permutations (ts ++ [t]) ~ permutations' (ts ++ [t])

tactic: refine'
  (perm_append_comm.trans ((IH₂.bind_right _).append ((IH _ h).map _))).trans
    (Perm.trans _ perm_append_comm.permutations')
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ (map (fun x => x ++ [t]) (permutations ts) ++
      List.bind (permutations (reverse ts)) fun y => (permutationsAux2 t [] [] y id).snd) ~
    permutations' (ts ++ [t])

tactic: rw [map_eq_bind, singleton_append, permutations']
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ (List.bind (permutations' ts) fun y => (permutationsAux2 t [] [] y id).snd) ++
      map (fun x => x ++ [t]) (permutations' ts) ~
    permutations' ([t] ++ ts)

tactic: refine' (bind_append_perm _ _ _).trans _
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ ((List.bind (permutations' ts) fun y => (permutationsAux2 t [] [] y id).snd) ++
      List.bind (permutations' ts) fun x => [x ++ [t]]) ~
    List.bind (permutations' ts) (permutations'Aux t)

tactic: refine' Perm.of_eq _
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ (List.bind (permutations' ts) fun x => (permutationsAux2 t [] [] x id).snd ++ [x ++ [t]]) ~
    List.bind (permutations' ts) (permutations'Aux t)

tactic: congr
state_before: case intro.succ.refine'_2
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ (List.bind (permutations' ts) fun x => (permutationsAux2 t [] [] x id).snd ++ [x ++ [t]]) =
    List.bind (permutations' ts) (permutations'Aux t)

tactic: funext _
state_before: case intro.succ.refine'_2.e_b
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
⊢ (fun x => (permutationsAux2 t [] [] x id).snd ++ [x ++ [t]]) = permutations'Aux t

tactic: rw [permutations'Aux_eq_permutationsAux2, permutationsAux2_append]
state_before: case intro.succ.refine'_2.e_b.h
α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝¹ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
IH₂ : permutations (reverse ts) ~ permutations' ts
x✝ : List α
⊢ (permutationsAux2 t [] [] x✝ id).snd ++ [x✝ ++ [t]] = permutations'Aux t x✝

tactic: cases h
state_before: case intro.zero
α : Type uu
β : Type vv
l₁ l₂ ts✝ : List α
n : ℕ
h✝ : length ts✝ < n
ts : List α
h : length ts < zero
⊢ permutations ts ~ permutations' ts

tactic: simp [permutations]
state_before: case intro.succ.refine'_1
α : Type uu
β : Type vv
l₁ l₂ ts✝ : List α
n✝ : ℕ
h✝ : length ts✝ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts : List α
h : length ts < succ n
x✝ : length [] < succ n
⊢ permutations [] ~ permutations' []

tactic: rwa [length_reverse]
state_before: α : Type uu
β : Type vv
l₁ l₂ ts✝¹ : List α
n✝ : ℕ
h✝¹ : length ts✝¹ < n✝
n : ℕ
IH : ∀ (ts : List α), length ts < n → permutations ts ~ permutations' ts
ts✝ : List α
h✝ : length ts✝ < succ n
ts : List α
t : α
x✝ : length ts < succ n → permutations ts ~ permutations' ts
h : length ts < n
⊢ length (reverse ts) < n