diff --git a/Invariant.lean b/Invariant.lean index f7b0335..c298ab1 100644 --- a/Invariant.lean +++ b/Invariant.lean @@ -1,47 +1,20 @@ +inductive StrictlyIncreasing : List Nat → Prop +| empty : StrictlyIncreasing [] +| singleton : StrictlyIncreasing [x] +| cons : (∀a, a ∈ xs → a > x) → StrictlyIncreasing xs → StrictlyIncreasing (x::xs) + -- sorted set of natural numbers -structure NatSet where - items : List Nat - invariant : List.Pairwise (· < ·) items +abbrev NatSet := { xs : List Nat // StrictlyIncreasing xs } namespace NatSet --- TODO: binary search -instance : Membership Nat NatSet where - mem l x := x ∈ l.items +def empty : NatSet := ⟨[], .empty⟩ +def singleton (x : Nat) : NatSet := ⟨[x], .singleton⟩ -instance (x : Nat) (l : NatSet) : Decidable (x ∈ l) := - List.instDecidableMemOfLawfulBEq x l.items - -def empty : NatSet := ⟨[], by simp⟩ - -def singleton (x : Nat) : NatSet := - ⟨[x], by simp⟩ - -def remove (x : Nat) (l : NatSet) : NatSet where - items := l.items.erase x - invariant := List.Pairwise.erase x l.invariant - -def insert (x : Nat) : NatSet → NatSet -| ⟨[], h⟩ => ⟨[x], List.pairwise_singleton ..⟩ -| l@⟨a::as, h⟩ => - if a = x - then l - else if hlt : x < a - then ⟨ - x::a::as, - by - apply List.pairwise_cons.mpr - constructor - · intro a' hmem - have := List.Pairwise.iff - sorry - · assumption - ⟩ +def remove (x : Nat) : NatSet → NatSet +| ⟨[], _⟩ => empty +| ⟨a::xs, h⟩ => + let tail := ⟨xs, by simp⟩ + if a = x then tail else - let ⟨rest, hr⟩ := (NatSet.mk as (List.Pairwise.of_cons h)).insert x - ⟨ - a::rest, - by - simp [*] - sorry, - ⟩ + ⟨a::xs, h⟩