]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/library/nat/div_and_mod.ma
* Obsolete debugging comments removed
[helm.git] / helm / matita / library / nat / div_and_mod.ma
index ca8b6c3faaaec0cd8c89c5bce373ba0efd9a588a..73344c7c46b0cf1466b0aea949755ced792fc13a 100644 (file)
@@ -15,8 +15,6 @@
 set "baseuri" "cic:/matita/nat/div_and_mod".
 
 include "nat/minus.ma".
-include "nat/orders_op.ma".
-include "nat/compare.ma".
 
 let rec mod_aux p m n: nat \def
 match (leb m n) with
@@ -128,15 +126,14 @@ cut b \leq (q1-q)*b+r1.
 cut b \leq r.
 apply lt_to_not_le r b H2 Hcut2.
 elim Hcut.assumption.
-apply trans_le ? ((q1-q)*b) ?.
+apply trans_le ? ((q1-q)*b).
 apply le_times_n.
 apply le_SO_minus.exact H6.
 rewrite < sym_plus.
 apply le_plus_n.
 rewrite < sym_times.
 rewrite > distr_times_minus.
-(* ATTENZIONE ALL' ORDINAMENTO DEI GOALS *)
-rewrite > plus_minus ? ? ? ?.
+rewrite > plus_minus.
 rewrite > sym_times.
 rewrite < H5.
 rewrite < sym_times.
@@ -156,14 +153,14 @@ cut b \leq (q-q1)*b+r.
 cut b \leq r1.
 apply lt_to_not_le r1 b H4 Hcut2.
 elim Hcut.assumption.
-apply trans_le ? ((q-q1)*b) ?.
+apply trans_le ? ((q-q1)*b).
 apply le_times_n.
 apply le_SO_minus.exact H6.
 rewrite < sym_plus.
 apply le_plus_n.
 rewrite < sym_times.
 rewrite > distr_times_minus.
-rewrite > plus_minus ? ? ? ?.
+rewrite > plus_minus.
 rewrite > sym_times.
 rewrite < H3.
 rewrite < sym_times.
@@ -174,3 +171,107 @@ apply le_times_r.
 apply lt_to_le.
 apply H6.
 qed.
+
+theorem div_mod_spec_to_eq2 :\forall a,b,q,r,q1,r1.
+(div_mod_spec a b q r) \to (div_mod_spec a b q1 r1) \to 
+(eq nat r r1).
+intros.elim H.elim H1.
+apply inj_plus_r (q*b).
+rewrite < H3.
+rewrite > div_mod_spec_to_eq a b q r q1 r1 H H1.
+assumption.
+qed.
+
+theorem div_mod_spec_times : \forall n,m:nat.div_mod_spec ((S n)*m) (S n) m O.
+intros.constructor 1.
+simplify.apply le_S_S.apply le_O_n.
+rewrite < plus_n_O.rewrite < sym_times.reflexivity.
+qed.
+
+(* some properties of div and mod *)
+theorem div_times: \forall n,m:nat. div ((S n)*m) (S n) = m.
+intros.
+apply div_mod_spec_to_eq ((S n)*m) (S n) ? ? ? O.
+goal 15. (* ?11 is closed with the following tactics *)
+apply div_mod_spec_div_mod.
+simplify.apply le_S_S.apply le_O_n.
+apply div_mod_spec_times.
+qed.
+
+theorem div_n_n: \forall n:nat. O < n \to div n n = S O.
+intros.
+apply div_mod_spec_to_eq n n (div n n) (mod n n) (S O) O.
+apply div_mod_spec_div_mod.assumption.
+constructor 1.assumption.
+rewrite < plus_n_O.simplify.rewrite < plus_n_O.reflexivity.
+qed.
+
+theorem mod_n_n: \forall n:nat. O < n \to mod n n = O.
+intros.
+apply div_mod_spec_to_eq2 n n (div n n) (mod n n) (S O) O.
+apply div_mod_spec_div_mod.assumption.
+constructor 1.assumption.
+rewrite < plus_n_O.simplify.rewrite < plus_n_O.reflexivity.
+qed.
+
+theorem mod_S: \forall n,m:nat. O < m \to S (mod n m) < m \to 
+(mod (S n) m) = S (mod n m).
+intros.
+apply div_mod_spec_to_eq2 (S n) m (div (S n) m) (mod (S n) m) (div n m) (S (mod n m)).
+apply div_mod_spec_div_mod.assumption.
+constructor 1.assumption.rewrite < plus_n_Sm.
+apply eq_f.
+apply div_mod.
+assumption.
+qed.
+
+theorem mod_O_n: \forall n:nat.mod O n = O.
+intro.elim n.simplify.reflexivity.
+simplify.reflexivity.
+qed.
+
+
+(* injectivity *)
+theorem injective_times_r: \forall n:nat.injective nat nat (\lambda m:nat.(S n)*m).
+change with \forall n,p,q:nat.(S n)*p = (S n)*q \to p=q.
+intros.
+rewrite < div_times n.
+rewrite < div_times n q.
+apply eq_f2.assumption.
+reflexivity.
+qed.
+
+variant inj_times_r : \forall n,p,q:nat.(S n)*p = (S n)*q \to p=q \def
+injective_times_r.
+
+theorem lt_O_to_injective_times_r: \forall n:nat. O < n \to injective nat nat (\lambda m:nat.n*m).
+change with \forall n. O < n \to \forall p,q:nat.n*p = n*q \to p=q.
+intros 4.
+apply lt_O_n_elim n H.intros.
+apply inj_times_r m.assumption.
+qed.
+
+variant inj_times_r1:\forall n. O < n \to \forall p,q:nat.n*p = n*q \to p=q
+\def lt_O_to_injective_times_r.
+
+theorem injective_times_l: \forall n:nat.injective nat nat (\lambda m:nat.m*(S n)).
+change with \forall n,p,q:nat.p*(S n) = q*(S n) \to p=q.
+intros.
+apply inj_times_r n p q.
+rewrite < sym_times.
+rewrite < sym_times q.
+assumption.
+qed.
+
+variant inj_times_l : \forall n,p,q:nat. p*(S n) = q*(S n) \to p=q \def
+injective_times_l.
+
+theorem lt_O_to_injective_times_l: \forall n:nat. O < n \to injective nat nat (\lambda m:nat.m*n).
+change with \forall n. O < n \to \forall p,q:nat.p*n = q*n \to p=q.
+intros 4.
+apply lt_O_n_elim n H.intros.
+apply inj_times_l m.assumption.
+qed.
+
+variant inj_times_l1:\forall n. O < n \to \forall p,q:nat.p*n = q*n \to p=q
+\def lt_O_to_injective_times_l.