]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/nat/times.ma
- init_cache_and_tables rewritten using the automation_cache
[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.apply eq_f.rewrite < H.
40 transitivity ((n1+m)+n1*m).symmetry.apply assoc_plus.
41 transitivity ((m+n1)+n1*m).
42 apply eq_f2.
43 apply sym_plus.
44 reflexivity.
45 apply assoc_plus.
46 qed.
47
48 theorem times_O_to_O: \forall n,m:nat.n*m = O \to n = O \lor m= O.
49 apply nat_elim2;intros
50   [left.reflexivity
51   |right.reflexivity
52   |apply False_ind.
53    simplify in H1.
54    apply (not_eq_O_S ? (sym_eq  ? ? ? H1))
55   ]
56 qed.
57
58 theorem times_n_SO : \forall n:nat. n = n * S O.
59 intros.
60 rewrite < times_n_Sm.
61 rewrite < times_n_O.
62 rewrite < plus_n_O.
63 reflexivity.
64 qed.
65
66 theorem times_SSO_n : \forall n:nat. n + n = S (S O) * n.
67 intros.
68 simplify.
69 rewrite < plus_n_O.
70 reflexivity.
71 qed.
72
73 alias num (instance 0) = "natural number".
74 lemma times_SSO: \forall n.2*(S n) = S(S(2*n)).
75 intro.simplify.rewrite < plus_n_Sm.reflexivity.
76 qed.
77
78 theorem or_eq_eq_S: \forall n.\exists m. 
79 n = (S(S O))*m \lor n = S ((S(S O))*m).
80 intro.elim n
81   [apply (ex_intro ? ? O).
82    left.reflexivity
83   |elim H.elim H1
84     [apply (ex_intro ? ? a).
85      right.apply eq_f.assumption
86     |apply (ex_intro ? ? (S a)).
87      left.rewrite > H2.
88      apply sym_eq.
89      apply times_SSO
90     ]
91   ]
92 qed.
93
94 theorem symmetric_times : symmetric nat times. 
95 unfold symmetric.
96 intros.elim x.
97 simplify.apply times_n_O.
98 (* applyS times_n_Sm. *) 
99 simplify.rewrite > H.apply times_n_Sm.
100 qed.
101
102 variant sym_times : \forall n,m:nat. n*m = m*n \def
103 symmetric_times.
104
105 theorem distributive_times_plus : distributive nat times plus.
106 unfold distributive.
107 intros.elim x.
108 simplify.reflexivity.
109 simplify.rewrite > H. rewrite > assoc_plus.rewrite > assoc_plus.
110 apply eq_f.rewrite < assoc_plus. rewrite < (sym_plus ? z).
111 rewrite > assoc_plus.reflexivity.
112 qed.
113
114 variant distr_times_plus: \forall n,m,p:nat. n*(m+p) = n*m + n*p
115 \def distributive_times_plus.
116
117 theorem associative_times: associative nat times.
118 unfold associative.
119 intros.
120 elim x. simplify.apply refl_eq. 
121 simplify.rewrite < sym_times.
122 rewrite > distr_times_plus.
123 rewrite < sym_times.
124 rewrite < (sym_times (times n y) z).
125 rewrite < H.apply refl_eq.
126 qed.
127
128 variant assoc_times: \forall n,m,p:nat. (n*m)*p = n*(m*p) \def
129 associative_times.
130
131 lemma times_times: ∀x,y,z. x*(y*z) = y*(x*z).
132 intros. 
133 demodulate. reflexivity;
134 (* autobatch paramodulation. *)
135 qed.
136