formal
stringlengths 41
427k
| informal
stringclasses 1
value |
---|---|
Nat.gcd_eq_left_iff_dvd ** m n : Nat h : m β£ n β’ gcd m n = m ** rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left] ** Qed | |
Nat.gcd_eq_right_iff_dvd ** m n : Nat β’ m β£ n β gcd n m = m ** rw [gcd_comm] ** m n : Nat β’ m β£ n β gcd m n = m ** exact gcd_eq_left_iff_dvd ** Qed | |
Nat.gcd_mul_left ** m n k : Nat β’ gcd (m * n) (m * k) = m * gcd n k ** induction n, k using gcd.induction with
| H0 k => simp
| H1 n k _ IH => rwa [β mul_mod_mul_left, β gcd_rec, β gcd_rec] at IH ** case H0 m k : Nat β’ gcd (m * 0) (m * k) = m * gcd 0 k ** simp ** case H1 m n k : Nat aβ : 0 < n IH : gcd (m * (k % n)) (m * n) = m * gcd (k % n) n β’ gcd (m * n) (m * k) = m * gcd n k ** rwa [β mul_mod_mul_left, β gcd_rec, β gcd_rec] at IH ** Qed | |
Nat.gcd_mul_right ** m n k : Nat β’ gcd (m * n) (k * n) = gcd m k * n ** rw [Nat.mul_comm m n, Nat.mul_comm k n, Nat.mul_comm (gcd m k) n, gcd_mul_left] ** Qed | |
Nat.eq_zero_of_gcd_eq_zero_right ** m n : Nat H : gcd m n = 0 β’ n = 0 ** rw [gcd_comm] at H ** m n : Nat H : gcd n m = 0 β’ n = 0 ** exact eq_zero_of_gcd_eq_zero_left H ** Qed | |
Nat.gcd_eq_right ** m n : Nat H : n β£ m β’ gcd m n = n ** rw [gcd_comm, gcd_eq_left H] ** Qed | |
Nat.gcd_mul_left_right ** m n : Nat β’ gcd n (m * n) = n ** rw [gcd_comm, gcd_mul_left_left] ** Qed | |
Nat.gcd_mul_right_left ** m n : Nat β’ gcd (n * m) n = n ** rw [Nat.mul_comm, gcd_mul_left_left] ** Qed | |
Nat.gcd_add_mul_self ** m n k : Nat β’ gcd m (n + k * m) = gcd m n ** simp [gcd_rec m (n + k * m), gcd_rec m n] ** Qed | |
Nat.gcd_eq_zero_iff ** i j : Nat h : i = 0 β§ j = 0 β’ gcd i j = 0 ** simp [h] ** Qed | |
Nat.gcd_eq_iff ** g a b : Nat β’ gcd a b = g β g β£ a β§ g β£ b β§ β (c : Nat), c β£ a β c β£ b β c β£ g ** constructor ** case mp g a b : Nat β’ gcd a b = g β g β£ a β§ g β£ b β§ β (c : Nat), c β£ a β c β£ b β c β£ g ** rintro rfl ** case mp a b : Nat β’ gcd a b β£ a β§ gcd a b β£ b β§ β (c : Nat), c β£ a β c β£ b β c β£ gcd a b ** exact β¨gcd_dvd_left _ _, gcd_dvd_right _ _, fun _ => Nat.dvd_gcdβ© ** case mpr g a b : Nat β’ (g β£ a β§ g β£ b β§ β (c : Nat), c β£ a β c β£ b β c β£ g) β gcd a b = g ** rintro β¨ha, hb, hcβ© ** case mpr.intro.intro g a b : Nat ha : g β£ a hb : g β£ b hc : β (c : Nat), c β£ a β c β£ b β c β£ g β’ gcd a b = g ** apply Nat.dvd_antisymm ** case mpr.intro.intro.a g a b : Nat ha : g β£ a hb : g β£ b hc : β (c : Nat), c β£ a β c β£ b β c β£ g β’ gcd a b β£ g ** apply hc ** case mpr.intro.intro.a.a g a b : Nat ha : g β£ a hb : g β£ b hc : β (c : Nat), c β£ a β c β£ b β c β£ g β’ gcd a b β£ a ** exact gcd_dvd_left a b ** case mpr.intro.intro.a.a g a b : Nat ha : g β£ a hb : g β£ b hc : β (c : Nat), c β£ a β c β£ b β c β£ g β’ gcd a b β£ b ** exact gcd_dvd_right a b ** case mpr.intro.intro.a g a b : Nat ha : g β£ a hb : g β£ b hc : β (c : Nat), c β£ a β c β£ b β c β£ g β’ g β£ gcd a b ** exact Nat.dvd_gcd ha hb ** Qed | |
Nat.lcm_comm ** m n : Nat β’ lcm m n = lcm n m ** rw [lcm, lcm, Nat.mul_comm n m, gcd_comm n m] ** Qed | |
Nat.lcm_zero_left ** m : Nat β’ lcm 0 m = 0 ** simp [lcm] ** Qed | |
Nat.lcm_zero_right ** m : Nat β’ lcm m 0 = 0 ** simp [lcm] ** Qed | |
Nat.lcm_one_left ** m : Nat β’ lcm 1 m = m ** simp [lcm] ** Qed | |
Nat.lcm_one_right ** m : Nat β’ lcm m 1 = m ** simp [lcm] ** Qed | |
Nat.lcm_self ** m : Nat β’ lcm m m = m ** match eq_zero_or_pos m with
| .inl h => rw [h, lcm_zero_left]
| .inr h => simp [lcm, Nat.mul_div_cancel _ h] ** m : Nat h : m = 0 β’ lcm m m = m ** rw [h, lcm_zero_left] ** m : Nat h : m > 0 β’ lcm m m = m ** simp [lcm, Nat.mul_div_cancel _ h] ** Qed | |
Nat.dvd_lcm_left ** m n : Nat β’ lcm m n = m * (n / gcd m n) ** rw [β Nat.mul_div_assoc m (Nat.gcd_dvd_right m n)] ** m n : Nat β’ lcm m n = m * n / gcd m n ** rfl ** Qed | |
Nat.gcd_mul_lcm ** m n : Nat β’ gcd m n * lcm m n = m * n ** rw [lcm, Nat.mul_div_cancel' (Nat.dvd_trans (gcd_dvd_left m n) (Nat.dvd_mul_right m n))] ** Qed | |
Nat.lcm_ne_zero ** m n : Nat hm : m β 0 hn : n β 0 β’ lcm m n β 0 ** intro h ** m n : Nat hm : m β 0 hn : n β 0 h : lcm m n = 0 β’ False ** have h1 := gcd_mul_lcm m n ** m n : Nat hm : m β 0 hn : n β 0 h : lcm m n = 0 h1 : gcd m n * lcm m n = m * n β’ False ** rw [h, Nat.mul_zero] at h1 ** m n : Nat hm : m β 0 hn : n β 0 h : lcm m n = 0 h1 : 0 = m * n β’ False ** match mul_eq_zero.1 h1.symm with
| .inl hm1 => exact hm hm1
| .inr hn1 => exact hn hn1 ** m n : Nat hm : m β 0 hn : n β 0 h : lcm m n = 0 h1 : 0 = m * n hm1 : m = 0 β’ False ** exact hm hm1 ** m n : Nat hm : m β 0 hn : n β 0 h : lcm m n = 0 h1 : 0 = m * n hn1 : n = 0 β’ False ** exact hn hn1 ** Qed | |
Nat.Coprime.dvd_of_dvd_mul_right ** k n m : Nat H1 : Coprime k n H2 : k β£ m * n β’ k β£ m ** let t := dvd_gcd (Nat.dvd_mul_left k m) H2 ** k n m : Nat H1 : Coprime k n H2 : k β£ m * n t : k β£ gcd (m * k) (m * n) := dvd_gcd (Nat.dvd_mul_left k m) H2 β’ k β£ m ** rwa [gcd_mul_left, H1.gcd_eq_one, Nat.mul_one] at t ** Qed | |
Nat.Coprime.dvd_of_dvd_mul_left ** k m n : Nat H1 : Coprime k m H2 : k β£ m * n β’ k β£ n * m ** rwa [Nat.mul_comm] ** Qed | |
Nat.Coprime.gcd_mul_right_cancel ** k n m : Nat H : Coprime k n β’ gcd (m * k) n = gcd m n ** rw [Nat.mul_comm m k, H.gcd_mul_left_cancel m] ** Qed | |
Nat.Coprime.gcd_mul_left_cancel_right ** k m n : Nat H : Coprime k m β’ gcd m (k * n) = gcd m n ** rw [gcd_comm m n, gcd_comm m (k * n), H.gcd_mul_left_cancel n] ** Qed | |
Nat.Coprime.gcd_mul_right_cancel_right ** k m n : Nat H : Coprime k m β’ gcd m (n * k) = gcd m n ** rw [Nat.mul_comm n k, H.gcd_mul_left_cancel_right n] ** Qed | |
Nat.coprime_div_gcd_div_gcd ** m n : Nat H : 0 < gcd m n β’ Coprime (m / gcd m n) (n / gcd m n) ** rw [coprime_iff_gcd_eq_one, gcd_div (gcd_dvd_left m n) (gcd_dvd_right m n), Nat.div_self H] ** Qed | |
Nat.not_coprime_of_dvd_of_dvd ** d m n : Nat dgt1 : 1 < d Hm : d β£ m Hn : d β£ n co : Coprime m n β’ d β£ 1 ** rw [β co.gcd_eq_one] ** d m n : Nat dgt1 : 1 < d Hm : d β£ m Hn : d β£ n co : Coprime m n β’ d β£ gcd m n ** exact dvd_gcd Hm Hn ** Qed | |
Nat.Coprime.coprime_dvd_left ** m k n : Nat H1 : m β£ k H2 : Coprime k n β’ Coprime m n ** apply eq_one_of_dvd_one ** case H m k n : Nat H1 : m β£ k H2 : Coprime k n β’ gcd m n β£ 1 ** rw [Coprime] at H2 ** case H m k n : Nat H1 : m β£ k H2 : gcd k n = 1 β’ gcd m n β£ 1 ** have := Nat.gcd_dvd_gcd_of_dvd_left n H1 ** case H m k n : Nat H1 : m β£ k H2 : gcd k n = 1 this : gcd m n β£ gcd k n β’ gcd m n β£ 1 ** rwa [β H2] ** Qed | |
Nat.Coprime.coprime_div_left ** m n a : Nat cmn : Coprime m n dvd : a β£ m β’ Coprime (m / a) n ** match eq_zero_or_pos a with
| .inl h0 =>
rw [h0] at dvd
rw [Nat.eq_zero_of_zero_dvd dvd] at cmn β’
simp; assumption
| .inr hpos =>
let β¨k, hkβ© := dvd
rw [hk, Nat.mul_div_cancel_left _ hpos]
rw [hk] at cmn
exact cmn.coprime_mul_left ** m n a : Nat cmn : Coprime m n dvd : a β£ m h0 : a = 0 β’ Coprime (m / a) n ** rw [h0] at dvd ** m n a : Nat cmn : Coprime m n dvd : 0 β£ m h0 : a = 0 β’ Coprime (m / a) n ** rw [Nat.eq_zero_of_zero_dvd dvd] at cmn β’ ** m n a : Nat cmn : Coprime 0 n dvd : 0 β£ m h0 : a = 0 β’ Coprime (0 / a) n ** simp ** m n a : Nat cmn : Coprime 0 n dvd : 0 β£ m h0 : a = 0 β’ Coprime 0 n ** assumption ** m n a : Nat cmn : Coprime m n dvd : a β£ m hpos : a > 0 β’ Coprime (m / a) n ** let β¨k, hkβ© := dvd ** m n a : Nat cmn : Coprime m n dvd : a β£ m hpos : a > 0 k : Nat hk : m = a * k β’ Coprime (m / a) n ** rw [hk, Nat.mul_div_cancel_left _ hpos] ** m n a : Nat cmn : Coprime m n dvd : a β£ m hpos : a > 0 k : Nat hk : m = a * k β’ Coprime k n ** rw [hk] at cmn ** m n a : Nat dvd : a β£ m hpos : a > 0 k : Nat cmn : Coprime (a * k) n hk : m = a * k β’ Coprime k n ** exact cmn.coprime_mul_left ** Qed | |
Nat.coprime_mul_iff_left ** m n k : Nat xβ : Coprime m k β§ Coprime n k h : Coprime m k rightβ : Coprime n k β’ Coprime (m * n) k ** rwa [coprime_iff_gcd_eq_one, h.gcd_mul_left_cancel n] ** Qed | |
Nat.coprime_mul_iff_right ** k m n : Nat β’ Coprime k (m * n) β Coprime k m β§ Coprime k n ** rw [@coprime_comm k, @coprime_comm k, @coprime_comm k, coprime_mul_iff_left] ** Qed | |
Nat.coprime_zero_left ** n : Nat β’ Coprime 0 n β n = 1 ** simp [Coprime] ** Qed | |
Nat.coprime_zero_right ** n : Nat β’ Coprime n 0 β n = 1 ** simp [Coprime] ** Qed | |
Nat.coprime_self ** n : Nat β’ Coprime n n β n = 1 ** simp [Coprime] ** Qed | |
Nat.Coprime.pow_left ** m k n : Nat H1 : Coprime m k β’ Coprime (m ^ n) k ** induction n with
| zero => exact coprime_one_left _
| succ n ih => have hm := H1.mul ih; rwa [Nat.pow_succ, Nat.mul_comm] ** case zero m k : Nat H1 : Coprime m k β’ Coprime (m ^ zero) k ** exact coprime_one_left _ ** case succ m k : Nat H1 : Coprime m k n : Nat ih : Coprime (m ^ n) k β’ Coprime (m ^ succ n) k ** have hm := H1.mul ih ** case succ m k : Nat H1 : Coprime m k n : Nat ih : Coprime (m ^ n) k hm : Coprime (m * m ^ n) k β’ Coprime (m ^ succ n) k ** rwa [Nat.pow_succ, Nat.mul_comm] ** Qed | |
Nat.Coprime.eq_one_of_dvd ** k m : Nat H : Coprime k m d : k β£ m β’ k = 1 ** rw [β H.gcd_eq_one, gcd_eq_left d] ** Qed | |
Nat.gcd_mul_dvd_mul_gcd ** k m n : Nat β’ gcd k (m * n) β£ gcd k m * gcd k n ** let β¨β¨β¨m', hm'β©, β¨n', hn'β©β©, (h : gcd k (m * n) = m' * n')β© :=
prod_dvd_and_dvd_of_dvd_prod <| gcd_dvd_right k (m * n) ** k m n m' : Nat hm' : m' β£ m n' : Nat hn' : n' β£ n h : gcd k (m * n) = m' * n' β’ gcd k (m * n) β£ gcd k m * gcd k n ** rw [h] ** k m n m' : Nat hm' : m' β£ m n' : Nat hn' : n' β£ n h : gcd k (m * n) = m' * n' β’ m' * n' β£ gcd k m * gcd k n ** have h' : m' * n' β£ k := h βΈ gcd_dvd_left .. ** k m n m' : Nat hm' : m' β£ m n' : Nat hn' : n' β£ n h : gcd k (m * n) = m' * n' h' : m' * n' β£ k β’ m' * n' β£ gcd k m * gcd k n ** exact Nat.mul_dvd_mul
(dvd_gcd (Nat.dvd_trans (Nat.dvd_mul_right m' n') h') hm')
(dvd_gcd (Nat.dvd_trans (Nat.dvd_mul_left n' m') h') hn') ** Qed | |
Rat.normalize.reduced ** num : Int den g : Nat den_nz : den β 0 e : g = Nat.gcd (Int.natAbs num) den β’ Int.natAbs (Int.div num βg) = Int.natAbs num / g ** match num, num.eq_nat_or_neg with
| _, β¨_, .inl rflβ© => rfl
| _, β¨_, .inr rflβ© => rw [Int.neg_div, Int.natAbs_neg, Int.natAbs_neg]; rfl ** num : Int den g : Nat den_nz : den β 0 wβ : Nat e : g = Nat.gcd (Int.natAbs βwβ) den β’ Int.natAbs (Int.div βwβ βg) = Int.natAbs βwβ / g ** rfl ** num : Int den g : Nat den_nz : den β 0 wβ : Nat e : g = Nat.gcd (Int.natAbs (-βwβ)) den β’ Int.natAbs (Int.div (-βwβ) βg) = Int.natAbs (-βwβ) / g ** rw [Int.neg_div, Int.natAbs_neg, Int.natAbs_neg] ** num : Int den g : Nat den_nz : den β 0 wβ : Nat e : g = Nat.gcd (Int.natAbs (-βwβ)) den β’ Int.natAbs (Int.div βwβ βg) = Int.natAbs βwβ / g ** rfl ** Qed | |
Int.ofNat_fdiv ** xβ : Nat β’ β(0 / xβ) = fdiv β0 βxβ ** simp [fdiv] ** Qed | |
Int.zero_div ** aβ : Nat β’ ofNat (0 / aβ) = 0 ** simp ** aβ : Nat β’ -ofNat (0 / succ aβ) = 0 ** simp ** Qed | |
Int.zero_ediv ** aβ : Nat β’ ofNat (0 / aβ) = 0 ** simp ** aβ : Nat β’ -ofNat (0 / succ aβ) = 0 ** simp ** Qed | |
Int.zero_fdiv ** b : Int β’ fdiv 0 b = 0 ** cases b <;> rfl ** Qed | |
Int.div_zero ** aβ : Nat β’ ofNat (aβ / 0) = 0 ** simp ** Qed | |
Int.ediv_zero ** aβ : Nat β’ ofNat (aβ / 0) = 0 ** simp ** Qed | |
Int.fdiv_eq_ediv ** aβ : Nat xβ : 0 β€ 0 β’ fdiv -[aβ+1] 0 = -[aβ+1] / 0 ** simp ** Qed | |
Int.div_eq_ediv ** xβΒ² : Int xβΒΉ : 0 β€ xβΒ² xβ : 0 β€ 0 β’ div xβΒ² 0 = xβΒ² / 0 ** simp ** Qed | |
Int.div_neg ** m : Nat β’ ofNat (m / 0) = -β(m / 0) ** rw [Nat.div_zero] ** m : Nat β’ ofNat 0 = -β0 ** rfl ** Qed | |
Int.ediv_neg ** m : Nat β’ ofNat (m / 0) = -β(m / 0) ** rw [Nat.div_zero] ** m : Nat β’ ofNat 0 = -β0 ** rfl ** Qed | |
Int.neg_div ** n : Int β’ div (-0) n = -div 0 n ** simp [Int.neg_zero] ** Qed | |
Int.neg_div_neg ** a b : Int β’ div (-a) (-b) = div a b ** simp [Int.div_neg, Int.neg_div, Int.neg_neg] ** Qed | |
Int.div_one ** n : Nat β’ div -[n+1] 1 = -[n+1] ** simp [Int.div, neg_ofNat_succ] ** Qed | |
Int.add_ediv_of_dvd_right ** a b c : Int H : c β£ b h : c = 0 β’ (a + b) / c = a / c + b / c ** simp [h] ** a b c : Int H : c β£ b h : Β¬c = 0 β’ (a + b) / c = a / c + b / c ** let β¨k, hkβ© := H ** a b c : Int H : c β£ b h : Β¬c = 0 k : Int hk : b = c * k β’ (a + b) / c = a / c + b / c ** rw [hk, Int.mul_comm c k, Int.add_mul_ediv_right _ _ h,
β Int.zero_add (k * c), Int.add_mul_ediv_right _ _ h, Int.zero_ediv, Int.zero_add] ** Qed | |
Int.add_ediv_of_dvd_left ** a b c : Int H : c β£ a β’ (a + b) / c = a / c + b / c ** rw [Int.add_comm, Int.add_ediv_of_dvd_right H, Int.add_comm] ** Qed | |
Int.mul_ediv_cancel ** a b : Int H : b β 0 β’ a * b / b = a ** have := Int.add_mul_ediv_right 0 a H ** a b : Int H : b β 0 this : (0 + a * b) / b = 0 / b + a β’ a * b / b = a ** rwa [Int.zero_add, Int.zero_ediv, Int.zero_add] at this ** Qed | |
Int.mul_fdiv_cancel ** a b : Int H : b β 0 b0 : 0 β€ b β’ fdiv (a * b) b = a ** rw [fdiv_eq_ediv _ b0, mul_ediv_cancel _ H] ** a b xβΒΉ : Int xβ : xβΒΉ < 0 H : xβΒΉ β 0 b0 : Β¬0 β€ xβΒΉ β’ fdiv (0 * xβΒΉ) xβΒΉ = 0 ** simp [Int.zero_mul] ** Qed | |
Int.div_self ** a : Int H : a β 0 β’ div a a = 1 ** have := Int.mul_div_cancel 1 H ** a : Int H : a β 0 this : div (1 * a) a = 1 β’ div a a = 1 ** rwa [Int.one_mul] at this ** Qed | |
Int.fdiv_self ** a : Int H : a β 0 β’ fdiv a a = 1 ** have := Int.mul_fdiv_cancel 1 H ** a : Int H : a β 0 this : fdiv (1 * a) a = 1 β’ fdiv a a = 1 ** rwa [Int.one_mul] at this ** Qed | |
Int.ediv_self ** a : Int H : a β 0 β’ a / a = 1 ** have := Int.mul_ediv_cancel 1 H ** a : Int H : a β 0 this : 1 * a / a = 1 β’ a / a = 1 ** rwa [Int.one_mul] at this ** Qed | |
Int.ofNat_fmod ** m n : Nat β’ β(m % n) = fmod βm βn ** cases m <;> simp [fmod] ** Qed | |
Int.negSucc_emod ** m : Nat b : Int bpos : 0 < b β’ -[m+1] % b = b - 1 - βm % b ** rw [Int.sub_sub, Int.add_comm] ** m : Nat b : Int bpos : 0 < b β’ -[m+1] % b = b - (βm % b + 1) ** match b, eq_succ_of_zero_lt bpos with
| _, β¨n, rflβ© => rfl ** m : Nat b : Int n : Nat bpos : 0 < β(succ n) β’ -[m+1] % β(succ n) = β(succ n) - (βm % β(succ n) + 1) ** rfl ** Qed | |
Int.zero_mod ** b : Int β’ mod 0 b = 0 ** cases b <;> simp [mod] ** Qed | |
Int.zero_fmod ** b : Int β’ fmod 0 b = 0 ** cases b <;> rfl ** Qed | |
Int.mod_add_div ** m n : Nat β’ mod (ofNat m) -[n+1] + -[n+1] * div (ofNat m) -[n+1] = ofNat m ** show (m % succ n + -β(succ n) * -β(m / succ n) : Int) = m ** m n : Nat β’ βm % β(succ n) + -β(succ n) * -β(m / succ n) = βm ** rw [Int.neg_mul_neg] ** m n : Nat β’ βm % β(succ n) + β(succ n) * β(m / succ n) = βm ** exact congrArg ofNat (Nat.mod_add_div ..) ** m n : Nat β’ mod -[m+1] (ofNat n) + ofNat n * div -[m+1] (ofNat n) = -[m+1] ** show -(β((succ m) % n) : Int) + βn * -β(succ m / n) = -β(succ m) ** m n : Nat β’ -β(succ m % n) + βn * -β(succ m / n) = -β(succ m) ** rw [Int.mul_neg, β Int.neg_add] ** m n : Nat β’ mod -[m+1] -[n+1] + -[n+1] * div -[m+1] -[n+1] = -[m+1] ** show -(β(succ m % succ n) : Int) + -β(succ n) * β(succ m / succ n) = -β(succ m) ** m n : Nat β’ -β(succ m % succ n) + -β(succ n) * β(succ m / succ n) = -β(succ m) ** rw [Int.neg_mul, β Int.neg_add] ** Qed | |
Int.emod_add_ediv ** m n : Nat β’ ofNat m % -[n+1] + -[n+1] * (ofNat m / -[n+1]) = ofNat m ** show (m % succ n + -β(succ n) * -β(m / succ n) : Int) = m ** m n : Nat β’ βm % β(succ n) + -β(succ n) * -β(m / succ n) = βm ** rw [Int.neg_mul_neg] ** m n : Nat β’ βm % β(succ n) + β(succ n) * β(m / succ n) = βm ** exact congrArg ofNat <| Nat.mod_add_div .. ** aβ : Nat β’ -[aβ+1] % 0 + 0 * (-[aβ+1] / 0) = -[aβ+1] ** rw [emod_zero] ** aβ : Nat β’ -[aβ+1] + 0 * (-[aβ+1] / 0) = -[aβ+1] ** rfl ** xβΒΉ xβ : Int m n : Nat β’ βn - (βm % βn + 1) - (βn * (βm / βn) + βn) = -[m+1] ** rw [β ofNat_emod, β ofNat_ediv, β Int.sub_sub, negSucc_eq, Int.sub_sub n,
β Int.neg_neg (_-_), Int.neg_sub, Int.sub_sub_self, Int.add_right_comm] ** xβΒΉ xβ : Int m n : Nat β’ -(β(m % n) + βn * β(m / n) + 1) = -(βm + 1) ** exact congrArg (fun x => -(ofNat x + 1)) (Nat.mod_add_div ..) ** Qed | |
Int.mod_def ** a b : Int β’ mod a b = a - b * div a b ** rw [β Int.add_sub_cancel (mod a b), mod_add_div] ** Qed | |
Int.fmod_def ** a b : Int β’ fmod a b = a - b * fdiv a b ** rw [β Int.add_sub_cancel (a.fmod b), fmod_add_fdiv] ** Qed | |
Int.emod_def ** a b : Int β’ a % b = a - b * (a / b) ** rw [β Int.add_sub_cancel (a % b), emod_add_ediv] ** Qed | |
Int.fmod_eq_emod ** a b : Int hb : 0 β€ b β’ fmod a b = a % b ** simp [fmod_def, emod_def, fdiv_eq_ediv _ hb] ** Qed | |
Int.mod_eq_emod ** a b : Int ha : 0 β€ a hb : 0 β€ b β’ mod a b = a % b ** simp [emod_def, mod_def, div_eq_ediv ha hb] ** Qed | |
Int.mod_neg ** a b : Int β’ mod a (-b) = mod a b ** rw [mod_def, mod_def, Int.div_neg, Int.neg_mul_neg] ** Qed | |
Int.emod_neg ** a b : Int β’ a % -b = a % b ** rw [emod_def, emod_def, Int.ediv_neg, Int.neg_mul_neg] ** Qed | |
Int.emod_one ** a : Int β’ a % 1 = 0 ** simp [emod_def, Int.one_mul, Int.sub_self] ** Qed | |
Int.fmod_one ** a : Int β’ fmod a 1 = 0 ** simp [fmod_def, Int.one_mul, Int.sub_self] ** Qed | |
Int.mod_eq_of_lt ** a b : Int H1 : 0 β€ a H2 : a < b β’ mod a b = a ** rw [mod_eq_emod H1 (Int.le_trans H1 (Int.le_of_lt H2)), emod_eq_of_lt H1 H2] ** Qed | |
Int.fmod_eq_of_lt ** a b : Int H1 : 0 β€ a H2 : a < b β’ fmod a b = a ** rw [fmod_eq_emod _ (Int.le_trans H1 (Int.le_of_lt H2)), emod_eq_of_lt H1 H2] ** Qed | |
Int.mod_add_div' ** m k : Int β’ mod m k + div m k * k = m ** rw [Int.mul_comm] ** m k : Int β’ mod m k + k * div m k = m ** apply mod_add_div ** Qed | |
Int.div_add_mod' ** m k : Int β’ div m k * k + mod m k = m ** rw [Int.mul_comm] ** m k : Int β’ k * div m k + mod m k = m ** apply div_add_mod ** Qed | |
Int.emod_add_ediv' ** m k : Int β’ m % k + m / k * k = m ** rw [Int.mul_comm] ** m k : Int β’ m % k + k * (m / k) = m ** apply emod_add_ediv ** Qed | |
Int.add_mul_emod_self ** a b c : Int cz : c = 0 β’ (a + b * c) % c = a % c ** rw [cz, Int.mul_zero, Int.add_zero] ** a b c : Int cz : Β¬c = 0 β’ (a + b * c) % c = a % c ** rw [Int.emod_def, Int.emod_def, Int.add_mul_ediv_right _ _ cz, Int.add_comm _ b,
Int.mul_add, Int.mul_comm, β Int.sub_sub, Int.add_sub_cancel] ** Qed | |
Int.add_mul_emod_self_left ** a b c : Int β’ (a + b * c) % b = a % b ** rw [Int.mul_comm, Int.add_mul_emod_self] ** Qed | |
Int.add_emod_self ** a b : Int β’ (a + b) % b = a % b ** have := add_mul_emod_self_left a b 1 ** a b : Int this : (a + b * 1) % b = a % b β’ (a + b) % b = a % b ** rwa [Int.mul_one] at this ** Qed | |
Int.add_emod_self_left ** a b : Int β’ (a + b) % a = b % a ** rw [Int.add_comm, Int.add_emod_self] ** Qed | |
Int.emod_add_emod ** m n k : Int β’ (m % n + k) % n = (m + k) % n ** have := (add_mul_emod_self_left (m % n + k) n (m / n)).symm ** m n k : Int this : (m % n + k) % n = (m % n + k + n * (m / n)) % n β’ (m % n + k) % n = (m + k) % n ** rwa [Int.add_right_comm, emod_add_ediv] at this ** Qed | |
Int.add_emod_emod ** m n k : Int β’ (m + n % k) % k = (m + n) % k ** rw [Int.add_comm, emod_add_emod, Int.add_comm] ** Qed | |
Int.add_emod ** a b n : Int β’ (a + b) % n = (a % n + b % n) % n ** rw [add_emod_emod, emod_add_emod] ** Qed | |
Int.add_emod_eq_add_emod_right ** m n k i : Int H : m % n = k % n β’ (m + i) % n = (k + i) % n ** rw [β emod_add_emod, β emod_add_emod k, H] ** Qed | |
Int.add_emod_eq_add_emod_left ** m n k i : Int H : m % n = k % n β’ (i + m) % n = (i + k) % n ** rw [Int.add_comm, add_emod_eq_add_emod_right _ H, Int.add_comm] ** Qed | |
Int.emod_add_cancel_right ** m n k i : Int H : (m + i) % n = (k + i) % n β’ m % n = k % n ** have := add_emod_eq_add_emod_right (-i) H ** m n k i : Int H : (m + i) % n = (k + i) % n this : (m + i + -i) % n = (k + i + -i) % n β’ m % n = k % n ** rwa [Int.add_neg_cancel_right, Int.add_neg_cancel_right] at this ** Qed | |
Int.emod_add_cancel_left ** m n k i : Int β’ (i + m) % n = (i + k) % n β m % n = k % n ** rw [Int.add_comm, Int.add_comm i, emod_add_cancel_right] ** Qed | |
Int.emod_eq_emod_iff_emod_sub_eq_zero ** m n k : Int β’ (m - k) % n = (k - k) % n β (m - k) % n = 0 ** simp [Int.sub_self] ** Qed | |
Int.mul_mod_left ** a b : Int h : b = 0 β’ mod (a * b) b = 0 ** simp [h, Int.mul_zero] ** a b : Int h : Β¬b = 0 β’ mod (a * b) b = 0 ** rw [Int.mod_def, Int.mul_div_cancel _ h, Int.mul_comm, Int.sub_self] ** Qed | |
Int.mul_fmod_left ** a b : Int h : b = 0 β’ fmod (a * b) b = 0 ** simp [h, Int.mul_zero] ** a b : Int h : Β¬b = 0 β’ fmod (a * b) b = 0 ** rw [Int.fmod_def, Int.mul_fdiv_cancel _ h, Int.mul_comm, Int.sub_self] ** Qed | |
Int.mul_emod_left ** a b : Int β’ a * b % b = 0 ** rw [β Int.zero_add (a * b), Int.add_mul_emod_self, Int.zero_emod] ** Qed | |
Int.mul_mod_right ** a b : Int β’ mod (a * b) a = 0 ** rw [Int.mul_comm, mul_mod_left] ** Qed | |
Int.mul_fmod_right ** a b : Int β’ fmod (a * b) a = 0 ** rw [Int.mul_comm, mul_fmod_left] ** Qed | |
Int.mul_emod_right ** a b : Int β’ a * b % a = 0 ** rw [Int.mul_comm, mul_emod_left] ** Qed | |
Int.mod_self ** a : Int β’ mod a a = 0 ** have := mul_mod_left 1 a ** a : Int this : mod (1 * a) a = 0 β’ mod a a = 0 ** rwa [Int.one_mul] at this ** Qed | |
Int.fmod_self ** a : Int β’ fmod a a = 0 ** have := mul_fmod_left 1 a ** a : Int this : fmod (1 * a) a = 0 β’ fmod a a = 0 ** rwa [Int.one_mul] at this ** Qed | |
Int.emod_self ** a : Int β’ a % a = 0 ** have := mul_emod_left 1 a ** a : Int this : 1 * a % a = 0 β’ a % a = 0 ** rwa [Int.one_mul] at this ** Qed | |
Int.emod_emod_of_dvd ** n m k : Int h : m β£ k β’ n % k % m = n % m ** conv => rhs; rw [β emod_add_ediv n k] ** n m k : Int h : m β£ k β’ n % k % m = (n % k + k * (n / k)) % m ** match k, h with
| _, β¨t, rflβ© => rw [Int.mul_assoc, add_mul_emod_self_left] ** n m k : Int h : m β£ k t : Int β’ n % (m * t) % m = (n % (m * t) + m * t * (n / (m * t))) % m ** rw [Int.mul_assoc, add_mul_emod_self_left] ** Qed |