X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2Flibrary%2Fnat%2Fgcd.ma;h=90de2013a5e9f9ba02f681e2cfe7d4761179897b;hb=8b55faddb06e3c4b0a13839210bb49170939b33e;hp=8475fc06aa026aacff1fd29c46c264ff25575947;hpb=30b7e65d641fe7243c4f36ed448f56360a1c5e1c;p=helm.git diff --git a/helm/matita/library/nat/gcd.ma b/helm/matita/library/nat/gcd.ma index 8475fc06a..90de2013a 100644 --- a/helm/matita/library/nat/gcd.ma +++ b/helm/matita/library/nat/gcd.ma @@ -22,7 +22,7 @@ match divides_b n m with | false \Rightarrow match p with [O \Rightarrow n - |(S q) \Rightarrow gcd_aux q n (mod m n)]]. + |(S q) \Rightarrow gcd_aux q n (m \mod n)]]. definition gcd : nat \to nat \to nat \def \lambda n,m:nat. @@ -37,28 +37,24 @@ definition gcd : nat \to nat \to nat \def | (S p) \Rightarrow gcd_aux (S p) n (S p) ]]. theorem divides_mod: \forall p,m,n:nat. O < n \to p \divides m \to p \divides n \to -p \divides mod m n. +p \divides (m \mod n). intros.elim H1.elim H2. -apply witness ? ? (n2 - n1*(div m n)). +apply witness ? ? (n2 - n1*(m / n)). rewrite > distr_times_minus. rewrite < H3. rewrite < assoc_times. rewrite < H4. apply sym_eq. apply plus_to_minus. -rewrite > div_mod m n in \vdash (? ? %). rewrite > sym_times. -apply eq_plus_to_le ? ? (mod m n). -reflexivity. +apply div_mod. assumption. -rewrite > sym_times. -apply div_mod.assumption. qed. theorem divides_mod_to_divides: \forall p,m,n:nat. O < n \to -p \divides mod m n \to p \divides n \to p \divides m. +p \divides (m \mod n) \to p \divides n \to p \divides m. intros.elim H1.elim H2. -apply witness p m ((n1*(div m n))+n2). +apply witness p m ((n1*(m / n))+n2). rewrite > distr_times_plus. rewrite < H3. rewrite < assoc_times. @@ -74,25 +70,25 @@ cut (n1 \divides m) \lor (n1 \ndivides m). change with (match divides_b n1 m with [ true \Rightarrow n1 -| false \Rightarrow gcd_aux n n1 (mod m n1)]) \divides m \land +| false \Rightarrow gcd_aux n n1 (m \mod n1)]) \divides m \land (match divides_b n1 m with [ true \Rightarrow n1 -| false \Rightarrow gcd_aux n n1 (mod m n1)]) \divides n1. +| false \Rightarrow gcd_aux n n1 (m \mod n1)]) \divides n1. elim Hcut.rewrite > divides_to_divides_b_true. simplify. split.assumption.apply witness n1 n1 (S O).apply times_n_SO. assumption.assumption. rewrite > not_divides_to_divides_b_false. change with -gcd_aux n n1 (mod m n1) \divides m \land -gcd_aux n n1 (mod m n1) \divides n1. -cut gcd_aux n n1 (mod m n1) \divides n1 \land -gcd_aux n n1 (mod m n1) \divides mod m n1. +gcd_aux n n1 (m \mod n1) \divides m \land +gcd_aux n n1 (m \mod n1) \divides n1. +cut gcd_aux n n1 (m \mod n1) \divides n1 \land +gcd_aux n n1 (m \mod n1) \divides mod m n1. elim Hcut1. split.apply divides_mod_to_divides ? ? n1. assumption.assumption.assumption.assumption. apply H. -cut O \lt mod m n1 \lor O = mod m n1. +cut O \lt m \mod n1 \lor O = mod m n1. elim Hcut1.assumption. apply False_ind.apply H4.apply mod_O_to_divides. assumption.apply sym_eq.assumption. @@ -101,7 +97,7 @@ apply lt_to_le. apply lt_mod_m_m.assumption. apply le_S_S_to_le. apply trans_le ? n1. -change with mod m n1 < n1. +change with m \mod n1 < n1. apply lt_mod_m_m.assumption.assumption. assumption.assumption. apply decidable_divides n1 m.assumption. @@ -119,7 +115,7 @@ match leb n m with | false \Rightarrow match m with [ O \Rightarrow n - | (S p) \Rightarrow gcd_aux (S p) n (S p) ]] \divides m + | (S p) \Rightarrow gcd_aux (S p) n (S p) ] ] \divides m \land match leb n m with [ true \Rightarrow @@ -129,7 +125,7 @@ match leb n m with | false \Rightarrow match m with [ O \Rightarrow n - | (S p) \Rightarrow gcd_aux (S p) n (S p) ]] \divides n. + | (S p) \Rightarrow gcd_aux (S p) n (S p) ] ] \divides n. apply leb_elim n m. apply nat_case1 n. simplify.intros.split. @@ -180,16 +176,16 @@ change with d \divides (match divides_b n1 m with [ true \Rightarrow n1 -| false \Rightarrow gcd_aux n n1 (mod m n1)]). +| false \Rightarrow gcd_aux n n1 (m \mod n1)]). cut n1 \divides m \lor n1 \ndivides m. elim Hcut. rewrite > divides_to_divides_b_true. simplify.assumption. assumption.assumption. rewrite > not_divides_to_divides_b_false. -change with d \divides gcd_aux n n1 (mod m n1). +change with d \divides gcd_aux n n1 (m \mod n1). apply H. -cut O \lt mod m n1 \lor O = mod m n1. +cut O \lt m \mod n1 \lor O = m \mod n1. elim Hcut1.assumption. absurd n1 \divides m.apply mod_O_to_divides. assumption.apply sym_eq.assumption.assumption. @@ -198,7 +194,7 @@ apply lt_to_le. apply lt_mod_m_m.assumption. apply le_S_S_to_le. apply trans_le ? n1. -change with mod m n1 < n1. +change with m \mod n1 < n1. apply lt_mod_m_m.assumption.assumption. assumption. apply divides_mod.assumption.assumption.assumption. @@ -247,11 +243,11 @@ change with \exists a,b. a*n1 - b*m = match divides_b n1 m with [ true \Rightarrow n1 -| false \Rightarrow gcd_aux n n1 (mod m n1)] +| false \Rightarrow gcd_aux n n1 (m \mod n1)] \lor b*m - a*n1 = match divides_b n1 m with [ true \Rightarrow n1 -| false \Rightarrow gcd_aux n n1 (mod m n1)]. +| false \Rightarrow gcd_aux n n1 (m \mod n1)]. elim Hcut1. rewrite > divides_to_divides_b_true. simplify. @@ -263,18 +259,18 @@ assumption.assumption. rewrite > not_divides_to_divides_b_false. change with \exists a,b. -a*n1 - b*m = gcd_aux n n1 (mod m n1) +a*n1 - b*m = gcd_aux n n1 (m \mod n1) \lor -b*m - a*n1 = gcd_aux n n1 (mod m n1). +b*m - a*n1 = gcd_aux n n1 (m \mod n1). cut \exists a,b. -a*(mod m n1) - b*n1= gcd_aux n n1 (mod m n1) +a*(m \mod n1) - b*n1= gcd_aux n n1 (m \mod n1) \lor -b*n1 - a*(mod m n1) = gcd_aux n n1 (mod m n1). +b*n1 - a*(m \mod n1) = gcd_aux n n1 (m \mod n1). elim Hcut2.elim H5.elim H6. (* first case *) rewrite < H7. -apply ex_intro ? ? (a1+a*(div m n1)). +apply ex_intro ? ? (a1+a*(m / n1)). apply ex_intro ? ? a. right. rewrite < sym_plus. @@ -294,9 +290,10 @@ apply le_n. assumption. (* second case *) rewrite < H7. -apply ex_intro ? ? (a1+a*(div m n1)). +apply ex_intro ? ? (a1+a*(m / n1)). apply ex_intro ? ? a. left. +(* clear Hcut2.clear H5.clear H6.clear H. *) rewrite > sym_times. rewrite > distr_times_plus. rewrite > sym_times. @@ -310,8 +307,8 @@ rewrite < plus_minus. rewrite < minus_n_n.reflexivity. apply le_n. assumption. -apply H n1 (mod m n1). -cut O \lt mod m n1 \lor O = mod m n1. +apply H n1 (m \mod n1). +cut O \lt m \mod n1 \lor O = m \mod n1. elim Hcut2.assumption. absurd n1 \divides m.apply mod_O_to_divides. assumption. @@ -321,7 +318,7 @@ apply lt_to_le. apply lt_mod_m_m.assumption. apply le_S_S_to_le. apply trans_le ? n1. -change with mod m n1 < n1. +change with m \mod n1 < n1. apply lt_mod_m_m. assumption.assumption.assumption.assumption. apply decidable_divides n1 m.assumption. @@ -331,28 +328,7 @@ qed. theorem eq_minus_gcd: \forall m,n.\exists a,b.a*n - b*m = (gcd n m) \lor b*m - a*n = (gcd n m). intros. -change with -\exists a,b. -a*n - b*m = -match leb n m with - [ true \Rightarrow - match n with - [ O \Rightarrow m - | (S p) \Rightarrow gcd_aux (S p) m (S p) ] - | false \Rightarrow - match m with - [ O \Rightarrow n - | (S p) \Rightarrow gcd_aux (S p) n (S p) ]] -\lor b*m - a*n = -match leb n m with - [ true \Rightarrow - match n with - [ O \Rightarrow m - | (S p) \Rightarrow gcd_aux (S p) m (S p) ] - | false \Rightarrow - match m with - [ O \Rightarrow n - | (S p) \Rightarrow gcd_aux (S p) n (S p) ]]. +unfold gcd. apply leb_elim n m. apply nat_case1 n. simplify.intros.