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 "hints_declaration.ma".
17 include "basics/functions.ma".
18 include "basics/eq.ma".
20 ninductive nat : Type[0] ≝
24 interpretation "Natural numbers" 'N = nat.
26 alias num (instance 0) = "nnatural number".
30 {n:>nat; is_pos: n ≠ 0}.
32 ncoercion nat_to_pos: ∀n:nat. n ≠0 →pos ≝ mk_pos on
35 (* default "natural numbers" cic:/matita/ng/arithmetics/nat/nat.ind.
43 ntheorem pred_Sn : ∀n. n = pred (S n).
46 ntheorem injective_S : injective nat nat S.
50 ntheorem inj_S : \forall n,m:nat.(S n)=(S m) \to n=m.
53 ntheorem not_eq_S: ∀n,m:nat. n ≠ m → S n ≠ S m.
56 ndefinition not_zero: nat → Prop ≝
61 ntheorem not_eq_O_S : ∀n:nat. O ≠ S n.
62 #n; #eqOS; nchange with (not_zero O); nrewrite > eqOS; //.
65 ntheorem not_eq_n_Sn : ∀n:nat. n ≠ S n.
66 #n; nelim n; /2/; nqed.
70 (n=O → P O) → (∀m:nat. (n=(S m) → P (S m))) → P n.
71 #n; #P; nelim n; /2/; nqed.
77 → (∀n,m:nat. R n m → R (S n) (S m))
79 #R; #ROn; #RSO; #RSS; #n; nelim n;//;
80 #n0; #Rn0m; #m; ncases m;/2/; nqed.
82 ntheorem decidable_eq_nat : \forall n,m:nat.decidable (n=m).
86 ##| #m; #Hind; ncases Hind; /3/; (* ??? /2/;#neqnm; /3/; *)
90 (*************************** plus ******************************)
95 | S p ⇒ S (plus p m) ].
97 interpretation "natural plus" 'plus x y = (plus x y).
99 ntheorem plus_O_n: ∀n:nat. n = 0+n.
103 ntheorem plus_Sn_m: ∀n,m:nat. S (n + m) = S n + m.
107 ntheorem plus_n_O: ∀n:nat. n = n+0.
108 #n; nelim n; nnormalize; //; nqed.
110 ntheorem plus_n_Sm : ∀n,m:nat. S (n+m) = n + S m.
111 #n; nelim n; nnormalize; //; nqed.
114 ntheorem plus_Sn_m1: ∀n,m:nat. S m + n = n + S m.
115 #n; nelim n; nnormalize; //; nqed.
119 ntheorem plus_n_SO : ∀n:nat. S n = n+S O.
122 ntheorem symmetric_plus: symmetric ? plus.
123 #n; nelim n; nnormalize; //; nqed.
125 ntheorem associative_plus : associative nat plus.
126 #n; nelim n; nnormalize; //; nqed.
128 ntheorem assoc_plus1: ∀a,b,c. b + (a + c) = a + (b + c).
131 ntheorem injective_plus_r: ∀n:nat.injective nat nat (λm.n+m).
132 #n; nelim n; nnormalize; /3/; nqed.
134 (* ntheorem inj_plus_r: \forall p,n,m:nat. p+n = p+m \to n=m
135 \def injective_plus_r.
137 ntheorem injective_plus_l: ∀m:nat.injective nat nat (λn.n+m).
140 (* ntheorem inj_plus_l: \forall p,n,m:nat. n+p = m+p \to n=m
141 \def injective_plus_l. *)
143 (*************************** times *****************************)
148 | S p ⇒ m+(times p m) ].
150 interpretation "natural times" 'times x y = (times x y).
152 ntheorem times_Sn_m: ∀n,m:nat. m+n*m = S n*m.
155 ntheorem times_O_n: ∀n:nat. O = O*n.
158 ntheorem times_n_O: ∀n:nat. O = n*O.
159 #n; nelim n; //; nqed.
161 ntheorem times_n_Sm : ∀n,m:nat. n+(n*m) = n*(S m).
162 #n; nelim n; nnormalize; //; nqed.
164 ntheorem symmetric_times : symmetric nat times.
165 #n; nelim n; nnormalize; //; nqed.
167 (* variant sym_times : \forall n,m:nat. n*m = m*n \def
170 ntheorem distributive_times_plus : distributive nat times plus.
171 #n; nelim n; nnormalize; //; nqed.
173 ntheorem distributive_times_plus_r:
174 \forall a,b,c:nat. (b+c)*a = b*a + c*a.
177 ntheorem associative_times: associative nat times.
178 #n; nelim n; nnormalize; //; nqed.
180 nlemma times_times: ∀x,y,z. x*(y*z) = y*(x*z).
183 (* ci servono questi risultati?
184 ntheorem times_O_to_O: ∀n,m:nat.n*m=O → n=O ∨ m=O.
185 napply nat_elim2; /2/;
186 #n; #m; #H; nnormalize; #H1; napply False_ind;napply not_eq_O_S;
189 ntheorem times_n_SO : ∀n:nat. n = n * S O.
192 ntheorem times_SSO_n : ∀n:nat. n + n = (S(S O)) * n.
193 nnormalize; //; nqed.
195 nlemma times_SSO: \forall n.(S(S O))*(S n) = S(S((S(S O))*n)).
198 ntheorem or_eq_eq_S: \forall n.\exists m.
199 n = (S(S O))*m \lor n = S ((S(S O))*m).
202 ##|#a; #H; nelim H; #b;#or;nelim or;#aeq;
204 ##|@ (S b); @ 1; /2/;
209 (************************** compare ****************************)