Skip to content

Instantly share code, notes, and snippets.

@kbuzzard
Created February 23, 2018 20:26
Show Gist options
  • Save kbuzzard/b613f9854b110b1df288dabeafaeb105 to your computer and use it in GitHub Desktop.
Save kbuzzard/b613f9854b110b1df288dabeafaeb105 to your computer and use it in GitHub Desktop.
def extended_le : option ℕ → option ℕ → Prop
| _ none := true
| none (some n) := false
| (some m) (some n) := m ≤ n
instance : has_le (option ℕ) := ⟨extended_le⟩
lemma none_le_none : (none : option ℕ) ≤ none := trivial
lemma some_le_none (m : ℕ) : (some m) ≤ none := trivial
lemma le_none : ∀ (a : option ℕ) , a ≤ none
| none := none_le_none
| (some m) := some_le_none m
lemma none_not_le_some (n) : ¬ ((none : option ℕ) ≤ some n) := id
lemma some_le_some (m n : ℕ) : (some m) ≤ (some n) → m ≤ n := id
-- example : decidable_eq (option ℕ) := by apply_instance
lemma extended_le_refl : ∀ (a : option ℕ), a ≤ a
| none := none_le_none
| (some m) := show m ≤ m, from le_refl m
lemma extended_le_antisymm : ∀ (a b : option ℕ), a ≤ b → b ≤ a → a = b
| none none := λ _ _,rfl
| (some m) none := λ _ H, false.elim (none_not_le_some m H)
| none (some n) := λ H _, false.elim (none_not_le_some n H)
| (some m) (some n) := λ H₁ H₂, congr_arg some (nat.le_antisymm H₁ H₂)
lemma extended_le_trans : ∀ (a b c : option ℕ), a ≤ b → b ≤ c → a ≤ c
| _ _ none := λ _ _, le_none _
| _ none (some c) := λ _ H, false.elim (none_not_le_some c H)
| none (some b) (some c) := λ H _, false.elim (none_not_le_some b H)
| (some a) (some b) (some c) := λ H₁ H₂, nat.le_trans H₁ H₂
lemma extended_le_total : ∀ (a b : option ℕ), a ≤ b ∨ b ≤ a
| _ none := or.inl (le_none _)
| none _ := or.inr (le_none _)
| (some a) (some b) := nat.le_total
instance extended_decidable_le : ∀ a b : option ℕ, decidable (a ≤ b)
| none none := is_true (none_le_none)
| none (some n) := is_false (none_not_le_some n)
| (some m) none := is_true (some_le_none m)
| (some m) (some n) := match nat.decidable_le m n with
| is_true h := is_true h
| is_false h := is_false h
end
instance : decidable_linear_order (option ℕ) :=
{ le := extended_le,
le_refl := extended_le_refl,
le_trans := extended_le_trans,
le_antisymm := extended_le_antisymm,
le_total := extended_le_total,
decidable_le := extended_decidable_le,
}
#eval min (some 5:option ℕ) (some 6:option ℕ)
#eval min (none) (some 6)
#eval min (none) (none:option ℕ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment