File size: 11,281 Bytes
e9f356b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | import Mathlib
import OAI.NumberTheory.CubicGram.ResidueCharacters
import OAI.NumberTheory.CubicGram.PrimeFactors
namespace OAI
/-! Unique primary associates and canonical prime factorization. -/
section
noncomputable section
open scoped BigOperators
open Module
attribute [local instance] Classical.propDecidable
namespace CubicFirstMoment
open UniqueFactorizationMonoid
lemma normNat_of_isUnit {u : Eisenstein} (hu : IsUnit u) : normNat u = 1 :=
Nat.isUnit_iff.mp (hu.map normNatHom)
lemma norm_of_isUnit {u : Eisenstein} (hu : IsUnit u) : norm u = 1 := by
rw [← normNat_cast, normNat_of_isUnit hu, Nat.cast_one]
lemma primary_iff_residue_one (z : Eisenstein) :
primary z ↔ Ideal.Quotient.mk (modulus 3) z = 1 := by
rw [primary, ← Ideal.mem_span_singleton, ← Ideal.Quotient.eq_zero_iff_mem]
change Ideal.Quotient.mk (modulus 3) (z-1) = 0 ↔ _
rw [map_sub, map_one, sub_eq_zero]
lemma primary_mul {a b : Eisenstein} (ha : primary a) (hb : primary b) : primary (a*b) := by
rw [primary_iff_residue_one, map_mul, (primary_iff_residue_one a).mp ha,
(primary_iff_residue_one b).mp hb, one_mul]
lemma primary_unit_eq_one {u : Eisenstein} (hu : IsUnit u) (hprimary : primary u) : u = 1 := by
have hnu : ‖(u : ℂ)‖ = 1 := by
have hnorm := norm_of_isUnit hu
rw [norm, Complex.normSq_eq_norm_sq] at hnorm
nlinarith [_root_.norm_nonneg (u : ℂ)]
have hsub : ‖(u : ℂ) - 1‖ ≤ 2 := by
calc
_ ≤ ‖(u : ℂ)‖ + ‖(1 : ℂ)‖ := norm_sub_le _ _
_ = 2 := by rw [hnu, norm_one]; norm_num
obtain ⟨w, hw⟩ := hprimary
have hnorm : norm (u-1) = 9 * norm w := by
rw [hw, norm, Subalgebra.coe_mul, Complex.normSq_mul]
change Complex.normSq (3 : ℂ) * norm w = 9 * norm w
norm_num [Complex.normSq_apply]
have hwlt : (normNat w : ℝ) < 1 := by
rw [normNat_cast]
rw [norm, Subalgebra.coe_sub, Subalgebra.coe_one, Complex.normSq_eq_norm_sq] at hnorm
nlinarith [_root_.norm_nonneg ((u : ℂ)-1)]
have hwzero : normNat w = 0 := by
have hnat : normNat w < 1 := by exact_mod_cast hwlt
omega
have hw' : w = 0 := by
by_contra h
exact normNat_ne_zero h hwzero
rw [hw', mul_zero, sub_eq_zero] at hw
exact hw
lemma primary_associated_eq {a b : Eisenstein} (ha : primary a) (hb : primary b)
(hab : Associated a b) : a = b := by
obtain ⟨u, hu⟩ := hab
have hm := congrArg (Ideal.Quotient.mk (modulus 3)) hu
rw [map_mul, (primary_iff_residue_one a).mp ha,
(primary_iff_residue_one b).mp hb, one_mul] at hm
have huone := primary_unit_eq_one u.isUnit ((primary_iff_residue_one u).mpr hm)
simpa only [huone, mul_one] using hu
lemma residue_three_eq_zero : Ideal.Quotient.mk (modulus (3 : Eisenstein)) 3 = 0 :=
Ideal.Quotient.eq_zero_iff_mem.mpr (Ideal.subset_span (Set.mem_singleton _))
lemma residue_ofCoords_mod_three (a b : ℤ) :
Ideal.Quotient.mk (modulus (3 : Eisenstein)) (ofCoords a b) =
Ideal.Quotient.mk (modulus (3 : Eisenstein)) (ofCoords (a%3) (b%3)) := by
apply Ideal.Quotient.eq.mpr
apply Ideal.mem_span_singleton.mpr
refine ⟨ofCoords (a/3) (b/3), ?_⟩
have ha := Int.emod_add_mul_ediv a 3
have hb := Int.emod_add_mul_ediv b 3
have ha' : (a : Eisenstein) = (a%3 : ℤ) + 3*(a/3 : ℤ) := by exact_mod_cast ha.symm
have hb' : (b : Eisenstein) = (b%3 : ℤ) + 3*(b/3 : ℤ) := by exact_mod_cast hb.symm
dsimp only [ofCoords]
rw [ha', hb']
ring
lemma residue_three_nontrivial : Nontrivial (Residues (3 : Eisenstein)) := by
let : Finite (Residues (3 : Eisenstein)) := finite_residues (by norm_num)
apply Finite.one_lt_card_iff_nontrivial.mp
rw [residues_card (by norm_num : (3 : Eisenstein) ≠ 0)]
change 1 < ⌊Complex.normSq (3 : ℂ)⌋₊
norm_num [Complex.normSq_apply]
lemma omegaE_isUnit : IsUnit omegaE := by
apply isUnit_iff_exists_inv.mpr
exact ⟨omegaE^2, by simpa only [← pow_succ'] using omegaE_cube⟩
lemma unit_lift_mod_three {z : Eisenstein}
(hz : IsUnit (Ideal.Quotient.mk (modulus 3) z)) :
∃ u : Eisenstein, IsUnit u ∧ primary (z*u) := by
let := residue_three_nontrivial
obtain ⟨⟨a,b⟩, rfl⟩ := ofCoords_surjective z
have ha : 0 ≤ a%3 ∧ a%3 < 3 := ⟨Int.emod_nonneg _ (by norm_num), Int.emod_lt_of_pos _ (by norm_num)⟩
have hb : 0 ≤ b%3 ∧ b%3 < 3 := ⟨Int.emod_nonneg _ (by norm_num), Int.emod_lt_of_pos _ (by norm_num)⟩
let q := Ideal.Quotient.mk (modulus (3 : Eisenstein))
have hreduce : q (ofCoords a b) = q (ofCoords (a%3) (b%3)) := residue_ofCoords_mod_three a b
have hω : (q omegaE)^2 + q omegaE + 1 = 0 := by
have he : omegaE^2 + omegaE + 1 = 0 := Subtype.ext omega_quadratic
simpa only [map_add, map_pow, map_one, map_zero] using congrArg q he
have h3 : (3 : Residues (3 : Eisenstein)) = 0 := by
simpa only [map_ofNat] using residue_three_eq_zero
have hunit : IsUnit (q (ofCoords (a%3) (b%3))) := hreduce ▸ hz
have hbad {v : Residues (3 : Eisenstein)} (hv : IsUnit v) (hsq : v^2 = 0) : False :=
(hv.pow 2).ne_zero hsq
have hprimary (u : Eisenstein) (heq : q (ofCoords (a%3) (b%3)) * q u = 1) :
primary (ofCoords a b * u) := by
rw [primary_iff_residue_one, map_mul]
exact (congrArg (· * q u) hreduce).trans heq
obtain ⟨ha0,ha3⟩ := ha
obtain ⟨hb0,hb3⟩ := hb
interval_cases hA : a%3 <;> interval_cases hB : b%3
· simp [ofCoords] at hunit
· refine ⟨omegaE^2, omegaE_isUnit.pow 2, hprimary _ ?_⟩
simpa only [hA, hB, ofCoords, Int.cast_zero, Int.cast_one, zero_add, one_mul,
map_pow, map_one, ← pow_succ'] using congrArg q omegaE_cube
· refine ⟨-omegaE^2, (omegaE_isUnit.pow 2).neg, hprimary _ ?_⟩
simp only [ofCoords, Int.cast_zero, Int.cast_ofNat, zero_add,
map_mul, map_ofNat, map_neg, map_pow]
have hc : (q omegaE)^3 = 1 := by simpa only [map_pow, map_one] using congrArg q omegaE_cube
linear_combination -2*hc - h3
· refine ⟨1, isUnit_one, hprimary _ ?_⟩
simp [ofCoords]
· refine ⟨-omegaE, omegaE_isUnit.neg, hprimary _ ?_⟩
simp only [ofCoords, Int.cast_one, one_mul, map_add, map_one, map_neg]
linear_combination -hω
· apply (hbad hunit ?_).elim
simp only [ofCoords, Int.cast_one, Int.cast_ofNat, map_add, map_mul, map_one, map_ofNat]
linear_combination 4*hω - h3
· refine ⟨-1, isUnit_one.neg, hprimary _ ?_⟩
simp only [ofCoords, Int.cast_zero, Int.cast_ofNat, zero_mul, add_zero,
map_ofNat, map_neg, map_one]
linear_combination -h3
· apply (hbad hunit ?_).elim
simp only [ofCoords, Int.cast_one, Int.cast_ofNat, one_mul, map_add, map_ofNat]
linear_combination hω + h3 * (q omegaE+1)
· refine ⟨omegaE, omegaE_isUnit, hprimary _ ?_⟩
simp only [ofCoords, Int.cast_ofNat, map_add, map_mul, map_ofNat]
linear_combination 2*hω - h3
lemma unit_residue_of_dvd_primary {n d : Eisenstein} (hn : primary n) (hd : d ∣ n) :
IsUnit (Ideal.Quotient.mk (modulus 3) d) := by
apply isUnit_of_dvd_one
rw [← (primary_iff_residue_one n).mp hn]
exact map_dvd (Ideal.Quotient.mk (modulus 3)) hd
def primaryNormalize (z : Eisenstein) : Eisenstein :=
if h : IsUnit (Ideal.Quotient.mk (modulus 3) z) then
z * Classical.choose (unit_lift_mod_three h)
else z
lemma primaryNormalize_associated (z : Eisenstein) : Associated z (primaryNormalize z) := by
unfold primaryNormalize
split_ifs with h
· exact associated_mul_unit_right _ _ (Classical.choose_spec (unit_lift_mod_three h)).1
· rfl
lemma primaryNormalize_primary {z : Eisenstein}
(hz : IsUnit (Ideal.Quotient.mk (modulus 3) z)) : primary (primaryNormalize z) := by
rw [primaryNormalize, dite_eq_left hz]
exact (Classical.choose_spec (unit_lift_mod_three hz)).2
lemma primaryNormalize_eq_self {z : Eisenstein} (hz : primary z) : primaryNormalize z = z := by
exact primary_associated_eq
(primaryNormalize_primary (unit_residue_of_dvd_primary hz (dvd_refl z))) hz
(primaryNormalize_associated z).symm
lemma exists_unique_primary_associate {z : Eisenstein}
(hz : IsUnit (Ideal.Quotient.mk (modulus 3) z)) :
∃! w : Eisenstein, primary w ∧ Associated z w := by
refine ⟨primaryNormalize z, ⟨primaryNormalize_primary hz, primaryNormalize_associated z⟩, ?_⟩
intro w hw
exact primary_associated_eq hw.1 (primaryNormalize_primary hz)
(hw.2.symm.trans (primaryNormalize_associated z))
lemma normNat_primaryNormalize (z : Eisenstein) : normNat (primaryNormalize z) = normNat z :=
(associated_normNat (primaryNormalize_associated z)).symm
lemma prime_primaryNormalize {z : Eisenstein} (hz : Prime z) : Prime (primaryNormalize z) :=
(primaryNormalize_associated z).prime_iff.mp hz
lemma primaryNormalize_injOn_primeFactors (n : Eisenstein) :
Set.InjOn primaryNormalize (primeFactors n : Set Eisenstein) := by
intro a ha b hb hab
apply mem_normalizedFactors_eq_of_associated
(Multiset.mem_toFinset.mp ha) (Multiset.mem_toFinset.mp hb)
exact (primaryNormalize_associated a).trans (hab ▸ (primaryNormalize_associated b).symm)
def primaryPrimeFactors (n : Eisenstein) : Finset Eisenstein :=
(primeFactors n).image primaryNormalize
lemma primaryPrimeFactor_spec {n p : Eisenstein} (hn : primary n)
(hp : p ∈ primaryPrimeFactors n) : primaryPrime p ∧ p ∣ n := by
obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hp
have hq' : q ∈ normalizedFactors n := Multiset.mem_toFinset.mp hq
have hd : q ∣ n := dvd_of_mem_normalizedFactors hq'
exact ⟨⟨primaryNormalize_primary (unit_residue_of_dvd_primary hn hd),
prime_primaryNormalize (prime_of_normalized_factor q hq')⟩,
(primaryNormalize_associated q).dvd_iff_dvd_left.mp hd⟩
lemma primary_finset_prod {ι : Type*} (s : Finset ι) (f : ι → Eisenstein)
(hf : ∀ i ∈ s, primary (f i)) : primary (∏ i ∈ s, f i) := by
classical
induction s using Finset.induction_on with
| empty => simp [primary]
| @insert i s hi ih =>
rw [Finset.prod_insert hi]
exact primary_mul (hf _ (Finset.mem_insert_self _ _))
(ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)))
lemma primaryPrimeFactors_prod {n : Eisenstein} (hn : primary n) (hs : Squarefree n) :
∏ p ∈ primaryPrimeFactors n, p = n := by
have heq : (∏ p ∈ primeFactors n, p) = (normalizedFactors n).prod := by
rw [primeFactors, Finset.prod_eq_multiset_prod, Multiset.toFinset_val,
Multiset.dedup_eq_self.mpr (primeFactors_nodup hs)]
simp
apply primary_associated_eq
(primary_finset_prod _ _ (fun p hp => (primaryPrimeFactor_spec hn hp).1.1)) hn
rw [primaryPrimeFactors, Finset.prod_image (primaryNormalize_injOn_primeFactors n)]
exact ((Associated.prod _ _ _ (fun p _ => primaryNormalize_associated p)).symm).trans
(heq ▸ prod_normalizedFactors hs.ne_zero)
lemma primaryPrimeFactors_card (n : Eisenstein) :
(primaryPrimeFactors n).card = (primeFactors n).card :=
Finset.card_image_of_injOn (primaryNormalize_injOn_primeFactors n)
lemma primaryPrimeFactors_norm_prod {n : Eisenstein} (hn : primary n) (hs : Squarefree n) :
∏ p ∈ primaryPrimeFactors n, normNat p = normNat n := by
calc
_ = normNat (∏ p ∈ primaryPrimeFactors n, p) := (map_prod normNatHom _ _).symm
_ = normNat n := congrArg normNat (primaryPrimeFactors_prod hn hs)
end CubicFirstMoment
end
end
end OAI
|