l3lab/ntp-mathlib huggingface dataset:
theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) :
    nextOr (y :: xs) x d = nextOr xs x d := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
y x d : α
h : x ≠ y
⊢ nextOr (y :: xs) x d = nextOr xs x d

Next tactic:
cases' xs with z zs
theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) :
    nextOr (y :: xs) x d = nextOr xs x d := by
  cases' xs with z zs
  · 

Proof state:
case nil
α : Type u_1
inst✝ : DecidableEq α
y x d : α
h : x ≠ y
⊢ nextOr [y] x d = nextOr [] x d

Next tactic:
rfl
theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) :
    nextOr (y :: xs) x d = nextOr xs x d := by
  cases' xs with z zs
  · rfl
  · 

Proof state:
case cons
α : Type u_1
inst✝ : DecidableEq α
y x d : α
h : x ≠ y
z : α
zs : List α
⊢ nextOr (y :: z :: zs) x d = nextOr (z :: zs) x d

Next tactic:
exact if_neg h
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d d' : α
x_mem : x ∈ xs
x_ne : x ≠ getLast xs (_ : xs ≠ [])
⊢ nextOr xs x d = nextOr xs x d'

Next tactic:
induction' xs with y ys IH
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · 

Proof state:
case nil
α : Type u_1
inst✝ : DecidableEq α
x d d' : α
x_mem : x ∈ []
x_ne : x ≠ getLast [] (_ : [] ≠ [])
⊢ nextOr [] x d = nextOr [] x d'

Next tactic:
cases x_mem
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  

Proof state:
case cons
α : Type u_1
inst✝ : DecidableEq α
x d d' y : α
ys : List α
IH : ∀ (x_mem : x ∈ ys), x ≠ getLast ys (_ : ys ≠ []) → nextOr ys x d = nextOr ys x d'
x_mem : x ∈ y :: ys
x_ne : x ≠ getLast (y :: ys) (_ : y :: ys ≠ [])
⊢ nextOr (y :: ys) x d = nextOr (y :: ys) x d'

Next tactic:
cases' ys with z zs
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · 

Proof state:
case cons.nil
α : Type u_1
inst✝ : DecidableEq α
x d d' y : α
IH : ∀ (x_mem : x ∈ []), x ≠ getLast [] (_ : [] ≠ []) → nextOr [] x d = nextOr [] x d'
x_mem : x ∈ [y]
x_ne : x ≠ getLast [y] (_ : [y] ≠ [])
⊢ nextOr [y] x d = nextOr [y] x d'

Next tactic:
simp at x_mem x_ne
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    

Proof state:
case cons.nil
α : Type u_1
inst✝ : DecidableEq α
x d d' y : α
IH : ∀ (x_mem : x ∈ []), x ≠ getLast [] (_ : [] ≠ []) → nextOr [] x d = nextOr [] x d'
x_ne : ¬x = y
x_mem : x = y
⊢ nextOr [y] x d = nextOr [y] x d'

Next tactic:
contradiction
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    contradiction
  

Proof state:
case cons.cons
α : Type u_1
inst✝ : DecidableEq α
x d d' y z : α
zs : List α
IH : ∀ (x_mem : x ∈ z :: zs), x ≠ getLast (z :: zs) (_ : z :: zs ≠ []) → nextOr (z :: zs) x d = nextOr (z :: zs) x d'
x_mem : x ∈ y :: z :: zs
x_ne : x ≠ getLast (y :: z :: zs) (_ : y :: z :: zs ≠ [])
⊢ nextOr (y :: z :: zs) x d = nextOr (y :: z :: zs) x d'

Next tactic:
by_cases h : x = y
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    contradiction
  by_cases h : x = y
  · 

Proof state:
case pos
α : Type u_1
inst✝ : DecidableEq α
x d d' y z : α
zs : List α
IH : ∀ (x_mem : x ∈ z :: zs), x ≠ getLast (z :: zs) (_ : z :: zs ≠ []) → nextOr (z :: zs) x d = nextOr (z :: zs) x d'
x_mem : x ∈ y :: z :: zs
x_ne : x ≠ getLast (y :: z :: zs) (_ : y :: z :: zs ≠ [])
h : x = y
⊢ nextOr (y :: z :: zs) x d = nextOr (y :: z :: zs) x d'

