l3lab/ntp-mathlib huggingface dataset:
set_option linter.deprecated false in
theorem nthLe_permutations'Aux (s : List α) (x : α) (n : ℕ)
    (hn : n < length (permutations'Aux x s)) :
    (permutations'Aux x s).nthLe n hn = s.insertNth n x := by
  induction' s with y s IH generalizing n
  · simp only [length, zero_add, lt_one_iff] at hn
    simp [hn]
  · cases n
    · simp [nthLe]
    · 

Proof state:
case cons.succ
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : ∀ (n : ℕ) (hn : n < length (permutations'Aux x s)), nthLe (permutations'Aux x s) n hn = insertNth n x s
n✝ : ℕ
hn : succ n✝ < length (permutations'Aux x (y :: s))
⊢ nthLe (permutations'Aux x (y :: s)) (succ n✝) hn = insertNth (succ n✝) x (y :: s)

Next tactic:
simpa [nthLe] using IH _ _
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  

Proof state:
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
l : List α
x : α
⊢ count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1

Next tactic:
induction' l with y l IH generalizing x
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · 

Proof state:
case nil
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
x : α
⊢ count [x] (permutations'Aux x []) = length (takeWhile (fun x_1 => decide (x = x_1)) []) + 1

Next tactic:
simp [takeWhile, count]
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · 

Proof state:
case cons
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
y : α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
⊢ count (x :: y :: l) (permutations'Aux x (y :: l)) = length (takeWhile (fun x_1 => decide (x = x_1)) (y :: l)) + 1

Next tactic:
rw [permutations'Aux, DecEq_eq, count_cons_self]
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · rw [permutations'Aux, DecEq_eq, count_cons_self]
    

Proof state:
case cons
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
y : α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
⊢ count (x :: y :: l) (map (cons y) (permutations'Aux x l)) + 1 =
    length (takeWhile (fun x_1 => decide (x = x_1)) (y :: l)) + 1

Next tactic:
by_cases hx : x = y
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · rw [permutations'Aux, DecEq_eq, count_cons_self]
    by_cases hx : x = y
    · 

Proof state:
case pos
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
y : α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
hx : x = y
⊢ count (x :: y :: l) (map (cons y) (permutations'Aux x l)) + 1 =
    length (takeWhile (fun x_1 => decide (x = x_1)) (y :: l)) + 1

Next tactic:
subst hx
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · rw [permutations'Aux, DecEq_eq, count_cons_self]
    by_cases hx : x = y
    · subst hx
      

Proof state:
case pos
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
⊢ count (x :: x :: l) (map (cons x) (permutations'Aux x l)) + 1 =
    length (takeWhile (fun x_1 => decide (x = x_1)) (x :: l)) + 1

Next tactic:
simpa [takeWhile, Nat.succ_inj', DecEq_eq] using IH _
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · rw [permutations'Aux, DecEq_eq, count_cons_self]
    by_cases hx : x = y
    · subst hx
      simpa [takeWhile, Nat.succ_inj', DecEq_eq] using IH _
    · 

Proof state:
case neg
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
y : α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
hx : ¬x = y
⊢ count (x :: y :: l) (map (cons y) (permutations'Aux x l)) + 1 =
    length (takeWhile (fun x_1 => decide (x = x_1)) (y :: l)) + 1

Next tactic:
rw [takeWhile]
theorem count_permutations'Aux_self [DecidableEq α] (l : List α) (x : α) :
    count (x :: l) (permutations'Aux x l) = length (takeWhile (x = ·) l) + 1 := by
  induction' l with y l IH generalizing x
  · simp [takeWhile, count]
  · rw [permutations'Aux, DecEq_eq, count_cons_self]
    by_cases hx : x = y
    · subst hx
      simpa [takeWhile, Nat.succ_inj', DecEq_eq] using IH _
    · rw [takeWhile]
      

Proof state:
case neg
α : Type u_1
β : Type u_2
l✝ l₁ l₂ : List α
a : α
inst✝ : DecidableEq α
y : α
l : List α
IH : ∀ (x : α), count (x :: l) (permutations'Aux x l) = length (takeWhile (fun x_1 => decide (x = x_1)) l) + 1
x : α
hx : ¬x = y
⊢ count (x :: y :: l) (map (cons y) (permutations'Aux x l)) + 1 =
    length
        (match decide (x = y) with
        | true => y :: takeWhile (fun x_1 => decide (x = x_1)) l
        | false => []) +
      1

Next tactic:
simp only [mem_map, cons.injEq, Ne.symm hx, false_and, and_false, exists_false,
        not_false_iff, count_eq_zero_of_not_mem, zero_add, hx, decide_False, length_nil]
@[simp]
theorem length_permutations'Aux (s : List α) (x : α) :
    length (permutations'Aux x s) = length s + 1 := by
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
⊢ length (permutations'Aux x s) = length s + 1

Next tactic:
induction' s with y s IH
@[simp]
theorem length_permutations'Aux (s : List α) (x : α) :
    length (permutations'Aux x s) = length s + 1 := by
  induction' s with y s IH
  · 

Proof state:
case nil
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
⊢ length (permutations'Aux x []) = length [] + 1

Next tactic:
simp
@[simp]
theorem length_permutations'Aux (s : List α) (x : α) :
    length (permutations'Aux x s) = length s + 1 := by
  induction' s with y s IH
  · simp
  · 

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : length (permutations'Aux x s) = length s + 1
⊢ length (permutations'Aux x (y :: s)) = length (y :: s) + 1

Next tactic:
simpa using IH
@[simp]
theorem permutations'Aux_nthLe_zero (s : List α) (x : α)
    (hn : 0 < length (permutations'Aux x s) := (by 

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
⊢ 0 < length (permutations'Aux x s)

Next tactic:
simp
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
⊢ Function.Injective (permutations'Aux x)

Next tactic:
intro s t h
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
⊢ s = t

Next tactic:
apply insertNth_injective s.length x
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  

Proof state:
case a
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
⊢ insertNth (length s) x s = insertNth (length s) x t

Next tactic:
have hl : s.length = t.length := by simpa using congr_arg length h
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  have hl : s.length = t.length := by 

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
⊢ length s = length t

Next tactic:
simpa using congr_arg length h
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  have hl : s.length = t.length := by simpa using congr_arg length h
  

Proof state:
case a
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
hl : length s = length t
⊢ insertNth (length s) x s = insertNth (length s) x t

Next tactic:
rw [← nthLe_permutations'Aux s x s.length (by simp), ←
    nthLe_permutations'Aux t x s.length (by simp [hl])]
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  have hl : s.length = t.length := by simpa using congr_arg length h
  rw [← nthLe_permutations'Aux s x s.length (by 

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
hl : length s = length t
⊢ length s < length (permutations'Aux x s)

Next tactic:
simp
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  have hl : s.length = t.length := by simpa using congr_arg length h
  rw [← nthLe_permutations'Aux s x s.length (by simp), ←
    nthLe_permutations'Aux t x s.length (by 

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
hl : length s = length t
⊢ length s < length (permutations'Aux x t)

Next tactic:
simp [hl]
theorem injective_permutations'Aux (x : α) : Function.Injective (permutations'Aux x) := by
  intro s t h
  apply insertNth_injective s.length x
  have hl : s.length = t.length := by simpa using congr_arg length h
  rw [← nthLe_permutations'Aux s x s.length (by simp), ←
    nthLe_permutations'Aux t x s.length (by simp [hl])]
  

Proof state:
case a
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
s t : List α
h : permutations'Aux x s = permutations'Aux x t
hl : length s = length t
⊢ nthLe (permutations'Aux x s) (length s) (_ : length s < length (permutations'Aux x s)) =
    nthLe (permutations'Aux x t) (length s) (_ : length s < length (permutations'Aux x t))

Next tactic:
simp [h, hl]
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
hx : x ∉ s
⊢ Nodup (permutations'Aux x s)

Next tactic:
induction' s with y s IH
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · 

Proof state:
case nil
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x : α
hx : x ∉ []
⊢ Nodup (permutations'Aux x [])

Next tactic:
simp
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · 

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : x ∉ y :: s
⊢ Nodup (permutations'Aux x (y :: s))

Next tactic:
simp only [not_or, mem_cons] at hx
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · simp only [not_or, mem_cons] at hx
    

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : ¬x = y ∧ x ∉ s
⊢ Nodup (permutations'Aux x (y :: s))

Next tactic:
simp only [permutations'Aux, nodup_cons, mem_map, cons.injEq, exists_eq_right_right, not_and]
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · simp only [not_or, mem_cons] at hx
    simp only [permutations'Aux, nodup_cons, mem_map, cons.injEq, exists_eq_right_right, not_and]
    

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : ¬x = y ∧ x ∉ s
⊢ (y :: s ∈ permutations'Aux x s → ¬y = x) ∧ Nodup (map (cons y) (permutations'Aux x s))

Next tactic:
refine' ⟨fun _ => Ne.symm hx.left, _⟩
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · simp only [not_or, mem_cons] at hx
    simp only [permutations'Aux, nodup_cons, mem_map, cons.injEq, exists_eq_right_right, not_and]
    refine' ⟨fun _ => Ne.symm hx.left, _⟩
    

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : ¬x = y ∧ x ∉ s
⊢ Nodup (map (cons y) (permutations'Aux x s))

Next tactic:
rw [nodup_map_iff]
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · simp only [not_or, mem_cons] at hx
    simp only [permutations'Aux, nodup_cons, mem_map, cons.injEq, exists_eq_right_right, not_and]
    refine' ⟨fun _ => Ne.symm hx.left, _⟩
    rw [nodup_map_iff]
    · 

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : ¬x = y ∧ x ∉ s
⊢ Nodup (permutations'Aux x s)

Next tactic:
exact IH hx.right
theorem nodup_permutations'Aux_of_not_mem (s : List α) (x : α) (hx : x ∉ s) :
    Nodup (permutations'Aux x s) := by
  induction' s with y s IH
  · simp
  · simp only [not_or, mem_cons] at hx
    simp only [permutations'Aux, nodup_cons, mem_map, cons.injEq, exists_eq_right_right, not_and]
    refine' ⟨fun _ => Ne.symm hx.left, _⟩
    rw [nodup_map_iff]
    · exact IH hx.right
    · 

Proof state:
case cons
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a x y : α
s : List α
IH : x ∉ s → Nodup (permutations'Aux x s)
hx : ¬x = y ∧ x ∉ s
⊢ Function.Injective (cons y)

Next tactic:
simp
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
⊢ Nodup (permutations'Aux x s) ↔ x ∉ s

Next tactic:
refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h : Nodup (permutations'Aux x s)
⊢ x ∉ s

Next tactic:
intro H
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h : Nodup (permutations'Aux x s)
H : x ∈ s
⊢ False

Next tactic:
obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h : Nodup (permutations'Aux x s)
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ False

Next tactic:
rw [nodup_iff_nthLe_inj] at h
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ False

Next tactic:
suffices k = k + 1 by simp at this
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by 

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
this : k = k + 1
⊢ False

Next tactic:
simp at this
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  

Proof state:
case intro.intro
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ k = k + 1

Next tactic:
refine' h k (k + 1) _ _ _
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · 

Proof state:
case intro.intro.refine'_1
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ k < length (permutations'Aux x s)

Next tactic:
simpa [Nat.lt_succ_iff] using hk.le
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · simpa [Nat.lt_succ_iff] using hk.le
  · 

Proof state:
case intro.intro.refine'_2
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ k + 1 < length (permutations'Aux x s)

Next tactic:
simpa using hk
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · simpa [Nat.lt_succ_iff] using hk.le
  · simpa using hk
  

Proof state:
case intro.intro.refine'_3
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ nthLe (permutations'Aux x s) k (_ : k < length (permutations'Aux x s)) =
    nthLe (permutations'Aux x s) (k + 1) (_ : k + 1 < length (permutations'Aux x s))

Next tactic:
rw [nthLe_permutations'Aux, nthLe_permutations'Aux]
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · simpa [Nat.lt_succ_iff] using hk.le
  · simpa using hk
  rw [nthLe_permutations'Aux, nthLe_permutations'Aux]
  

Proof state:
case intro.intro.refine'_3
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ insertNth k x s = insertNth (k + 1) x s

Next tactic:
have hl : length (insertNth k x s) = length (insertNth (k + 1) x s) := by
    rw [length_insertNth _ _ hk.le, length_insertNth _ _ (Nat.succ_le_of_lt hk)]
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · simpa [Nat.lt_succ_iff] using hk.le
  · simpa using hk
  rw [nthLe_permutations'Aux, nthLe_permutations'Aux]
  have hl : length (insertNth k x s) = length (insertNth (k + 1) x s) := by
    

Proof state:
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
⊢ length (insertNth k x s) = length (insertNth (k + 1) x s)

Next tactic:
rw [length_insertNth _ _ hk.le, length_insertNth _ _ (Nat.succ_le_of_lt hk)]
set_option linter.deprecated false in
theorem nodup_permutations'Aux_iff {s : List α} {x : α} : Nodup (permutations'Aux x s) ↔ x ∉ s := by
  refine' ⟨fun h => _, nodup_permutations'Aux_of_not_mem _ _⟩
  intro H
  obtain ⟨k, hk, hk'⟩ := nthLe_of_mem H
  rw [nodup_iff_nthLe_inj] at h
  suffices k = k + 1 by simp at this
  refine' h k (k + 1) _ _ _
  · simpa [Nat.lt_succ_iff] using hk.le
  · simpa using hk
  rw [nthLe_permutations'Aux, nthLe_permutations'Aux]
  have hl : length (insertNth k x s) = length (insertNth (k + 1) x s) := by
    rw [length_insertNth _ _ hk.le, length_insertNth _ _ (Nat.succ_le_of_lt hk)]
  

Proof state:
case intro.intro.refine'_3
α : Type u_1
β : Type u_2
l l₁ l₂ : List α
a : α
s : List α
x : α
h :
  ∀ (i j : ℕ) (h₁ : i < length (permutations'Aux x s)) (h₂ : j < length (permutations'Aux x s)),
    nthLe (permutations'Aux x s) i h₁ = nthLe (permutations'Aux x s) j h₂ → i = j
H : x ∈ s
k : ℕ
hk : k < length s
hk' : nthLe s k hk = x
hl : length (insertNth k x s) = length (insertNth (k + 1) x s)
⊢ insertNth k x s = insertNth (k + 1) x s

Next tactic:
refine' ext_nthLe hl fun n hn hn' => _