Theorem: List.Perm.drop_inter
File: Mathlib/Data/List/Perm.lean

tactic: by_cases h'' : n ≤ xs.length
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: let n' := xs.length - n
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: have h₀ : n = xs.length - n' := by
  rwa [tsub_tsub_cancel_of_le]
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: have h₁ : n' ≤ xs.length := by apply tsub_le_self
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: have h₂ : xs.drop n = (xs.reverse.take n').reverse := by
  rw [reverse_take _ h₁, h₀, reverse_reverse]
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: rw [h₂]
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: apply (reverse_perm _).trans
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ reverse (take n' (reverse xs)) ~ List.inter ys (reverse (take n' (reverse xs)))

tactic: rw [inter_reverse]
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ take n' (reverse xs) ~ List.inter ys (reverse (take n' (reverse xs)))

tactic: apply Perm.take_inter _ _ h'
state_before: case pos
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ take n' (reverse xs) ~ List.inter ys (take n' (reverse xs))

tactic: apply (reverse_perm _).trans
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ reverse xs ~ ys

tactic: assumption
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
h₂ : drop n xs = reverse (take n' (reverse xs))
⊢ xs ~ ys

tactic: rwa [tsub_tsub_cancel_of_le]
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
⊢ n = length xs - n'

tactic: apply tsub_le_self
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
⊢ n' ≤ length xs

tactic: rw [reverse_take _ h₁, h₀, reverse_reverse]
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : n ≤ length xs
n' : ℕ := length xs - n
h₀ : n = length xs - n'
h₁ : n' ≤ length xs
⊢ drop n xs = reverse (take n' (reverse xs))

tactic: have : drop n xs = [] := by
  apply eq_nil_of_length_eq_zero
  rw [length_drop, tsub_eq_zero_iff_le]
  apply le_of_not_ge h''
state_before: case neg
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : ¬n ≤ length xs
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: simp [this, List.inter]
state_before: case neg
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : ¬n ≤ length xs
this : drop n xs = []
⊢ drop n xs ~ List.inter ys (drop n xs)

tactic: apply eq_nil_of_length_eq_zero
state_before: α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : ¬n ≤ length xs
⊢ drop n xs = []

tactic: rw [length_drop, tsub_eq_zero_iff_le]
state_before: case x
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : ¬n ≤ length xs
⊢ length (drop n xs) = 0

tactic: apply le_of_not_ge h''
state_before: case x
α✝ : Type uu
β : Type vv
l₁ l₂ : List α✝
α : Type u_1
inst✝ : DecidableEq α
xs ys : List α
n : ℕ
h : xs ~ ys
h' : Nodup ys
h'' : ¬n ≤ length xs
⊢ length xs ≤ n