Next tactic:
rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons]
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    contradiction
  by_cases h : x = y
  · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons]
  · 

Proof state:
case neg
α : Type u_1
inst✝ : DecidableEq α
x d d' y z : α
zs : List α
IH : ∀ (x_mem : x ∈ z :: zs), x ≠ getLast (z :: zs) (_ : z :: zs ≠ []) → nextOr (z :: zs) x d = nextOr (z :: zs) x d'
x_mem : x ∈ y :: z :: zs
x_ne : x ≠ getLast (y :: z :: zs) (_ : y :: z :: zs ≠ [])
h : ¬x = y
⊢ nextOr (y :: z :: zs) x d = nextOr (y :: z :: zs) x d'

Next tactic:
rw [nextOr, nextOr, IH]
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    contradiction
  by_cases h : x = y
  · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons]
  · rw [nextOr, nextOr, IH]
    · 

Proof state:
case neg.x_mem
α : Type u_1
inst✝ : DecidableEq α
x d d' y z : α
zs : List α
IH : ∀ (x_mem : x ∈ z :: zs), x ≠ getLast (z :: zs) (_ : z :: zs ≠ []) → nextOr (z :: zs) x d = nextOr (z :: zs) x d'
x_mem : x ∈ y :: z :: zs
x_ne : x ≠ getLast (y :: z :: zs) (_ : y :: z :: zs ≠ [])
h : ¬x = y
⊢ x ∈ z :: zs

Next tactic:
simpa [h] using x_mem
/-- `nextOr` does not depend on the default value, if the next value appears. -/
theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs)
    (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by
  induction' xs with y ys IH
  · cases x_mem
  cases' ys with z zs
  · simp at x_mem x_ne
    contradiction
  by_cases h : x = y
  · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons]
  · rw [nextOr, nextOr, IH]
    · simpa [h] using x_mem
    · 

Proof state:
case neg.x_ne
α : Type u_1
inst✝ : DecidableEq α
x d d' y z : α
zs : List α
IH : ∀ (x_mem : x ∈ z :: zs), x ≠ getLast (z :: zs) (_ : z :: zs ≠ []) → nextOr (z :: zs) x d = nextOr (z :: zs) x d'
x_mem : x ∈ y :: z :: zs
x_ne : x ≠ getLast (y :: z :: zs) (_ : y :: z :: zs ≠ [])
h : ¬x = y
⊢ x ≠ getLast (z :: zs) (_ : z :: zs ≠ [])

Next tactic:
simpa using x_ne
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
h : nextOr xs x d ≠ d
⊢ x ∈ xs

Next tactic:
induction' xs with y ys IH
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · 

Proof state:
case nil
α : Type u_1
inst✝ : DecidableEq α
x d : α
h : nextOr [] x d ≠ d
⊢ x ∈ []

Next tactic:
simp at h
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  

Proof state:
case cons
α : Type u_1
inst✝ : DecidableEq α
x d y : α
ys : List α
IH : nextOr ys x d ≠ d → x ∈ ys
h : nextOr (y :: ys) x d ≠ d
⊢ x ∈ y :: ys

Next tactic:
cases' ys with z zs
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  cases' ys with z zs
  · 

Proof state:
case cons.nil
α : Type u_1
inst✝ : DecidableEq α
x d y : α
IH : nextOr [] x d ≠ d → x ∈ []
h : nextOr [y] x d ≠ d
⊢ x ∈ [y]

Next tactic:
simp at h
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  cases' ys with z zs
  · simp at h
  · 

Proof state:
case cons.cons
α : Type u_1
inst✝ : DecidableEq α
x d y z : α
zs : List α
IH : nextOr (z :: zs) x d ≠ d → x ∈ z :: zs
h : nextOr (y :: z :: zs) x d ≠ d
⊢ x ∈ y :: z :: zs

