]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/nat/minus.ma
A little bit more of notation here and there.
[helm.git] / helm / matita / library / nat / minus.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
16 set "baseuri" "cic:/matita/nat/minus".
17
18 include "nat/orders_op.ma".
19 include "nat/compare.ma".
20
21 let rec minus n m \def 
22  match n with 
23  [ O \Rightarrow O
24  | (S p) \Rightarrow 
25         match m with
26         [O \Rightarrow (S p)
27         | (S q) \Rightarrow minus p q ]].
28
29 interpretation "natural minus" 'minus x y = (cic:/matita/nat/minus/minus.con x y).
30
31 theorem minus_n_O: \forall n:nat.n=n-O.
32 intros.elim n.simplify.reflexivity.
33 simplify.reflexivity.
34 qed.
35
36 theorem minus_n_n: \forall n:nat.O=n-n.
37 intros.elim n.simplify.
38 reflexivity.
39 simplify.apply H.
40 qed.
41
42 theorem minus_Sn_n: \forall n:nat. S O = (S n)-n.
43 intro.elim n.
44 simplify.reflexivity.
45 elim H.reflexivity.
46 qed.
47
48 theorem minus_Sn_m: \forall n,m:nat. m \leq n \to (S n)-m = S (n-m).
49 intros 2.
50 apply nat_elim2
51 (\lambda n,m.m \leq n \to (S n)-m = S (n-m)).
52 intros.apply le_n_O_elim n1 H.
53 simplify.reflexivity.
54 intros.simplify.reflexivity.
55 intros.rewrite < H.reflexivity.
56 apply le_S_S_to_le. assumption.
57 qed.
58
59 theorem plus_minus:
60 \forall n,m,p:nat. m \leq n \to (n-m)+p = (n+p)-m.
61 intros 2.
62 apply nat_elim2
63 (\lambda n,m.\forall p:nat.m \leq n \to (n-m)+p = (n+p)-m).
64 intros.apply le_n_O_elim ? H.
65 simplify.rewrite < minus_n_O.reflexivity.
66 intros.simplify.reflexivity.
67 intros.simplify.apply H.apply le_S_S_to_le.assumption.
68 qed.
69
70 theorem plus_minus_m_m: \forall n,m:nat.
71 m \leq n \to n = (n-m)+m.
72 intros 2.
73 apply nat_elim2 (\lambda n,m.m \leq n \to n = (n-m)+m).
74 intros.apply le_n_O_elim n1 H.
75 reflexivity.
76 intros.simplify.rewrite < plus_n_O.reflexivity.
77 intros.simplify.rewrite < sym_plus.simplify.
78 apply eq_f.rewrite < sym_plus.apply H.
79 apply le_S_S_to_le.assumption.
80 qed.
81
82 theorem minus_to_plus :\forall n,m,p:nat.m \leq n \to n-m = p \to 
83 n = m+p.
84 intros.apply trans_eq ? ? ((n-m)+m) ?.
85 apply plus_minus_m_m.
86 apply H.elim H1.
87 apply sym_plus.
88 qed.
89
90 theorem plus_to_minus :\forall n,m,p:nat.m \leq n \to
91 n = m+p \to n-m = p.
92 intros.
93 apply inj_plus_r m.
94 rewrite < H1.
95 rewrite < sym_plus.
96 symmetry.
97 apply plus_minus_m_m.assumption.
98 qed.
99
100 theorem eq_minus_n_m_O: \forall n,m:nat.
101 n \leq m \to n-m = O.
102 intros 2.
103 apply nat_elim2 (\lambda n,m.n \leq m \to n-m = O).
104 intros.simplify.reflexivity.
105 intros.apply False_ind.
106 (* ancora problemi con il not *)
107 apply not_le_Sn_O n1 H.
108 intros.
109 simplify.apply H.apply le_S_S_to_le. apply H1.
110 qed.
111
112 theorem le_SO_minus: \forall n,m:nat.S n \leq m \to S O \leq m-n.
113 intros.elim H.elim minus_Sn_n n.apply le_n.
114 rewrite > minus_Sn_m.
115 apply le_S.assumption.
116 apply lt_to_le.assumption.
117 qed.
118
119 (*
120 theorem le_plus_minus: \forall n,m,p. n+m \leq p \to n \leq p-m.
121 intros 3.
122 elim p.simplify.apply trans_le ? (n+m) ?.
123 elim sym_plus ? ?.
124 apply plus_le.assumption.
125 apply le_n_Sm_elim ? ? H1.
126 intros.
127 *)
128
129 theorem distributive_times_minus: distributive nat times minus.
130 simplify.
131 intros.
132 apply (leb_elim z y).intro.
133 cut x*(y-z)+x*z = (x*y-x*z)+x*z.
134 apply inj_plus_l (x*z).
135 assumption.
136 apply trans_eq nat ? (x*y).
137 rewrite < times_plus_distr. 
138 rewrite < plus_minus_m_m ? ? H.reflexivity.
139 rewrite < plus_minus_m_m ? ? ?.reflexivity.
140 apply le_times_r.
141 assumption.
142 intro.
143 rewrite > eq_minus_n_m_O.
144 rewrite > eq_minus_n_m_O (x*y).
145 rewrite < sym_times.simplify.reflexivity.
146 apply lt_to_le.
147 apply not_le_to_lt.assumption.
148 apply le_times_r.apply lt_to_le.
149 apply not_le_to_lt.assumption.
150 qed.
151
152 theorem distr_times_minus: \forall n,m,p:nat. n*(m-p) = n*m-n*p
153 \def distributive_times_minus.
154
155 theorem le_minus_m: \forall n,m:nat. n-m \leq n.
156 intro.elim n.simplify.apply le_n.
157 elim m.simplify.apply le_n.
158 simplify.apply le_S.apply H.
159 qed.