Skip to content
33 changes: 6 additions & 27 deletions Mathlib/NumberTheory/ADEInequality.lean
Original file line number Diff line number Diff line change
Expand Up @@ -152,52 +152,31 @@ theorem Admissible.one_lt_sumInv {pqr : Multiset ℕ+} : Admissible pqr → 1 <
norm_num

theorem lt_three {p q r : ℕ+} (hpq : p ≤ q) (hqr : q ≤ r) (H : 1 < sumInv {p, q, r}) : p < 3 := by
have h3 : (0 : ℚ) < 3 := by simp
contrapose! H
rw [sumInv_pqr]
have h3q := H.trans hpq
have h3r := h3q.trans hqr
have hp : (p : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv₀ _ h3]
· assumption_mod_cast
· simp
have hq : (q : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv₀ _ h3]
· assumption_mod_cast
· simp
have hr : (r : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv₀ _ h3]
· assumption_mod_cast
· simp
have hp : (p : ℚ)⁻¹ ≤ 3⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast H)
have hq : (q : ℚ)⁻¹ ≤ 3⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast h3q)
have hr : (r : ℚ)⁻¹ ≤ 3⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast h3r)
calc
(p : ℚ)⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹ ≤ 3⁻¹ + 3⁻¹ + 3⁻¹ := add_le_add (add_le_add hp hq) hr
_ = 1 := by norm_num

theorem lt_four {q r : ℕ+} (hqr : q ≤ r) (H : 1 < sumInv {2, q, r}) : q < 4 := by
have h4 : (0 : ℚ) < 4 := by simp
contrapose! H
rw [sumInv_pqr]
have h4r := H.trans hqr
have hq : (q : ℚ)⁻¹ ≤ 4⁻¹ := by
rw [inv_le_inv₀ _ h4]
· assumption_mod_cast
· simp
have hr : (r : ℚ)⁻¹ ≤ 4⁻¹ := by
rw [inv_le_inv₀ _ h4]
· assumption_mod_cast
· simp
have hq : (q : ℚ)⁻¹ ≤ 4⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast H)
have hr : (r : ℚ)⁻¹ ≤ 4⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast h4r)
calc
(2⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹) ≤ 2⁻¹ + 4⁻¹ + 4⁻¹ := add_le_add (add_le_add le_rfl hq) hr
_ = 1 := by norm_num

theorem lt_six {r : ℕ+} (H : 1 < sumInv {2, 3, r}) : r < 6 := by
have h6 : (0 : ℚ) < 6 := by simp
contrapose! H
rw [sumInv_pqr]
have hr : (r : ℚ)⁻¹ ≤ 6⁻¹ := by
rw [inv_le_inv₀ _ h6]
· assumption_mod_cast
· simp
have hr : (r : ℚ)⁻¹ ≤ 6⁻¹ := inv_anti₀ (by positivity) (by exact_mod_cast H)
calc
(2⁻¹ + 3⁻¹ + (r : ℚ)⁻¹ : ℚ) ≤ 2⁻¹ + 3⁻¹ + 6⁻¹ := add_le_add (add_le_add le_rfl le_rfl) hr
_ = 1 := by norm_num
Expand Down
26 changes: 8 additions & 18 deletions Mathlib/NumberTheory/ArithmeticFunction/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :

theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
rw [smul_apply, ← Nat.map_div_right_divisors, sum_map, sum_eq_single 1]
· simp
intro y ymem ynotMem
have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff]
simp [y1ne]
· intro d hd hd1
simp [one_apply_ne hd1]
· simpa using fun hx : x = 0 => by simp [hx]

end Module

Expand All @@ -282,17 +278,11 @@ instance instMonoid : Monoid (ArithmeticFunction R) where
one_mul := one_smul'
mul_one f := by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
rw [mul_apply, ← Nat.map_div_left_divisors, sum_map, sum_eq_single 1]
· simp
intro ⟨y₁, y₂⟩ ymem ynotMem
have y2ne : y₂ ≠ 1 := by
intro con
simp_all
simp [y2ne]
· intro d hd hd1
simp [one_apply_ne hd1]
· simpa using fun hx : x = 0 => by simp [hx]
mul_assoc := mul_smul'

instance instSemiring : Semiring (ArithmeticFunction R) where
Expand Down
16 changes: 6 additions & 10 deletions Mathlib/NumberTheory/ArithmeticFunction/Zeta.lean
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply

theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]

theorem coe_zeta_mul_comm [Semiring R] {f : ArithmeticFunction R} : ζ * f = f * ζ := by
ext x
rw [coe_zeta_mul_apply, coe_mul_zeta_apply]
rw [mul_apply, ← map_swap_divisorsAntidiagonal, Finset.sum_map]
simp [mul_apply]

theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [← coe_zeta_mul_comm, coe_zeta_mul_apply]

theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_zeta_mul_apply]
Expand Down
19 changes: 5 additions & 14 deletions Mathlib/NumberTheory/BernoulliPolynomials.lean
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ theorem bernoulli_one : bernoulli 1 = X - C 2⁻¹ := by

@[simp]
theorem bernoulli_eval_zero (n : ℕ) : (bernoulli n).eval 0 = _root_.bernoulli n := by
rw [bernoulli, eval_finset_sum, sum_range_succ]
have : ∑ x ∈ range n, _root_.bernoulli x * n.choose x * 0 ^ (n - x) = 0 := by
apply sum_eq_zero fun x hx => _
intro x hx
simp [tsub_eq_zero_iff_le, mem_range.1 hx]
simp [this]
rw [← coeff_zero_eq_eval_zero, coeff_bernoulli, if_pos (Nat.zero_le n), Nat.sub_zero,
Nat.choose_zero_right, Nat.cast_one, mul_one]

@[simp]
theorem bernoulli_eval_one (n : ℕ) : (bernoulli n).eval 1 = bernoulli' n := by
Expand Down Expand Up @@ -147,15 +143,10 @@ nonrec theorem sum_bernoulli (n : ℕ) :
simp only [add_eq_left, mul_one, cast_one, cast_add, add_tsub_cancel_left,
choose_succ_self_right, one_smul, _root_.bernoulli_zero, sum_singleton, zero_add,
map_add, range_one, mul_one]
apply sum_eq_zero fun x hx => _
have f : ∀ x ∈ range n, ¬n + 1 - x = 1 := by grind
refine sum_eq_zero ?_
intro x hx
rw [sum_bernoulli]
have g : ite (n + 1 - x = 1) (1 : ℚ) 0 = 0 := by
simp only [ite_eq_right_iff, one_ne_zero]
intro h₁
exact (f x hx) h₁
rw [g, zero_smul]
have hx1 : n + 1 - x ≠ 1 := by grind
simp [_root_.sum_bernoulli, hx1]

/-- Another version of `Polynomial.sum_bernoulli`. -/
theorem bernoulli_eq_sub_sum (n : ℕ) :
Expand Down
50 changes: 16 additions & 34 deletions Mathlib/NumberTheory/Cyclotomic/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -549,42 +549,24 @@ theorem nonempty_algEquiv_adjoin_of_isSepClosed [IsCyclotomicExtension S K L]
have := isSeparable S K L
let i : L →ₐ[K] M := IsSepClosed.lift
refine ⟨(show L ≃ₐ[K] i.fieldRange from AlgEquiv.ofInjectiveField i).trans
(IntermediateField.equivOfEq (le_antisymm ?_ ?_))⟩
· rintro x (hx : x ∈ i.range)
let e := Subalgebra.equivOfEq _ _ ((IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_›).2
|>.trans Subalgebra.topEquiv
have hrange : i.range = (i.comp (AlgHomClass.toAlgHom e)).range := by
ext x
simp only [AlgHom.mem_range, AlgHom.coe_comp, AlgHom.coe_coe, Function.comp_apply]
constructor
· rintro ⟨y, rfl⟩; exact ⟨e.symm y, by simp⟩
· rintro ⟨y, rfl⟩; exact ⟨e y, rfl⟩
rw [hrange, AlgHom.mem_range] at hx
obtain ⟨⟨y, hy⟩, rfl⟩ := hx
induction hy using Algebra.adjoin_induction with
| mem x hx =>
obtain ⟨n, hn, h1, h2⟩ := hx
apply IntermediateField.subset_adjoin
use n, hn, h1
rw [← map_pow, ← map_one (i.comp (AlgHomClass.toAlgHom e))]
congr 1
apply_fun _ using Subtype.val_injective
simpa
| algebraMap x =>
convert IntermediateField.algebraMap_mem _ x
exact AlgHom.commutes _ x
| add x y hx hy ihx ihy =>
convert add_mem ihx ihy
exact map_add (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
| mul x y hx hy ihx ihy =>
convert mul_mem ihx ihy
exact map_mul (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
· rw [IntermediateField.adjoin_le_iff]
rintro x ⟨n, hn, h1, h2⟩
have := NeZero.mk h1
(IntermediateField.equivOfEq ?_)⟩
rw [AlgHom.fieldRange_eq_map]
have htop : IntermediateField.adjoin K {x : L | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1} = ⊤ := by
exact IntermediateField.adjoin_eq_top_of_algebra (F := K)
(S := {x : L | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1})
(((IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_›).2)
rw [← htop, IntermediateField.adjoin_map]
apply le_antisymm <;> rw [IntermediateField.adjoin_le_iff]
· rintro _ ⟨y, ⟨n, hn, h1, h2⟩, rfl⟩
exact IntermediateField.subset_adjoin (F := K)
(S := {x : M | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) ⟨n, hn, h1, by
simpa using congrArg i h2⟩
· rintro x ⟨n, hn, h1, h2⟩
have : NeZero n := ⟨h1⟩
obtain ⟨y, hy⟩ := exists_isPrimitiveRoot K L hn h1
obtain ⟨m, -, rfl⟩ := (hy.map_of_injective (f := i) i.injective).eq_pow_of_pow_eq_one h2
exact ⟨y ^ m, by simp⟩
exact pow_mem (IntermediateField.subset_adjoin (F := K)
(S := i '' {x : L | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) ⟨y, ⟨n, hn, h1, hy.pow_eq_one⟩, rfl⟩) m

theorem isGalois [IsCyclotomicExtension S K L] : IsGalois K L := by
rw [isGalois_iff]
Expand Down
22 changes: 4 additions & 18 deletions Mathlib/NumberTheory/Cyclotomic/Gal.lean
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,10 @@ variable [CommRing L] [IsDomain L] (hμ : IsPrimitiveRoot μ n) [Algebra K L]
field extension. -/
theorem autToPow_injective : Function.Injective <| hμ.autToPow K := by
intro f g hfg
apply_fun Units.val at hfg
simp only [IsPrimitiveRoot.coe_autToPow_apply] at hfg
generalize_proofs hf' hg' at hfg
have hf := hf'.choose_spec
have hg := hg'.choose_spec
generalize_proofs hζ at hf hg
suffices f (hμ.toRootsOfUnity : Lˣ) = g (hμ.toRootsOfUnity : Lˣ) by
apply AlgEquiv.coe_algHom_injective
apply (hμ.powerBasis K).algHom_ext
exact this
rw [ZMod.natCast_eq_natCast_iff] at hfg
refine (hf.trans ?_).trans hg.symm
rw [← rootsOfUnity.coe_pow _ hf'.choose, ← rootsOfUnity.coe_pow _ hg'.choose]
congr 2
rw [pow_eq_pow_iff_modEq]
convert hfg
conv => enter [2]; rw [hμ.eq_orderOf, ← hμ.val_toRootsOfUnity_coe]
rw [orderOf_units, Subgroup.orderOf_coe]
apply AlgEquiv.coe_algHom_injective
apply (hμ.powerBasis K).algHom_ext
simpa only [IsPrimitiveRoot.autToPow_spec] using
congrArg (fun t : (ZMod n)ˣ ↦ μ ^ (t : ZMod n).val) hfg

end IsPrimitiveRoot

Expand Down
12 changes: 3 additions & 9 deletions Mathlib/NumberTheory/Cyclotomic/PrimitiveRoots.lean
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,9 @@ theorem norm_pow_sub_one_eq_prime_pow_of_ne_zero {k s : ℕ} (hζ : IsPrimitiveR
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (hs : s ≤ k) (hk : k ≠ 0) :
norm K (ζ ^ p ^ s - 1) = (p : K) ^ p ^ s := by
by_cases htwo : p ^ (k - s + 1) = 2
· have hp : p = 2 := by
rw [← pow_one 2] at htwo
exact eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (succ_pos _) htwo
replace hs : s = k := by
rw [hp] at htwo
nth_rw 2 [← pow_one 2] at htwo
replace htwo := Nat.pow_right_injective rfl.le htwo
rw [add_eq_right, Nat.sub_eq_zero_iff_le] at htwo
exact le_antisymm hs htwo
· obtain ⟨hp, hks⟩ := (Nat.prime_two.pow_eq_iff).1 htwo
simp only [add_eq_right] at hks
replace hs : s = k := le_antisymm hs (Nat.sub_eq_zero_iff_le.mp hks)
simp only [hp, hs] at hζ hirr hcycl ⊢
obtain ⟨k₁, hk₁⟩ := Nat.exists_eq_succ_of_ne_zero hk
rw [hζ.norm_pow_sub_one_two hirr, hk₁, _root_.pow_succ', pow_mul, neg_eq_neg_one_mul,
Expand Down
22 changes: 6 additions & 16 deletions Mathlib/NumberTheory/Dioph.lean
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,8 @@ theorem sub_dioph : DiophFn fun v => f v - g v :=
(diophFn_vec _).2 <|
ext (D&1 D= D&0 D+ D&2 D∨ D&1 D≤ D&2 D∧ D&0 D= D.0) <|
(vectorAll_iff_forall _).1 fun x y z =>
show y = x + z ∨ y ≤ z ∧ x = 0 ↔ y - z = x from
⟨fun o => by
rcases o with (ae | ⟨yz, x0⟩)
· rw [ae, add_tsub_cancel_right]
· rw [x0, tsub_eq_zero_iff_le.mpr yz], by
lia⟩
show y = x + z ∨ y ≤ z ∧ x = 0 ↔ y - z = x by
grind

@[inherit_doc]
scoped infixl:80 " D- " => Dioph.sub_dioph
Expand Down Expand Up @@ -623,16 +619,10 @@ theorem div_dioph : DiophFn fun v => f v / g v :=
ext this <|
(vectorAll_iff_forall _).1 fun z x y =>
show y = 0 ∧ z = 0 ∨ z * y ≤ x ∧ x < (z + 1) * y ↔ x / y = z by
refine Iff.trans ?_ eq_comm
exact y.eq_zero_or_pos.elim
(fun y0 => by
rw [y0, Nat.div_zero]
exact ⟨fun o => (o.resolve_right fun ⟨_, h2⟩ => Nat.not_lt_zero _ h2).right,
fun z0 => Or.inl ⟨rfl, z0⟩⟩)
fun ypos =>
Iff.trans ⟨fun o => o.resolve_left fun ⟨h1, _⟩ => Nat.ne_of_gt ypos h1, Or.inr⟩
(le_antisymm_iff.trans <| and_congr (Nat.le_div_iff_mul_le ypos) <|
Iff.trans ⟨lt_succ_of_le, le_of_lt_succ⟩ (div_lt_iff_lt_mul ypos)).symm
rcases y.eq_zero_or_pos with rfl | hy
· simp [eq_comm]
· rw [Nat.div_eq_iff hy, Nat.succ_mul]
grind

end

Expand Down
10 changes: 2 additions & 8 deletions Mathlib/NumberTheory/DiophantineApproximation/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,12 @@ theorem convergent_succ (ξ : ℝ) (n : ℕ) :
/-- All convergents of `0` are zero. -/
@[simp]
theorem convergent_of_zero (n : ℕ) : convergent 0 n = 0 := by
induction n with
| zero => simp only [convergent_zero, floor_zero, cast_zero]
| succ n ih =>
simp only [ih, convergent_succ, floor_zero, cast_zero, fract_zero, add_zero, inv_zero]
induction n <;> simp [convergent, *]

/-- If `ξ` is an integer, all its convergents equal `ξ`. -/
@[simp]
theorem convergent_of_int {ξ : ℤ} (n : ℕ) : convergent ξ n = ξ := by
cases n
· simp only [convergent_zero, floor_intCast]
· simp only [convergent_succ, floor_intCast, fract_intCast, convergent_of_zero, add_zero,
inv_zero]
cases n <;> simp [convergent, convergent_of_zero]

end Real

Expand Down
Loading
Loading