Next tactic:
by_cases hx : x = y
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  cases' ys with z zs
  · simp at h
  · by_cases hx : x = y
    · 

Proof state:
case pos
α : Type u_1
inst✝ : DecidableEq α
x d y z : α
zs : List α
IH : nextOr (z :: zs) x d ≠ d → x ∈ z :: zs
h : nextOr (y :: z :: zs) x d ≠ d
hx : x = y
⊢ x ∈ y :: z :: zs

Next tactic:
simp [hx]
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  cases' ys with z zs
  · simp at h
  · by_cases hx : x = y
    · simp [hx]
    · 

Proof state:
case neg
α : Type u_1
inst✝ : DecidableEq α
x d y z : α
zs : List α
IH : nextOr (z :: zs) x d ≠ d → x ∈ z :: zs
h : nextOr (y :: z :: zs) x d ≠ d
hx : ¬x = y
⊢ x ∈ y :: z :: zs

Next tactic:
rw [nextOr_cons_of_ne _ _ _ _ hx] at h
theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by
  induction' xs with y ys IH
  · simp at h
  cases' ys with z zs
  · simp at h
  · by_cases hx : x = y
    · simp [hx]
    · rw [nextOr_cons_of_ne _ _ _ _ hx] at h
      

Proof state:
case neg
α : Type u_1
inst✝ : DecidableEq α
x d y z : α
zs : List α
IH : nextOr (z :: zs) x d ≠ d → x ∈ z :: zs
h : nextOr (z :: zs) x d ≠ d
hx : ¬x = y
⊢ x ∈ y :: z :: zs

Next tactic:
simpa [hx] using IH h
theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
h : x ∉ xs
⊢ nextOr (xs ++ [x]) x d = d

Next tactic:
induction' xs with z zs IH
theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by
  induction' xs with z zs IH
  · 

Proof state:
case nil
α : Type u_1
inst✝ : DecidableEq α
x d : α
h : x ∉ []
⊢ nextOr ([] ++ [x]) x d = d

Next tactic:
simp
theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by
  induction' xs with z zs IH
  · simp
  · 

Proof state:
case cons
α : Type u_1
inst✝ : DecidableEq α
x d z : α
zs : List α
IH : x ∉ zs → nextOr (zs ++ [x]) x d = d
h : x ∉ z :: zs
⊢ nextOr (z :: zs ++ [x]) x d = d

Next tactic:
obtain ⟨hz, hzs⟩ := not_or.mp (mt mem_cons.2 h)
theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by
  induction' xs with z zs IH
  · simp
  · obtain ⟨hz, hzs⟩ := not_or.mp (mt mem_cons.2 h)
    

Proof state:
case cons.intro
α : Type u_1
inst✝ : DecidableEq α
x d z : α
zs : List α
IH : x ∉ zs → nextOr (zs ++ [x]) x d = d
h : x ∉ z :: zs
hz : ¬x = z
hzs : x ∉ zs
⊢ nextOr (z :: zs ++ [x]) x d = d

Next tactic:
rw [cons_append, nextOr_cons_of_ne _ _ _ _ hz, IH hzs]
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
hd : d ∈ xs
⊢ nextOr xs x d ∈ xs

Next tactic:
revert hd
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
⊢ d ∈ xs → nextOr xs x d ∈ xs

