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/library_autobatch/nat/minus".
18 include "auto/nat/le_arith.ma".
19 include "auto/nat/compare.ma".
21 let rec minus n m \def
27 | (S q) \Rightarrow minus p q ]].
29 interpretation "natural minus" 'minus x y = (minus x y).
31 theorem minus_n_O: \forall n:nat.n=n-O.
34 autobatch. (* applico autobatch su entrambi i goal aperti*)
35 (*simplify;reflexivity.*)
38 theorem minus_n_n: \forall n:nat.O=n-n.
46 theorem minus_Sn_n: \forall n:nat. S O = (S n)-n.
50 (*simplify.reflexivity.*)
57 theorem minus_Sn_m: \forall n,m:nat. m \leq n \to (S n)-m = S (n-m).
60 (\lambda n,m.m \leq n \to (S n)-m = S (n-m)));intros
61 [ apply (le_n_O_elim n1 H).
78 \forall n,m,p:nat. m \leq n \to (n-m)+p = (n+p)-m.
81 (\lambda n,m.\forall p:nat.m \leq n \to (n-m)+p = (n+p)-m));intros
82 [ apply (le_n_O_elim ? H).
98 theorem minus_plus_m_m: \forall n,m:nat.n = (n+m)-m.
100 generalize in match n.
102 [ rewrite < minus_n_O.
108 | rewrite < plus_n_Sm.
109 change with (S n3 = (S n3 + n1)-n1).
115 theorem plus_minus_m_m: \forall n,m:nat.
116 m \leq n \to n = (n-m)+m.
118 apply (nat_elim2 (\lambda n,m.m \leq n \to n = (n-m)+m));intros
119 [ apply (le_n_O_elim n1 H).
137 theorem minus_to_plus :\forall n,m,p:nat.m \leq n \to n-m = p \to
139 intros.apply (trans_eq ? ? ((n-m)+m));autobatch.
140 (*[ apply plus_minus_m_m.
147 theorem plus_to_minus :\forall n,m,p:nat.
150 apply (inj_plus_r m).
155 (*apply plus_minus_m_m.
161 theorem minus_S_S : \forall n,m:nat.
162 eq nat (minus (S n) (S m)) (minus n m).
167 theorem minus_pred_pred : \forall n,m:nat. lt O n \to lt O m \to
168 eq nat (minus (pred n) (pred m)) (minus n m).
170 apply (lt_O_n_elim n H).
172 apply (lt_O_n_elim m H1).
175 (*simplify.reflexivity.*)
178 theorem eq_minus_n_m_O: \forall n,m:nat.
179 n \leq m \to n-m = O.
181 apply (nat_elim2 (\lambda n,m.n \leq m \to n-m = O));intros
188 goal 15.*) (*prima goal 13*)
189 (* effettuando un'esecuzione passo-passo, quando si arriva a dover
190 considerare questa tattica, la finestra di dimostrazione scompare
191 e viene generato il seguente errore:
192 Uncaught exception: File "matitaMathView.ml", line 677, characters
193 6-12: Assertion failed.
195 tuttavia l'esecuzione continua, ed il teorema viene comunque
207 theorem le_SO_minus: \forall n,m:nat.S n \leq m \to S O \leq m-n.
210 [ elim (minus_Sn_n n).apply le_n
211 | rewrite > minus_Sn_m;autobatch
212 (*apply le_S.assumption.
213 apply lt_to_le.assumption.*)
217 theorem minus_le_S_minus_S: \forall n,m:nat. m-n \leq S (m-(S n)).
218 intros.apply (nat_elim2 (\lambda n,m.m-n \leq S (m-(S n))));intros
221 | rewrite < minus_n_O.
225 (*simplify.apply le_n_Sn.*)
230 theorem lt_minus_S_n_to_le_minus_n : \forall n,m,p:nat. m-(S n) < p \to m-n \leq p.
235 apply (trans_le (m-n) (S (m-(S n))) p).
236 apply minus_le_S_minus_S.
240 theorem le_minus_m: \forall n,m:nat. n-m \leq n.
241 intros.apply (nat_elim2 (\lambda m,n. n-m \leq n));intros
243 (*rewrite < minus_n_O.
255 theorem lt_minus_m: \forall n,m:nat. O < n \to O < m \to n-m \lt n.
257 apply (lt_O_n_elim n H).
259 apply (lt_O_n_elim m H1).
268 theorem minus_le_O_to_le: \forall n,m:nat. n-m \leq O \to n \leq m.
270 apply (nat_elim2 (\lambda n,m:nat.n-m \leq O \to n \leq m))
286 theorem monotonic_le_minus_r:
287 \forall p,q,n:nat. q \leq p \to n-p \le n-q.
291 (\lambda p,q.\forall a.q \leq p \to a-p \leq a-q));intros
292 [ apply (le_n_O_elim n H).
294 | rewrite < minus_n_O.
309 theorem le_minus_to_plus: \forall n,m,p. (le (n-m) p) \to (le n (p+m)).
311 apply (nat_elim2 (\lambda n,m.\forall p.(le (n-m) p) \to (le n (p+m))));intros
313 | rewrite < plus_n_O.
315 | rewrite < plus_n_Sm.
322 theorem le_plus_to_minus: \forall n,m,p. (le n (p+m)) \to (le (n-m) p).
324 apply (nat_elim2 (\lambda n,m.\forall p.(le n (p+m)) \to (le (n-m) p)))
344 (* the converse of le_plus_to_minus does not hold *)
345 theorem le_plus_to_minus_r: \forall n,m,p. (le (n+m) p) \to (le n (p-m)).
347 apply (nat_elim2 (\lambda m,p.(le (n+m) p) \to (le n (p-m))));intro
348 [ rewrite < plus_n_O.
361 (*apply (trans_le ? (n+(S n1)))
362 [ rewrite < sym_plus.
376 (* minus and lt - to be completed *)
377 theorem lt_minus_to_plus: \forall n,m,p. (lt n (p-m)) \to (lt (n+m) p).
379 apply (nat_elim2 (\lambda m,p.(lt n (p-m)) \to (lt (n+m) p)))
389 apply (not_le_Sn_O n H)
401 theorem distributive_times_minus: distributive nat times minus.
404 apply ((leb_elim z y));intro
405 [ cut (x*(y-z)+x*z = (x*y-x*z)+x*z)
407 (*apply (inj_plus_l (x*z)).
409 | apply (trans_eq nat ? (x*y))
410 [ rewrite < distr_times_plus.
412 (*rewrite < (plus_minus_m_m ? ? H).
414 | rewrite < plus_minus_m_m;autobatch
421 | rewrite > eq_minus_n_m_O
422 [ rewrite > (eq_minus_n_m_O (x*y))
424 (*rewrite < sym_times.
430 (*apply not_le_to_lt.
441 theorem distr_times_minus: \forall n,m,p:nat. n*(m-p) = n*m-n*p
442 \def distributive_times_minus.
444 theorem eq_minus_plus_plus_minus: \forall n,m,p:nat. p \le m \to (n+m)-p = n+(m-p).
447 rewrite > sym_plus in \vdash (? ? ? %).
448 rewrite > assoc_plus.
450 (*rewrite < plus_minus_m_m.
456 theorem eq_minus_minus_minus_plus: \forall n,m,p:nat. (n-m)-p = n-(m+p).
458 cut (m+p \le n \or m+p \nleq n)
462 rewrite > assoc_plus.
463 rewrite > (sym_plus p).
464 rewrite < plus_minus_m_m
465 [ rewrite > sym_plus.
466 rewrite < plus_minus_m_m ; autobatch
468 | apply (trans_le ? (m+p))
469 [ rewrite < sym_plus.
474 | apply le_plus_to_minus_r.
478 | rewrite > (eq_minus_n_m_O n (m+p))
479 [ rewrite > (eq_minus_n_m_O (n-m) p)
481 | apply le_plus_to_minus.
485 (*apply not_le_to_lt.
494 | apply (decidable_le (m+p) n)
498 theorem eq_plus_minus_minus_minus: \forall n,m,p:nat. p \le m \to m \le n \to
503 rewrite < assoc_plus.
504 rewrite < plus_minus_m_m;
505 [ rewrite < sym_plus.
507 (*rewrite < plus_minus_m_m