]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/common/option_lemmas.ma
freescale porting
[helm.git] / helm / software / matita / contribs / ng_assembly / common / option_lemmas.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "common/option.ma".
24 include "num/bool_lemmas.ma".
25
26 (* ****** *)
27 (* OPTION *)
28 (* ****** *)
29
30 nlemma option_destruct_some_some : ∀T.∀x1,x2:T.Some T x1 = Some T x2 → x1 = x2.
31  #T; #x1; #x2; #H;
32  nchange with (match Some T x2 with [ None ⇒ False | Some a ⇒ x1 = a ]);
33  nrewrite < H;
34  nnormalize;
35  napply refl_eq.
36 nqed.
37
38 (* !!! da togliere *)
39 nlemma option_destruct_some_none : ∀T.∀x:T.Some T x = None T → False.
40  #T; #x; #H;
41  nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
42  nrewrite > H;
43  nnormalize;
44  napply I.
45 nqed.
46
47 (* !!! da togliere *)
48 nlemma option_destruct_none_some : ∀T.∀x:T.None T = Some T x → False.
49  #T; #x; #H;
50  nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
51  nrewrite < H;
52  nnormalize;
53  napply I.
54 nqed.
55
56 nlemma symmetric_eqoption :
57 ∀T:Type.∀f:T → T → bool.∀op1,op2:option T.
58  (symmetricT T bool f) →
59  (eq_option T f op1 op2 = eq_option T f op2 op1).
60  #T; #f; #op1; #op2; #H;
61  nelim op1;
62  nelim op2;
63  nnormalize;
64  ##[ ##1: napply refl_eq
65  ##| ##2,3: #H; napply refl_eq
66  ##| ##4: #a; #a0;
67           nrewrite > (H a0 a);
68           napply refl_eq
69  ##]
70 nqed.
71
72 nlemma eq_to_eqoption :
73 ∀T.∀f:T → T → bool.∀op1,op2:option T.
74  (∀x1,x2:T.x1 = x2 → f x1 x2 = true) →
75  (op1 = op2 → eq_option T f op1 op2 = true).
76  #T; #f; #op1; #op2; #H;
77  nelim op1;
78  nelim op2;
79  nnormalize;
80  ##[ ##1: #H1; napply refl_eq
81  ##| ##2: #a; #H1;
82          (* !!! ndestruct: assert false *)
83          nelim (option_destruct_none_some ?? H1)
84  ##| ##3: #a; #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));
89           napply refl_eq
90  ##]
91 nqed.
92
93 nlemma eqoption_to_eq :
94 ∀T.∀f:T → T → bool.∀op1,op2:option T.
95  (∀x1,x2:T.f x1 x2 = true → x1 = x2) →
96  (eq_option T f op1 op2 = true → op1 = op2).
97  #T; #f; #op1; #op2; #H;
98  nelim op1;
99  nelim op2;
100  nnormalize;
101  ##[ ##1: #H1; napply refl_eq
102  ##| ##2,3: #a; #H1; ndestruct (*napply (bool_destruct … H1)*)
103  ##| ##4: #a; #a0; #H1;
104           nrewrite > (H … H1);
105           napply refl_eq
106  ##]
107 nqed.
108
109 nlemma decidable_option : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀x,y:option T.decidable (x = y).
110  #T; #H; #x; nelim x;
111  ##[ ##1: #y; ncases y;
112           ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
113           ##| ##2: #yy; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
114                    nnormalize; #H1;
115                    (* !!! ndestruct: assert false *)
116                    napply (option_destruct_none_some T … H1)
117           ##]
118  ##| ##2: #xx; #y; ncases y;
119           ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
120                    nnormalize; #H2;
121                    (* !!! ndestruct: assert false *)
122                    napply (option_destruct_some_none T … H2)
123           ##| ##2: #yy; nnormalize; napply (or2_elim (xx = yy) (xx ≠ yy) ? (H …));
124                    ##[ ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
125                             nnormalize; #H2;
126                             napply (H1 (option_destruct_some_some T … H2))
127                    ##| ##1: #H1; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
128                             nrewrite > H1; napply refl_eq
129                    ##]
130           ##]
131  ##]
132 nqed.
133
134 nlemma neq_to_neqoption :
135 ∀T.∀f:T → T → bool.∀op1,op2:option T.
136  (∀x1,x2:T.x1 ≠ x2 → f x1 x2 = false) →
137  (op1 ≠ op2 → eq_option T f op1 op2 = false).
138  #T; #f; #op1; nelim op1;
139  ##[ ##1: #op2; ncases op2;
140           ##[ ##1: nnormalize; #H; #H1; nelim (H1 (refl_eq …))
141           ##| ##2: #yy; #H; nnormalize; #H1; napply refl_eq
142           ##]
143  ##| ##2: #xx; #op2; ncases op2;
144           ##[ ##1: #H; nnormalize; #H1; napply refl_eq
145           ##| ##2: #yy; #H; nnormalize; #H1; napply (H xx yy …);
146                    nnormalize; #H2; nrewrite > H2 in H1:(%); #H1;
147                    napply (H1 (refl_eq …))
148           ##]
149  ##]
150 nqed.
151
152 nlemma neqoption_to_neq :
153 ∀T.∀f:T → T → bool.∀op1,op2:option T.
154  (∀x1,x2:T.f x1 x2 = false → x1 ≠ x2) →
155  (eq_option T f op1 op2 = false → op1 ≠ op2).
156  #T; #f; #op1; nelim op1;
157  ##[ ##1: #op2; ncases op2;
158           ##[ ##1: nnormalize; #H; #H1;
159                    ndestruct (*napply (bool_destruct … H1)*)
160           ##| ##2: #yy; #H; nnormalize; #H1; #H2;
161                    (* !!! ndestruct: assert false *)
162                    napply (option_destruct_none_some T … H2)
163           ##]
164  ##| ##2: #xx; #op2; ncases op2;
165           ##[ ##1: nnormalize; #H; #H1; #H2;
166                    (* !!! ndestruct: assert false *)
167                    napply (option_destruct_some_none T … H2)
168           ##| ##2: #yy; #H; nnormalize; #H1; #H2; napply (H xx yy H1 ?);
169                    napply (option_destruct_some_some T … H2)
170           ##]
171  ##]
172 nqed.