]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/nat/times.ma
ec0f861998c2314536888bae8882de035fb21682
[helm.git] / helm / software / matita / library / nat / times.ma
1 (**************************************************************************)
2 (*       __                                                               *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 set "baseuri" "cic:/matita/nat/times".
16
17 include "nat/plus.ma".
18
19 let rec times n m \def 
20  match n with 
21  [ O \Rightarrow O
22  | (S p) \Rightarrow m+(times p m) ].
23
24 interpretation "natural times" 'times x y = (cic:/matita/nat/times/times.con x y).
25
26 theorem times_n_O: \forall n:nat. O = n*O.
27 intros.elim n.
28 simplify.reflexivity.
29 simplify.assumption.
30 qed.
31
32 theorem times_n_Sm : 
33 \forall n,m:nat. n+(n*m) = n*(S m).
34 intros.elim n.
35 simplify.reflexivity.
36 simplify.apply eq_f.rewrite < H.
37 transitivity ((n1+m)+n1*m).symmetry.apply assoc_plus.
38 transitivity ((m+n1)+n1*m).
39 apply eq_f2.
40 apply sym_plus.
41 reflexivity.
42 apply assoc_plus.
43 qed.
44
45 theorem times_O_to_O: \forall n,m:nat.n*m = O \to n = O \lor m= O.
46 apply nat_elim2;intros
47   [left.reflexivity
48   |right.reflexivity
49   |apply False_ind.
50    simplify in H1.
51    apply (not_eq_O_S ? (sym_eq  ? ? ? H1))
52   ]
53 qed.
54
55 theorem times_n_SO : \forall n:nat. n = n * S O.
56 intros.
57 rewrite < times_n_Sm.
58 rewrite < times_n_O.
59 rewrite < plus_n_O.
60 reflexivity.
61 qed.
62
63 theorem times_SSO_n : \forall n:nat. n + n = S (S O) * n.
64 intros.
65 simplify.
66 rewrite < plus_n_O.
67 reflexivity.
68 qed.
69
70 alias num (instance 0) = "natural number".
71 lemma times_SSO: \forall n.2*(S n) = S(S(2*n)).
72 intro.simplify.rewrite < plus_n_Sm.reflexivity.
73 qed.
74
75 theorem or_eq_eq_S: \forall n.\exists m. 
76 n = (S(S O))*m \lor n = S ((S(S O))*m).
77 intro.elim n
78   [apply (ex_intro ? ? O).
79    left.reflexivity
80   |elim H.elim H1
81     [apply (ex_intro ? ? a).
82      right.apply eq_f.assumption
83     |apply (ex_intro ? ? (S a)).
84      left.rewrite > H2.
85      apply sym_eq.
86      apply times_SSO
87     ]
88   ]
89 qed.
90
91 theorem symmetric_times : symmetric nat times. 
92 unfold symmetric.
93 intros.elim x.
94 simplify.apply times_n_O.
95 simplify.rewrite > H.apply times_n_Sm.
96 qed.
97
98 variant sym_times : \forall n,m:nat. n*m = m*n \def
99 symmetric_times.
100
101 theorem distributive_times_plus : distributive nat times plus.
102 unfold distributive.
103 intros.elim x.
104 simplify.reflexivity.
105 simplify.rewrite > H. rewrite > assoc_plus.rewrite > assoc_plus.
106 apply eq_f.rewrite < assoc_plus. rewrite < (sym_plus ? z).
107 rewrite > assoc_plus.reflexivity.
108 qed.
109
110 variant distr_times_plus: \forall n,m,p:nat. n*(m+p) = n*m + n*p
111 \def distributive_times_plus.
112
113 theorem associative_times: associative nat times.
114 unfold associative.intros.
115 elim x.simplify.apply refl_eq.
116 simplify.rewrite < sym_times.
117 rewrite > distr_times_plus.
118 rewrite < sym_times.
119 rewrite < (sym_times (times n y) z).
120 rewrite < H.apply refl_eq.
121 qed.
122
123 variant assoc_times: \forall n,m,p:nat. (n*m)*p = n*(m*p) \def
124 associative_times.