]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/nat/times.ma
- transcript: we have now two styles of mma's from grafite:
[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 include "nat/plus.ma".
16
17 let rec times n m \def 
18  match n with 
19  [ O \Rightarrow O
20  | (S p) \Rightarrow m+(times p m) ].
21
22 interpretation "natural times" 'times x y = (times x y).
23
24 theorem times_Sn_m:
25 \forall n,m:nat. m+n*m = S n*m.
26 intros. reflexivity.
27 qed.
28
29 theorem times_n_O: \forall n:nat. O = n*O.
30 intros.elim n.
31 simplify.reflexivity.
32 simplify.assumption.
33 qed.
34
35 theorem times_n_Sm : 
36 \forall n,m:nat. n+(n*m) = n*(S m).
37 intros.elim n.
38 simplify.reflexivity.
39 simplify.
40 demodulate all steps=3.
41 (*
42 apply eq_f.rewrite < H.
43 transitivity ((n1+m)+n1*m).symmetry.apply assoc_plus.
44 transitivity ((m+n1)+n1*m).
45 apply eq_f2.
46 apply sym_plus.
47 reflexivity.
48 apply assoc_plus.
49 *)
50 qed.
51
52 theorem times_O_to_O: \forall n,m:nat.n*m = O \to n = O \lor m= O.
53 apply nat_elim2;intros
54   [left.reflexivity
55   |right.reflexivity
56   |apply False_ind.
57    simplify in H1.
58    apply (not_eq_O_S ? (sym_eq  ? ? ? H1))
59   ]
60 qed.
61
62 theorem times_n_SO : \forall n:nat. n = n * S O.
63 intros. demodulate. reflexivity. (*
64 rewrite < times_n_Sm.
65 rewrite < times_n_O.
66 rewrite < plus_n_O.
67 reflexivity.*)
68 qed.
69
70 theorem times_SSO_n : \forall n:nat. n + n = S (S O) * n.
71 intros.
72 simplify.
73 rewrite < plus_n_O.
74 reflexivity.
75 qed.
76
77 alias num (instance 0) = "natural number".
78 lemma times_SSO: \forall n.2*(S n) = S(S(2*n)).
79 intro.simplify.rewrite < plus_n_Sm.reflexivity.
80 qed.
81
82 theorem or_eq_eq_S: \forall n.\exists m. 
83 n = (S(S O))*m \lor n = S ((S(S O))*m).
84 intro.elim n
85   [apply (ex_intro ? ? O).
86    left.reflexivity
87   |elim H.elim H1
88     [apply (ex_intro ? ? a).
89      right.apply eq_f.assumption
90     |apply (ex_intro ? ? (S a)).
91      left.rewrite > H2.
92      apply sym_eq.
93      apply times_SSO
94     ]
95   ]
96 qed.
97
98 theorem symmetric_times : symmetric nat times. 
99 unfold symmetric.
100 intros.elim x;
101  [ simplify. apply times_n_O.
102  | demodulate. reflexivity. (*
103 (* applyS times_n_Sm. *) 
104 simplify.rewrite > H.apply times_n_Sm.*)]
105 qed.
106
107 variant sym_times : \forall n,m:nat. n*m = m*n \def
108 symmetric_times.
109
110 theorem distributive_times_plus : distributive nat times plus.
111 unfold distributive.
112 intros.elim x.
113 simplify.reflexivity.
114 simplify.
115 demodulate all steps=16.
116 (*
117 rewrite > H. rewrite > assoc_plus.rewrite > assoc_plus.
118 apply eq_f.rewrite < assoc_plus. rewrite < (sym_plus ? z).
119 rewrite > assoc_plus.reflexivity. *)
120 qed.
121
122 variant distr_times_plus: \forall n,m,p:nat. n*(m+p) = n*m + n*p
123 \def distributive_times_plus.
124
125 theorem associative_times: associative nat times.
126 unfold associative.
127 intros.
128 elim x. simplify.apply refl_eq. 
129 simplify.
130 demodulate all steps=4.
131 (*
132 rewrite < sym_times.
133 rewrite > distr_times_plus.
134 rewrite < sym_times.
135 rewrite < (sym_times (times n y) z).
136 rewrite < H.apply refl_eq.
137 *)
138 qed.
139
140 variant assoc_times: \forall n,m,p:nat. (n*m)*p = n*(m*p) \def
141 associative_times.
142
143 lemma times_times: ∀x,y,z. x*(y*z) = y*(x*z).
144 intros. 
145 demodulate. reflexivity.
146 (* autobatch paramodulation. *)
147 qed.
148