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 (**************************************************************************)
16 set "baseuri" "cic:/matita/nat/minus".
18 include "nat/orders_op.ma".
19 include "nat/compare.ma".
21 let rec minus n m \def
27 | (S q) \Rightarrow minus p q ]].
29 interpretation "natural minus" 'minus x y = (cic:/matita/nat/minus/minus.con x y).
31 theorem minus_n_O: \forall n:nat.n=n-O.
32 intros.elim n.simplify.reflexivity.
36 theorem minus_n_n: \forall n:nat.O=n-n.
37 intros.elim n.simplify.
42 theorem minus_Sn_n: \forall n:nat. S O = (S n)-n.
48 theorem minus_Sn_m: \forall n,m:nat. m \leq n \to (S n)-m = S (n-m).
51 (\lambda n,m.m \leq n \to (S n)-m = S (n-m)).
52 intros.apply le_n_O_elim n1 H.
54 intros.simplify.reflexivity.
55 intros.rewrite < H.reflexivity.
56 apply le_S_S_to_le. assumption.
60 \forall n,m,p:nat. m \leq n \to (n-m)+p = (n+p)-m.
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.
70 theorem plus_minus_m_m: \forall n,m:nat.
71 m \leq n \to n = (n-m)+m.
73 apply nat_elim2 (\lambda n,m.m \leq n \to n = (n-m)+m).
74 intros.apply le_n_O_elim n1 H.
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.
82 theorem minus_to_plus :\forall n,m,p:nat.m \leq n \to n-m = p \to
84 intros.apply trans_eq ? ? ((n-m)+m) ?.
90 theorem plus_to_minus :\forall n,m,p:nat.m \leq n \to
97 apply plus_minus_m_m.assumption.
100 theorem eq_minus_n_m_O: \forall n,m:nat.
101 n \leq m \to n-m = O.
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.
109 simplify.apply H.apply le_S_S_to_le. apply H1.
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.
120 theorem le_plus_minus: \forall n,m,p. n+m \leq p \to n \leq p-m.
122 elim p.simplify.apply trans_le ? (n+m) ?.
124 apply plus_le.assumption.
125 apply le_n_Sm_elim ? ? H1.
129 theorem distributive_times_minus: distributive nat times minus.
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).
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.
143 rewrite > eq_minus_n_m_O.
144 rewrite > eq_minus_n_m_O (x*y).
145 rewrite < sym_times.simplify.reflexivity.
147 apply not_le_to_lt.assumption.
148 apply le_times_r.apply lt_to_le.
149 apply not_le_to_lt.assumption.
152 theorem distr_times_minus: \forall n,m,p:nat. n*(m-p) = n*m-n*p
153 \def distributive_times_minus.
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.