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