Imports
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Tooby-Smith
-/
module
public import Physlib.Mathematics.List
import all Physlib.Mathematics.ListList lemmas
@[expose] public sectionlemma insertionSortMin_lt_length_succ {α : Type} (r : α → α → Prop) [DecidableRel r]
(i : α) (l : List α) :
insertionSortMinPos r i l < (insertionSortDropMinPos r i l).length.succ := α:Typer:α → α → Propinst✝:DecidableRel ri:αl:List α⊢ ↑(insertionSortMinPos r i l) < (insertionSortDropMinPos r i l).length.succ
All goals completed! 🐙
Given a list i :: l the left-most minimal position a of i :: l wrt r
as an element of Fin (insertionSortDropMinPos r i l).length.succ.
def insertionSortMinPosFin {α : Type} (r : α → α → Prop) [DecidableRel r] (i : α) (l : List α) :
Fin (insertionSortDropMinPos r i l).length.succ :=
⟨insertionSortMinPos r i l, insertionSortMin_lt_length_succ r i l⟩α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthhl1:(∀ a' ∈ List.insertionSort r (insertionSortDropMinPos r a l), r (insertionSortMin r a l) a') ∧
List.Pairwise r (List.insertionSort r (insertionSortDropMinPos r a l))⊢ r (insertionSortMin r a l) (insertionSortDropMinPos r a l)[i]
exact hl1.1 _ (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthhl1:(∀ a' ∈ List.insertionSort r (insertionSortDropMinPos r a l), r (insertionSortMin r a l) a') ∧
List.Pairwise r (List.insertionSort r (insertionSortDropMinPos r a l))⊢ (insertionSortDropMinPos r a l)[i] ∈ List.insertionSort r (insertionSortDropMinPos r a l) simp All goals completed! 🐙)
lemma insertionSortMinPos_insertionSortEquiv {α : Type} (r : α → α → Prop) [DecidableRel r]
(a : α) (l : List α) :
insertionSortEquiv r (a ::l) (insertionSortMinPos r a l) =
⟨0, by n:ℕα:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ 0 < (List.insertionSort r (a :: l)).length simp [List.orderedInsert_length] All goals completed! 🐙⟩ := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (insertionSortEquiv r (a :: l)) (insertionSortMinPos r a l) = ⟨0, ⋯⟩
rw [insertionSortMinPos α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (insertionSortEquiv r (a :: l)) ((insertionSortEquiv r (a :: l)).symm ⟨0, ⋯⟩) = ⟨0, ⋯⟩ α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (insertionSortEquiv r (a :: l)) ((insertionSortEquiv r (a :: l)).symm ⟨0, ⋯⟩) = ⟨0, ⋯⟩] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (insertionSortEquiv r (a :: l)) ((insertionSortEquiv r (a :: l)).symm ⟨0, ⋯⟩) = ⟨0, ⋯⟩
exact Equiv.apply_symm_apply (insertionSortEquiv r (a :: l)) ⟨0, _⟩ All goals completed! 🐙lemma insertionSortEquiv_gt_zero_of_ne_insertionSortMinPos {α : Type} (r : α → α → Prop)
[DecidableRel r] (a : α) (l : List α) (k : Fin (a :: l).length)
(hk : k ≠ insertionSortMinPos r a l) :
⟨0, by n:ℕα:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:k ≠ insertionSortMinPos r a l⊢ 0 < (List.insertionSort r (a :: l)).length simp [List.orderedInsert_length] All goals completed! 🐙⟩ < insertionSortEquiv r (a :: l) k := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:k ≠ insertionSortMinPos r a l⊢ ⟨0, ⋯⟩ < (insertionSortEquiv r (a :: l)) k
by_contra hn α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:k ≠ insertionSortMinPos r a lhn:¬⟨0, ⋯⟩ < (insertionSortEquiv r (a :: l)) k⊢ False
simp only [List.length_cons, not_lt] at hn α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:k ≠ insertionSortMinPos r a lhn:(insertionSortEquiv r (a :: l)) k ≤ ⟨0, ⋯⟩⊢ False
refine hk ((Equiv.apply_eq_iff_eq_symm_apply (insertionSortEquiv r (a :: l))).mp ?_) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:k ≠ insertionSortMinPos r a lhn:(insertionSortEquiv r (a :: l)) k ≤ ⟨0, ⋯⟩⊢ (insertionSortEquiv r (a :: l)) k = ⟨0, ⋯⟩
simp_all only [List.length_cons, ne_eq, Fin.le_def, nonpos_iff_eq_zero] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αk:Fin (a :: l).lengthhk:¬k = insertionSortMinPos r a lhn:↑((insertionSortEquiv r (a :: l)) k) = 0⊢ (insertionSortEquiv r (a :: l)) k = ⟨0, ⋯⟩
exact Fin.ext hn All goals completed! 🐙
lemma insertionSortMin_lt_mem_insertionSortDropMinPos_of_lt {α : Type} (r : α → α → Prop)
[DecidableRel r] (a : α) (l : List α)
(i : Fin (insertionSortDropMinPos r a l).length)
(h : (insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l) :
¬ r ((insertionSortDropMinPos r a l)[i]) (insertionSortMin r a l) := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ¬r (insertionSortDropMinPos r a l)[i] (insertionSortMin r a l)
simp only [Fin.getElem_fin, insertionSortMin, List.get_eq_getElem, List.length_cons] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
have h1 : (insertionSortDropMinPos r a l)[(i : ℕ)] =
(a :: l).get (finCongr (eraseIdx_length_succ (a :: l) (insertionSortMinPos r a l))
((insertionSortMinPosFin r a l).succAbove i)) := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ¬r (insertionSortDropMinPos r a l)[i] (insertionSortMin r a l) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
trans (insertionSortDropMinPos r a l).get i α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ (insertionSortDropMinPos r a l)[↑i] = (insertionSortDropMinPos r a l).get iα:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ (insertionSortDropMinPos r a l).get i = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
simp only [List.get_eq_getElem] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ (insertionSortDropMinPos r a l).get i = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
simp only [insertionSortDropMinPos, List.length_cons, Nat.succ_eq_add_one, finCongr_apply] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ((a :: l).eraseIdx ↑(insertionSortMinPos r a l)).get i =
(a :: l).get (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
rw [eraseIdx_get α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ((a :: l).get ∘ Fin.cast ⋯ ∘ (Fin.cast ⋯ (insertionSortMinPos r a l)).succAbove) i =
(a :: l).get (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ((a :: l).get ∘ Fin.cast ⋯ ∘ (Fin.cast ⋯ (insertionSortMinPos r a l)).succAbove) i =
(a :: l).get (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ((a :: l).get ∘ Fin.cast ⋯ ∘ (Fin.cast ⋯ (insertionSortMinPos r a l)).succAbove) i =
(a :: l).get (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i)) α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
simp only [List.length_cons, Function.comp_apply, List.get_eq_getElem, Fin.val_cast] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ (a :: l)[↑((Fin.cast ⋯ (insertionSortMinPos r a l)).succAbove i)] =
(a :: l)[↑((insertionSortMinPosFin r a l).succAbove i)] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
rfl α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (insertionSortDropMinPos r a l)[↑i] (a :: l)[↑(insertionSortMinPos r a l)]
rw [h1 α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r ((a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))) (a :: l)[↑(insertionSortMinPos r a l)] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r ((a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))) (a :: l)[↑(insertionSortMinPos r a l)]] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r ((a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))) (a :: l)[↑(insertionSortMinPos r a l)]
simp only [List.length_cons, Nat.succ_eq_add_one, List.get_eq_getElem] α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬r (a :: l)[↑((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))] (a :: l)[↑(insertionSortMinPos r a l)]
apply insertionSortEquiv_order hij α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ (finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i) < insertionSortMinPos r a lhij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ (insertionSortEquiv r (a :: l)) (insertionSortMinPos r a l) <
(insertionSortEquiv r (a :: l)) ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))
exact h hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ (insertionSortEquiv r (a :: l)) (insertionSortMinPos r a l) <
(insertionSortEquiv r (a :: l)) ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))
simp only [List.length_cons, finCongr_apply] hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ (insertionSortEquiv r (a :: l)) (insertionSortMinPos r a l) <
(insertionSortEquiv r (a :: l)) (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i))
apply lt_of_eq_of_lt (insertionSortMinPos_insertionSortEquiv r a l) hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ⟨0, ⋯⟩ < (insertionSortEquiv r (a :: l)) (Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i))
apply insertionSortEquiv_gt_zero_of_ne_insertionSortMinPos r a l hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ Fin.cast ⋯ ((insertionSortMinPosFin r a l).succAbove i) ≠ insertionSortMinPos r a l
simp only [List.length_cons, ne_eq, Fin.ext_iff, Fin.val_cast] hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))⊢ ¬↑((insertionSortMinPosFin r a l).succAbove i) = ↑(insertionSortMinPos r a l)
have hl : (insertionSortMinPos r a l).val = (insertionSortMinPosFin r a l).val := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a l⊢ ¬r (insertionSortDropMinPos r a l)[i] (insertionSortMin r a l) hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))hl:↑(insertionSortMinPos r a l) = ↑(insertionSortMinPosFin r a l)⊢ ¬↑((insertionSortMinPosFin r a l).succAbove i) = ↑(insertionSortMinPos r a l)
rflhij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))hl:↑(insertionSortMinPos r a l) = ↑(insertionSortMinPosFin r a l)⊢ ¬↑((insertionSortMinPosFin r a l).succAbove i) = ↑(insertionSortMinPos r a l)hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))hl:↑(insertionSortMinPos r a l) = ↑(insertionSortMinPosFin r a l)⊢ ¬↑((insertionSortMinPosFin r a l).succAbove i) = ↑(insertionSortMinPos r a l)
simp only [hl, Nat.succ_eq_add_one, Fin.val_eq_val, ne_eq] hij' α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List αi:Fin (insertionSortDropMinPos r a l).lengthh:(insertionSortMinPosFin r a l).succAbove i < insertionSortMinPosFin r a lh1:(insertionSortDropMinPos r a l)[↑i] = (a :: l).get ((finCongr ⋯) ((insertionSortMinPosFin r a l).succAbove i))hl:↑(insertionSortMinPos r a l) = ↑(insertionSortMinPosFin r a l)⊢ ¬(insertionSortMinPosFin r a l).succAbove i = insertionSortMinPosFin r a l
exact Fin.succAbove_ne (insertionSortMinPosFin r a l) i All goals completed! 🐙lemma insertionSort_insertionSort {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (l1 : List α) :
List.insertionSort r (List.insertionSort r l1) = List.insertionSort r l1 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl1:List α⊢ List.insertionSort r (List.insertionSort r l1) = List.insertionSort r l1
apply List.Pairwise.insertionSort_eq α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl1:List α⊢ List.Pairwise r (List.insertionSort r l1)
exact List.pairwise_insertionSort r l1 All goals completed! 🐙
lemma orderedInsert_commute {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a b : α) (hr : ¬ r a b) : (l : List α) →
List.orderedInsert r a (List.orderedInsert r b l) =
List.orderedInsert r b (List.orderedInsert r a l)
| [] => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ List.orderedInsert r a (List.orderedInsert r b []) = List.orderedInsert r b (List.orderedInsert r a []) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ List.orderedInsert r a (List.orderedInsert r b []) = List.orderedInsert r b (List.orderedInsert r a [])
have hrb : r b a := (Std.Total.total a b).resolve_left hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bhrb:r b a⊢ List.orderedInsert r a (List.orderedInsert r b []) = List.orderedInsert r b (List.orderedInsert r a [])
simp [hr, hrb] All goals completed! 🐙
| c :: l => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ List.orderedInsert r a (List.orderedInsert r b (c :: l)) = List.orderedInsert r b (List.orderedInsert r a (c :: l)) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ List.orderedInsert r a (List.orderedInsert r b (c :: l)) = List.orderedInsert r b (List.orderedInsert r a (c :: l))
have hrb : r b a := (Std.Total.total a b).resolve_left hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b a⊢ List.orderedInsert r a (List.orderedInsert r b (c :: l)) = List.orderedInsert r b (List.orderedInsert r a (c :: l))
simp only [List.orderedInsert] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b a⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
List.orderedInsert r b (if r a c then a :: c :: l else c :: List.orderedInsert r a l)
by_cases h : r a c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
List.orderedInsert r b (if r a c then a :: c :: l else c :: List.orderedInsert r a l)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
List.orderedInsert r b (if r a c then a :: c :: l else c :: List.orderedInsert r a l)
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
List.orderedInsert r b (if r a c then a :: c :: l else c :: List.orderedInsert r a l) simp only [h, ↓reduceIte, List.orderedInsert.eq_2, hrb] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) = b :: a :: c :: l
rw [if_pos (IsTrans.trans (r := r) _ _ _ hrb h) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (b :: c :: l) = b :: a :: c :: l pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (b :: c :: l) = b :: a :: c :: l] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:r a c⊢ List.orderedInsert r a (b :: c :: l) = b :: a :: c :: l
simp only [List.orderedInsert, hr, ↓reduceIte, h] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
List.orderedInsert r b (if r a c then a :: c :: l else c :: List.orderedInsert r a l) simp only [h, ↓reduceIte, List.orderedInsert.eq_2] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
if r b c then b :: c :: List.orderedInsert r a l else c :: List.orderedInsert r b (List.orderedInsert r a l)
by_cases hbc : r b c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a chbc:r b c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
if r b c then b :: c :: List.orderedInsert r a l else c :: List.orderedInsert r b (List.orderedInsert r a l)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a chbc:¬r b c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
if r b c then b :: c :: List.orderedInsert r a l else c :: List.orderedInsert r b (List.orderedInsert r a l)
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a chbc:r b c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
if r b c then b :: c :: List.orderedInsert r a l else c :: List.orderedInsert r b (List.orderedInsert r a l) simp [hbc, hr, h] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a chbc:¬r b c⊢ List.orderedInsert r a (if r b c then b :: c :: l else c :: List.orderedInsert r b l) =
if r b c then b :: c :: List.orderedInsert r a l else c :: List.orderedInsert r b (List.orderedInsert r a l) simp only [hbc, ↓reduceIte, List.orderedInsert.eq_2, h, List.cons.injEq, true_and] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrb:r b ah:¬r a chbc:¬r b c⊢ List.orderedInsert r a (List.orderedInsert r b l) = List.orderedInsert r b (List.orderedInsert r a l)
exact orderedInsert_commute r a b hr l All goals completed! 🐙
lemma insertionSort_orderedInsert_append {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a : α) : (l1 l2 : List α) →
List.insertionSort r (List.orderedInsert r a l1 ++ l2) = List.insertionSort r (a :: l1 ++ l2)
| [], l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl2:List α⊢ List.insertionSort r (List.orderedInsert r a [] ++ l2) = List.insertionSort r ([a] ++ l2) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl2:List α⊢ List.insertionSort r (List.orderedInsert r a [] ++ l2) = List.insertionSort r ([a] ++ l2)
simp All goals completed! 🐙
| b :: l1, l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ List.insertionSort r (List.orderedInsert r a (b :: l1) ++ l2) = List.insertionSort r (a :: b :: l1 ++ l2) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ List.insertionSort r (List.orderedInsert r a (b :: l1) ++ l2) = List.insertionSort r (a :: b :: l1 ++ l2)
conv_lhs => simp α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α| List.insertionSort r ((if r a b then a :: b :: l1 else b :: List.orderedInsert r a l1) ++ l2)
by_cases h : r a b pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:r a b⊢ List.insertionSort r ((if r a b then a :: b :: l1 else b :: List.orderedInsert r a l1) ++ l2) =
List.insertionSort r (a :: b :: l1 ++ l2)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.insertionSort r ((if r a b then a :: b :: l1 else b :: List.orderedInsert r a l1) ++ l2) =
List.insertionSort r (a :: b :: l1 ++ l2)
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:r a b⊢ List.insertionSort r ((if r a b then a :: b :: l1 else b :: List.orderedInsert r a l1) ++ l2) =
List.insertionSort r (a :: b :: l1 ++ l2) simp [h] All goals completed! 🐙
conv_lhs => simp [h] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b| List.orderedInsert r b (List.insertionSort r (List.orderedInsert r a l1 ++ l2))
rw [insertionSort_orderedInsert_append r a l1 l2 neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.orderedInsert r b (List.insertionSort r (a :: l1 ++ l2)) = List.insertionSort r (a :: b :: l1 ++ l2) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.orderedInsert r b (List.insertionSort r (a :: l1 ++ l2)) = List.insertionSort r (a :: b :: l1 ++ l2)] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.orderedInsert r b (List.insertionSort r (a :: l1 ++ l2)) = List.insertionSort r (a :: b :: l1 ++ l2)
simp only [List.cons_append, List.insertionSort_cons] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.orderedInsert r b (List.orderedInsert r a (List.insertionSort r (l1 ++ l2))) =
List.orderedInsert r a (List.orderedInsert r b (List.insertionSort r (l1 ++ l2)))
rw [orderedInsert_commute r a b h neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αh:¬r a b⊢ List.orderedInsert r b (List.orderedInsert r a (List.insertionSort r (l1 ++ l2))) =
List.orderedInsert r b (List.orderedInsert r a (List.insertionSort r (l1 ++ l2))) All goals completed! 🐙] All goals completed! 🐙
lemma insertionSort_insertionSort_append {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] : (l1 l2 : List α) →
List.insertionSort r (List.insertionSort r l1 ++ l2) = List.insertionSort r (l1 ++ l2)
| [], l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl2:List α⊢ List.insertionSort r (List.insertionSort r [] ++ l2) = List.insertionSort r ([] ++ l2) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl2:List α⊢ List.insertionSort r (List.insertionSort r [] ++ l2) = List.insertionSort r ([] ++ l2)
simp All goals completed! 🐙
| a :: l1, l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (List.insertionSort r (a :: l1) ++ l2) = List.insertionSort r (a :: l1 ++ l2) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (List.insertionSort r (a :: l1) ++ l2) = List.insertionSort r (a :: l1 ++ l2)
rw [List.insertionSort_cons, α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (List.orderedInsert r a (List.insertionSort r l1) ++ l2) = List.insertionSort r (a :: l1 ++ l2) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (a :: List.insertionSort r l1 ++ l2) = List.insertionSort r (a :: l1 ++ l2) insertionSort_orderedInsert_append α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (a :: List.insertionSort r l1 ++ l2) = List.insertionSort r (a :: l1 ++ l2) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (a :: List.insertionSort r l1 ++ l2) = List.insertionSort r (a :: l1 ++ l2)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (a :: List.insertionSort r l1 ++ l2) = List.insertionSort r (a :: l1 ++ l2)
simp only [List.cons_append, List.insertionSort_cons] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.orderedInsert r a (List.insertionSort r (List.insertionSort r l1 ++ l2)) =
List.orderedInsert r a (List.insertionSort r (l1 ++ l2))
rw [insertionSort_insertionSort_append r l1 l2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.orderedInsert r a (List.insertionSort r (l1 ++ l2)) = List.orderedInsert r a (List.insertionSort r (l1 ++ l2)) All goals completed! 🐙] All goals completed! 🐙
lemma insertionSort_append_insertionSort_append {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] : (l1 l2 l3 : List α) →
List.insertionSort r (l1 ++ List.insertionSort r l2 ++ l3) =
List.insertionSort r (l1 ++ l2 ++ l3)
| [], l2, l3 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl2:List αl3:List α⊢ List.insertionSort r ([] ++ List.insertionSort r l2 ++ l3) = List.insertionSort r ([] ++ l2 ++ l3) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α rl2:List αl3:List α⊢ List.insertionSort r ([] ++ List.insertionSort r l2 ++ l3) = List.insertionSort r ([] ++ l2 ++ l3)
simpa using insertionSort_insertionSort_append r l2 l3 All goals completed! 🐙
| a :: l1, l2, l3 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List αl3:List α⊢ List.insertionSort r (a :: l1 ++ List.insertionSort r l2 ++ l3) = List.insertionSort r (a :: l1 ++ l2 ++ l3) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List αl3:List α⊢ List.insertionSort r (a :: l1 ++ List.insertionSort r l2 ++ l3) = List.insertionSort r (a :: l1 ++ l2 ++ l3)
simp only [List.cons_append, List.insertionSort_cons] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List αl3:List α⊢ List.orderedInsert r a (List.insertionSort r (l1 ++ List.insertionSort r l2 ++ l3)) =
List.orderedInsert r a (List.insertionSort r (l1 ++ l2 ++ l3))
rw [insertionSort_append_insertionSort_append r l1 l2 l3 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List αl3:List α⊢ List.orderedInsert r a (List.insertionSort r (l1 ++ l2 ++ l3)) =
List.orderedInsert r a (List.insertionSort r (l1 ++ l2 ++ l3)) All goals completed! 🐙] All goals completed! 🐙@[simp]
lemma orderedInsert_length {α : Type} (r : α → α → Prop) [DecidableRel r] (a : α) (l : List α) :
(List.orderedInsert r a l).length = (a :: l).length := by α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (List.orderedInsert r a l).length = (a :: l).length
apply List.Perm.length_eq α:Typer:α → α → Propinst✝:DecidableRel ra:αl:List α⊢ (List.orderedInsert r a l).Perm (a :: l)
exact List.perm_orderedInsert r a l All goals completed! 🐙lemma takeWhile_orderedInsert {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r]
(a b : α) (hr : ¬ r a b) : (l : List α) →
(List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) l).length + 1
| [] => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ (List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b [])).length =
(List.takeWhile (fun c => !decide (r a c)) []).length + 1 by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ (List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b [])).length =
(List.takeWhile (fun c => !decide (r a c)) []).length + 1
simp [hr] All goals completed! 🐙
| c :: l => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ (List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b (c :: l))).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1 by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ (List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b (c :: l))).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1
simp only [List.orderedInsert] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ (List.takeWhile (fun c => !decide (r a c)) (if r b c then b :: c :: l else c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1
by_cases h : r b c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:r b c⊢ (List.takeWhile (fun c => !decide (r a c)) (if r b c then b :: c :: l else c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:¬r b c⊢ (List.takeWhile (fun c => !decide (r a c)) (if r b c then b :: c :: l else c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:r b c⊢ (List.takeWhile (fun c => !decide (r a c)) (if r b c then b :: c :: l else c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1 simp [h, hr] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:¬r b c⊢ (List.takeWhile (fun c => !decide (r a c)) (if r b c then b :: c :: l else c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1 simp only [h, ↓reduceIte] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:¬r b c⊢ (List.takeWhile (fun c => !decide (r a c)) (c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1
have hl : ¬ r a c :=
fun hn => h (IsTrans.trans _ _ _ ((Std.Total.total a b).resolve_left hr) hn) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:¬r b chl:¬r a c⊢ (List.takeWhile (fun c => !decide (r a c)) (c :: List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) (c :: l)).length + 1
simp only [hl, decide_false, Bool.not_false, List.takeWhile_cons_of_pos, List.length_cons,
add_left_inj] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αh:¬r b chl:¬r a c⊢ (List.takeWhile (fun c => !decide (r a c)) (List.orderedInsert r b l)).length =
(List.takeWhile (fun c => !decide (r a c)) l).length + 1
exact takeWhile_orderedInsert r a b hr l All goals completed! 🐙lemma takeWhile_orderedInsert' {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r]
(a b : α) (hr : ¬ r a b) : (l : List α) →
(List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) l).length
| [] => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a [])).length =
(List.takeWhile (fun c => !decide (r b c)) []).length by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a b⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a [])).length =
(List.takeWhile (fun c => !decide (r b c)) []).length
simp [List.orderedInsert, (Std.Total.total a b).resolve_left hr] All goals completed! 🐙
| c :: l => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a (c :: l))).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List α⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a (c :: l))).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length
have hrba : r b a := (Std.Total.total a b).resolve_left hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b a⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a (c :: l))).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length
simp only [List.orderedInsert] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b a⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length
by_cases h : r b c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).lengthneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length by_cases hac : r a c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b chac:r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).lengthneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b chac:¬r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length <;> pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b chac:r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).lengthneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:r b chac:¬r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length simp [h, hac, hrba] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length by_cases hac : r a c pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b chac:r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).lengthneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b chac:¬r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b chac:r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length exact absurd (IsTrans.trans _ _ _ hrba hac) h All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b chac:¬r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (if r a c then a :: c :: l else c :: List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) (c :: l)).length simp only [hac, ↓reduceIte, h, decide_false, Bool.not_false, List.takeWhile_cons_of_pos,
List.length_cons, add_left_inj] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bc:αl:List αhrba:r b ah:¬r b chac:¬r a c⊢ (List.takeWhile (fun c => !decide (r b c)) (List.orderedInsert r a l)).length =
(List.takeWhile (fun c => !decide (r b c)) l).length
exact takeWhile_orderedInsert' r a b hr l All goals completed! 🐙
set_option backward.isDefEq.respectTransparency false in
lemma insertionSortEquiv_commute {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a b : α) (hr : ¬ r a b) (n : ℕ) : (l : List α) →
(hn : n + 2 < (a :: b :: l).length) →
insertionSortEquiv r (a :: b :: l) ⟨n + 2, hn⟩ = (finCongr (by n✝:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕl:List αhn:n + 2 < (a :: b :: l).length⊢ (List.insertionSort r (b :: a :: l)).length = (List.insertionSort r (a :: b :: l)).length simp All goals completed! 🐙))
(insertionSortEquiv r (b :: a :: l) ⟨n + 2, hn⟩) := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩)
have hrba : r b a := (Std.Total.total a b).resolve_left hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b a⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩)
intro l hn α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ (insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩)
simp only [List.insertionSort, List.length_cons, insertionSortEquiv, Nat.succ_eq_add_one,
equivCons_trans, Equiv.trans_apply, equivCons_succ, finCongr_apply] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (b :: l)) a)
((equivCons (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) b))
((insertionSortEquiv r l) ⟨n, ⋯⟩).succ.succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (a :: l)) b)
((equivCons (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a))
((insertionSortEquiv r l) ⟨n, ⋯⟩).succ.succ))
conv_lhs => erw [equivCons_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (b :: l)) a)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) b) ⟨↑((insertionSortEquiv r l).1 ⟨n, ⋯⟩) + 1, ⋯⟩).succ
conv_rhs => erw [equivCons_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (a :: l)) b)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a)
⟨↑((insertionSortEquiv r l).1 ⟨n, ⋯⟩) + 1, ⋯⟩).succ)
simp only [Equiv.toFun_as_coe] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (b :: l)) a)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) b)
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (a :: l)) b)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a)
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ)
conv_lhs =>
rhs α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| ((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) b) ⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ
rhs α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) b) ⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩
erw [orderedInsertEquiv_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩), ⋯⟩)
conv_lhs => erw [orderedInsertEquiv_fin_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩), ⋯⟩)),
⋯⟩)
simp only [Fin.eta, Fin.val_cast] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (a :: l)) b)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a)
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ)
conv_rhs =>
rhs α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| (orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (a :: l)) b)
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a) ⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ
rhs α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| ((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] l) a) ⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩) + 1, ⋯⟩).succ
erw [orderedInsertEquiv_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| (Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩), ⋯⟩)).succ
conv_rhs => erw [orderedInsertEquiv_fin_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length| Fin.cast ⋯
(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩), ⋯⟩)),
⋯⟩))
ext α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ ↑(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)) =
↑(Fin.cast ⋯
(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(Fin.cast ⋯
(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
⟨↑((insertionSortEquiv r l) ⟨n, ⋯⟩), ⋯⟩)),
⋯⟩)))
simp only [Fin.val_cast, Fin.eta, Fin.cast_cast] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).length⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
let a1 : Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) :=
⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a),
orderedInsertPos_lt_length r (List.orderedInsert r b (List.insertionSort r l)) a⟩ α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
let b1 : Fin ((List.insertionSort r l).length + 1) :=
⟨↑(orderedInsertPos r (List.insertionSort r l) b),
orderedInsertPos_lt_length r (List.insertionSort r l) b⟩ α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
let a2 : Fin ((List.insertionSort r l).length + 1) :=
⟨↑(orderedInsertPos r (List.insertionSort r l) a),
orderedInsertPos_lt_length r (List.insertionSort r l) a⟩ α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
let b2 : Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) :=
⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b),
orderedInsertPos_lt_length r (List.orderedInsert r a (List.insertionSort r l)) b⟩ α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
have ht : (List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l))
= (List.takeWhile (fun c => !decide (r b c))
((List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l)))) := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
rw [List.takeWhile_takeWhile α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun a_1 => decide ((!decide (r b a_1)) = true ∧ (!decide (r a a_1)) = true)) (List.insertionSort r l) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun a_1 => decide ((!decide (r b a_1)) = true ∧ (!decide (r a a_1)) = true)) (List.insertionSort r l) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun a_1 => decide ((!decide (r b a_1)) = true ∧ (!decide (r a a_1)) = true)) (List.insertionSort r l) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [Bool.not_eq_eq_eq_not, Bool.not_true, decide_eq_false_iff_not, Bool.decide_and,
decide_not] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun a_1 => !decide (r b a_1) && !decide (r a a_1)) (List.insertionSort r l) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
congr e_p α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩⊢ (fun c => !decide (r b c)) = fun a_1 => !decide (r b a_1) && !decide (r a a_1) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
funext c e_p α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩c:α⊢ (!decide (r b c)) = (!decide (r b c) && !decide (r a c)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [Bool.eq_self_and, Bool.not_eq_eq_eq_not, Bool.not_true, decide_eq_false_iff_not] e_p α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩c:α⊢ ¬r b c → ¬r a c α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
intro hbc hac e_p α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩c:αhbc:¬r b chac:r a c⊢ False α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
refine hbc ?_ e_p α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩c:αhbc:¬r b chac:r a c⊢ r b c α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
exact IsTrans.trans _ _ _ hrba hac α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
have ha1 : b1.1 ≤ a2.1 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [orderedInsertPos, decide_not, b1] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun b_1 => !decide (r b b_1)) (List.insertionSort r l)).length ≤ ↑a2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
rw [ht α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun c => !decide (r b c))
(List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))).length ≤
↑a2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun c => !decide (r b c))
(List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))).length ≤
↑a2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun c => !decide (r b c))
(List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))).length ≤
↑a2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
apply List.Sublist.length_le α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))).Sublist
(List.takeWhile (fun b => decide ¬r a b) (List.insertionSort r l)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [decide_not] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))⊢ (List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))).Sublist
(List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
exact List.takeWhile_sublist _ α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
have ha2 : a1.1 = a2.1 + 1 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [orderedInsertPos, decide_not, a1, a2] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ (List.takeWhile (fun b => !decide (r a b)) (List.orderedInsert r b (List.insertionSort r l))).length =
(List.takeWhile (fun b => !decide (r a b)) (List.insertionSort r l)).length + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
rw [takeWhile_orderedInsert α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l)).length + 1 =
(List.takeWhile (fun b => !decide (r a b)) (List.insertionSort r l)).length + 1hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ¬r a b hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ¬r a b α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)]hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2⊢ ¬r a b α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
exact hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
have hb : b1.1 = b2.1 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
simp only [orderedInsertPos, decide_not, b1, b2] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ (List.takeWhile (fun b_1 => !decide (r b b_1)) (List.insertionSort r l)).length =
(List.takeWhile (fun b_1 => !decide (r b b_1)) (List.orderedInsert r a (List.insertionSort r l))).length α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
rw [takeWhile_orderedInsert' α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ (List.takeWhile (fun b_1 => !decide (r b b_1)) (List.insertionSort r l)).length =
(List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l)).lengthhr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ¬r a b hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ¬r a b α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)]hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1⊢ ¬r a b α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
exact hr α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
let n := ((insertionSortEquiv r l) ⟨n, by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2⊢ n < l.length α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) simpa using hn All goals completed! 🐙 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩⊢ ↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (b :: l)) a), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) b), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩) =
↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] (a :: l)) b), ⋯⟩.succAbove
⟨↑(⟨↑(orderedInsertPos r (List.foldr (List.orderedInsert r) [] l) a), ⋯⟩.succAbove
((insertionSortEquiv r l) ⟨n, ⋯⟩)),
⋯⟩)
change (a1.succAbove ⟨b1.succAbove n, _⟩).1 = (b2.succAbove ⟨a2.succAbove n, _⟩).1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)
have hba : b2.1 ≤ a2.1 := hb ▸ ha1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)
have val_succAbove {m : ℕ} (p : Fin (m + 1)) (i : Fin m) :
(p.succAbove i).1 = if i.1 < p.1 then i.1 else i.1 + 1 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn:ℕ⊢ ∀ (l : List α) (hn : n + 2 < (a :: b :: l).length),
(insertionSortEquiv r (a :: b :: l)) ⟨n + 2, hn⟩ = (finCongr ⋯) ((insertionSortEquiv r (b :: a :: l)) ⟨n + 2, hn⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)
rw [Fin.succAbove α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin m⊢ ↑(if i.castSucc < p then i.castSucc else i.succ) = if ↑i < ↑p then ↑i else ↑i + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin m⊢ ↑(if i.castSucc < p then i.castSucc else i.succ) = if ↑i < ↑p then ↑i else ↑i + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin m⊢ ↑(if i.castSucc < p then i.castSucc else i.succ) = if ↑i < ↑p then ↑i else ↑i + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)
split isTrue α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin mh✝:i.castSucc < p⊢ ↑i.castSucc = if ↑i < ↑p then ↑i else ↑i + 1isFalse α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin mh✝:¬i.castSucc < p⊢ ↑i.succ = if ↑i < ↑p then ↑i else ↑i + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩) <;> isTrue α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin mh✝:i.castSucc < p⊢ ↑i.castSucc = if ↑i < ↑p then ↑i else ↑i + 1isFalse α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2m:ℕp:Fin (m + 1)i:Fin mh✝:¬i.castSucc < p⊢ ↑i.succ = if ↑i < ↑p then ↑i else ↑i + 1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩) simp_all [Fin.lt_def] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ ↑(a1.succAbove ⟨↑(b1.succAbove n), ⋯⟩) = ↑(b2.succAbove ⟨↑(a2.succAbove n), ⋯⟩)
simp only [val_succAbove, ha2, hb] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1⊢ (if (if ↑n < ↑b2 then ↑n else ↑n + 1) < ↑a2 + 1 then if ↑n < ↑b2 then ↑n else ↑n + 1
else (if ↑n < ↑b2 then ↑n else ↑n + 1) + 1) =
if (if ↑n < ↑a2 then ↑n else ↑n + 1) < ↑b2 then if ↑n < ↑a2 then ↑n else ↑n + 1
else (if ↑n < ↑a2 then ↑n else ↑n + 1) + 1
split_ifs pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:↑n < ↑b2h✝¹:↑n < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n = ↑npos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:↑n < ↑b2h✝¹:¬↑n < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 = ↑npos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:¬↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:¬↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:¬↑n < ↑b2h✝¹:↑n + 1 < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 = ↑n + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:¬↑n < ↑b2h✝¹:¬↑n + 1 < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 + 1 = ↑n + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:¬↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:¬↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 + 1 = ↑n + 1 + 1 <;> pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:↑n < ↑b2h✝¹:↑n < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n = ↑npos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:↑n < ↑b2h✝¹:¬↑n < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 = ↑npos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:¬↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:↑n < ↑b2h✝²:¬↑n < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:¬↑n < ↑b2h✝¹:↑n + 1 < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 = ↑n + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 = ↑n + 1 + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝²:¬↑n < ↑b2h✝¹:¬↑n + 1 < ↑a2 + 1h✝:↑n < ↑a2⊢ ↑n + 1 + 1 = ↑n + 1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:¬↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:↑n + 1 < ↑b2⊢ ↑n + 1 + 1 = ↑n + 1neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αhr:¬r a bn✝:ℕhrba:r b al:List αhn:n + 2 < (a :: b :: l).lengtha1:Fin ((List.orderedInsert r b (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r b (List.insertionSort r l)) a), ⋯⟩b1:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) b), ⋯⟩a2:Fin ((List.insertionSort r l).length + 1) := ⟨↑(orderedInsertPos r (List.insertionSort r l) a), ⋯⟩b2:Fin ((List.orderedInsert r a (List.insertionSort r l)).length + 1) := ⟨↑(orderedInsertPos r (List.orderedInsert r a (List.insertionSort r l)) b), ⋯⟩ht:List.takeWhile (fun c => !decide (r b c)) (List.insertionSort r l) =
List.takeWhile (fun c => !decide (r b c)) (List.takeWhile (fun c => !decide (r a c)) (List.insertionSort r l))ha1:↑b1 ≤ ↑a2ha2:↑a1 = ↑a2 + 1hb:↑b1 = ↑b2n:Fin (List.insertionSort r l).length := (insertionSortEquiv r l) ⟨n✝, ⋯⟩hba:↑b2 ≤ ↑a2val_succAbove:∀ {m : ℕ} (p : Fin (m + 1)) (i : Fin m), ↑(p.succAbove i) = if ↑i < ↑p then ↑i else ↑i + 1h✝³:¬↑n < ↑b2h✝²:¬↑n + 1 < ↑a2 + 1h✝¹:¬↑n < ↑a2h✝:¬↑n + 1 < ↑b2⊢ ↑n + 1 + 1 = ↑n + 1 + 1 omega All goals completed! 🐙
set_option backward.isDefEq.respectTransparency false in
lemma insertionSortEquiv_orderedInsert_append {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a a2 : α) : (l1 l2 : List α) →
(insertionSortEquiv r (List.orderedInsert r a l1 ++ a2 :: l2) ⟨l1.length + 1, by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl1:List αl2:List α⊢ l1.length + 1 < (List.orderedInsert r a l1 ++ a2 :: l2).length
simp All goals completed! 🐙⟩)
= (finCongr (by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl1:List αl2:List α⊢ (List.insertionSort r (a :: l1 ++ a2 :: l2)).length =
(List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)).length
simp only [List.cons_append, List.insertionSort_cons, orderedInsert_length, List.length_cons,
List.length_insertionSort, List.length_append] n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl1:List αl2:List α⊢ l1.length + (l2.length + 1) + 1 = l1.length + 1 + (l2.length + 1)
omega All goals completed! 🐙))
((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl1:List αl2:List α⊢ l1.length + 1 < (a :: l1 ++ a2 :: l2).length simp All goals completed! 🐙⟩)
| [], l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a [] ++ a2 :: l2)) ⟨[].length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r ([a] ++ a2 :: l2)) ⟨[].length + 1, ⋯⟩) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a [] ++ a2 :: l2)) ⟨[].length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r ([a] ++ a2 :: l2)) ⟨[].length + 1, ⋯⟩)
simp only [List.insertionSort, List.length_nil, zero_add, Fin.mk_one, List.cons_append,
List.nil_append, List.foldr_cons, finCongr_refl, List.length_cons] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a [] ++ a2 :: l2)) 1 =
(Equiv.refl (Fin (List.orderedInsert r a (List.orderedInsert r a2 (List.foldr (List.orderedInsert r) [] l2))).length))
((insertionSortEquiv r (a :: a2 :: l2)) 1)
rfl All goals completed! 🐙
| b :: l1, l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
by_cases h : r a b pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a b⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a b⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a b⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) have h1 : (List.orderedInsert r a (b :: l1) ++ a2 :: l2) = (a :: b :: l1 ++ a2 :: l2) := by
simp [h] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = a :: b :: l1 ++ a2 :: l2⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = a :: b :: l1 ++ a2 :: l2⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
rw [insertionSortEquiv_congr _ _ h1 pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = a :: b :: l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = a :: b :: l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = a :: b :: l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
simp All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a b⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) have h1 : (List.orderedInsert r a (b :: l1) ++ a2 :: l2) =
(b :: List.orderedInsert r a (l1) ++ a2 :: l2) := by
simp [h] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
rw [insertionSortEquiv_congr _ _ h1 neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans
((insertionSortEquiv r (b :: List.orderedInsert r a l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans
((insertionSortEquiv r (b :: List.orderedInsert r a l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ ((Fin.castOrderIso ⋯).trans
((insertionSortEquiv r (b :: List.orderedInsert r a l1 ++ a2 :: l2)).trans (Fin.castOrderIso ⋯).toEquiv))
⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩)
simp only [List.cons_append, List.length_cons,
Equiv.trans_apply, RelIso.coe_fn_toEquiv, Fin.castOrderIso_apply, Fin.cast_mk,
finCongr_apply] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.orderedInsert r a l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
conv_lhs => simp [insertionSortEquiv] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2| Fin.cast ⋯
((orderedInsertEquiv r (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) b)
((insertionSortEquiv r (List.orderedInsert r a l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩).succ)
rw [insertionSortEquiv_orderedInsert_append r a neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) b)
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) b)
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) b)
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
have hl : (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) =
List.insertionSort r (a :: l1 ++ a2 :: l2) :=
insertionSort_orderedInsert_append r a l1 (a2 :: l2) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2)) b)
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
rw [orderedInsertEquiv_congr _ _ _ hl neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (a :: l1 ++ a2 :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (a :: l1 ++ a2 :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (a :: l1 ++ a2 :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
((finCongr ⋯) ((insertionSortEquiv r (a :: l1 ++ a2 :: l2)) ⟨l1.length + 1, ⋯⟩)).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
conv_lhs =>
enter [2, 1, 2, 1] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)| orderedInsertEquiv r (List.insertionSort r (a :: l1 ++ a2 :: l2)) b
simp [List.insertionSort_cons] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)| orderedInsertEquiv r (List.insertionSort r (a :: (l1 ++ a2 :: l2))) b
simp only [List.insertionSort, List.foldr_cons, List.cons_append, List.length_cons,
finCongr_apply, Equiv.trans_apply, RelIso.coe_fn_toEquiv, Fin.castOrderIso_apply,
Fin.cast_succ_eq, Fin.cast_cast, Fin.cast_eq_self] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.orderedInsert r a (List.foldr (List.orderedInsert r) [] (l1 ++ a2 :: l2))) b)
((insertionSortEquiv r (a :: (l1 ++ a2 :: l2))) ⟨l1.length + 1, ⋯⟩).succ) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
change Fin.cast _
((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)⊢ l1.length + 2 < (b :: a :: (l1 ++ a2 :: l2)).length simp All goals completed! 🐙⟩) = _
have hl : l1.length + 1 +1 = l1.length + 2 := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.orderedInsert r a (b :: l1) ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (a :: b :: l1 ++ a2 :: l2)) ⟨(b :: l1).length + 1, ⋯⟩) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩) omeganeg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 1 + 1, ⋯⟩)
simp only [List.insertionSort, List.length_cons, hl] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (a :: b :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩)
conv_rhs =>
erw [insertionSortEquiv_commute _ _ _ h _ _] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2| Fin.cast ⋯ ((finCongr ⋯) ((insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩))
simp neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αa2:αb:αl1:List αl2:List αh:¬r a bh1:List.orderedInsert r a (b :: l1) ++ a2 :: l2 = b :: List.orderedInsert r a l1 ++ a2 :: l2hl✝:List.insertionSort r (List.orderedInsert r a l1 ++ a2 :: l2) = List.insertionSort r (a :: l1 ++ a2 :: l2)hl:l1.length + 1 + 1 = l1.length + 2⊢ (insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩ =
(insertionSortEquiv r (b :: a :: (l1 ++ a2 :: l2))) ⟨l1.length + 2, ⋯⟩
rfl All goals completed! 🐙
set_option backward.isDefEq.respectTransparency false in
lemma insertionSortEquiv_insertionSort_append {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a : α) : (l1 l2 : List α) →
(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2) ⟨l1.length, by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ l1.length < (List.insertionSort r l1 ++ a :: l2).length simp All goals completed! 🐙⟩)
= finCongr (by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ (List.insertionSort r (l1 ++ a :: l2)).length = (List.insertionSort r (List.insertionSort r l1 ++ a :: l2)).length simp All goals completed! 🐙) (insertionSortEquiv r (l1 ++ a :: l2) ⟨l1.length, by n:ℕα:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ l1.length < (l1 ++ a :: l2).length simp All goals completed! 🐙⟩)
| [], l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl2:List α⊢ (insertionSortEquiv r (List.insertionSort r [] ++ a :: l2)) ⟨[].length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r ([] ++ a :: l2)) ⟨[].length, ⋯⟩) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl2:List α⊢ (insertionSortEquiv r (List.insertionSort r [] ++ a :: l2)) ⟨[].length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r ([] ++ a :: l2)) ⟨[].length, ⋯⟩)
apply insertionSortEquiv_congr_apply α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl2:List α⊢ List.insertionSort r [] ++ a :: l2 = [] ++ a :: l2
simp All goals completed! 🐙
| b :: l1, l2 => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.insertionSort r (b :: l1) ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (b :: l1 ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.insertionSort r (b :: l1) ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (b :: l1 ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩)
simp only [List.insertionSort, List.length_cons, List.cons_append, finCongr_apply] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.foldr (List.orderedInsert r) [] (b :: l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)
have hl := insertionSortEquiv_orderedInsert_append r b a (List.insertionSort r l1) l2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2))
⟨(List.insertionSort r l1).length + 1, ⋯⟩ =
(finCongr ⋯)
((insertionSortEquiv r (b :: List.insertionSort r l1 ++ a :: l2)) ⟨(List.insertionSort r l1).length + 1, ⋯⟩)⊢ (insertionSortEquiv r (List.foldr (List.orderedInsert r) [] (b :: l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)
simp only [List.length_insertionSort, List.cons_append, List.length_cons,
finCongr_apply] at hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)⊢ (insertionSortEquiv r (List.foldr (List.orderedInsert r) [] (b :: l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)
erw [hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)
have ih := insertionSortEquiv_insertionSort_append r a l1 l2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)⊢ Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩) =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)
simp only [insertionSortEquiv, Nat.succ_eq_add_one, List.insertionSort, Equiv.trans_apply,
equivCons_succ] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((insertionSortEquiv r (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
erw [ih α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
have hl : (List.insertionSort r (List.insertionSort r l1 ++ a :: l2)) =
(List.insertionSort r (l1 ++ a :: l2)) := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List α⊢ (insertionSortEquiv r (List.insertionSort r (b :: l1) ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (b :: l1 ++ a :: l2)) ⟨(b :: l1).length, ⋯⟩) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
exact insertionSort_insertionSort_append r l1 (a :: l2) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (List.foldr (List.orderedInsert r) [] l1 ++ a :: l2))
b)
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
erw [orderedInsertEquiv_congr _ _ _ hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (l1 ++ a :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (l1 ++ a :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
((finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
simp only [List.foldr_cons, finCongr_apply] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl1:List αl2:List αhl✝:(insertionSortEquiv r (List.orderedInsert r b (List.insertionSort r l1) ++ a :: l2)) ⟨l1.length + 1, ⋯⟩ =
Fin.cast ⋯ ((insertionSortEquiv r (b :: (List.insertionSort r l1 ++ a :: l2))) ⟨l1.length + 1, ⋯⟩)ih:(insertionSortEquiv r (List.insertionSort r l1 ++ a :: l2)) ⟨l1.length, ⋯⟩ =
(finCongr ⋯) ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)hl:List.insertionSort r (List.insertionSort r l1 ++ a :: l2) = List.insertionSort r (l1 ++ a :: l2)⊢ Fin.cast ⋯
(((Fin.castOrderIso ⋯).trans
((orderedInsertEquiv r (List.insertionSort r (l1 ++ a :: l2)) b).trans (Fin.castOrderIso ⋯).toEquiv))
(Fin.cast ⋯ ((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩)).succ) =
Fin.cast ⋯
((orderedInsertEquiv r (List.foldr (List.orderedInsert r) [] (l1 ++ a :: l2)) b)
((insertionSortEquiv r (l1 ++ a :: l2)) ⟨l1.length, ⋯⟩).succ)
rfl All goals completed! 🐙Insertion sort with equal fields
lemma orderedInsert_filter_of_pos {α : Type} (r : α → α → Prop) [DecidableRel r]
[IsTrans α r] (a : α) (p : α → Prop) [DecidablePred p] (h : p a) : (l : List α) →
(hl : l.Pairwise r) →
List.filter p (List.orderedInsert r a l) = List.orderedInsert r a (List.filter p l)
| [], hl => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ahl:List.Pairwise r []⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a []) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) []) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ahl:List.Pairwise r []⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a []) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) [])
simp only [List.orderedInsert, List.filter_nil, List.orderedInsert_nil, List.filter_eq_self,
List.mem_singleton, decide_eq_true_eq, forall_eq] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ahl:List.Pairwise r []⊢ p a
exact h All goals completed! 🐙
| b :: l, hl => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a (b :: l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a (b :: l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
simp only [List.orderedInsert] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
by_cases hpb : p b pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) <;> pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) by_cases hab : r a b pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp only [hab, ↓reduceIte, hpb, decide_true, List.filter_cons_of_pos,
List.orderedInsert.eq_2] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ List.filter (fun b => decide (p b)) (a :: b :: l) = a :: b :: List.filter (fun b => decide (p b)) l
rw [List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ decide (p a) = true pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) (b :: l) = a :: b :: List.filter (fun b => decide (p b)) l simp [h] All goals completed! 🐙 pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) (b :: l) = a :: b :: List.filter (fun b => decide (p b)) l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) (b :: l) = a :: b :: List.filter (fun b => decide (p b)) l
rw [List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:r a b⊢ decide (p b) = true All goals completed! 🐙 simp [hpb] All goals completed! 🐙 All goals completed! 🐙)] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp only [hab, ↓reduceIte] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
rw [List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ decide (p b) = true neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp [hpb] All goals completed! 🐙neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)))]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
rw [List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ decide (p b) = true neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (b :: List.filter (fun b => decide (p b)) l) simp [hpb] All goals completed! 🐙neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (b :: List.filter (fun b => decide (p b)) l))]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ b :: List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (b :: List.filter (fun b => decide (p b)) l)
simp only [List.orderedInsert, hab, ↓reduceIte, List.cons.injEq, true_and] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l)
simp only [List.pairwise_cons] at hl neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhpb:p bhab:¬r a bhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l)
exact orderedInsert_filter_of_pos r a p h l hl.2 All goals completed! 🐙
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp only [hab, ↓reduceIte] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ List.filter (fun b => decide (p b)) (a :: b :: l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
rw [List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ decide (p a) = true pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l = List.orderedInsert r a (List.filter (fun b => decide (p b)) l) simp [h] All goals completed! 🐙pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l = List.orderedInsert r a (List.filter (fun b => decide (p b)) l)),
List.filter_cons_of_neg (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ ¬decide (p b) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l = List.orderedInsert r a (List.filter (fun b => decide (p b)) l) simp [hpb] All goals completed! 🐙pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l = List.orderedInsert r a (List.filter (fun b => decide (p b)) l))]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l = List.orderedInsert r a (List.filter (fun b => decide (p b)) l)
rw [List.orderedInsert_eq_take_drop pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
have hl : List.takeWhile (fun b => decide ¬r a b)
(List.filter (fun b => decide (p b)) l) = [] := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a (b :: l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
rw [List.takeWhile_eq_nil_iff α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ ∀ (hl : 0 < (List.filter (fun b => decide (p b)) l).length),
¬(decide ¬r a ((List.filter (fun b => decide (p b)) l).get ⟨0, hl⟩)) = true α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ ∀ (hl : 0 < (List.filter (fun b => decide (p b)) l).length),
¬(decide ¬r a ((List.filter (fun b => decide (p b)) l).get ⟨0, hl⟩)) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a b⊢ ∀ (hl : 0 < (List.filter (fun b => decide (p b)) l).length),
¬(decide ¬r a ((List.filter (fun b => decide (p b)) l).get ⟨0, hl⟩)) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
intro c hc α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a bc:0 < (List.filter (fun b => decide (p b)) l).lengthhc:(decide ¬r a ((List.filter (fun b => decide (p b)) l).get ⟨0, c⟩)) = true⊢ Falsepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
simp only [List.get_eq_getElem, decide_not, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not] at hc α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a bc:0 < (List.filter (fun b => decide (p b)) l).lengthhc:¬r a (List.filter (fun b => decide (p b)) l)[0]⊢ Falsepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
apply hc α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a bc:0 < (List.filter (fun b => decide (p b)) l).lengthhc:¬r a (List.filter (fun b => decide (p b)) l)[0]⊢ r a (List.filter (fun b => decide (p b)) l)[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
apply IsTrans.trans a b _ hab α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:r a bc:0 < (List.filter (fun b => decide (p b)) l).lengthhc:¬r a (List.filter (fun b => decide (p b)) l)[0]⊢ r b (List.filter (fun b => decide (p b)) l)[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
simp only [List.pairwise_cons] at hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhpb:¬p bhab:r a bc:0 < (List.filter (fun b => decide (p b)) l).lengthhc:¬r a (List.filter (fun b => decide (p b)) l)[0]hl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ r b (List.filter (fun b => decide (p b)) l)[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
exact hl.1 _ (List.mem_filter.mp (List.getElem_mem c)).1pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
rw [hl pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
[] ++ a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
[] ++ a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ a :: List.filter (fun b => decide (p b)) l =
[] ++ a :: List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
simp only [decide_not, List.nil_append, List.cons.injEq, true_and] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ List.filter (fun b => decide (p b)) l =
List.dropWhile (fun b => !decide (r a b)) (List.filter (fun b => decide (p b)) l)
conv_lhs => rw [← List.takeWhile_append_dropWhile (p := fun b => decide ¬r a b)
(l := List.filter (fun b => decide (p b)) l)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []| List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) ++
List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l)
rw [hl pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ [] ++ List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) =
List.dropWhile (fun b => !decide (r a b)) (List.filter (fun b => decide (p b)) l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ [] ++ List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) =
List.dropWhile (fun b => !decide (r a b)) (List.filter (fun b => decide (p b)) l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl✝:List.Pairwise r (b :: l)hpb:¬p bhab:r a bhl:List.takeWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) = []⊢ [] ++ List.dropWhile (fun b => decide ¬r a b) (List.filter (fun b => decide (p b)) l) =
List.dropWhile (fun b => !decide (r a b)) (List.filter (fun b => decide (p b)) l)
simp All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (if r a b then a :: b :: l else b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp only [hab, ↓reduceIte] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (b :: List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
rw [List.filter_cons_of_neg (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ ¬decide (p b) = true neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)) simp [hpb] All goals completed! 🐙neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l)))]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (b :: l))
rw [List.filter_cons_of_neg (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ ¬decide (p b) = true neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l) simp [hpb] All goals completed! 🐙neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l))]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhl:List.Pairwise r (b :: l)hpb:¬p bhab:¬r a b⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l)
simp only [List.pairwise_cons] at hl neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:IsTrans α ra:αp:α → Propinst✝:DecidablePred ph:p ab:αl:List αhpb:¬p bhab:¬r a bhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) l)
exact orderedInsert_filter_of_pos r a p h l hl.2 All goals completed! 🐙
lemma orderedInsert_filter_of_neg {α : Type} (r : α → α → Prop) [DecidableRel r]
(a : α) (p : α → Prop) [DecidablePred p] (h : ¬ p a) (l : List α) :
List.filter p (List.orderedInsert r a l) = (List.filter p l) := by α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b)) (List.orderedInsert r a l) = List.filter (fun b => decide (p b)) l
rw [List.orderedInsert_eq_take_drop α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b))
(List.takeWhile (fun b => decide ¬r a b) l ++ a :: List.dropWhile (fun b => decide ¬r a b) l) =
List.filter (fun b => decide (p b)) l α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b))
(List.takeWhile (fun b => decide ¬r a b) l ++ a :: List.dropWhile (fun b => decide ¬r a b) l) =
List.filter (fun b => decide (p b)) l] α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b))
(List.takeWhile (fun b => decide ¬r a b) l ++ a :: List.dropWhile (fun b => decide ¬r a b) l) =
List.filter (fun b => decide (p b)) l
simp only [decide_not, List.filter_append] α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b)) (List.takeWhile (fun b => !decide (r a b)) l) ++
List.filter (fun b => decide (p b)) (a :: List.dropWhile (fun b => !decide (r a b)) l) =
List.filter (fun b => decide (p b)) l
rw [List.filter_cons_of_neg (by α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ ¬decide (p a) = true All goals completed! 🐙 simp [h] All goals completed! 🐙 All goals completed! 🐙), ← List.filter_append, α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b))
(List.takeWhile (fun b => !decide (r a b)) l ++ List.dropWhile (fun b => !decide (r a b)) l) =
List.filter (fun b => decide (p b)) l All goals completed! 🐙 List.takeWhile_append_dropWhile α:Typer:α → α → Propinst✝¹:DecidableRel ra:αp:α → Propinst✝:DecidablePred ph:¬p al:List α⊢ List.filter (fun b => decide (p b)) l = List.filter (fun b => decide (p b)) l All goals completed! 🐙] All goals completed! 🐙
lemma insertionSort_filter {α : Type} (r : α → α → Prop) [DecidableRel r] [Std.Total r]
[IsTrans α r] (p : α → Prop) [DecidablePred p] : (l : List α) →
List.insertionSort r (List.filter p l) =
List.filter p (List.insertionSort r l)
| [] => α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred p⊢ List.insertionSort r (List.filter (fun b => decide (p b)) []) =
List.filter (fun b => decide (p b)) (List.insertionSort r []) by α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred p⊢ List.insertionSort r (List.filter (fun b => decide (p b)) []) =
List.filter (fun b => decide (p b)) (List.insertionSort r []) simp All goals completed! 🐙
| a :: l => α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List α⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.insertionSort r (a :: l)) by α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List α⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.insertionSort r (a :: l))
simp only [List.insertionSort_cons] α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List α⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.orderedInsert r a (List.insertionSort r l))
by_cases h : p a pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.orderedInsert r a (List.insertionSort r l))neg α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:¬p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.orderedInsert r a (List.insertionSort r l))
· pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.orderedInsert r a (List.insertionSort r l)) rw [orderedInsert_filter_of_pos r a p h _ (List.pairwise_insertionSort r l), pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l)) pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (a :: List.filter (fun b => decide (p b)) l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l))
List.filter_cons_of_pos (by α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ decide (p a) = true pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (a :: List.filter (fun b => decide (p b)) l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l)) simpa using h All goals completed! 🐙pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (a :: List.filter (fun b => decide (p b)) l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l)))]pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.insertionSort r (a :: List.filter (fun b => decide (p b)) l) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l))
simp only [List.insertionSort_cons] pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.orderedInsert r a (List.insertionSort r (List.filter (fun b => decide (p b)) l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l))
rw [insertionSort_filter pos α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:p a⊢ List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l)) =
List.orderedInsert r a (List.filter (fun b => decide (p b)) (List.insertionSort r l)) All goals completed! 🐙] All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:¬p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.orderedInsert r a (List.insertionSort r l)) rw [orderedInsert_filter_of_neg r a p h, neg α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:¬p a⊢ List.insertionSort r (List.filter (fun b => decide (p b)) (a :: l)) =
List.filter (fun b => decide (p b)) (List.insertionSort r l) All goals completed! 🐙 List.filter_cons_of_neg (by α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:¬p a⊢ ¬decide (p a) = true All goals completed! 🐙 simpa using h All goals completed! 🐙 All goals completed! 🐙),
insertionSort_filter neg α:Typer:α → α → Propinst✝³:DecidableRel rinst✝²:Std.Total rinst✝¹:IsTrans α rp:α → Propinst✝:DecidablePred pa:αl:List αh:¬p a⊢ List.filter (fun b => decide (p b)) (List.insertionSort r l) =
List.filter (fun b => decide (p b)) (List.insertionSort r l) All goals completed! 🐙] All goals completed! 🐙lemma takeWhile_sorted_eq_filter {α : Type} (r : α → α → Prop) [DecidableRel r]
[IsTrans α r] (a : α) : (l : List α) → (hl : l.Pairwise r) →
List.takeWhile (fun c => ¬ r a c) l = List.filter (fun c => ¬ r a c) l
| [], _ => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.takeWhile (fun c => decide ¬r a c) [] = List.filter (fun c => decide ¬r a c) [] by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.takeWhile (fun c => decide ¬r a c) [] = List.filter (fun c => decide ¬r a c) [] simp All goals completed! 🐙
| b :: l, hl => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l) by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l)
simp only [List.pairwise_cons] at hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l)
by_cases hb : ¬ r a b pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l)
· pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l) simp only [decide_not, hb, decide_false, Bool.not_false, List.takeWhile_cons_of_pos,
List.filter_cons_of_pos, List.cons.injEq, true_and] pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.takeWhile (fun c => !decide (r a c)) l = List.filter (fun c => !decide (r a c)) l
simpa using takeWhile_sorted_eq_filter r a l hl.2 All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.takeWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide ¬r a c) (b :: l) simp_all only [Decidable.not_not, decide_not, decide_true, Bool.not_true, Bool.false_eq_true,
not_false_eq_true, List.takeWhile_cons_of_neg, List.filter_cons_of_neg, List.nil_eq,
List.filter_eq_nil_iff, Bool.not_eq_eq_eq_not, decide_eq_false_iff_not] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ ∀ a_1 ∈ l, r a a_1
exact fun c hc => IsTrans.trans a b c hb (hl.1 c hc) All goals completed! 🐙
lemma dropWhile_sorted_eq_filter {α : Type} (r : α → α → Prop) [DecidableRel r]
[IsTrans α r] (a : α) : (l : List α) → (hl : l.Pairwise r) →
List.dropWhile (fun c => ¬ r a c) l = List.filter (fun c => r a c) l
| [], _ => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.dropWhile (fun c => decide ¬r a c) [] = List.filter (fun c => decide (r a c)) [] by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.dropWhile (fun c => decide ¬r a c) [] = List.filter (fun c => decide (r a c)) [] simp All goals completed! 🐙
| b :: l, hl => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l) by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l)
simp only [List.pairwise_cons] at hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l)
by_cases hb : ¬ r a b pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l)
· pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l) simp only [decide_not, hb, decide_false, Bool.not_false, List.dropWhile_cons_of_pos,
Bool.false_eq_true, not_false_eq_true, List.filter_cons_of_neg] pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.dropWhile (fun c => !decide (r a c)) l = List.filter (fun c => decide (r a c)) l
simpa using dropWhile_sorted_eq_filter r a l hl.2 All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.dropWhile (fun c => decide ¬r a c) (b :: l) = List.filter (fun c => decide (r a c)) (b :: l) simp_all only [Decidable.not_not, decide_not, decide_true, Bool.not_true, Bool.false_eq_true,
not_false_eq_true, List.dropWhile_cons_of_neg, List.filter_cons_of_pos, List.cons.injEq,
true_and] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ l = List.filter (fun c => decide (r a c)) l
symm neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ List.filter (fun c => decide (r a c)) l = l
rw [List.filter_eq_self neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ ∀ a_1 ∈ l, decide (r a a_1) = true neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ ∀ a_1 ∈ l, decide (r a a_1) = true] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ ∀ a_1 ∈ l, decide (r a a_1) = true
intro c hc neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bc:αhc:c ∈ l⊢ decide (r a c) = true
simpa using IsTrans.trans a b c hb (hl.1 c hc) All goals completed! 🐙
lemma dropWhile_sorted_eq_filter_filter {α : Type} (r : α → α → Prop) [DecidableRel r]
[IsTrans α r] (a : α) :(l : List α) → (hl : l.Pairwise r) →
List.filter (fun c => r a c) l =
List.filter (fun c => r a c ∧ r c a) l ++ List.filter (fun c => r a c ∧ ¬ r c a) l
| [], _ => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.filter (fun c => decide (r a c)) [] =
List.filter (fun c => decide (r a c ∧ r c a)) [] ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) [] by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αx✝:List.Pairwise r []⊢ List.filter (fun c => decide (r a c)) [] =
List.filter (fun c => decide (r a c ∧ r c a)) [] ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) []
simp All goals completed! 🐙
| b :: l, hl => α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l) by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l)
simp only [List.pairwise_cons] at hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r l⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l)
by_cases hb : ¬ r a b pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l)
· pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l) simp only [hb, decide_false, Bool.false_eq_true, not_false_eq_true, List.filter_cons_of_neg,
Bool.decide_and, Bool.false_and, decide_not] pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬r a b⊢ List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) l
simpa using dropWhile_sorted_eq_filter_filter r a l hl.2 All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:¬¬r a b⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l) simp_all only [Decidable.not_not, decide_true, List.filter_cons_of_pos, Bool.decide_and,
decide_not] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a b⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
by_cases hba : r b a pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
· pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l) simp only [hba, decide_true, Bool.not_true, Bool.and_false, Bool.false_eq_true,
not_false_eq_true, List.filter_cons_of_neg] pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) l
rw [List.filter_cons_of_pos, pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
b :: List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
b :: List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) lpos.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ List.Pairwise r lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true dropWhile_sorted_eq_filter_filter pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
b :: List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) lpos.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ List.Pairwise r lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
b :: List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) lpos.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ List.Pairwise r lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true]pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
b :: List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) lpos.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ List.Pairwise r lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true
simp only [Bool.decide_and, decide_not, List.cons_append] pos.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ List.Pairwise r lpos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true
exact hl.2 pos α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:r b a⊢ (decide (r a b) && decide (r b a)) = true
simp_all All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l) simp only [hba, decide_false, Bool.and_false, Bool.false_eq_true, not_false_eq_true,
List.filter_cons_of_neg] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
have h1 : List.filter (fun c => decide (r a c) && decide (r c a)) l = [] := by α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:List.Pairwise r (b :: l)⊢ List.filter (fun c => decide (r a c)) (b :: l) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) (b :: l) neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
rw [@List.filter_eq_nil_iff α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && decide (r a_1 a)) = true α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && decide (r a_1 a)) = trueneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)] α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b a⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && decide (r a_1 a)) = trueneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
intro c hc α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ac:αhc:c ∈ l⊢ ¬(decide (r a c) && decide (r c a)) = trueneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
simp only [Bool.and_eq_true, decide_eq_true_eq, not_and] α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ac:αhc:c ∈ l⊢ r a c → ¬r c aneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
intro hac hca α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ac:αhc:c ∈ lhac:r a chca:r c a⊢ Falseneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
exact hba (IsTrans.trans b c a (hl.1 c hc) hca)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l =
List.filter (fun c => decide (r a c) && decide (r c a)) l ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)
rw [h1, neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c)) l = [] ++ List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l) neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
[] ++ List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l dropWhile_sorted_eq_filter_filter neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
[] ++ List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r lneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
[] ++ List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l]neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: (List.filter (fun c => decide (r a c ∧ r c a)) l ++ List.filter (fun c => decide (r a c ∧ ¬r c a)) l) =
[] ++ List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l
simp only [Bool.decide_and, h1, decide_not, List.nil_append] neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c) && !decide (r c a)) l =
List.filter (fun c => decide (r a c) && !decide (r c a)) (b :: l)neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l
rw [List.filter_cons_of_pos neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ b :: List.filter (fun c => decide (r a c) && !decide (r c a)) l =
b :: List.filter (fun c => decide (r a c) && !decide (r c a)) lneg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ (decide (r a b) && !decide (r b a)) = trueneg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ (decide (r a b) && !decide (r b a)) = trueneg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l]neg α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ (decide (r a b) && !decide (r b a)) = trueneg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l
simp_all only [List.filter_eq_nil_iff, Bool.and_eq_true, decide_eq_true_eq, not_and,
decide_true, decide_false, Bool.not_false, Bool.and_self] neg.hl α:Typer:α → α → Propinst✝¹:DecidableRel rinst✝:IsTrans α ra:αb:αl:List αhl:(∀ a' ∈ l, r b a') ∧ List.Pairwise r lhb:r a bhba:¬r b ah1:List.filter (fun c => decide (r a c) && decide (r c a)) l = []⊢ List.Pairwise r l
exact hl.2 All goals completed! 🐙
lemma filter_rel_eq_insertionSort {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a : α) : (l : List α) →
List.filter (fun c => r a c ∧ r c a) (l.insertionSort r) =
List.filter (fun c => r a c ∧ r c a) l
| [] => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r []) =
List.filter (fun c => decide (r a c ∧ r c a)) [] by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r []) =
List.filter (fun c => decide (r a c ∧ r c a)) [] simp All goals completed! 🐙
| b :: l => α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r (b :: l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r (b :: l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)
simp only [List.insertionSort_cons] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)
by_cases h : r a b ∧ r b a pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b a⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)
· pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b a⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) have hl := orderedInsert_filter_of_pos r b (fun c => r a c ∧ r c a) h
(List.insertionSort r l) (List.pairwise_insertionSort r l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b ∧ r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b ∧ r b a)) (List.insertionSort r l))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)
simp only [Bool.decide_and] at hl ⊢ pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [hl pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [List.orderedInsert_eq_take_drop pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
have ht : List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a))
(List.insertionSort r l)) = [] := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List α⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r (b :: l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [List.takeWhile_eq_nil_iff α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ ∀ (hl : 0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length),
¬(decide ¬r b ((List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).get ⟨0, hl⟩)) = true α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ ∀ (hl : 0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length),
¬(decide ¬r b ((List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).get ⟨0, hl⟩)) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))⊢ ∀ (hl : 0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length),
¬(decide ¬r b ((List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).get ⟨0, hl⟩)) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
intro hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length⊢ ¬(decide ¬r b ((List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).get ⟨0, hl⟩)) = truepos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
simp only [List.get_eq_getElem, decide_not, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not, Decidable.not_not] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
have hx := List.getElem_mem hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
simp only [List.mem_filter, List.mem_insertionSort, Bool.and_eq_true,
decide_eq_true_eq] at hx α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈ l ∧
r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∧
r (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] a⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
apply IsTrans.trans b a _ h.2 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈ l ∧
r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∧
r (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] a⊢ r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
simp_allpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [ht pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ [] ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ [] ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ [] ++
b ::
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
simp only [decide_not, List.nil_append] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ b ::
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (b :: l)
rw [List.filter_cons_of_pos pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ b ::
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
b :: List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ b ::
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
b :: List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ b ::
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
b :: List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp only [List.cons.injEq, true_and] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
have ih := filter_rel_eq_insertionSort r a l pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r l) = List.filter (fun c => decide (r a c ∧ r c a)) l⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp only [Bool.decide_and] at ih pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) l⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) lpos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
rw [← ih pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) l⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) l⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) l⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
have htd := List.takeWhile_append_dropWhile (p := fun b_1 => decide ¬r b b_1)
(l := List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp only [decide_not] at htd pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l)pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
conv_rhs => rw [← htd] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)| List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))
simp only [List.self_eq_append_left, List.takeWhile_eq_nil_iff, List.get_eq_getElem,
Bool.not_eq_eq_eq_not, Bool.not_true, decide_eq_false_iff_not, Decidable.not_not] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ∀ (hl : 0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length),
r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
intro hl pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).length⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
have hx := List.getElem_mem hl pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp only [List.mem_filter, List.mem_insertionSort, Bool.and_eq_true, decide_eq_true_eq] at hx pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈ l ∧
r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∧
r (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] a⊢ r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
apply IsTrans.trans b a _ h.2 pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl✝:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]ih:List.filter (fun c => decide (r a c) && decide (r c a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lhtd:List.takeWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) ++
List.dropWhile (fun b_1 => !decide (r b b_1))
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)hl:0 < (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)).lengthhx:(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∈ l ∧
r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] ∧
r (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0] a⊢ r a (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))[0]pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp_all only [decide_not, List.takeWhile_eq_nil_iff, List.get_eq_getElem,
Bool.not_eq_eq_eq_not, Bool.not_true, decide_eq_false_iff_not, Decidable.not_not,
List.takeWhile_append_dropWhile] pos α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:r a b ∧ r b ahl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.orderedInsert r b (List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l))ht:List.takeWhile (fun b_1 => decide ¬r b b_1)
(List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)) =
[]⊢ (decide (r a b) && decide (r b a)) = true
simp_all All goals completed! 🐙
· neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l) have hl := orderedInsert_filter_of_neg r b (fun c => r a c ∧ r c a) h (List.insertionSort r l) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b ∧ r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b ∧ r b a)) (List.insertionSort r l)⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c ∧ r c a)) (b :: l)
simp only [Bool.decide_and] at hl ⊢ neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun c => decide (r a c) && decide (r c a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [hl neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l) neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) (b :: l)
rw [List.filter_cons_of_neg neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ¬(decide (r a b) && decide (r b a)) = true neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ¬(decide (r a b) && decide (r b a)) = true]neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ¬(decide (r a b) && decide (r b a)) = true
have ih := filter_rel_eq_insertionSort r a l neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)ih:List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r l) = List.filter (fun c => decide (r a c ∧ r c a)) l⊢ List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l) =
List.filter (fun c => decide (r a c) && decide (r c a)) lneg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ¬(decide (r a b) && decide (r b a)) = true
simp_all only [not_and, Bool.decide_and] neg α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αb:αl:List αh:¬(r a b ∧ r b a)hl:List.filter (fun b => decide (r a b) && decide (r b a)) (List.orderedInsert r b (List.insertionSort r l)) =
List.filter (fun b => decide (r a b) && decide (r b a)) (List.insertionSort r l)⊢ ¬(decide (r a b) && decide (r b a)) = true
simpa using h All goals completed! 🐙
lemma insertionSort_of_eq_list {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a : α) (l1 l l2 : List α)
(h : ∀ b ∈ l, r a b ∧ r b a) :
List.insertionSort r (l1 ++ l ++ l2) =
(List.takeWhile (fun c => ¬ r a c) ((l1 ++ l2).insertionSort r))
++ (List.filter (fun c => r a c ∧ r c a) l1)
++ l
++ (List.filter (fun c => r a c ∧ r c a) l2)
++ (List.filter (fun c => r a c ∧ ¬ r c a) ((l1 ++ l2).insertionSort r)) := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
have hlt : List.takeWhile (fun c => ¬ r a c) ((l1 ++ l ++ l2).insertionSort r)
= List.takeWhile (fun c => ¬ r a c) ((l1 ++ l2).insertionSort r) := by
rw [takeWhile_sorted_eq_filter, α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2)) takeWhile_sorted_eq_filter α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
rw [← insertionSort_filter, α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2)) =
List.filter (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2)) =
List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2)) ← insertionSort_filter α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2)) =
List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2)) =
List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2)) =
List.insertionSort r (List.filter (fun b => decide ¬r a b) (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
congr 1 e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.filter (fun b => decide ¬r a b) (l1 ++ l ++ l2) = List.filter (fun b => decide ¬r a b) (l1 ++ l2)hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
simp only [decide_not, List.append_assoc, List.filter_append, List.append_cancel_left_eq,
List.append_left_eq_self, List.filter_eq_nil_iff, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not, Decidable.not_not] e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ ∀ a_1 ∈ l, r a a_1hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
exact fun b hb => (h b hb).1 hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
exact List.pairwise_insertionSort r (l1 ++ l2) hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.Pairwise r (List.insertionSort r (l1 ++ l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
exact List.pairwise_insertionSort r (l1 ++ l ++ l2) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
conv_lhs => rw [← List.takeWhile_append_dropWhile (p := fun c => decide ¬ r a c)
(l := (l1 ++ l ++ l2).insertionSort r), hlt] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))| List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.dropWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2))
simp only [decide_not, Bool.decide_and, List.append_assoc, List.append_cancel_left_eq] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))⊢ List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))
have h1 := dropWhile_sorted_eq_filter r a (List.insertionSort r (l1 ++ (l ++ l2))) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))
simp only [decide_not] at h1 α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))
rw [h1, α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (l1 ++ (l ++ l2)) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) dropWhile_sorted_eq_filter_filter, α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (l1 ++ (l ++ l2)) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) filter_rel_eq_insertionSort α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (l1 ++ (l ++ l2)) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (l1 ++ (l ++ l2)) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c ∧ r c a)) (l1 ++ (l ++ l2)) ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l1 ++
(l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp only [Bool.decide_and, List.filter_append, decide_not, List.append_assoc,
List.append_cancel_left_eq] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2)))) =
l ++
(List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2)))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
congr 1 e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) l = le_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp only [List.filter_eq_self, Bool.and_eq_true, decide_eq_true_eq] e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ ∀ b ∈ l, r a b ∧ r b ae_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
exact h e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && decide (r c a)) l2 ++
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
congr 1 e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
have h1 := insertionSort_filter r (fun c => decide (r a c) && !decide (r c a)) (l1 ++ (l ++ l2)) e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r (List.filter (fun b => decide ((decide (r a b) && !decide (r b a)) = true)) (l1 ++ (l ++ l2))) =
List.filter (fun b => decide ((decide (r a b) && !decide (r b a)) = true)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not, Bool.decide_and, decide_not, List.filter_append] at h1 e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
rw [← h1 e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))]e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
have h2 := insertionSort_filter r (fun c => decide (r a c) && !decide (r c a)) (l1 ++ l2) e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r (List.filter (fun b => decide ((decide (r a b) && !decide (r b a)) = true)) (l1 ++ l2)) =
List.filter (fun b => decide ((decide (r a b) && !decide (r b a)) = true)) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.not_eq_eq_eq_not, Bool.not_true,
decide_eq_false_iff_not, Bool.decide_and, decide_not, List.filter_append] at h2 e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun c => decide (r a c) && !decide (r c a)) (List.insertionSort r (l1 ++ l2))hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
rw [← h2 e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))]e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
congr e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
have hl : List.filter (fun b => decide (r a b) && !decide (r b a)) l = [] := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b a⊢ List.insertionSort r (l1 ++ l ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
l ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2)) e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
rw [@List.filter_eq_nil_iff α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && !decide (r a_1 a)) = true α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && !decide (r a_1 a)) = truee_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))] α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))⊢ ∀ a_1 ∈ l, ¬(decide (r a a_1) && !decide (r a_1 a)) = truee_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
intro c hc α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))c:αhc:c ∈ l⊢ ¬(decide (r a c) && !decide (r c a)) = truee_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp_alle_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
rw [hl e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ [] ++ List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ [] ++ List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))]e_a.e_a.e_a.e_a α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1✝:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))h1:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
(List.filter (fun b => decide (r a b) && !decide (r b a)) l ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2)) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ (l ++ l2)))h2:List.insertionSort r
(List.filter (fun b => decide (r a b) && !decide (r b a)) l1 ++
List.filter (fun b => decide (r a b) && !decide (r b a)) l2) =
List.filter (fun b => decide (r a b) && !decide (r b a)) (List.insertionSort r (l1 ++ l2))hl:List.filter (fun b => decide (r a b) && !decide (r b a)) l = []⊢ [] ++ List.filter (fun b => decide (r a b) && !decide (r b a)) l2 =
List.filter (fun b => decide (r a b) && !decide (r b a)) l2hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
simp only [List.nil_append] hl α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
exact List.pairwise_insertionSort r (l1 ++ (l ++ l2)) α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl:List αl2:List αh:∀ b ∈ l, r a b ∧ r b ahlt:List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l ++ l2)) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2))h1:List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2))) →
List.dropWhile (fun c => !decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2))) =
List.filter (fun c => decide (r a c)) (List.insertionSort r (l1 ++ (l ++ l2)))⊢ List.Pairwise r (List.insertionSort r (l1 ++ (l ++ l2)))
exact List.pairwise_insertionSort r (l1 ++ (l ++ l2)) All goals completed! 🐙lemma insertionSort_of_takeWhile_filter {α : Type} (r : α → α → Prop) [DecidableRel r]
[Std.Total r] [IsTrans α r] (a : α) (l1 l2 : List α) :
List.insertionSort r (l1 ++ l2) =
(List.takeWhile (fun c => ¬ r a c) ((l1 ++ l2).insertionSort r))
++ (List.filter (fun c => r a c ∧ r c a) l1)
++ (List.filter (fun c => r a c ∧ r c a) l2)
++ (List.filter (fun c => r a c ∧ ¬ r c a) ((l1 ++ l2).insertionSort r)) := by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ List.insertionSort r (l1 ++ l2) =
List.takeWhile (fun c => decide ¬r a c) (List.insertionSort r (l1 ++ l2)) ++
List.filter (fun c => decide (r a c ∧ r c a)) l1 ++
List.filter (fun c => decide (r a c ∧ r c a)) l2 ++
List.filter (fun c => decide (r a c ∧ ¬r c a)) (List.insertionSort r (l1 ++ l2))
simpa using insertionSort_of_eq_list r a l1 [] l2 (by α:Typer:α → α → Propinst✝²:DecidableRel rinst✝¹:Std.Total rinst✝:IsTrans α ra:αl1:List αl2:List α⊢ ∀ b ∈ [], r a b ∧ r b a simp All goals completed! 🐙)