Skip to content

Instantly share code, notes, and snippets.

@arademaker
Created December 4, 2024 16:53
Show Gist options
  • Save arademaker/57ccbe9bce39b7afd5a413eaa0e646e9 to your computer and use it in GitHub Desktop.
Save arademaker/57ccbe9bce39b7afd5a413eaa0e646e9 to your computer and use it in GitHub Desktop.
split proof reduction size
def split [Inhabited a] [LE a] [DecidableRel (α := a) (· ≤ ·)]
: List a → (a × List a × List a)
| [] => (default, [], [])
| x :: xs =>
let rec op x acc :=
if x ≤ acc.1
then (x, acc.1 :: acc.2.2, acc.2.1)
else (acc.1, x :: acc.2.2, acc.2.1)
xs.foldr op (x, [], [])
#eval split ([1,2,3,4,5] : List Nat)
theorem split_left_le [Inhabited a] [LE a] [DecidableRel (α := a) (· ≤ ·)]
(xs : List a) : (split xs).2.1.length ≤ xs.length := by
unfold split
split ; simp
rename_i x xs
induction xs with
| nil => simp [split]
| cons y xs ih =>
unfold List.foldr
simp [split.op]
split ; simp
induction xs with
| nil => simp [List.foldr_nil]
| cons y ys ih₁ =>
simp [List.foldr_cons]
cases decide (x ≤ y) with
| inl h =>
simp [h]
exact Nat.succ_le_succ ih
| inr h =>
simp [h]
exact ih
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment