Skip to content

Commit b38baa7

Browse files
joneugsterParcly-Taxeleric-wieser
committed
chore: re-port Algebra.CharP.Basic (#3191)
This forward-ports changes from leanprover-community/mathlib3#11364 One unrelated downstream file times out, presumably due to the import graph subtly changing. Co-authored-by: Parcly Taxel <reddeloostw@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent 3b6fdff commit b38baa7

File tree

3 files changed

+91
-39
lines changed

3 files changed

+91
-39
lines changed

Mathlib/Algebra/CharP/Basic.lean

Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Kenny Lau, Joey van Langen, Casper Putz
55
66
! This file was ported from Lean 3 source module algebra.char_p.basic
7-
! leanprover-community/mathlib commit 05a78c9451101108e638a0f213fb1bed82483545
7+
! leanprover-community/mathlib commit ceb887ddf3344dab425292e497fa2af91498437c
88
! Please do not edit these lines, except to modify the commit id
99
! if you have ported upstream changes.
1010
-/
11-
import Mathlib.Algebra.Hom.Iterate
1211
import Mathlib.Data.Int.ModEq
13-
import Mathlib.Data.Nat.Choose.Dvd
14-
import Mathlib.Data.Nat.Choose.Sum
12+
import Mathlib.Data.Nat.Multiplicity
1513
import Mathlib.GroupTheory.OrderOfElement
1614
import Mathlib.RingTheory.Nilpotent
1715

@@ -22,7 +20,79 @@ import Mathlib.RingTheory.Nilpotent
2220

2321
universe u v
2422

25-
variable (R : Type u)
23+
open Finset
24+
25+
open BigOperators
26+
27+
variable {R : Type _}
28+
29+
namespace Commute
30+
31+
variable [Semiring R] {p : ℕ} {x y : R}
32+
33+
protected theorem add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
34+
(x + y) ^ p ^ n =
35+
x ^ p ^ n + y ^ p ^ n +
36+
p * ∑ k in Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) := by
37+
trans x ^ p ^ n + y ^ p ^ n + ∑ k in Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * (p ^ n).choose k
38+
· simp_rw [h.add_pow, ← Nat.Ico_zero_eq_range, Nat.Ico_succ_right, Icc_eq_cons_Ico (zero_le _),
39+
Finset.sum_cons, Ico_eq_cons_Ioo (pow_pos hp.pos _), Finset.sum_cons, tsub_self, tsub_zero,
40+
pow_zero, Nat.choose_zero_right, Nat.choose_self, Nat.cast_one, mul_one, one_mul, ← add_assoc]
41+
· congr 1
42+
simp_rw [Finset.mul_sum, Nat.cast_comm, mul_assoc _ _ (p : R), ← Nat.cast_mul]
43+
refine' Finset.sum_congr rfl fun i hi => _
44+
rw [mem_Ioo] at hi
45+
rw [Nat.div_mul_cancel (hp.dvd_choose_pow hi.1.ne' hi.2.ne)]
46+
#align commute.add_pow_prime_pow_eq Commute.add_pow_prime_pow_eq
47+
48+
protected theorem add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
49+
(x + y) ^ p =
50+
x ^ p + y ^ p + p * ∑ k in Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) :=
51+
by simpa using h.add_pow_prime_pow_eq hp 1
52+
#align commute.add_pow_prime_eq Commute.add_pow_prime_eq
53+
54+
protected theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
55+
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
56+
⟨_, h.add_pow_prime_pow_eq hp n⟩
57+
#align commute.exists_add_pow_prime_pow_eq Commute.exists_add_pow_prime_pow_eq
58+
59+
protected theorem exists_add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
60+
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
61+
⟨_, h.add_pow_prime_eq hp⟩
62+
#align commute.exists_add_pow_prime_eq Commute.exists_add_pow_prime_eq
63+
64+
end Commute
65+
66+
section CommSemiring
67+
68+
variable [CommSemiring R] {p : ℕ} {x y : R}
69+
70+
theorem add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
71+
(x + y) ^ p ^ n =
72+
x ^ p ^ n + y ^ p ^ n +
73+
p * ∑ k in Finset.Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) :=
74+
(Commute.all x y).add_pow_prime_pow_eq hp n
75+
#align add_pow_prime_pow_eq add_pow_prime_pow_eq
76+
77+
theorem add_pow_prime_eq (hp : p.Prime) (x y : R) :
78+
(x + y) ^ p =
79+
x ^ p + y ^ p + p * ∑ k in Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) :=
80+
(Commute.all x y).add_pow_prime_eq hp
81+
#align add_pow_prime_eq add_pow_prime_eq
82+
83+
theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
84+
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
85+
(Commute.all x y).exists_add_pow_prime_pow_eq hp n
86+
#align exists_add_pow_prime_pow_eq exists_add_pow_prime_pow_eq
87+
88+
theorem exists_add_pow_prime_eq (hp : p.Prime) (x y : R) :
89+
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
90+
(Commute.all x y).exists_add_pow_prime_eq hp
91+
#align exists_add_pow_prime_eq exists_add_pow_prime_eq
92+
93+
end CommSemiring
94+
95+
variable (R)
2696

2797
/-- The generator of the kernel of the unique homomorphism ℕ → R for a semiring R.
2898
@@ -46,6 +116,7 @@ theorem CharP.cast_eq_zero_iff (R : Type u) [AddMonoidWithOne R] (p : ℕ) [Char
46116
(x : R) = 0 ↔ p ∣ x :=
47117
CharP.cast_eq_zero_iff' (R := R) (p := p) x
48118

119+
@[simp]
49120
theorem CharP.cast_eq_zero [AddMonoidWithOne R] (p : ℕ) [CharP R p] : (p : R) = 0 :=
50121
(CharP.cast_eq_zero_iff R p p).2 (dvd_refl p)
51122
#align char_p.cast_eq_zero CharP.cast_eq_zero
@@ -162,39 +233,22 @@ theorem eq_zero [CharZero R] : ringChar R = 0 :=
162233
eq R 0
163234
#align ring_char.eq_zero ringChar.eq_zero
164235

165-
@[simp]
236+
-- @[simp] -- Porting note: simp can prove this
166237
theorem Nat.cast_ringChar : (ringChar R : R) = 0 := by rw [ringChar.spec]
167238
#align ring_char.nat.cast_ring_char ringChar.Nat.cast_ringChar
168239

169240
end ringChar
170241

171-
theorem add_pow_char_of_commute [Semiring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R)
242+
theorem add_pow_char_of_commute [Semiring R] {p : ℕ} [hp : Fact p.Prime] [CharP R p] (x y : R)
172243
(h : Commute x y) : (x + y) ^ p = x ^ p + y ^ p := by
173-
rw [Commute.add_pow h, Finset.sum_range_succ_comm, tsub_self, pow_zero, Nat.choose_self]
174-
rw [Nat.cast_one, mul_one, mul_one]; congr 1
175-
convert Finset.sum_eq_single (f := fun (x_1 : ℕ) => x ^ x_1 * y ^ (p - x_1) * (Nat.choose p x_1))
176-
(s := Finset.range p) 0
177-
(by
178-
intro b h1 h2
179-
suffices (p.choose b : R) = 0 by
180-
simp [this]
181-
rw [CharP.cast_eq_zero_iff R p]
182-
exact Nat.Prime.dvd_choose_self Fact.out h2 (Finset.mem_range.1 h1))
183-
(by
184-
intro h1
185-
contrapose! h1
186-
rw [Finset.mem_range]
187-
exact Nat.Prime.pos Fact.out)
188-
simp only [mul_one, one_mul, Nat.choose_zero_right, tsub_zero, Nat.cast_one, pow_zero]
244+
let ⟨r, hr⟩ := h.exists_add_pow_prime_eq hp.out
245+
simp [hr]
189246
#align add_pow_char_of_commute add_pow_char_of_commute
190247

191-
theorem add_pow_char_pow_of_commute [Semiring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ}
248+
theorem add_pow_char_pow_of_commute [Semiring R] {p n : ℕ} [hp : Fact p.Prime] [CharP R p]
192249
(x y : R) (h : Commute x y) : (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n := by
193-
induction n with
194-
| zero => simp
195-
| succ n n_ih =>
196-
rw [pow_succ', pow_mul, pow_mul, pow_mul, n_ih]
197-
apply add_pow_char_of_commute; apply Commute.pow_pow h
250+
let ⟨r, hr⟩ := h.exists_add_pow_prime_pow_eq hp.out n
251+
simp [hr]
198252
#align add_pow_char_pow_of_commute add_pow_char_pow_of_commute
199253

200254
theorem sub_pow_char_of_commute [Ring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R)
@@ -509,7 +563,7 @@ end Semiring
509563
section Ring
510564

511565
variable [Ring R] [NoZeroDivisors R] [Nontrivial R] [Finite R]
512-
-- porting note: redundant binder annotation update
566+
-- porting note: removed redundant binder annotation update `(R)`
513567

514568
theorem char_is_prime (p : ℕ) [CharP R p] : p.Prime :=
515569
Or.resolve_right (char_is_prime_or_zero R p) (char_ne_zero_of_finite R p)
@@ -589,12 +643,11 @@ end
589643
section
590644

591645
variable [NonAssocRing R] [Fintype R] (n : ℕ)
592-
-- porting note: redundant binder annotation update
646+
-- porting note: removed redundant binder annotation update `(R)`
593647

594648
theorem charP_of_ne_zero (hn : Fintype.card R = n) (hR : ∀ i < n, (i : R) = 0 → i = 0) :
595649
CharP R n :=
596-
{ cast_eq_zero_iff' :=
597-
by
650+
{ cast_eq_zero_iff' := by
598651
have H : (n : R) = 0 := by rw [← hn, CharP.cast_card_eq_zero]
599652
intro k
600653
constructor
@@ -660,8 +713,7 @@ theorem Int.cast_injOn_of_ringChar_ne_two {R : Type _} [NonAssocRing R] [Nontriv
660713
by_contra hf
661714
replace ha : a = 0 ∨ a = 1 ∨ a = -1 := ha
662715
replace hb : b = 0 ∨ b = 1 ∨ b = -1 := hb
663-
have hh : a - b = 1 ∨ b - a = 1 ∨ a - b = 2 ∨ b - a = 2 :=
664-
by
716+
have hh : a - b = 1 ∨ b - a = 1 ∨ a - b = 2 ∨ b - a = 2 := by
665717
rcases ha with (ha | ha | ha) <;> rcases hb with (hb | hb | hb)
666718
pick_goal 5
667719
pick_goal 9
@@ -687,7 +739,7 @@ end
687739
namespace NeZero
688740

689741
variable [AddMonoidWithOne R] {r : R} {n p : ℕ} {a : ℕ+}
690-
-- porting note: redundant binder annotation update
742+
-- porting note: removed redundant binder annotation update `(R)`
691743

692744
theorem of_not_dvd [CharP R p] (h : ¬p ∣ n) : NeZero (n : R) :=
693745
⟨(CharP.cast_eq_zero_iff R p n).not.mpr h⟩

Mathlib/Data/ZMod/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
126126
exact ZMod.charP n
127127
#align zmod.ring_char_zmod_n ZMod.ringChar_zmod_n
128128

129-
@[simp]
129+
-- @[simp] -- Porting note: simp can prove this
130130
theorem nat_cast_self (n : ℕ) : (n : ZMod n) = 0 :=
131131
CharP.cast_eq_zero (ZMod n) n
132132
#align zmod.nat_cast_self ZMod.nat_cast_self

Mathlib/RingTheory/Polynomial/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ set_option linter.uppercaseLean3 false in
759759
theorem is_fg_degreeLe [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) :
760760
Submodule.Fg (I.degreeLe n) :=
761761
isNoetherian_submodule_left.1
762-
(isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLe_eq_span_X_pow.symm⟩) _
762+
-- porting note: times out without explicit `R`.
763+
(isNoetherian_of_fg_of_noetherian _ ⟨_, (degreeLe_eq_span_X_pow (R := R)).symm⟩) _
763764
#align ideal.is_fg_degree_le Ideal.is_fg_degreeLe
764765

765766
end CommRing
@@ -1301,4 +1302,3 @@ instance (priority := 100) : UniqueFactorizationMonoid (MvPolynomial σ D) := by
13011302
end MvPolynomial
13021303

13031304
end UniqueFactorizationDomain
1304-

0 commit comments

Comments
 (0)