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 (* Ultima modifica: 05/08/2009 *)
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 ]);
38 nlemma option_destruct_some_none : ∀T.∀x:T.Some T x = None T → False.
40 nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
46 nlemma option_destruct_none_some : ∀T.∀x:T.None T = Some T x → False.
48 nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
54 nlemma symmetric_eqoption :
55 ∀T:Type.∀op1,op2:option T.∀f:T → T → bool.
56 (symmetricT T bool f) →
57 (eq_option T op1 op2 f = eq_option T op2 op1 f).
58 #T; #op1; #op2; #f; #H;
62 ##[ ##1: napply refl_eq
63 ##| ##2,3: #H; napply refl_eq
70 nlemma eq_to_eqoption :
71 ∀T.∀op1,op2:option T.∀f:T → T → bool.
72 (∀x1,x2:T.x1 = x2 → f x1 x2 = true) →
73 (op1 = op2 → eq_option T op1 op2 f = true).
74 #T; #op1; #op2; #f; #H;
78 ##[ ##1: #H1; napply refl_eq
79 ##| ##2: #a; #H1; nelim (option_destruct_none_some ?? H1)
80 ##| ##3: #a; #H1; nelim (option_destruct_some_none ?? H1)
81 ##| ##4: #a; #a0; #H1;
82 nrewrite > (H … (option_destruct_some_some … H1));
87 nlemma eqoption_to_eq :
88 ∀T.∀op1,op2:option T.∀f:T → T → bool.
89 (∀x1,x2:T.f x1 x2 = true → x1 = x2) →
90 (eq_option T op1 op2 f = true → op1 = op2).
91 #T; #op1; #op2; #f; #H;
95 ##[ ##1: #H1; napply refl_eq
96 ##| ##2,3: #a; #H1; napply (bool_destruct … H1)
97 ##| ##4: #a; #a0; #H1;
103 nlemma decidable_option : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀x,y:option T.decidable (x = y).
105 ##[ ##1: #y; ncases y;
106 ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
107 ##| ##2: #yy; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
108 nnormalize; #H1; napply (option_destruct_none_some T … H1)
110 ##| ##2: #xx; #y; ncases y;
111 ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
112 nnormalize; #H2; napply (option_destruct_some_none T … H2)
113 ##| ##2: #yy; nnormalize; napply (or2_elim (xx = yy) (xx ≠ yy) ? (H …));
114 ##[ ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
115 nnormalize; #H2; napply (H1 (option_destruct_some_some T … H2))
116 ##| ##1: #H1; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
117 nrewrite > H1; napply refl_eq
123 nlemma neq_to_neqoption :
124 ∀T.∀op1,op2:option T.∀f:T → T → bool.
125 (∀x1,x2:T.x1 ≠ x2 → f x1 x2 = false) →
126 (op1 ≠ op2 → eq_option T op1 op2 f = false).
128 ##[ ##1: #op2; ncases op2;
129 ##[ ##1: nnormalize; #f; #H; #H1; nelim (H1 (refl_eq …))
130 ##| ##2: #yy; #f; #H; nnormalize; #H1; napply refl_eq
132 ##| ##2: #xx; #op2; ncases op2;
133 ##[ ##1: #f; #H; nnormalize; #H1; napply refl_eq
134 ##| ##2: #yy; #f; #H; nnormalize; #H1; napply (H xx yy …);
135 nnormalize; #H2; nrewrite > H2 in H1:(%); #H1;
136 napply (H1 (refl_eq …))
141 nlemma neqoption_to_neq :
142 ∀T.∀op1,op2:option T.∀f:T → T → bool.
143 (∀x1,x2:T.f x1 x2 = false → x1 ≠ x2) →
144 (eq_option T op1 op2 f = false → op1 ≠ op2).
146 ##[ ##1: #op2; ncases op2;
147 ##[ ##1: nnormalize; #f; #H; #H1; napply (bool_destruct … H1)
148 ##| ##2: #yy; #f; #H; nnormalize; #H1; #H2; napply (option_destruct_none_some T … H2)
150 ##| ##2: #xx; #op2; ncases op2;
151 ##[ ##1: nnormalize; #f; #H; #H1; #H2; napply (option_destruct_some_none T … H2)
152 ##| ##2: #yy; #f; #H; nnormalize; #H1; #H2; napply (H xx yy H1 ?);
153 napply (option_destruct_some_some T … H2)