1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Sviluppo: 2008-2010 *)
21 (* ********************************************************************** *)
23 include "common/comp.ma".
24 include "common/option_base.ma".
25 include "num/bool_lemmas.ma".
31 nlemma option_destruct_some_some : ∀T.∀x1,x2:T.Some T x1 = Some T x2 → x1 = x2.
33 nchange with (match Some T x2 with [ None ⇒ False | Some a ⇒ x1 = a ]);
39 nlemma option_destruct_some_none : ∀T.∀x:T.Some T x = None T → False.
41 nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
47 nlemma option_destruct_none_some : ∀T.∀x:T.None T = Some T x → False.
49 nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
55 nlemma symmetric_eqoption :
56 ∀T:Type.∀f:T → T → bool.
57 (symmetricT T bool f) →
59 (eq_option T f op1 op2 = eq_option T f op2 op1)).
61 #op1; #op2; nelim op1; nelim op2;
63 ##[ ##1: napply refl_eq
64 ##| ##2,3: #H; napply refl_eq
71 nlemma eq_to_eqoption :
73 (∀x1,x2:T.x1 = x2 → f x1 x2 = true) →
75 (op1 = op2 → eq_option T f op1 op2 = true)).
77 #op1; #op2; nelim op1; nelim op2;
79 ##[ ##1: #H1; napply refl_eq
81 (* !!! ndestruct: assert false *)
82 nelim (option_destruct_none_some ?? H1)
84 (* !!! ndestruct: assert false *)
85 nelim (option_destruct_some_none ?? H1)
86 ##| ##4: #a; #a0; #H1;
87 nrewrite > (H … (option_destruct_some_some … H1));
92 nlemma eqoption_to_eq :
94 (∀x1,x2:T.f x1 x2 = true → x1 = x2) →
96 (eq_option T f op1 op2 = true → op1 = op2)).
98 #op1; #op2; nelim op1; nelim op2;
100 ##[ ##1: #H1; napply refl_eq
101 ##| ##2,3: #a; #H1; ndestruct (*napply (bool_destruct … H1)*)
102 ##| ##4: #a; #a0; #H1;
108 nlemma decidable_option :
109 ∀T.(Πx,y:T.decidable (x = y)) →
110 (∀x,y:option T.decidable (x = y)).
112 ##[ ##1: #y; ncases y;
113 ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
114 ##| ##2: #yy; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
116 (* !!! ndestruct: assert false *)
117 napply (option_destruct_none_some T … H1)
119 ##| ##2: #xx; #y; ncases y;
120 ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
122 (* !!! ndestruct: assert false *)
123 napply (option_destruct_some_none T … H2)
124 ##| ##2: #yy; nnormalize; napply (or2_elim (xx = yy) (xx ≠ yy) ? (H …));
125 ##[ ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
127 napply (H1 (option_destruct_some_some T … H2))
128 ##| ##1: #H1; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
129 nrewrite > H1; napply refl_eq
135 nlemma neq_to_neqoption :
137 (∀x1,x2:T.x1 ≠ x2 → f x1 x2 = false) →
139 (op1 ≠ op2 → eq_option T f op1 op2 = false)).
140 #T; #f; #H; #op1; nelim op1;
141 ##[ ##1: #op2; ncases op2;
142 ##[ ##1: nnormalize; #H1; nelim (H1 (refl_eq …))
143 ##| ##2: #yy; nnormalize; #H1; napply refl_eq
145 ##| ##2: #xx; #op2; ncases op2;
146 ##[ ##1: nnormalize; #H1; napply refl_eq
147 ##| ##2: #yy; nnormalize; #H1; napply (H xx yy …);
148 nnormalize; #H2; nrewrite > H2 in H1:(%); #H1;
149 napply (H1 (refl_eq …))
154 nlemma neqoption_to_neq :
156 (∀x1,x2:T.f x1 x2 = false → x1 ≠ x2) →
158 (eq_option T f op1 op2 = false → op1 ≠ op2)).
159 #T; #f; #H; #op1; nelim op1;
160 ##[ ##1: #op2; ncases op2;
161 ##[ ##1: nnormalize; #H1;
162 ndestruct (*napply (bool_destruct … H1)*)
163 ##| ##2: #yy; nnormalize; #H1; #H2;
164 (* !!! ndestruct: assert false *)
165 napply (option_destruct_none_some T … H2)
167 ##| ##2: #xx; #op2; ncases op2;
168 ##[ ##1: nnormalize; #H1; #H2;
169 (* !!! ndestruct: assert false *)
170 napply (option_destruct_some_none T … H2)
171 ##| ##2: #yy; nnormalize; #H1; #H2; napply (H xx yy H1 ?);
172 napply (option_destruct_some_some T … H2)
177 nlemma option_is_comparable :
178 comparable → comparable.
179 #T; napply (mk_comparable (option T));
181 ##| napply (λx.false)
182 ##| napply (eq_option … (eqc T))
183 ##| napply (eqoption_to_eq … (eqc T));
185 ##| napply (eq_to_eqoption … (eqc T));
187 ##| napply (neqoption_to_neq … (eqc T));
188 napply (neqc_to_neq T)
189 ##| napply (neq_to_neqoption … (eqc T));
190 napply (neq_to_neqc T)
191 ##| napply decidable_option;
192 napply (decidable_c T)
193 ##| napply symmetric_eqoption;
194 napply (symmetric_eqc T)
198 unification hint 0 ≔ S: comparable;
200 X ≟ (option_is_comparable S)
201 (*********************************************) ⊢