]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/library/nat/div_and_mod.ma
The library grows...
[helm.git] / helm / matita / library / nat / div_and_mod.ma
index 619ba68151a48183109400077fc9e1d034d6919a..8c1e0e95317be691c9d9b78b03ec8ba4c72c747e 100644 (file)
@@ -175,12 +175,23 @@ 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.
@@ -189,6 +200,34 @@ 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.
+
+(* 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.