2014-08-02 23:59:01 +00:00
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
2014-06-30 18:44:47 +00:00
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
-- Author: Leonardo de Moura
|
2014-08-20 22:49:44 +00:00
|
|
|
|
2014-08-28 01:39:55 +00:00
|
|
|
import logic.core.eq logic.classes.inhabited logic.classes.decidable
|
2014-09-03 23:00:38 +00:00
|
|
|
open eq_ops decidable
|
2014-08-01 01:40:09 +00:00
|
|
|
|
2014-08-02 23:59:01 +00:00
|
|
|
namespace option
|
2014-08-20 22:49:44 +00:00
|
|
|
|
2014-06-30 02:30:38 +00:00
|
|
|
inductive option (A : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
none {} : option A,
|
|
|
|
some : A → option A
|
2014-06-30 02:30:38 +00:00
|
|
|
|
2014-09-03 22:13:03 +00:00
|
|
|
theorem induction_on [protected] {A : Type} {p : option A → Prop} (o : option A)
|
2014-08-20 22:49:44 +00:00
|
|
|
(H1 : p none) (H2 : ∀a, p (some a)) : p o :=
|
2014-08-02 23:59:01 +00:00
|
|
|
option_rec H1 H2 o
|
|
|
|
|
2014-09-03 22:13:03 +00:00
|
|
|
definition rec_on [protected] {A : Type} {C : option A → Type} (o : option A)
|
2014-08-20 22:49:44 +00:00
|
|
|
(H1 : C none) (H2 : ∀a, C (some a)) : C o :=
|
2014-08-02 23:59:01 +00:00
|
|
|
option_rec H1 H2 o
|
|
|
|
|
|
|
|
definition is_none {A : Type} (o : option A) : Prop :=
|
|
|
|
option_rec true (λ a, false) o
|
|
|
|
|
|
|
|
theorem is_none_none {A : Type} : is_none (@none A) :=
|
|
|
|
trivial
|
|
|
|
|
|
|
|
theorem not_is_none_some {A : Type} (a : A) : ¬ is_none (some a) :=
|
|
|
|
not_false_trivial
|
|
|
|
|
|
|
|
theorem none_ne_some {A : Type} (a : A) : none ≠ some a :=
|
|
|
|
assume H : none = some a, absurd
|
|
|
|
(H ▸ is_none_none)
|
|
|
|
(not_is_none_some a)
|
|
|
|
|
|
|
|
theorem some_inj {A : Type} {a₁ a₂ : A} (H : some a₁ = some a₂) : a₁ = a₂ :=
|
2014-08-20 02:32:44 +00:00
|
|
|
congr_arg (option_rec a₁ (λ a, a)) H
|
2014-08-02 23:59:01 +00:00
|
|
|
|
2014-08-20 22:49:44 +00:00
|
|
|
theorem option_inhabited [instance] (A : Type) : inhabited (option A) :=
|
2014-08-20 02:32:44 +00:00
|
|
|
inhabited_mk none
|
2014-08-02 23:59:01 +00:00
|
|
|
|
2014-08-22 22:46:10 +00:00
|
|
|
theorem decidable_eq [instance] {A : Type} {H : ∀a₁ a₂ : A, decidable (a₁ = a₂)}
|
2014-08-20 22:49:44 +00:00
|
|
|
(o₁ o₂ : option A) : decidable (o₁ = o₂) :=
|
2014-08-02 23:59:01 +00:00
|
|
|
rec_on o₁
|
2014-08-26 05:54:44 +00:00
|
|
|
(rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))
|
2014-08-02 23:59:01 +00:00
|
|
|
(take a₁ : A, rec_on o₂
|
|
|
|
(inr (ne_symm (none_ne_some a₁)))
|
|
|
|
(take a₂ : A, decidable.rec_on (H a₁ a₂)
|
2014-08-26 05:54:44 +00:00
|
|
|
(assume Heq : a₁ = a₂, inl (Heq ▸ rfl))
|
2014-08-02 23:59:01 +00:00
|
|
|
(assume Hne : a₁ ≠ a₂, inr (assume Hn : some a₁ = some a₂, absurd (some_inj Hn) Hne))))
|
2014-08-20 22:49:44 +00:00
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
end option
|