2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
7 ||A|| This file is distributed under the terms of the
8 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "arithmetics/primes.ma".
15 definition S_mod: nat → nat → nat ≝
16 λn,m:nat. (S m) \mod n.
18 definition congruent: nat → nat → nat → Prop ≝
19 λn,m,p:nat. mod n p = mod m p.
21 interpretation "congruent" 'congruent n m p = (congruent n m p).
23 notation "hvbox(n break ≅_{p} m)"
24 non associative with precedence 45
25 for @{ 'congruent $n $m $p }.
27 theorem congruent_n_n: ∀n,p:nat.n ≅_{p} n .
30 theorem transitive_congruent:
31 ∀p.transitive nat (λn,m.congruent n m p).
34 theorem le_to_mod: ∀n,m:nat. n < m → n = n \mod m.
35 #n #m #ltnm @(div_mod_spec_to_eq2 n m O n (n/m) (n \mod m))
36 % // @lt_mod_m_m @(ltn_to_ltO … ltnm)
39 theorem mod_mod : ∀n,p:nat. O<p → n \mod p = (n \mod p) \mod p.
40 #n #p #posp >(div_mod (n \mod p) p) in ⊢ (? ? % ?)
41 >(eq_div_O ? p) // @lt_mod_m_m //
44 theorem mod_times_mod : ∀n,m,p:nat. O<p → O<m →
45 n \mod p = (n \mod (m*p)) \mod p.
47 @(div_mod_spec_to_eq2 n p (n/p) (n \mod p)
48 (n/(m*p)*m + (n \mod (m*p)/p)))
49 [@div_mod_spec_div_mod //
50 |% [@lt_mod_m_m //] >distributive_times_plus_r
51 >associative_plus <div_mod >associative_times <div_mod //
55 theorem congruent_n_mod_n : ∀n,p:nat. O < p →
59 theorem congruent_n_mod_times : ∀n,m,p:nat. O < p → O < m →
60 n ≅_{p} (n \mod (m*p)).
63 theorem eq_times_plus_to_congruent: ∀n,m,p,r:nat. O< p →
64 n = r*p+m → n ≅_{p} m .
65 #n #m #p #r #posp #eqn
66 @(div_mod_spec_to_eq2 n p (div n p) (mod n p) (r +(div m p)) (mod m p))
67 [@div_mod_spec_div_mod //
68 |% [@lt_mod_m_m //] >distributive_times_plus_r
69 >associative_plus <div_mod //
73 theorem divides_to_congruent: ∀n,m,p:nat. O < p → m ≤ n →
74 p ∣(n - m) → n ≅_{p} m .
75 #n #m #p #posp #lemn * #l #eqpl
76 @(eq_times_plus_to_congruent … l posp) /2/
79 theorem congruent_to_divides: ∀n,m,p:nat.O < p →
80 n ≅_{p} m → p ∣ (n - m).
81 #n #m #p #posp #congnm @(quotient ? ? ((n / p)-(m / p)))
82 >commutative_times >(div_mod n p) in ⊢ (??%?)
83 >(div_mod m p) in ⊢ (??%?) <(commutative_plus (m \mod p))
84 <congnm <(minus_plus ? (n \mod p)) <minus_plus_m_m //
87 theorem mod_times: ∀n,m,p:nat. O < p →
88 n*m ≅_{p} (n \mod p)*(m \mod p).
89 #n #m #p #posp @(eq_times_plus_to_congruent ?? p
90 ((n / p)*p*(m / p) + (n / p)*(m \mod p) + (n \mod p)*(m / p))) //
91 @(trans_eq ?? (((n/p)*p+(n \mod p))*((m/p)*p+(m \mod p))))
93 |@(trans_eq ? ? (((n/p)*p)*((m/p)*p) + (n/p)*p*(m \mod p) +
94 (n \mod p)*((m / p)*p) + (n \mod p)*(m \mod p))) //
95 >distributive_times_plus >distributive_times_plus_r
96 >distributive_times_plus_r <associative_plus @eq_f2 //
100 theorem congruent_times: ∀n,m,n1,m1,p. O < p →
101 n ≅_{p} n1 → m ≅_{p} m1 → n*m ≅_{p} n1*m1 .
102 #n #m #n1 #m1 #p #posp #congn #congm
103 @(transitive_congruent … (mod_times n m p posp))
104 >congn >congm @sym_eq @mod_times //
108 theorem congruent_pi: \forall f:nat \to nat. \forall n,m,p:nat.O < p \to
109 congruent (pi n f m) (pi n (\lambda m. mod (f m) p) m) p.
112 apply congruent_n_mod_n.assumption.
114 apply congruent_times.
116 apply congruent_n_mod_n.assumption.