Next tactic:
suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
this : ∀ (xs' : List α), (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs'
⊢ d ∈ xs → nextOr xs x d ∈ xs

Next tactic:
exact this xs fun _ => id
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
⊢ ∀ (xs' : List α), (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs'

Next tactic:
intro xs' hxs' hd
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
xs : List α
x d : α
xs' : List α
hxs' : ∀ x ∈ xs, x ∈ xs'
hd : d ∈ xs'
⊢ nextOr xs x d ∈ xs'

Next tactic:
induction' xs with y ys ih
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · 

Proof state:
case nil
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
hxs' : ∀ x ∈ [], x ∈ xs'
⊢ nextOr [] x d ∈ xs'

Next tactic:
exact hd
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  

Proof state:
case cons
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y : α
ys : List α
ih : (∀ x ∈ ys, x ∈ xs') → nextOr ys x d ∈ xs'
hxs' : ∀ x ∈ y :: ys, x ∈ xs'
⊢ nextOr (y :: ys) x d ∈ xs'

Next tactic:
cases' ys with z zs
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  cases' ys with z zs
  · 

Proof state:
case cons.nil
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y : α
ih : (∀ x ∈ [], x ∈ xs') → nextOr [] x d ∈ xs'
hxs' : ∀ x ∈ [y], x ∈ xs'
⊢ nextOr [y] x d ∈ xs'

Next tactic:
exact hd
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  cases' ys with z zs
  · exact hd
  

Proof state:
case cons.cons
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y z : α
zs : List α
ih : (∀ x ∈ z :: zs, x ∈ xs') → nextOr (z :: zs) x d ∈ xs'
hxs' : ∀ x ∈ y :: z :: zs, x ∈ xs'
⊢ nextOr (y :: z :: zs) x d ∈ xs'

Next tactic:
rw [nextOr]
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  cases' ys with z zs
  · exact hd
  rw [nextOr]
  

Proof state:
case cons.cons
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y z : α
zs : List α
ih : (∀ x ∈ z :: zs, x ∈ xs') → nextOr (z :: zs) x d ∈ xs'
hxs' : ∀ x ∈ y :: z :: zs, x ∈ xs'
⊢ (if x = y then z else nextOr (z :: zs) x d) ∈ xs'

Next tactic:
split_ifs with h
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  cases' ys with z zs
  · exact hd
  rw [nextOr]
  split_ifs with h
  · 

Proof state:
case pos
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y z : α
zs : List α
ih : (∀ x ∈ z :: zs, x ∈ xs') → nextOr (z :: zs) x d ∈ xs'
hxs' : ∀ x ∈ y :: z :: zs, x ∈ xs'
h : x = y
⊢ z ∈ xs'

Next tactic:
exact hxs' _ (mem_cons_of_mem _ (mem_cons_self _ _))
theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by
  revert hd
  suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by
    exact this xs fun _ => id
  intro xs' hxs' hd
  induction' xs with y ys ih
  · exact hd
  cases' ys with z zs
  · exact hd
  rw [nextOr]
  split_ifs with h
  · exact hxs' _ (mem_cons_of_mem _ (mem_cons_self _ _))
  · 

Proof state:
case neg
α : Type u_1
inst✝ : DecidableEq α
x d : α
xs' : List α
hd : d ∈ xs'
y z : α
zs : List α
ih : (∀ x ∈ z :: zs, x ∈ xs') → nextOr (z :: zs) x d ∈ xs'
hxs' : ∀ x ∈ y :: z :: zs, x ∈ xs'
h : ¬x = y
⊢ nextOr (z :: zs) x d ∈ xs'

Next tactic:
exact ih fun _ h => hxs' _ (mem_cons_of_mem _ h)
/-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the previous
element of `l`. This works from head to tail, (including a check for last element)
so it will match on first hit, ignoring later duplicates.

 * `prev [1, 2, 3] 2 _ = 1`
 * `prev [1, 2, 3] 1 _ = 3`
 * `prev [1, 2, 3, 2, 4] 2 _ = 1`
 * `prev [1, 2, 3, 4, 2] 2 _ = 1`
 * `prev [1, 1, 2] 1 _ = 2`
-/
def prev : ∀ l : List α, ∀ x ∈ l, α
  | [], _, h => by 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
x✝ : α
h : x✝ ∈ []
⊢ α

Next tactic:
simp at h
/-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the previous
element of `l`. This works from head to tail, (including a check for last element)
so it will match on first hit, ignoring later duplicates.

 * `prev [1, 2, 3] 2 _ = 1`
 * `prev [1, 2, 3] 1 _ = 3`
 * `prev [1, 2, 3, 2, 4] 2 _ = 1`
 * `prev [1, 2, 3, 4, 2] 2 _ = 1`
 * `prev [1, 1, 2] 1 _ = 2`
-/
def prev : ∀ l : List α, ∀ x ∈ l, α
  | [], _, h => by simp at h
  | [y], _, _ => y
  | y :: z :: xs, x, h =>
    if hx : x = y then getLast (z :: xs) (cons_ne_nil _ _)
    else if x = z then y else prev (z :: xs) x (by 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
y z : α
xs : List α
x : α
h : x ∈ y :: z :: xs
hx : ¬x = y
⊢ x ∈ z :: xs

Next tactic:
simpa [hx] using h
theorem next_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) :
    next (y :: z :: l) x h = z := by 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x y z : α
h : x ∈ y :: z :: l
hx : x = y
⊢ next (y :: z :: l) x h = z

Next tactic:
rw [next, nextOr, if_pos hx]
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ x ∈ l

Next tactic:
simpa [hy] using h
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by simpa [hy] using h) := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ next (y :: l) x h = next l x (_ : x ∈ l)

Next tactic:
rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne]
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by simpa [hy] using h) := by
  rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne]
  · 

Proof state:
case x_mem
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ x ∈ l

Next tactic:
rwa [getLast_cons] at hx
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by simpa [hy] using h) := by
  rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne]
  · rwa [getLast_cons] at hx
    

Proof state:
case x_mem
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ l ≠ []

Next tactic:
exact ne_nil_of_mem (by assumption)
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by simpa [hy] using h) := by
  rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne]
  · rwa [getLast_cons] at hx
    exact ne_nil_of_mem (by 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ ?m.63390 ∈ l

Next tactic:
assumption
theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) :
    next (y :: l) x h = next l x (by simpa [hy] using h) := by
  rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne]
  · rwa [getLast_cons] at hx
    exact ne_nil_of_mem (by assumption)
  · 

