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_auto/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 (*CSC: the URI must disappear: there is a bug now *)
30 interpretation "natural minus" 'minus x y = (cic:/matita/library_auto/nat/minus/minus.con x y).
32 theorem minus_n_O: \forall n:nat.n=n-O.
35 auto. (* applico auto su entrambi i goal aperti*)
36 (*simplify;reflexivity.*)
39 theorem minus_n_n: \forall n:nat.O=n-n.
47 theorem minus_Sn_n: \forall n:nat. S O = (S n)-n.
51 (*simplify.reflexivity.*)
58 theorem minus_Sn_m: \forall n,m:nat. m \leq n \to (S n)-m = S (n-m).
61 (\lambda n,m.m \leq n \to (S n)-m = S (n-m)));intros
62 [ apply (le_n_O_elim n1 H).
79 \forall n,m,p:nat. m \leq n \to (n-m)+p = (n+p)-m.
82 (\lambda n,m.\forall p:nat.m \leq n \to (n-m)+p = (n+p)-m));intros
83 [ apply (le_n_O_elim ? H).
99 theorem minus_plus_m_m: \forall n,m:nat.n = (n+m)-m.
101 generalize in match n.
103 [ rewrite < minus_n_O.
109 | rewrite < plus_n_Sm.
110 change with (S n3 = (S n3 + n1)-n1).
116 theorem plus_minus_m_m: \forall n,m:nat.
117 m \leq n \to n = (n-m)+m.
119 apply (nat_elim2 (\lambda n,m.m \leq n \to n = (n-m)+m));intros
120 [ apply (le_n_O_elim n1 H).
138 theorem minus_to_plus :\forall n,m,p:nat.m \leq n \to n-m = p \to
140 intros.apply (trans_eq ? ? ((n-m)+m));auto.
141 (*[ apply plus_minus_m_m.
148 theorem plus_to_minus :\forall n,m,p:nat.
151 apply (inj_plus_r m).
156 (*apply plus_minus_m_m.
162 theorem minus_S_S : \forall n,m:nat.
163 eq nat (minus (S n) (S m)) (minus n m).
168 theorem minus_pred_pred : \forall n,m:nat. lt O n \to lt O m \to
169 eq nat (minus (pred n) (pred m)) (minus n m).
171 apply (lt_O_n_elim n H).
173 apply (lt_O_n_elim m H1).
176 (*simplify.reflexivity.*)
179 theorem eq_minus_n_m_O: \forall n,m:nat.
180 n \leq m \to n-m = O.
182 apply (nat_elim2 (\lambda n,m.n \leq m \to n-m = O));intros
189 goal 15.*) (*prima goal 13*)
190 (* effettuando un'esecuzione passo-passo, quando si arriva a dover
191 considerare questa tattica, la finestra di dimostrazione scompare
192 e viene generato il seguente errore:
193 Uncaught exception: File "matitaMathView.ml", line 677, characters
194 6-12: Assertion failed.
196 tuttavia l'esecuzione continua, ed il teorema viene comunque
208 theorem le_SO_minus: \forall n,m:nat.S n \leq m \to S O \leq m-n.
211 [ elim (minus_Sn_n n).apply le_n
212 | rewrite > minus_Sn_m;auto
213 (*apply le_S.assumption.
214 apply lt_to_le.assumption.*)
218 theorem minus_le_S_minus_S: \forall n,m:nat. m-n \leq S (m-(S n)).
219 intros.apply (nat_elim2 (\lambda n,m.m-n \leq S (m-(S n))));intros
222 | rewrite < minus_n_O.
226 (*simplify.apply le_n_Sn.*)
231 theorem lt_minus_S_n_to_le_minus_n : \forall n,m,p:nat. m-(S n) < p \to m-n \leq p.
236 apply (trans_le (m-n) (S (m-(S n))) p).
237 apply minus_le_S_minus_S.
241 theorem le_minus_m: \forall n,m:nat. n-m \leq n.
242 intros.apply (nat_elim2 (\lambda m,n. n-m \leq n));intros
244 (*rewrite < minus_n_O.
256 theorem lt_minus_m: \forall n,m:nat. O < n \to O < m \to n-m \lt n.
258 apply (lt_O_n_elim n H).
260 apply (lt_O_n_elim m H1).
269 theorem minus_le_O_to_le: \forall n,m:nat. n-m \leq O \to n \leq m.
271 apply (nat_elim2 (\lambda n,m:nat.n-m \leq O \to n \leq m))
287 theorem monotonic_le_minus_r:
288 \forall p,q,n:nat. q \leq p \to n-p \le n-q.
292 (\lambda p,q.\forall a.q \leq p \to a-p \leq a-q));intros
293 [ apply (le_n_O_elim n H).
295 | rewrite < minus_n_O.
310 theorem le_minus_to_plus: \forall n,m,p. (le (n-m) p) \to (le n (p+m)).
312 apply (nat_elim2 (\lambda n,m.\forall p.(le (n-m) p) \to (le n (p+m))));intros
314 | rewrite < plus_n_O.
316 | rewrite < plus_n_Sm.
323 theorem le_plus_to_minus: \forall n,m,p. (le n (p+m)) \to (le (n-m) p).
325 apply (nat_elim2 (\lambda n,m.\forall p.(le n (p+m)) \to (le (n-m) p)))
345 (* the converse of le_plus_to_minus does not hold *)
346 theorem le_plus_to_minus_r: \forall n,m,p. (le (n+m) p) \to (le n (p-m)).
348 apply (nat_elim2 (\lambda m,p.(le (n+m) p) \to (le n (p-m))));intro
349 [ rewrite < plus_n_O.
362 (*apply (trans_le ? (n+(S n1)))
363 [ rewrite < sym_plus.
377 (* minus and lt - to be completed *)
378 theorem lt_minus_to_plus: \forall n,m,p. (lt n (p-m)) \to (lt (n+m) p).
380 apply (nat_elim2 (\lambda m,p.(lt n (p-m)) \to (lt (n+m) p)))
390 apply (not_le_Sn_O n H)
402 theorem distributive_times_minus: distributive nat times minus.
405 apply ((leb_elim z y));intro
406 [ cut (x*(y-z)+x*z = (x*y-x*z)+x*z)
408 (*apply (inj_plus_l (x*z)).
410 | apply (trans_eq nat ? (x*y))
411 [ rewrite < distr_times_plus.
413 (*rewrite < (plus_minus_m_m ? ? H).
415 | rewrite < plus_minus_m_m;auto
422 | rewrite > eq_minus_n_m_O
423 [ rewrite > (eq_minus_n_m_O (x*y))
425 (*rewrite < sym_times.
431 (*apply not_le_to_lt.
442 theorem distr_times_minus: \forall n,m,p:nat. n*(m-p) = n*m-n*p
443 \def distributive_times_minus.
445 theorem eq_minus_plus_plus_minus: \forall n,m,p:nat. p \le m \to (n+m)-p = n+(m-p).
448 rewrite > sym_plus in \vdash (? ? ? %).
449 rewrite > assoc_plus.
451 (*rewrite < plus_minus_m_m.
457 theorem eq_minus_minus_minus_plus: \forall n,m,p:nat. (n-m)-p = n-(m+p).
459 cut (m+p \le n \or m+p \nleq n)
463 rewrite > assoc_plus.
464 rewrite > (sym_plus p).
465 rewrite < plus_minus_m_m
466 [ rewrite > sym_plus.
467 rewrite < plus_minus_m_m ; auto
469 | apply (trans_le ? (m+p))
470 [ rewrite < sym_plus.
475 | apply le_plus_to_minus_r.
479 | rewrite > (eq_minus_n_m_O n (m+p))
480 [ rewrite > (eq_minus_n_m_O (n-m) p)
482 | apply le_plus_to_minus.
486 (*apply not_le_to_lt.
495 | apply (decidable_le (m+p) n)
499 theorem eq_plus_minus_minus_minus: \forall n,m,p:nat. p \le m \to m \le n \to
504 rewrite < assoc_plus.
505 rewrite < plus_minus_m_m;
506 [ rewrite < sym_plus.
508 (*rewrite < plus_minus_m_m