number_theory.sum_four_squares
⟷
Mathlib.NumberTheory.SumFourSquares
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -56,7 +56,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
hp.1.eq_two_or_odd.elim (fun hp2 => hp2.symm ▸ ⟨1, 0, 1, rfl, by decide⟩) fun hp1 =>
let ⟨a, b, hab⟩ := ZMod.sq_add_sq p (-1)
have hab' : (p : ℤ) ∣ a.valMinAbs ^ 2 + b.valMinAbs ^ 2 + 1 :=
- (CharP.int_cast_eq_zero_iff (ZMod p) p _).1 <| by simpa [eq_neg_iff_add_eq_zero] using hab
+ (CharP.intCast_eq_zero_iff (ZMod p) p _).1 <| by simpa [eq_neg_iff_add_eq_zero] using hab
let ⟨k, hk⟩ := hab'
have hk0 : 0 ≤ k :=
nonneg_of_mul_nonneg_right
@@ -113,10 +113,10 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
rfl)
let σ := swap i 0
have h01 : 2 ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2 :=
- (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
+ (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by
simpa only [Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
have h23 : 2 ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2 :=
- (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
+ (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by
simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2
let ⟨x, hx⟩ := h01
let ⟨y, hy⟩ := h23
@@ -199,15 +199,15 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
((a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 : ℤ) : ZMod m) :=
by push_cast
have hwxyz0 : ((w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 : ℤ) : ZMod m) = 0 := by
- rw [hwxyzabcd, habcd, Int.cast_mul, cast_coe_nat, ZMod.nat_cast_self, MulZeroClass.zero_mul]
- let ⟨n, hn⟩ := (CharP.int_cast_eq_zero_iff _ m _).1 hwxyz0
+ rw [hwxyzabcd, habcd, Int.cast_mul, cast_coe_nat, ZMod.natCast_self, MulZeroClass.zero_mul]
+ let ⟨n, hn⟩ := (CharP.intCast_eq_zero_iff _ m _).1 hwxyz0
have hn0 : 0 < n.natAbs :=
Int.natAbs_pos fun hn0 =>
have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 := by
rw [← Int.natCast_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
- pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
+ pow_eq_zero_iff two_pos, CharP.intCast_eq_zero_iff _ m _] using hwxyz0
let ⟨ma, hma⟩ := habcd0.1
let ⟨mb, hmb⟩ := habcd0.2.1
let ⟨mc, hmc⟩ := habcd0.2.2.1
@@ -220,13 +220,13 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(hp.1.eq_one_or_self_of_dvd _ hmdvdp).elim hm1 fun hmeqp => by
simpa [lt_irrefl, hmeqp] using hmp
have hawbxcydz : ((m : ℕ) : ℤ) ∣ a * w + b * x + c * y + d * z :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by rw [← hwxyz0]; simp_rw [sq]; push_cast
+ (CharP.intCast_eq_zero_iff (ZMod m) m _).1 <| by rw [← hwxyz0]; simp_rw [sq]; push_cast
have haxbwczdy : ((m : ℕ) : ℤ) ∣ a * x - b * w - c * z + d * y :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
+ (CharP.intCast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
have haybzcwdx : ((m : ℕ) : ℤ) ∣ a * y + b * z - c * w - d * x :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
+ (CharP.intCast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
have hazbycxdw : ((m : ℕ) : ℤ) ∣ a * z - b * y + c * x - d * w :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
+ (CharP.intCast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
let ⟨s, hs⟩ := hawbxcydz
let ⟨t, ht⟩ := haxbwczdy
let ⟨u, hu⟩ := haybzcwdx
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -61,7 +61,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
have hk0 : 0 ≤ k :=
nonneg_of_mul_nonneg_right
(by rw [← hk] <;> exact add_nonneg (add_nonneg (sq_nonneg _) (sq_nonneg _)) zero_le_one)
- (Int.coe_nat_pos.2 hp.1.Pos)
+ (Int.natCast_pos.2 hp.1.Pos)
⟨a.valMinAbs, b.valMinAbs, k.natAbs, by rw [hk, Int.natAbs_of_nonneg hk0, mul_comm],
lt_of_mul_lt_mul_left
(calc
@@ -234,7 +234,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hn_nonneg : 0 ≤ n :=
nonneg_of_mul_nonneg_right
(by erw [← hn]; repeat' try refine' add_nonneg _ _; try exact sq_nonneg _)
- (Int.coe_nat_pos.2 <| NeZero.pos m)
+ (Int.natCast_pos.2 <| NeZero.pos m)
have hnm : n.natAbs < m :=
Int.ofNat_lt.1
(lt_of_mul_lt_mul_left (by rw [Int.natAbs_of_nonneg hn_nonneg, ← hn, ← sq]; exact hwxyzlt)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Algebra.GroupPower.Identities
-import Data.Zmod.Basic
+import Data.ZMod.Basic
import FieldTheory.Finite.Basic
import Data.Int.Parity
import Data.Fintype.BigOperators
@@ -46,7 +46,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
rw [even_iff_two_dvd] at hxsuby hxaddy
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
- simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
+ simp [mul_add, pow_succ', mul_comm, mul_assoc, mul_left_comm]
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
-/
@@ -66,7 +66,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
lt_of_mul_lt_mul_left
(calc
p * k.natAbs = a.valMinAbs.natAbs ^ 2 + b.valMinAbs.natAbs ^ 2 + 1 := by
- rw [← Int.coe_nat_inj', Int.ofNat_add, Int.ofNat_add, Int.coe_nat_pow, Int.coe_nat_pow,
+ rw [← Int.natCast_inj, Int.ofNat_add, Int.ofNat_add, Int.coe_nat_pow, Int.coe_nat_pow,
Int.natAbs_sq, Int.natAbs_sq, Int.ofNat_one, hk, Int.ofNat_mul,
Int.natAbs_of_nonneg hk0]
_ ≤ (p / 2) ^ 2 + (p / 2) ^ 2 + 1 :=
@@ -189,7 +189,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
((lt_add_iff_pos_right _).2
(by
rw [hm2, Int.ofNat_one, one_pow, mul_one]
- exact add_pos_of_nonneg_of_pos (Int.coe_nat_nonneg _) zero_lt_one))
+ exact add_pos_of_nonneg_of_pos (Int.natCast_nonneg _) zero_lt_one))
_ = m ^ 2 := by
conv_rhs => rw [← Nat.mod_add_div m 2]
simp [-Nat.mod_add_div, mul_add, add_mul, bit0, bit1, mul_comm, mul_assoc,
@@ -202,9 +202,9 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
rw [hwxyzabcd, habcd, Int.cast_mul, cast_coe_nat, ZMod.nat_cast_self, MulZeroClass.zero_mul]
let ⟨n, hn⟩ := (CharP.int_cast_eq_zero_iff _ m _).1 hwxyz0
have hn0 : 0 < n.natAbs :=
- Int.natAbs_pos_of_ne_zero fun hn0 =>
+ Int.natAbs_pos fun hn0 =>
have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 := by
- rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
+ rw [← Int.natCast_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
@@ -213,9 +213,9 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
let ⟨mc, hmc⟩ := habcd0.2.2.1
let ⟨md, hmd⟩ := habcd0.2.2.2
have hmdvdp : m ∣ p :=
- Int.coe_nat_dvd.1
+ Int.natCast_dvd_natCast.1
⟨ma ^ 2 + mb ^ 2 + mc ^ 2 + md ^ 2,
- (mul_right_inj' (show (m : ℤ) ≠ 0 from Int.coe_nat_ne_zero.2 hm0.1)).1 <| by
+ (mul_right_inj' (show (m : ℤ) ≠ 0 from Int.natCast_ne_zero.2 hm0.1)).1 <| by
rw [← habcd, hma, hmb, hmc, hmd]; ring⟩
(hp.1.eq_one_or_self_of_dvd _ hmdvdp).elim hm1 fun hmeqp => by
simpa [lt_irrefl, hmeqp] using hmp
@@ -238,10 +238,10 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hnm : n.natAbs < m :=
Int.ofNat_lt.1
(lt_of_mul_lt_mul_left (by rw [Int.natAbs_of_nonneg hn_nonneg, ← hn, ← sq]; exact hwxyzlt)
- (Int.coe_nat_nonneg m))
+ (Int.natCast_nonneg m))
have hstuv : s ^ 2 + t ^ 2 + u ^ 2 + v ^ 2 = n.natAbs * p :=
(mul_right_inj'
- (show (m ^ 2 : ℤ) ≠ 0 from pow_ne_zero 2 (Int.coe_nat_ne_zero.2 hm0.1))).1 <|
+ (show (m ^ 2 : ℤ) ≠ 0 from pow_ne_zero 2 (Int.natCast_ne_zero.2 hm0.1))).1 <|
calc
(m : ℤ) ^ 2 * (s ^ 2 + t ^ 2 + u ^ 2 + v ^ 2) =
((m : ℕ) * s) ^ 2 + ((m : ℕ) * t) ^ 2 + ((m : ℕ) * u) ^ 2 + ((m : ℕ) * v) ^ 2 :=
@@ -266,8 +266,7 @@ theorem sum_four_squares : ∀ n : ℕ, ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2
⟨(a * w - b * x - c * y - d * z).natAbs, (a * x + b * w + c * z - d * y).natAbs,
(a * y - b * z + c * w + d * x).natAbs, (a * z + b * y - c * x + d * w).natAbs,
by
- rw [← Int.coe_nat_inj', ← Nat.mul_div_cancel' (min_fac_dvd (k + 2)), Int.ofNat_mul, ← h₁, ←
- h₂]
+ rw [← Int.natCast_inj, ← Nat.mul_div_cancel' (min_fac_dvd (k + 2)), Int.ofNat_mul, ← h₁, ← h₂]
simp [sum_four_sq_mul_sum_four_sq]⟩
#align nat.sum_four_squares Nat.sum_four_squares
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -43,7 +43,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
2 * 2 * m = (x - y) ^ 2 + (x + y) ^ 2 := by rw [mul_assoc, h] <;> ring
_ = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2 :=
by
- rw [even_iff_two_dvd] at hxsuby hxaddy
+ rw [even_iff_two_dvd] at hxsuby hxaddy
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
@@ -136,7 +136,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
⟨k, hk.2,
Nat.pos_of_ne_zero fun hk0 =>
by
- rw [hk0, Int.ofNat_zero, MulZeroClass.zero_mul] at hk
+ rw [hk0, Int.ofNat_zero, MulZeroClass.zero_mul] at hk
exact
ne_of_gt
(show a ^ 2 + b ^ 2 + 1 > 0 from
@@ -151,7 +151,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(fun hm2 : m % 2 = 0 =>
let ⟨k, hk⟩ := Nat.dvd_iff_mod_eq_zero.2 hm2
have hk0 : 0 < k :=
- Nat.pos_of_ne_zero <| by rintro rfl; rw [MulZeroClass.mul_zero] at hk ; exact NeZero.ne m hk
+ Nat.pos_of_ne_zero <| by rintro rfl; rw [MulZeroClass.mul_zero] at hk; exact NeZero.ne m hk
have hkm : k < m := by rw [hk, two_mul]; exact (lt_add_iff_pos_left _).2 hk0
False.elim <|
Nat.find_min hm hkm
@@ -204,7 +204,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hn0 : 0 < n.natAbs :=
Int.natAbs_pos_of_ne_zero fun hn0 =>
have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 := by
- rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
+ rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -71,8 +71,8 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
Int.natAbs_of_nonneg hk0]
_ ≤ (p / 2) ^ 2 + (p / 2) ^ 2 + 1 :=
(add_le_add
- (add_le_add (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _)
- (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
+ (add_le_add (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _)
+ (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _))
le_rfl)
_ < (p / 2) ^ 2 + (p / 2) ^ 2 + (p % 2) ^ 2 + (2 * (p / 2) ^ 2 + 4 * (p / 2) * (p % 2)) :=
by
@@ -179,10 +179,10 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(Int.ofNat_le.2 <|
add_le_add
(add_le_add
- (add_le_add (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _)
- (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
- (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
- (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
+ (add_le_add (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _)
+ (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _))
+ (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _))
+ (Nat.pow_le_pow_left (ZMod.natAbs_valMinAbs_le _) _))
_ = 4 * (m / 2 : ℕ) ^ 2 := by
simp only [bit0_mul, one_mul, two_smul, Nat.cast_add, Nat.cast_pow, add_assoc]
_ < 4 * (m / 2 : ℕ) ^ 2 + ((4 * (m / 2) : ℕ) * (m % 2 : ℕ) + (m % 2 : ℕ) ^ 2) :=
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -169,7 +169,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hnat_abs :
w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 =
(w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) :=
- by push_cast ; simp_rw [sq_abs]
+ by push_cast; simp_rw [sq_abs]
have hwxyzlt : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 < m ^ 2 :=
calc
w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 =
@@ -222,11 +222,11 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hawbxcydz : ((m : ℕ) : ℤ) ∣ a * w + b * x + c * y + d * z :=
(CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by rw [← hwxyz0]; simp_rw [sq]; push_cast
have haxbwczdy : ((m : ℕ) : ℤ) ∣ a * x - b * w - c * z + d * y :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
have haybzcwdx : ((m : ℕ) : ℤ) ∣ a * y + b * z - c * w - d * x :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
have hazbycxdw : ((m : ℕ) : ℤ) ∣ a * z - b * y + c * x - d * w :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast; ring
let ⟨s, hs⟩ := hawbxcydz
let ⟨t, ht⟩ := haxbwczdy
let ⟨u, hu⟩ := haybzcwdx
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,11 +3,11 @@ Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
-import Mathbin.Algebra.GroupPower.Identities
-import Mathbin.Data.Zmod.Basic
-import Mathbin.FieldTheory.Finite.Basic
-import Mathbin.Data.Int.Parity
-import Mathbin.Data.Fintype.BigOperators
+import Algebra.GroupPower.Identities
+import Data.Zmod.Basic
+import FieldTheory.Finite.Basic
+import Data.Int.Parity
+import Data.Fintype.BigOperators
#align_import number_theory.sum_four_squares from "leanprover-community/mathlib"@"575b4ea3738b017e30fb205cb9b4a8742e5e82b6"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,11 +2,6 @@
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-
-! This file was ported from Lean 3 source module number_theory.sum_four_squares
-! leanprover-community/mathlib commit 575b4ea3738b017e30fb205cb9b4a8742e5e82b6
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Algebra.GroupPower.Identities
import Mathbin.Data.Zmod.Basic
@@ -14,6 +9,8 @@ import Mathbin.FieldTheory.Finite.Basic
import Mathbin.Data.Int.Parity
import Mathbin.Data.Fintype.BigOperators
+#align_import number_theory.sum_four_squares from "leanprover-community/mathlib"@"575b4ea3738b017e30fb205cb9b4a8742e5e82b6"
+
/-!
# Lagrange's four square theorem
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -35,6 +35,7 @@ open scoped BigOperators
namespace Int
+#print Int.sq_add_sq_of_two_mul_sq_add_sq /-
theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2) :
m = ((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2 :=
have : Even (x ^ 2 + y ^ 2) := by simp [← h, even_mul]
@@ -50,7 +51,9 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
+-/
+#print Int.exists_sq_add_sq_add_one_eq_k /-
theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
∃ (a b : ℤ) (k : ℕ), a ^ 2 + b ^ 2 + 1 = k * p ∧ k < p :=
hp.1.eq_two_or_odd.elim (fun hp2 => hp2.symm ▸ ⟨1, 0, 1, rfl, by decide⟩) fun hp1 =>
@@ -84,6 +87,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
_ = p * p := by conv_rhs => rw [← Nat.mod_add_div p 2]; ring)
(show 0 ≤ p from Nat.zero_le _)⟩
#align int.exists_sq_add_sq_add_one_eq_k Int.exists_sq_add_sq_add_one_eq_k
+-/
end Int
mathlib commit https://github.com/leanprover-community/mathlib/commit/a3e83f0fa4391c8740f7d773a7a9b74e311ae2a3
@@ -125,7 +125,7 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
rw [← Int.sq_add_sq_of_two_mul_sq_add_sq hx.symm, add_assoc, ←
Int.sq_add_sq_of_two_mul_sq_add_sq hy.symm, ← mul_right_inj' (show (2 : ℤ) ≠ 0 by decide), ←
h, mul_add, ← hx, ← hy]
- have : (∑ x, f (σ x) ^ 2) = ∑ x, f x ^ 2 := by conv_rhs => rw [← Equiv.sum_comp σ]
+ have : ∑ x, f (σ x) ^ 2 = ∑ x, f x ^ 2 := by conv_rhs => rw [← Equiv.sum_comp σ]
simpa only [Fin.sum_univ_four, add_assoc] using this⟩
private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
mathlib commit https://github.com/leanprover-community/mathlib/commit/7e5137f579de09a059a5ce98f364a04e221aabf0
@@ -49,7 +49,6 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
-
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
@@ -82,8 +81,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
(lt_add_iff_pos_right _).2
(add_pos_of_nonneg_of_pos (Nat.zero_le _)
(mul_pos (by decide) (Nat.div_pos hp.1.two_le (by decide))))
- _ = p * p := by conv_rhs => rw [← Nat.mod_add_div p 2]; ring
- )
+ _ = p * p := by conv_rhs => rw [← Nat.mod_add_div p 2]; ring)
(show 0 ≤ p from Nat.zero_le _)⟩
#align int.exists_sq_add_sq_add_one_eq_k Int.exists_sq_add_sq_add_one_eq_k
@@ -195,7 +193,6 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
conv_rhs => rw [← Nat.mod_add_div m 2]
simp [-Nat.mod_add_div, mul_add, add_mul, bit0, bit1, mul_comm, mul_assoc,
mul_left_comm, pow_add, add_comm, add_left_comm]
-
have hwxyzabcd :
((w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 : ℤ) : ZMod m) =
((a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 : ℤ) : ZMod m) :=
@@ -251,7 +248,6 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
_ = (w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2) * (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) := by
simp only [hs.symm, ht.symm, hu.symm, hv.symm]; ring
_ = _ := by rw [hn, habcd, Int.natAbs_of_nonneg hn_nonneg]; dsimp [m]; ring
-
False.elim <| Nat.find_min hm hnm ⟨lt_trans hnm hmp, hn0, s, t, u, v, hstuv⟩
#print Nat.sum_four_squares /-
mathlib commit https://github.com/leanprover-community/mathlib/commit/a3209ddf94136d36e5e5c624b10b2a347cc9d090
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
! This file was ported from Lean 3 source module number_theory.sum_four_squares
-! leanprover-community/mathlib commit bd9851ca476957ea4549eb19b40e7b5ade9428cc
+! leanprover-community/mathlib commit 575b4ea3738b017e30fb205cb9b4a8742e5e82b6
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
@@ -17,6 +17,9 @@ import Mathbin.Data.Fintype.BigOperators
/-!
# Lagrange's four square theorem
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
The main result in this file is `sum_four_squares`,
a proof that every natural number is the sum of four square numbers.
mathlib commit https://github.com/leanprover-community/mathlib/commit/5f25c089cb34db4db112556f23c50d12da81b297
@@ -251,6 +251,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
False.elim <| Nat.find_min hm hnm ⟨lt_trans hnm hmp, hn0, s, t, u, v, hstuv⟩
+#print Nat.sum_four_squares /-
/-- **Four squares theorem** -/
theorem sum_four_squares : ∀ n : ℕ, ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
| 0 => ⟨0, 0, 0, 0, rfl⟩
@@ -269,6 +270,7 @@ theorem sum_four_squares : ∀ n : ℕ, ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2
h₂]
simp [sum_four_sq_mul_sum_four_sq]⟩
#align nat.sum_four_squares Nat.sum_four_squares
+-/
end Nat
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -42,7 +42,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
2 * 2 * m = (x - y) ^ 2 + (x + y) ^ 2 := by rw [mul_assoc, h] <;> ring
_ = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2 :=
by
- rw [even_iff_two_dvd] at hxsuby hxaddy
+ rw [even_iff_two_dvd] at hxsuby hxaddy
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
@@ -50,7 +50,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
- ∃ (a b : ℤ)(k : ℕ), a ^ 2 + b ^ 2 + 1 = k * p ∧ k < p :=
+ ∃ (a b : ℤ) (k : ℕ), a ^ 2 + b ^ 2 + 1 = k * p ∧ k < p :=
hp.1.eq_two_or_odd.elim (fun hp2 => hp2.symm ▸ ⟨1, 0, 1, rfl, by decide⟩) fun hp1 =>
let ⟨a, b, hab⟩ := ZMod.sq_add_sq p (-1)
have hab' : (p : ℤ) ∣ a.valMinAbs ^ 2 + b.valMinAbs ^ 2 + 1 :=
@@ -134,7 +134,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
⟨k, hk.2,
Nat.pos_of_ne_zero fun hk0 =>
by
- rw [hk0, Int.ofNat_zero, MulZeroClass.zero_mul] at hk
+ rw [hk0, Int.ofNat_zero, MulZeroClass.zero_mul] at hk
exact
ne_of_gt
(show a ^ 2 + b ^ 2 + 1 > 0 from
@@ -149,7 +149,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(fun hm2 : m % 2 = 0 =>
let ⟨k, hk⟩ := Nat.dvd_iff_mod_eq_zero.2 hm2
have hk0 : 0 < k :=
- Nat.pos_of_ne_zero <| by rintro rfl; rw [MulZeroClass.mul_zero] at hk; exact NeZero.ne m hk
+ Nat.pos_of_ne_zero <| by rintro rfl; rw [MulZeroClass.mul_zero] at hk ; exact NeZero.ne m hk
have hkm : k < m := by rw [hk, two_mul]; exact (lt_add_iff_pos_left _).2 hk0
False.elim <|
Nat.find_min hm hkm
@@ -203,7 +203,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hn0 : 0 < n.natAbs :=
Int.natAbs_pos_of_ne_zero fun hn0 =>
have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 := by
- rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
+ rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -28,7 +28,7 @@ The proof used is close to Lagrange's original proof.
open Finset Polynomial FiniteField Equiv
-open BigOperators
+open scoped BigOperators
namespace Int
@@ -90,7 +90,7 @@ namespace Nat
open Int
-open Classical
+open scoped Classical
private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
(h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m) :
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -79,9 +79,7 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
(lt_add_iff_pos_right _).2
(add_pos_of_nonneg_of_pos (Nat.zero_le _)
(mul_pos (by decide) (Nat.div_pos hp.1.two_le (by decide))))
- _ = p * p := by
- conv_rhs => rw [← Nat.mod_add_div p 2]
- ring
+ _ = p * p := by conv_rhs => rw [← Nat.mod_add_div p 2]; ring
)
(show 0 ≤ p from Nat.zero_le _)⟩
#align int.exists_sq_add_sq_add_one_eq_k Int.exists_sq_add_sq_add_one_eq_k
@@ -151,19 +149,14 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(fun hm2 : m % 2 = 0 =>
let ⟨k, hk⟩ := Nat.dvd_iff_mod_eq_zero.2 hm2
have hk0 : 0 < k :=
- Nat.pos_of_ne_zero <| by
- rintro rfl
- rw [MulZeroClass.mul_zero] at hk
- exact NeZero.ne m hk
+ Nat.pos_of_ne_zero <| by rintro rfl; rw [MulZeroClass.mul_zero] at hk; exact NeZero.ne m hk
have hkm : k < m := by rw [hk, two_mul]; exact (lt_add_iff_pos_left _).2 hk0
False.elim <|
Nat.find_min hm hkm
⟨lt_trans hkm hmp, hk0,
sum_four_squares_of_two_mul_sum_four_squares
- (show a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * (k * p)
- by
- rw [habcd, hk, Int.ofNat_mul, mul_assoc]
- norm_num)⟩)
+ (show a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * (k * p) by
+ rw [habcd, hk, Int.ofNat_mul, mul_assoc]; norm_num)⟩)
fun hm2 : m % 2 = 1 =>
if hm1 : m = 1 then ⟨a, b, c, d, by simp only [hm1, habcd, Int.ofNat_one, one_mul]⟩
else
@@ -174,9 +167,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hnat_abs :
w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 =
(w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) :=
- by
- push_cast
- simp_rw [sq_abs]
+ by push_cast ; simp_rw [sq_abs]
have hwxyzlt : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 < m ^ 2 :=
calc
w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 =
@@ -211,10 +202,8 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
let ⟨n, hn⟩ := (CharP.int_cast_eq_zero_iff _ m _).1 hwxyz0
have hn0 : 0 < n.natAbs :=
Int.natAbs_pos_of_ne_zero fun hn0 =>
- have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 :=
- by
- rw [← Int.coe_nat_eq_zero, ← hnat_abs]
- rwa [hn0, MulZeroClass.mul_zero] at hn
+ have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 := by
+ rw [← Int.coe_nat_eq_zero, ← hnat_abs]; rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
@@ -225,49 +214,29 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hmdvdp : m ∣ p :=
Int.coe_nat_dvd.1
⟨ma ^ 2 + mb ^ 2 + mc ^ 2 + md ^ 2,
- (mul_right_inj' (show (m : ℤ) ≠ 0 from Int.coe_nat_ne_zero.2 hm0.1)).1 <|
- by
- rw [← habcd, hma, hmb, hmc, hmd]
- ring⟩
+ (mul_right_inj' (show (m : ℤ) ≠ 0 from Int.coe_nat_ne_zero.2 hm0.1)).1 <| by
+ rw [← habcd, hma, hmb, hmc, hmd]; ring⟩
(hp.1.eq_one_or_self_of_dvd _ hmdvdp).elim hm1 fun hmeqp => by
simpa [lt_irrefl, hmeqp] using hmp
have hawbxcydz : ((m : ℕ) : ℤ) ∣ a * w + b * x + c * y + d * z :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <|
- by
- rw [← hwxyz0]
- simp_rw [sq]
- push_cast
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by rw [← hwxyz0]; simp_rw [sq]; push_cast
have haxbwczdy : ((m : ℕ) : ℤ) ∣ a * x - b * w - c * z + d * y :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <|
- by
- push_cast
- ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
have haybzcwdx : ((m : ℕ) : ℤ) ∣ a * y + b * z - c * w - d * x :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <|
- by
- push_cast
- ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
have hazbycxdw : ((m : ℕ) : ℤ) ∣ a * z - b * y + c * x - d * w :=
- (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <|
- by
- push_cast
- ring
+ (CharP.int_cast_eq_zero_iff (ZMod m) m _).1 <| by push_cast ; ring
let ⟨s, hs⟩ := hawbxcydz
let ⟨t, ht⟩ := haxbwczdy
let ⟨u, hu⟩ := haybzcwdx
let ⟨v, hv⟩ := hazbycxdw
have hn_nonneg : 0 ≤ n :=
nonneg_of_mul_nonneg_right
- (by
- erw [← hn]
- repeat' try refine' add_nonneg _ _; try exact sq_nonneg _)
+ (by erw [← hn]; repeat' try refine' add_nonneg _ _; try exact sq_nonneg _)
(Int.coe_nat_pos.2 <| NeZero.pos m)
have hnm : n.natAbs < m :=
Int.ofNat_lt.1
- (lt_of_mul_lt_mul_left
- (by
- rw [Int.natAbs_of_nonneg hn_nonneg, ← hn, ← sq]
- exact hwxyzlt)
+ (lt_of_mul_lt_mul_left (by rw [Int.natAbs_of_nonneg hn_nonneg, ← hn, ← sq]; exact hwxyzlt)
(Int.coe_nat_nonneg m))
have hstuv : s ^ 2 + t ^ 2 + u ^ 2 + v ^ 2 = n.natAbs * p :=
(mul_right_inj'
@@ -275,17 +244,10 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
calc
(m : ℤ) ^ 2 * (s ^ 2 + t ^ 2 + u ^ 2 + v ^ 2) =
((m : ℕ) * s) ^ 2 + ((m : ℕ) * t) ^ 2 + ((m : ℕ) * u) ^ 2 + ((m : ℕ) * v) ^ 2 :=
- by
- simp [mul_pow]
- ring
- _ = (w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2) * (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) :=
- by
- simp only [hs.symm, ht.symm, hu.symm, hv.symm]
- ring
- _ = _ := by
- rw [hn, habcd, Int.natAbs_of_nonneg hn_nonneg]
- dsimp [m]
- ring
+ by simp [mul_pow]; ring
+ _ = (w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2) * (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) := by
+ simp only [hs.symm, ht.symm, hu.symm, hv.symm]; ring
+ _ = _ := by rw [hn, habcd, Int.natAbs_of_nonneg hn_nonneg]; dsimp [m]; ring
False.elim <| Nat.find_min hm hnm ⟨lt_trans hnm hmp, hn0, s, t, u, v, hstuv⟩
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -128,7 +128,6 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
h, mul_add, ← hx, ← hy]
have : (∑ x, f (σ x) ^ 2) = ∑ x, f x ^ 2 := by conv_rhs => rw [← Equiv.sum_comp σ]
simpa only [Fin.sum_univ_four, add_assoc] using this⟩
-#align nat.sum_four_squares_of_two_mul_sum_four_squares nat.sum_four_squares_of_two_mul_sum_four_squares
private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
∃ a b c d : ℤ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p :=
@@ -289,7 +288,6 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
ring
False.elim <| Nat.find_min hm hnm ⟨lt_trans hnm hmp, hn0, s, t, u, v, hstuv⟩
-#align nat.prime_sum_four_squares nat.prime_sum_four_squares
/-- **Four squares theorem** -/
theorem sum_four_squares : ∀ n : ℕ, ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
mathlib commit https://github.com/leanprover-community/mathlib/commit/3180fab693e2cee3bff62675571264cb8778b212
@@ -107,8 +107,8 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
let ⟨i, hσ⟩ :=
this (fun x => coe (f x))
(by
- rw [← @zero_mul (ZMod 2) _ m, ← show ((2 : ℤ) : ZMod 2) = 0 from rfl, ← Int.cast_mul, ←
- h] <;>
+ rw [← @MulZeroClass.zero_mul (ZMod 2) _ m, ← show ((2 : ℤ) : ZMod 2) = 0 from rfl, ←
+ Int.cast_mul, ← h] <;>
simp only [Int.cast_add, Int.cast_pow] <;>
rfl)
let σ := swap i 0
@@ -137,7 +137,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
⟨k, hk.2,
Nat.pos_of_ne_zero fun hk0 =>
by
- rw [hk0, Int.ofNat_zero, zero_mul] at hk
+ rw [hk0, Int.ofNat_zero, MulZeroClass.zero_mul] at hk
exact
ne_of_gt
(show a ^ 2 + b ^ 2 + 1 > 0 from
@@ -154,7 +154,7 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
have hk0 : 0 < k :=
Nat.pos_of_ne_zero <| by
rintro rfl
- rw [mul_zero] at hk
+ rw [MulZeroClass.mul_zero] at hk
exact NeZero.ne m hk
have hkm : k < m := by rw [hk, two_mul]; exact (lt_add_iff_pos_left _).2 hk0
False.elim <|
@@ -208,14 +208,14 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
((a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 : ℤ) : ZMod m) :=
by push_cast
have hwxyz0 : ((w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 : ℤ) : ZMod m) = 0 := by
- rw [hwxyzabcd, habcd, Int.cast_mul, cast_coe_nat, ZMod.nat_cast_self, zero_mul]
+ rw [hwxyzabcd, habcd, Int.cast_mul, cast_coe_nat, ZMod.nat_cast_self, MulZeroClass.zero_mul]
let ⟨n, hn⟩ := (CharP.int_cast_eq_zero_iff _ m _).1 hwxyz0
have hn0 : 0 < n.natAbs :=
Int.natAbs_pos_of_ne_zero fun hn0 =>
have hwxyz0 : (w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) = 0 :=
by
rw [← Int.coe_nat_eq_zero, ← hnat_abs]
- rwa [hn0, mul_zero] at hn
+ rwa [hn0, MulZeroClass.mul_zero] at hn
have habcd0 : (m : ℤ) ∣ a ∧ (m : ℤ) ∣ b ∧ (m : ℤ) ∣ c ∧ (m : ℤ) ∣ d := by
simpa only [add_eq_zero_iff, Int.natAbs_eq_zero, ZMod.valMinAbs_eq_zero, and_assoc,
pow_eq_zero_iff two_pos, CharP.int_cast_eq_zero_iff _ m _] using hwxyz0
mathlib commit https://github.com/leanprover-community/mathlib/commit/4c586d291f189eecb9d00581aeb3dd998ac34442
@@ -68,10 +68,10 @@ theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [hp : Fact p.Prime] :
Int.natAbs_sq, Int.natAbs_sq, Int.ofNat_one, hk, Int.ofNat_mul,
Int.natAbs_of_nonneg hk0]
_ ≤ (p / 2) ^ 2 + (p / 2) ^ 2 + 1 :=
- add_le_add
+ (add_le_add
(add_le_add (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _)
(Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
- le_rfl
+ le_rfl)
_ < (p / 2) ^ 2 + (p / 2) ^ 2 + (p % 2) ^ 2 + (2 * (p / 2) ^ 2 + 4 * (p / 2) * (p % 2)) :=
by
rw [hp1, one_pow, mul_one] <;>
@@ -184,20 +184,20 @@ private theorem prime_sum_four_squares (p : ℕ) [hp : Fact p.Prime] :
(w.natAbs ^ 2 + x.natAbs ^ 2 + y.natAbs ^ 2 + z.natAbs ^ 2 : ℕ) :=
hnat_abs
_ ≤ ((m / 2) ^ 2 + (m / 2) ^ 2 + (m / 2) ^ 2 + (m / 2) ^ 2 : ℕ) :=
- Int.ofNat_le.2 <|
+ (Int.ofNat_le.2 <|
add_le_add
(add_le_add
(add_le_add (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _)
(Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
(Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
- (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _)
+ (Nat.pow_le_pow_of_le_left (ZMod.natAbs_valMinAbs_le _) _))
_ = 4 * (m / 2 : ℕ) ^ 2 := by
simp only [bit0_mul, one_mul, two_smul, Nat.cast_add, Nat.cast_pow, add_assoc]
_ < 4 * (m / 2 : ℕ) ^ 2 + ((4 * (m / 2) : ℕ) * (m % 2 : ℕ) + (m % 2 : ℕ) ^ 2) :=
- (lt_add_iff_pos_right _).2
+ ((lt_add_iff_pos_right _).2
(by
rw [hm2, Int.ofNat_one, one_pow, mul_one]
- exact add_pos_of_nonneg_of_pos (Int.coe_nat_nonneg _) zero_lt_one)
+ exact add_pos_of_nonneg_of_pos (Int.coe_nat_nonneg _) zero_lt_one))
_ = m ^ 2 := by
conv_rhs => rw [← Nat.mod_add_div m 2]
simp [-Nat.mod_add_div, mul_add, add_mul, bit0, bit1, mul_comm, mul_assoc,
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
nat_cast
/int_cast
/rat_cast
to natCast
/intCast
/ratCast
(#11486)
Now that I am defining NNRat.cast
, I want a definitive answer to this naming issue. Plenty of lemmas in mathlib already use natCast
/intCast
/ratCast
over nat_cast
/int_cast
/rat_cast
, and this matches with the general expectation that underscore-separated name parts correspond to a single declaration.
@@ -125,10 +125,10 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
rfl
set σ := swap i 0
obtain ⟨x, hx⟩ : (2 : ℤ) ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2 :=
- (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
+ (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by
simpa only [σ, Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
obtain ⟨y, hy⟩ : (2 : ℤ) ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2 :=
- (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
+ (CharP.intCast_eq_zero_iff (ZMod 2) 2 _).1 <| by
simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2
refine ⟨(f (σ 0) - f (σ 1)) / 2, (f (σ 0) + f (σ 1)) / 2, (f (σ 2) - f (σ 3)) / 2,
(f (σ 2) + f (σ 3)) / 2, ?_⟩
@@ -178,7 +178,7 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
-- `m ∣ |f a| ^ 2 + |f b| ^ 2 + |f c| ^ 2 + |f d| ^ 2`
obtain ⟨r, hr⟩ :
m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2 := by
- simp only [← Int.natCast_dvd_natCast, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
+ simp only [← Int.natCast_dvd_natCast, ← ZMod.intCast_zmod_eq_zero_iff_dvd]
push_cast [hf_mod, sq_abs]
norm_cast
simp [habcd]
@@ -187,7 +187,7 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
rcases (zero_le r).eq_or_gt with rfl | hr₀
· replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0 := by simpa [and_assoc] using hr
obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d := by
- simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
+ simp only [← ZMod.natCast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩
rw [mul_dvd_mul_iff_left hm₀.ne'] at this
exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne
@@ -213,14 +213,14 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
have := congr_arg₂ (· * Nat.cast ·) hr habcd
simp only [← _root_.euler_four_squares, Nat.cast_add, Nat.cast_pow] at this
refine ⟨_, _, _, _, ?_, ?_, ?_, ?_, this⟩
- · simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
+ · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
· suffices ((a : ZMod m) ^ 2 + (b : ZMod m) ^ 2 + (c : ZMod m) ^ 2 + (d : ZMod m) ^ 2) = 0 by
- simpa [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc,
+ simpa [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc,
add_left_comm] using this
norm_cast
simp [habcd]
- · simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
- · simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
+ · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
+ · simp [← ZMod.intCast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
/-- **Four squares theorem** -/
theorem sum_four_squares (n : ℕ) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n := by
coe_nat
to natCast
(#11637)
Reduce the diff of #11499
All in the Int
namespace:
ofNat_eq_cast
→ ofNat_eq_natCast
cast_eq_cast_iff_Nat
→ natCast_inj
natCast_eq_ofNat
→ ofNat_eq_natCast
coe_nat_sub
→ natCast_sub
coe_nat_nonneg
→ natCast_nonneg
sign_coe_add_one
→ sign_natCast_add_one
nat_succ_eq_int_succ
→ natCast_succ
succ_neg_nat_succ
→ succ_neg_natCast_succ
coe_pred_of_pos
→ natCast_pred_of_pos
coe_nat_div
→ natCast_div
coe_nat_ediv
→ natCast_ediv
sign_coe_nat_of_nonzero
→ sign_natCast_of_ne_zero
toNat_coe_nat
→ toNat_natCast
toNat_coe_nat_add_one
→ toNat_natCast_add_one
coe_nat_dvd
→ natCast_dvd_natCast
coe_nat_dvd_left
→ natCast_dvd
coe_nat_dvd_right
→ dvd_natCast
le_coe_nat_sub
→ le_natCast_sub
succ_coe_nat_pos
→ succ_natCast_pos
coe_nat_modEq_iff
→ natCast_modEq_iff
coe_natAbs
→ natCast_natAbs
coe_nat_eq_zero
→ natCast_eq_zero
coe_nat_ne_zero
→ natCast_ne_zero
coe_nat_ne_zero_iff_pos
→ natCast_ne_zero_iff_pos
abs_coe_nat
→ abs_natCast
coe_nat_nonpos_iff
→ natCast_nonpos_iff
Also rename Nat.coe_nat_dvd
to Nat.cast_dvd_cast
@@ -39,7 +39,7 @@ theorem Nat.euler_four_squares (a b c d x y z w : ℕ) :
((a : ℤ) * z - b * w + c * x + d * y).natAbs ^ 2 +
((a : ℤ) * w + b * z - c * y + d * x).natAbs ^ 2 =
(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2) := by
- rw [← Int.coe_nat_inj']
+ rw [← Int.natCast_inj]
push_cast
simp only [sq_abs, _root_.euler_four_squares]
@@ -178,7 +178,7 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
-- `m ∣ |f a| ^ 2 + |f b| ^ 2 + |f c| ^ 2 + |f d| ^ 2`
obtain ⟨r, hr⟩ :
m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2 := by
- simp only [← Int.coe_nat_dvd, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
+ simp only [← Int.natCast_dvd_natCast, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
push_cast [hf_mod, sq_abs]
norm_cast
simp [habcd]
@@ -61,7 +61,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
--- Porting note: new theorem
+-- Porting note (#10756): new theorem
theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
(h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m)
(ha : 2 * a < m) (hb : 2 * b < m) (hc : 2 * c < m) (hd : 2 * d < m) :
@@ -76,7 +76,7 @@ theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
fin_cases i <;> assumption
_ = 2 ^ 2 * (m * m) := by simp; ring
--- Porting note: new theorem
+-- Porting note (#10756): new theorem
theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
∃ (a b k : ℕ), 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p := by
rcases hp.1.eq_two_or_odd' with (rfl | hodd)
@@ -234,7 +234,6 @@ theorem sum_four_squares (n : ℕ) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 +
rcases hm with ⟨a, b, c, d, rfl⟩
rcases hn with ⟨w, x, y, z, rfl⟩
exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
-
#align nat.sum_four_squares Nat.sum_four_squares
end Nat
Homogenises porting notes via capitalisation and addition of whitespace.
It makes the following changes:
@@ -61,7 +61,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
--- porting note: new theorem
+-- Porting note: new theorem
theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
(h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m)
(ha : 2 * a < m) (hb : 2 * b < m) (hc : 2 * c < m) (hd : 2 * d < m) :
@@ -76,7 +76,7 @@ theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
fin_cases i <;> assumption
_ = 2 ^ 2 * (m * m) := by simp; ring
--- porting note: new theorem
+-- Porting note: new theorem
theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
∃ (a b k : ℕ), 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p := by
rcases hp.1.eq_two_or_odd' with (rfl | hodd)
@@ -169,14 +169,16 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
exact hmin m hm₂ ⟨hm₂.trans hmp, hm₀, _, _, _, _, natAbs_iff.2 h⟩
· -- For each `x` in `a`, `b`, `c`, `d`, take a number `f x ≡ x [ZMOD m]` with least possible
-- absolute value
- obtain ⟨f, hf_lt, hf_mod⟩ : ∃ f : ℕ → ℤ, (∀ x, 2 * (f x).natAbs < m) ∧ ∀ x, (f x : ZMod m) = x
- · refine ⟨fun x ↦ (x : ZMod m).valMinAbs, fun x ↦ ?_, fun x ↦ (x : ZMod m).coe_valMinAbs⟩
+ obtain ⟨f, hf_lt, hf_mod⟩ :
+ ∃ f : ℕ → ℤ, (∀ x, 2 * (f x).natAbs < m) ∧ ∀ x, (f x : ZMod m) = x := by
+ refine ⟨fun x ↦ (x : ZMod m).valMinAbs, fun x ↦ ?_, fun x ↦ (x : ZMod m).coe_valMinAbs⟩
exact (mul_le_mul' le_rfl (x : ZMod m).natAbs_valMinAbs_le).trans_lt
(Nat.mul_div_lt_iff_not_dvd.2 hm)
-- Since `|f x| ^ 2 = (f x) ^ 2 ≡ x ^ 2 [ZMOD m]`, we have
-- `m ∣ |f a| ^ 2 + |f b| ^ 2 + |f c| ^ 2 + |f d| ^ 2`
- obtain ⟨r, hr⟩ : m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2
- · simp only [← Int.coe_nat_dvd, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
+ obtain ⟨r, hr⟩ :
+ m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2 := by
+ simp only [← Int.coe_nat_dvd, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
push_cast [hf_mod, sq_abs]
norm_cast
simp [habcd]
@@ -184,8 +186,8 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
-- `m` divides each `a`, `b`, `c`, `d`, thus `m ∣ p` which is impossible.
rcases (zero_le r).eq_or_gt with rfl | hr₀
· replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0 := by simpa [and_assoc] using hr
- obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d
- · simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
+ obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d := by
+ simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩
rw [mul_dvd_mul_iff_left hm₀.ne'] at this
exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne
@@ -126,7 +126,7 @@ private theorem sum_four_squares_of_two_mul_sum_four_squares {m a b c d : ℤ}
set σ := swap i 0
obtain ⟨x, hx⟩ : (2 : ℤ) ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2 :=
(CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
- simpa only [Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
+ simpa only [σ, Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
obtain ⟨y, hy⟩ : (2 : ℤ) ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2 :=
(CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2
@@ -66,7 +66,8 @@ theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
(h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m)
(ha : 2 * a < m) (hb : 2 * b < m) (hc : 2 * c < m) (hd : 2 * d < m) :
k < m := by
- refine lt_of_mul_lt_mul_right (lt_of_mul_lt_mul_left ?_ (zero_le (2 ^ 2))) (zero_le m)
+ refine _root_.lt_of_mul_lt_mul_right
+ (_root_.lt_of_mul_lt_mul_left ?_ (zero_le (2 ^ 2))) (zero_le m)
calc
2 ^ 2 * (k * ↑m) = ∑ i : Fin 4, (2 * ![a, b, c, d] i) ^ 2 := by
simp [← h, Fin.sum_univ_succ, mul_add, mul_pow, add_assoc]
have
, replace
and suffices
(#10640)
No changes to tactic file, it's just boring fixes throughout the library.
This follows on from #6964.
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@@ -83,14 +83,13 @@ theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
rcases Nat.sq_add_sq_zmodEq p (-1) with ⟨a, b, ha, hb, hab⟩
rcases Int.modEq_iff_dvd.1 hab.symm with ⟨k, hk⟩
rw [sub_neg_eq_add, mul_comm] at hk
- have hk₀ : 0 < k
- · refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p)
+ have hk₀ : 0 < k := by
+ refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p)
rw [← hk]
positivity
lift k to ℕ using hk₀.le
refine ⟨a, b, k, Nat.cast_pos.1 hk₀, ?_, mod_cast hk⟩
- replace hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
- · exact mod_cast hk
+ replace hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p := mod_cast hk
refine lt_of_sum_four_squares_eq_mul hk ?_ ?_ ?_ ?_
· exact (mul_le_mul' le_rfl ha).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
· exact (mul_le_mul' le_rfl hb).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
@@ -146,8 +145,8 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
a.natAbs ^ 2 + b.natAbs ^ 2 + c.natAbs ^ 2 + d.natAbs ^ 2 = k ↔
a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k := by
rw [← @Nat.cast_inj ℤ]; push_cast [sq_abs]; rfl
- have hm : ∃ m < p, 0 < m ∧ ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
- · obtain ⟨a, b, k, hk₀, hkp, hk⟩ := exists_sq_add_sq_add_one_eq_mul p
+ have hm : ∃ m < p, 0 < m ∧ ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p := by
+ obtain ⟨a, b, k, hk₀, hkp, hk⟩ := exists_sq_add_sq_add_one_eq_mul p
refine ⟨k, hkp, hk₀, a, b, 1, 0, ?_⟩
simpa
-- Take the minimal possible `m`
@@ -183,37 +182,37 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
-- The quotient `r` is not zero, because otherwise `f a = f b = f c = f d = 0`, hence
-- `m` divides each `a`, `b`, `c`, `d`, thus `m ∣ p` which is impossible.
rcases (zero_le r).eq_or_gt with rfl | hr₀
- · replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0; · simpa [and_assoc] using hr
+ · replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0 := by simpa [and_assoc] using hr
obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d
· simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩
rw [mul_dvd_mul_iff_left hm₀.ne'] at this
exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne
-- Since `2 * |f x| < m` for each `x ∈ {a, b, c, d}`, we have `r < m`
- have hrm : r < m
- · rw [mul_comm] at hr
+ have hrm : r < m := by
+ rw [mul_comm] at hr
apply lt_of_sum_four_squares_eq_mul hr <;> apply hf_lt
-- Now it suffices to represent `r * p` as a sum of four squares
-- More precisely, we will represent `(m * r) * (m * p)` as a sum of squares of four numbers,
-- each of them is divisible by `m`
rsuffices ⟨w, x, y, z, hw, hx, hy, hz, h⟩ : ∃ w x y z : ℤ, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧
w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
- · have : (w / m) ^ 2 + (x / m) ^ 2 + (y / m) ^ 2 + (z / m) ^ 2 = ↑(r * p)
- · refine mul_left_cancel₀ (pow_ne_zero 2 (Nat.cast_ne_zero.2 hm₀.ne')) ?_
+ · have : (w / m) ^ 2 + (x / m) ^ 2 + (y / m) ^ 2 + (z / m) ^ 2 = ↑(r * p) := by
+ refine mul_left_cancel₀ (pow_ne_zero 2 (Nat.cast_ne_zero.2 hm₀.ne')) ?_
conv_rhs => rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h]
simp only [mul_add, ← mul_pow, Int.mul_ediv_cancel', *]
rw [← natAbs_iff] at this
exact hmin r hrm ⟨hrm.trans hmp, hr₀, _, _, _, _, this⟩
-- To do the last step, we apply the Euler's four square identity once more
- replace hr : (f b) ^ 2 + (f a) ^ 2 + (f d) ^ 2 + (-f c) ^ 2 = ↑(m * r)
- · rw [← natAbs_iff, natAbs_neg, ← hr]
+ replace hr : (f b) ^ 2 + (f a) ^ 2 + (f d) ^ 2 + (-f c) ^ 2 = ↑(m * r) := by
+ rw [← natAbs_iff, natAbs_neg, ← hr]
ac_rfl
have := congr_arg₂ (· * Nat.cast ·) hr habcd
simp only [← _root_.euler_four_squares, Nat.cast_add, Nat.cast_pow] at this
refine ⟨_, _, _, _, ?_, ?_, ?_, ?_, this⟩
· simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
- · suffices : ((a : ZMod m) ^ 2 + (b : ZMod m) ^ 2 + (c : ZMod m) ^ 2 + (d : ZMod m) ^ 2) = 0
- · simpa [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc,
+ · suffices ((a : ZMod m) ^ 2 + (b : ZMod m) ^ 2 + (c : ZMod m) ^ 2 + (d : ZMod m) ^ 2) = 0 by
+ simpa [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc,
add_left_comm] using this
norm_cast
simp [habcd]
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>
@@ -57,6 +57,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
rw [even_iff_two_dvd] at hxsuby hxaddy
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
+ set_option simprocs false in
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
#align int.sq_add_sq_of_two_mul_sq_add_sq Int.sq_add_sq_of_two_mul_sq_add_sq
@@ -3,7 +3,6 @@ Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
-import Mathlib.Algebra.GroupPower.Identities
import Mathlib.Data.ZMod.Basic
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.Data.Int.Parity
0 ≤ a * b ↔ (0 < a → 0 ≤ b) ∧ (0 < b → 0 ≤ a)
(#9219)
I had a slightly logic-heavy argument that was nicely simplified by stating this lemma. Also fix a few lemma names.
From LeanAPAP and LeanCamCombi
@@ -161,7 +161,7 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
by_cases hm : 2 ∣ m
· -- If `m` is an even number, then `(m / 2) * p` can be represented as a sum of four squares
rcases hm with ⟨m, rfl⟩
- rw [zero_lt_mul_left two_pos] at hm₀
+ rw [mul_pos_iff_of_pos_left two_pos] at hm₀
have hm₂ : m < 2 * m := by simpa [two_mul]
apply_fun (Nat.cast : ℕ → ℤ) at habcd
push_cast [mul_assoc] at habcd
The names for lemmas about monotonicity of (a ^ ·)
and (· ^ n)
were a mess. This PR tidies up everything related by following the naming convention for (a * ·)
and (· * b)
. Namely, (a ^ ·)
is pow_right
and (· ^ n)
is pow_left
in lemma names. All lemma renames follow the corresponding multiplication lemma names closely.
Algebra.GroupPower.Order
pow_mono
→ pow_right_mono
pow_le_pow
→ pow_le_pow_right
pow_le_pow_of_le_left
→ pow_le_pow_left
pow_lt_pow_of_lt_left
→ pow_lt_pow_left
strictMonoOn_pow
→ pow_left_strictMonoOn
pow_strictMono_right
→ pow_right_strictMono
pow_lt_pow
→ pow_lt_pow_right
pow_lt_pow_iff
→ pow_lt_pow_iff_right
pow_le_pow_iff
→ pow_le_pow_iff_right
self_lt_pow
→ lt_self_pow
strictAnti_pow
→ pow_right_strictAnti
pow_lt_pow_iff_of_lt_one
→ pow_lt_pow_iff_right_of_lt_one
pow_lt_pow_of_lt_one
→ pow_lt_pow_right_of_lt_one
lt_of_pow_lt_pow
→ lt_of_pow_lt_pow_left
le_of_pow_le_pow
→ le_of_pow_le_pow_left
pow_lt_pow₀
→ pow_lt_pow_right₀
Algebra.GroupPower.CovariantClass
pow_le_pow_of_le_left'
→ pow_le_pow_left'
nsmul_le_nsmul_of_le_right
→ nsmul_le_nsmul_right
pow_lt_pow'
→ pow_lt_pow_right'
nsmul_lt_nsmul
→ nsmul_lt_nsmul_left
pow_strictMono_left
→ pow_right_strictMono'
nsmul_strictMono_right
→ nsmul_left_strictMono
StrictMono.pow_right'
→ StrictMono.pow_const
StrictMono.nsmul_left
→ StrictMono.const_nsmul
pow_strictMono_right'
→ pow_left_strictMono
nsmul_strictMono_left
→ nsmul_right_strictMono
Monotone.pow_right
→ Monotone.pow_const
Monotone.nsmul_left
→ Monotone.const_nsmul
lt_of_pow_lt_pow'
→ lt_of_pow_lt_pow_left'
lt_of_nsmul_lt_nsmul
→ lt_of_nsmul_lt_nsmul_right
pow_le_pow'
→ pow_le_pow_right'
nsmul_le_nsmul
→ nsmul_le_nsmul_left
pow_le_pow_of_le_one'
→ pow_le_pow_right_of_le_one'
nsmul_le_nsmul_of_nonpos
→ nsmul_le_nsmul_left_of_nonpos
le_of_pow_le_pow'
→ le_of_pow_le_pow_left'
le_of_nsmul_le_nsmul'
→ le_of_nsmul_le_nsmul_right'
pow_le_pow_iff'
→ pow_le_pow_iff_right'
nsmul_le_nsmul_iff
→ nsmul_le_nsmul_iff_left
pow_lt_pow_iff'
→ pow_lt_pow_iff_right'
nsmul_lt_nsmul_iff
→ nsmul_lt_nsmul_iff_left
Data.Nat.Pow
Nat.pow_lt_pow_of_lt_left
→ Nat.pow_lt_pow_left
Nat.pow_le_iff_le_left
→ Nat.pow_le_pow_iff_left
Nat.pow_lt_iff_lt_left
→ Nat.pow_lt_pow_iff_left
pow_le_pow_iff_left
pow_lt_pow_iff_left
pow_right_injective
pow_right_inj
Nat.pow_le_pow_left
to have the correct name since Nat.pow_le_pow_of_le_left
is in Std.Nat.pow_le_pow_right
to have the correct name since Nat.pow_le_pow_of_le_right
is in Std.self_le_pow
was a duplicate of le_self_pow
.Nat.pow_lt_pow_of_lt_right
is defeq to pow_lt_pow_right
.Nat.pow_right_strictMono
is defeq to pow_right_strictMono
.Nat.pow_le_iff_le_right
is defeq to pow_le_pow_iff_right
.Nat.pow_lt_iff_lt_right
is defeq to pow_lt_pow_iff_right
.0 < n
or 1 ≤ n
to n ≠ 0
.Nat
lemmas have been protected
.@@ -71,7 +71,7 @@ theorem lt_of_sum_four_squares_eq_mul {a b c d k m : ℕ}
2 ^ 2 * (k * ↑m) = ∑ i : Fin 4, (2 * ![a, b, c, d] i) ^ 2 := by
simp [← h, Fin.sum_univ_succ, mul_add, mul_pow, add_assoc]
_ < ∑ _i : Fin 4, m ^ 2 := Finset.sum_lt_sum_of_nonempty Finset.univ_nonempty fun i _ ↦ by
- refine pow_lt_pow_of_lt_left ?_ (zero_le _) two_pos
+ refine pow_lt_pow_left ?_ (zero_le _) two_ne_zero
fin_cases i <;> assumption
_ = 2 ^ 2 * (m * m) := by simp; ring
exact_mod_cast
tactic with mod_cast
elaborator where possible (#8404)
We still have the exact_mod_cast
tactic, used in a few places, which somehow (?) works a little bit harder to prevent the expected type influencing the elaboration of the term. I would like to get to the bottom of this, and it will be easier once the only usages of exact_mod_cast
are the ones that don't work using the term elaborator by itself.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -88,9 +88,9 @@ theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
rw [← hk]
positivity
lift k to ℕ using hk₀.le
- refine ⟨a, b, k, Nat.cast_pos.1 hk₀, ?_, by exact_mod_cast hk⟩
+ refine ⟨a, b, k, Nat.cast_pos.1 hk₀, ?_, mod_cast hk⟩
replace hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
- · exact_mod_cast hk
+ · exact mod_cast hk
refine lt_of_sum_four_squares_eq_mul hk ?_ ?_ ?_ ?_
· exact (mul_le_mul' le_rfl ha).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
· exact (mul_le_mul' le_rfl hb).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
@@ -101,7 +101,7 @@ theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
theorem exists_sq_add_sq_add_one_eq_k (p : ℕ) [Fact p.Prime] :
∃ (a b : ℤ) (k : ℕ), a ^ 2 + b ^ 2 + 1 = k * p ∧ k < p :=
let ⟨a, b, k, _, hkp, hk⟩ := exists_sq_add_sq_add_one_eq_mul p
- ⟨a, b, k, by exact_mod_cast hk, hkp⟩
+ ⟨a, b, k, mod_cast hk, hkp⟩
#align int.exists_sq_add_sq_add_one_eq_k Int.exists_sq_add_sq_add_one_eq_k
end Int
This is the supremum of
along with some minor fixes from failures on nightly-testing as Mathlib master
is merged into it.
Note that some PRs for changes that are already compatible with the current toolchain and will be necessary have already been split out: #8380.
I am hopeful that in future we will be able to progressively merge adaptation PRs into a bump/v4.X.0
branch, so we never end up with a "big merge" like this. However one of these adaptation PRs (#8056) predates my new scheme for combined CI, and it wasn't possible to keep that PR viable in the meantime.
In particular this includes adjustments for the Lean PRs
We can get rid of all the
local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue [lean4#2220](https://github.com/leanprover/lean4/pull/2220)
macros across Mathlib (and in any projects that want to write natural number powers of reals).
Changes the default behaviour of simp
to (config := {decide := false})
. This makes simp
(and consequentially norm_num
) less powerful, but also more consistent, and less likely to blow up in long failures. This requires a variety of changes: changing some previously by simp
or norm_num
to decide
or rfl
, or adding (config := {decide := true})
.
This changed the behaviour of simp
so that simp [f]
will only unfold "fully applied" occurrences of f
. The old behaviour can be recovered with simp (config := { unfoldPartialApp := true })
. We may in future add a syntax for this, e.g. simp [!f]
; please provide feedback! In the meantime, we have made the following changes:
(config := { unfoldPartialApp := true })
in some places, to recover the old behaviour@[eqns]
to manually adjust the equation lemmas for a particular definition, recovering the old behaviour just for that definition. See #8371, where we do this for Function.comp
and Function.flip
.This change in Lean may require further changes down the line (e.g. adding the !f
syntax, and/or upstreaming the special treatment for Function.comp
and Function.flip
, and/or removing this special treatment). Please keep an open and skeptical mind about these changes!
Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com> Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Mauricio Collares <mauricio@collares.org>
@@ -27,8 +27,6 @@ open Finset Polynomial FiniteField Equiv
open scoped BigOperators
-local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue lean4#2220
-
/-- **Euler's four-square identity**. -/
theorem euler_four_squares {R : Type*} [CommRing R] (a b c d x y z w : R) :
(a * x - b * y - c * z - d * w) ^ 2 + (a * y + b * x + c * w - d * z) ^ 2 +
@@ -187,7 +185,7 @@ protected theorem Prime.sum_four_squares {p : ℕ} (hp : p.Prime) :
rcases (zero_le r).eq_or_gt with rfl | hr₀
· replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0; · simpa [and_assoc] using hr
obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d
- · simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero]
+ · simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero, and_self]
have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩
rw [mul_dvd_mul_iff_left hm₀.ne'] at this
exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne
Type _
and Sort _
(#6499)
We remove all possible occurences of Type _
and Sort _
in favor of Type*
and Sort*
.
This has nice performance benefits.
@@ -30,7 +30,7 @@ open scoped BigOperators
local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue lean4#2220
/-- **Euler's four-square identity**. -/
-theorem euler_four_squares {R : Type _} [CommRing R] (a b c d x y z w : R) :
+theorem euler_four_squares {R : Type*} [CommRing R] (a b c d x y z w : R) :
(a * x - b * y - c * z - d * w) ^ 2 + (a * y + b * x + c * w - d * z) ^ 2 +
(a * z - b * w + c * x + d * y) ^ 2 + (a * w + b * z - c * y + d * x) ^ 2 =
(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2) := by ring
@@ -27,7 +27,7 @@ open Finset Polynomial FiniteField Equiv
open scoped BigOperators
-local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See Lean 4 issue #2220
+local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y) -- Porting note: See issue lean4#2220
/-- **Euler's four-square identity**. -/
theorem euler_four_squares {R : Type _} [CommRing R] (a b c d x y z w : R) :
@@ -2,11 +2,6 @@
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-
-! This file was ported from Lean 3 source module number_theory.sum_four_squares
-! leanprover-community/mathlib commit bd9851ca476957ea4549eb19b40e7b5ade9428cc
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Algebra.GroupPower.Identities
import Mathlib.Data.ZMod.Basic
@@ -14,6 +9,8 @@ import Mathlib.FieldTheory.Finite.Basic
import Mathlib.Data.Int.Parity
import Mathlib.Data.Fintype.BigOperators
+#align_import number_theory.sum_four_squares from "leanprover-community/mathlib"@"bd9851ca476957ea4549eb19b40e7b5ade9428cc"
+
/-!
# Lagrange's four square theorem
@@ -60,7 +60,7 @@ theorem sq_add_sq_of_two_mul_sq_add_sq {m x y : ℤ} (h : 2 * m = x ^ 2 + y ^ 2)
calc
2 * 2 * m = (x - y) ^ 2 + (x + y) ^ 2 := by rw [mul_assoc, h]; ring
_ = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2 := by
- rw [even_iff_two_dvd] at hxsuby hxaddy
+ rw [even_iff_two_dvd] at hxsuby hxaddy
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
_ = 2 * 2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2) := by
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
@@ -89,7 +89,7 @@ theorem exists_sq_add_sq_add_one_eq_mul (p : ℕ) [hp : Fact p.Prime] :
rcases Int.modEq_iff_dvd.1 hab.symm with ⟨k, hk⟩
rw [sub_neg_eq_add, mul_comm] at hk
have hk₀ : 0 < k
- · refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p)
+ · refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p)
rw [← hk]
positivity
lift k to ℕ using hk₀.le
@@ -237,7 +237,7 @@ theorem sum_four_squares (n : ℕ) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 +
rcases hm with ⟨a, b, c, d, rfl⟩
rcases hn with ⟨w, x, y, z, rfl⟩
exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
-
+
#align nat.sum_four_squares Nat.sum_four_squares
end Nat
The unported dependencies are