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/option.ma".
24 include "num/bool_lemmas.ma".
30 nlemma option_destruct_some_some : ∀T.∀x1,x2:T.Some T x1 = Some T x2 → x1 = x2.
32 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 ]);
48 nlemma option_destruct_none_some : ∀T.∀x:T.None T = Some T x → False.
50 nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
56 nlemma symmetric_eqoption :
57 ∀T:Type.∀f:T → T → bool.
58 (symmetricT T bool f) →
60 (eq_option T f op1 op2 = eq_option T f op2 op1)).
62 #op1; #op2; nelim op1; nelim op2;
64 ##[ ##1: napply refl_eq
65 ##| ##2,3: #H; napply refl_eq
72 nlemma eq_to_eqoption :
74 (∀x1,x2:T.x1 = x2 → f x1 x2 = true) →
76 (op1 = op2 → eq_option T f op1 op2 = true)).
78 #op1; #op2; nelim op1; nelim op2;
80 ##[ ##1: #H1; napply refl_eq
82 (* !!! ndestruct: assert false *)
83 nelim (option_destruct_none_some ?? H1)
85 (* !!! ndestruct: assert false *)
86 nelim (option_destruct_some_none ?? H1)
87 ##| ##4: #a; #a0; #H1;
88 nrewrite > (H … (option_destruct_some_some … H1));
93 nlemma eqoption_to_eq :
95 (∀x1,x2:T.f x1 x2 = true → x1 = x2) →
97 (eq_option T f op1 op2 = true → op1 = op2)).
99 #op1; #op2; nelim op1; nelim op2;
101 ##[ ##1: #H1; napply refl_eq
102 ##| ##2,3: #a; #H1; ndestruct (*napply (bool_destruct … H1)*)
103 ##| ##4: #a; #a0; #H1;
109 nlemma decidable_option :
110 ∀T.(Πx,y:T.decidable (x = y)) →
111 (∀x,y:option T.decidable (x = y)).
113 ##[ ##1: #y; ncases y;
114 ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
115 ##| ##2: #yy; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
117 (* !!! ndestruct: assert false *)
118 napply (option_destruct_none_some T … H1)
120 ##| ##2: #xx; #y; ncases y;
121 ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
123 (* !!! ndestruct: assert false *)
124 napply (option_destruct_some_none T … H2)
125 ##| ##2: #yy; nnormalize; napply (or2_elim (xx = yy) (xx ≠ yy) ? (H …));
126 ##[ ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
128 napply (H1 (option_destruct_some_some T … H2))
129 ##| ##1: #H1; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
130 nrewrite > H1; napply refl_eq
136 nlemma neq_to_neqoption :
138 (∀x1,x2:T.x1 ≠ x2 → f x1 x2 = false) →
140 (op1 ≠ op2 → eq_option T f op1 op2 = false)).
141 #T; #f; #H; #op1; nelim op1;
142 ##[ ##1: #op2; ncases op2;
143 ##[ ##1: nnormalize; #H1; nelim (H1 (refl_eq …))
144 ##| ##2: #yy; nnormalize; #H1; napply refl_eq
146 ##| ##2: #xx; #op2; ncases op2;
147 ##[ ##1: nnormalize; #H1; napply refl_eq
148 ##| ##2: #yy; nnormalize; #H1; napply (H xx yy …);
149 nnormalize; #H2; nrewrite > H2 in H1:(%); #H1;
150 napply (H1 (refl_eq …))
155 nlemma neqoption_to_neq :
157 (∀x1,x2:T.f x1 x2 = false → x1 ≠ x2) →
159 (eq_option T f op1 op2 = false → op1 ≠ op2)).
160 #T; #f; #H; #op1; nelim op1;
161 ##[ ##1: #op2; ncases op2;
162 ##[ ##1: nnormalize; #H1;
163 ndestruct (*napply (bool_destruct … H1)*)
164 ##| ##2: #yy; nnormalize; #H1; #H2;
165 (* !!! ndestruct: assert false *)
166 napply (option_destruct_none_some T … H2)
168 ##| ##2: #xx; #op2; ncases op2;
169 ##[ ##1: nnormalize; #H1; #H2;
170 (* !!! ndestruct: assert false *)
171 napply (option_destruct_some_none T … H2)
172 ##| ##2: #yy; nnormalize; #H1; #H2; napply (H xx yy H1 ?);
173 napply (option_destruct_some_some T … H2)