set "baseuri" "cic:/matita/nat/div_and_mod".
include "nat/minus.ma".
-include "nat/le_arith.ma".
-include "nat/compare.ma".
let rec mod_aux p m n: nat \def
match (leb m n) with
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.
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.
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.
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.
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.
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.