1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 (* include "higher_order_defs/functions.ma". *)
16 include "basics/functions.ma".
17 include "basics/eq.ma".
19 ninductive nat : Type[0] ≝
23 interpretation "Natural numbers" 'N = nat.
25 default "natural numbers" cic:/matita/ng/arithmetics/nat/nat.ind.
27 alias num (instance 0) = "natural number".
34 ntheorem pred_Sn : ∀n. n = pred (S n).
37 ntheorem injective_S : injective nat nat S.
38 (* nwhd; #a; #b;#H;napplyS pred_Sn. *)
42 ntheorem inj_S : \forall n,m:nat.(S n)=(S m) \to n=m.
45 ntheorem not_eq_S: ∀n,m:nat. n ≠ m → S n ≠ S m.
48 ndefinition not_zero: nat → Prop ≝
53 ntheorem not_eq_O_S : ∀n:nat. O ≠ S n.
54 #n; #eqOS; nchange with (not_zero O); nrewrite > eqOS; //.
57 ntheorem not_eq_n_Sn : ∀n:nat. n ≠ S n.
58 #n; nelim n; /2/; nqed.
62 (n=O → P O) → (∀m:nat. (n=(S m) → P (S m))) → P n.
63 #n; #P; nelim n; /2/; nqed.
69 → (∀n,m:nat. R n m → R (S n) (S m))
71 #R; #ROn; #RSO; #RSS; #n; nelim n;//;
72 #n0; #Rn0m; #m; ncases m;/2/; nqed.
74 ntheorem decidable_eq_nat : \forall n,m:nat.decidable (n=m).
78 ##| #m; #Hind; ncases Hind; /3/; (* ??? /2/;#neqnm; /3/; *)
82 (*************************** plus ******************************)
87 | S p ⇒ S (plus p m) ].
89 interpretation "natural plus" 'plus x y = (plus x y).
91 ntheorem plus_n_O: ∀n:nat. n = n+O.
92 #n; nelim n; /2/; nqed.
94 ntheorem plus_n_Sm : ∀n,m:nat. S (n+m) = n+(S m).
95 #n; nelim n; nnormalize; //; nqed.
97 ntheorem plus_n_SO : ∀n:nat. S n = n+(S O).
100 ntheorem sym_plus: ∀n,m:nat. n+m = m+n.
101 #n; nelim n; nnormalize; //; nqed.
103 ntheorem associative_plus : associative nat plus.
104 #n; nelim n; nnormalize; //; nqed.
106 (* ntheorem assoc_plus : \forall n,m,p:nat. (n+m)+p = n+(m+p)
107 \def associative_plus. *)
109 ntheorem injective_plus_r: ∀n:nat.injective nat nat (λm.n+m).
110 #n; nelim n; nnormalize; /3/; nqed.
112 (* ntheorem inj_plus_r: \forall p,n,m:nat. p+n = p+m \to n=m
113 \def injective_plus_r. *)
115 ntheorem injective_plus_l: ∀m:nat.injective nat nat (λn.n+m).
118 (* ntheorem inj_plus_l: \forall p,n,m:nat. n+p = m+p \to n=m
119 \def injective_plus_l. *)
121 (*************************** times *****************************)
126 | S p ⇒ m+(times p m) ].
128 interpretation "natural times" 'times x y = (times x y).
130 ntheorem times_Sn_m: ∀n,m:nat. m+n*m = S n*m.
133 ntheorem times_n_O: ∀n:nat. O = n*O.
134 #n; nelim n; //; nqed.
136 ntheorem times_n_Sm : ∀n,m:nat. n+(n*m) = n*(S m).
137 #n; nelim n; nnormalize; /2/; nqed.
139 ntheorem times_O_to_O: ∀n,m:nat.n*m=O → n=O ∨ m=O.
140 napply nat_elim2; (* /2/ slow! *)
142 ##|#n; #H; @2; //; (* ?? *)
143 ##|#n; #m; #H; #H1; napply False_ind;napply not_eq_O_S;
144 (* why two steps? *) /2/;
148 ntheorem times_n_SO : ∀n:nat. n = n * S O.
153 ntheorem times_SSO_n : ∀n:nat. n + n = 2 * n.
160 alias num (instance 0) = "natural number".
161 lemma times_SSO: \forall n.2*(S n) = S(S(2*n)).
163 simplify.rewrite < plus_n_Sm.reflexivity.
166 theorem or_eq_eq_S: \forall n.\exists m.
167 n = (S(S O))*m \lor n = S ((S(S O))*m).
169 [apply (ex_intro ? ? O).
172 [apply (ex_intro ? ? a).
173 right.apply eq_f.assumption
174 |apply (ex_intro ? ? (S a)).
182 theorem symmetric_times : symmetric nat times.
185 [simplify.apply times_n_O.
186 | simplify.rewrite > H.apply times_n_Sm.]
189 variant sym_times : \forall n,m:nat. n*m = m*n \def
192 theorem distributive_times_plus : distributive nat times plus.
195 simplify.reflexivity.
199 rewrite > H. rewrite > assoc_plus.rewrite > assoc_plus.
200 apply eq_f.rewrite < assoc_plus. rewrite < (sym_plus ? z).
201 rewrite > assoc_plus.reflexivity. *)
204 variant distr_times_plus: \forall n,m,p:nat. n*(m+p) = n*m + n*p
205 \def distributive_times_plus.
207 theorem associative_times: associative nat times.
210 elim x. simplify.apply refl_eq.
216 rewrite > distr_times_plus.
218 rewrite < (sym_times (times n y) z).
219 rewrite < H.apply refl_eq.
223 variant assoc_times: \forall n,m,p:nat. (n*m)*p = n*(m*p) \def
226 lemma times_times: ∀x,y,z. x*(y*z) = y*(x*z).
228 demodulate. reflexivity.
229 (* autobatch paramodulation. *)