Proof state:
case x_ne
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x ≠ getLast (y :: l) (_ : y :: l ≠ [])
⊢ x ≠ getLast l (_ : l ≠ [])

Next tactic:
rwa [getLast_cons] at hx
theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l)
    (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) :
    next (y :: l ++ [x]) x h = y := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x y : α
hy : x ≠ y
hx : x ∉ l
h : optParam (x ∈ y :: l ++ [x]) (_ : x ∈ y :: l ++ [x])
⊢ next (y :: l ++ [x]) x h = y

Next tactic:
rw [next, nextOr_concat]
theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l)
    (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) :
    next (y :: l ++ [x]) x h = y := by
  rw [next, nextOr_concat]
  · 

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x y : α
hy : x ≠ y
hx : x ∉ l
h : optParam (x ∈ y :: l ++ [x]) (_ : x ∈ y :: l ++ [x])
⊢ get (y :: l ++ [x]) { val := 0, isLt := (_ : 0 < length (y :: l ++ [x])) } = y

Next tactic:
rfl
theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l)
    (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) :
    next (y :: l ++ [x]) x h = y := by
  rw [next, nextOr_concat]
  · rfl
  · 

Proof state:
case h
α : Type u_1
inst✝ : DecidableEq α
l : List α
x y : α
hy : x ≠ y
hx : x ∉ l
h : optParam (x ∈ y :: l ++ [x]) (_ : x ∈ y :: l ++ [x])
⊢ x ∉ y :: l

Next tactic:
simp [hy, hx]
theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by
  

Proof state:
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x = getLast (y :: l) (_ : y :: l ≠ [])
hl : Nodup l
⊢ next (y :: l) x h = y

Next tactic:
rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat]
theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by
  rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat]
  

Proof state:
case h
α : Type u_1
inst✝ : DecidableEq α
l : List α
x : α
h✝ : x ∈ l
y : α
h : x ∈ y :: l
hy : x ≠ y
hx : x = getLast (y :: l) (_ : y :: l ≠ [])
hl : Nodup l
⊢ getLast (y :: l) (_ : y :: l ≠ []) ∉ dropLast (y :: l)

Next tactic:
subst hx