X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matita%2Flibrary%2Fnat%2Fdiv_and_mod.ma;h=73ff78998bce36d1edaff044378b0145fc0a8940;hb=fd972f2c23de4c32d1335fb2b27e21854c6eb806;hp=2f186dd31ae1ff0cf31eb5971c59c388d14ba349;hpb=04e27500136c94e4f2ac072a5e4d330b75da35f0;p=helm.git diff --git a/matita/library/nat/div_and_mod.ma b/matita/library/nat/div_and_mod.ma index 2f186dd31..73ff78998 100644 --- a/matita/library/nat/div_and_mod.ma +++ b/matita/library/nat/div_and_mod.ma @@ -14,6 +14,7 @@ set "baseuri" "cic:/matita/nat/div_and_mod". +include "datatypes/constructors.ma". include "nat/minus.ma". let rec mod_aux p m n: nat \def @@ -296,3 +297,17 @@ 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. + +(* n_divides computes the pair (div,mod) *) + +(* p is just an upper bound, acc is an accumulator *) +let rec n_divides_aux p n m acc \def + match n \mod m with + [ O \Rightarrow + match p with + [ O \Rightarrow pair nat nat acc n + | (S p) \Rightarrow n_divides_aux p (n / m) m (S acc)] + | (S a) \Rightarrow pair nat nat acc n]. + +(* n_divides n m = if m divides n q times, with remainder r *) +definition n_divides \def \lambda n,m:nat.n_divides_aux n n m O.