Skip to content

Commit 9d2bcc5

Browse files
yapudpillrotarc75
andcommitted
feat(RingTheory): golf IsPrincipalIdealRing.of_prime (leanprover-community#28477)
In complement to leanprover-community#28451 and as discussed in leanprover-community#27200, this PR uses the newly added Oka predicates to golf the proof of `IsPrincipalIdealRing.of_prime`. Co-authored-by: Marc Robin <[email protected]>
1 parent 49fa7a7 commit 9d2bcc5

File tree

2 files changed

+85
-57
lines changed

2 files changed

+85
-57
lines changed

Mathlib/RingTheory/PrincipalIdealDomain.lean

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ principal ideal domain (PID) is an integral domain which is a principal ideal ri
1818
1919
The definition of `IsPrincipalIdealRing` can be found in `Mathlib/RingTheory/Ideal/Span.lean`.
2020
21-
# Main definitions
21+
## Main definitions
2222
2323
Note that for principal ideal domains, one should use
2424
`[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID.
@@ -28,7 +28,7 @@ Theorems about PID's are in the `PrincipalIdealRing` namespace.
2828
- `generator`: a generator of a principal ideal (or more generally submodule)
2929
- `to_uniqueFactorizationMonoid`: a PID is a unique factorization domain
3030
31-
# Main results
31+
## Main results
3232
3333
- `Ideal.IsPrime.to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
3434
- `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID.
@@ -482,35 +482,77 @@ end
482482

483483
section PrincipalOfPrime
484484

485-
open Set Ideal
485+
namespace Ideal
486+
487+
variable (R) [Semiring R]
488+
489+
/-- `nonPrincipals R` is the set of all ideals of `R` that are not principal ideals. -/
490+
abbrev nonPrincipals := { I : Ideal R | ¬I.IsPrincipal }
491+
492+
variable {R}
493+
494+
theorem nonPrincipals_eq_empty_iff : nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R := by
495+
simp [Set.eq_empty_iff_forall_notMem, isPrincipalIdealRing_iff]
496+
497+
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
498+
(Namely, the union of the chain is such an upper bound.)
499+
500+
If you want the existence of a maximal non-principal ideal see
501+
`Ideal.exists_maximal_not_isPrincipal`. -/
502+
theorem nonPrincipals_zorn (hR : ¬IsPrincipalIdealRing R) (c : Set (Ideal R))
503+
(hs : c ⊆ nonPrincipals R) (hchain : IsChain (· ≤ ·) c) :
504+
∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
505+
by_cases H : c.Nonempty
506+
· obtain ⟨K, hKmem⟩ := Set.nonempty_def.1 H
507+
refine ⟨sSup c, fun ⟨x, hx⟩ ↦ ?_, fun _ ↦ le_sSup⟩
508+
have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
509+
obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
510+
have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
511+
exact hs hJc ⟨hsSupJ ▸ ⟨x, hx⟩⟩
512+
· simpa [Set.not_nonempty_iff_eq_empty.1 H, isPrincipalIdealRing_iff] using hR
513+
514+
theorem exists_maximal_not_isPrincipal (hR : ¬IsPrincipalIdealRing R) :
515+
∃ I : Ideal R, Maximal (¬·.IsPrincipal) I :=
516+
zorn_le₀ _ (nonPrincipals_zorn hR)
517+
518+
end Ideal
519+
520+
end PrincipalOfPrime
521+
522+
section PrincipalOfPrime_old
486523

487524
variable (R) [CommRing R]
488525

489526
/-- `nonPrincipals R` is the set of all ideals of `R` that are not principal ideals. -/
527+
@[deprecated Ideal.nonPrincipals (since := "2025-09-30")]
490528
def nonPrincipals :=
491529
{ I : Ideal R | ¬I.IsPrincipal }
492530

493-
theorem nonPrincipals_def {I : Ideal R} : I ∈ nonPrincipals R ↔ ¬I.IsPrincipal :=
531+
@[deprecated "Not necessary anymore since Ideal.nonPrincipals is an abrev." (since := "2025-09-30")]
532+
theorem nonPrincipals_def {I : Ideal R} : I ∈ { I : Ideal R | ¬I.IsPrincipal } ↔ ¬I.IsPrincipal :=
494533
Iff.rfl
495534

496535
variable {R}
497536

498-
theorem nonPrincipals_eq_empty_iff : nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R := by
499-
simp [Set.eq_empty_iff_forall_notMem, isPrincipalIdealRing_iff, nonPrincipals_def]
537+
@[deprecated Ideal.nonPrincipals_eq_empty_iff (since := "2025-09-30")]
538+
theorem nonPrincipals_eq_empty_iff :
539+
{ I : Ideal R | ¬I.IsPrincipal } = ∅ ↔ IsPrincipalIdealRing R := by
540+
simp [Set.eq_empty_iff_forall_notMem, isPrincipalIdealRing_iff]
500541

501542
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
502543
(Namely, the union of the chain is such an upper bound.)
503544
-/
504-
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
545+
@[deprecated Ideal.nonPrincipals_zorn (since := "2025-09-30")]
546+
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ { I : Ideal R | ¬I.IsPrincipal })
505547
(hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
506-
∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
548+
∃ I ∈ { I : Ideal R | ¬I.IsPrincipal }, ∀ J ∈ c, J ≤ I := by
507549
refine ⟨sSup c, ?_, fun J hJ => le_sSup hJ⟩
508550
rintro ⟨x, hx⟩
509551
have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
510552
obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
511553
have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
512554
specialize hs hJc
513-
rw [← hsSupJ, hx, nonPrincipals_def] at hs
555+
rw [← hsSupJ, hx] at hs
514556
exact hs ⟨⟨x, rfl⟩⟩
515557

516-
end PrincipalOfPrime
558+
end PrincipalOfPrime_old

Mathlib/RingTheory/PrincipalIdealDomainOfPrime.lean

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,49 @@ Copyright (c) 2018 Chris Hughes. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Anne Baanen
55
-/
6-
import Mathlib.RingTheory.Ideal.Colon
6+
import Mathlib.RingTheory.Ideal.Oka
77
import Mathlib.RingTheory.PrincipalIdealDomain
88

99
/-!
1010
# Principal ideal domains and prime ideals
1111
12-
# Main results
12+
## Main results
1313
14-
- `IsPrincipalIdeal.of_prime`: a ring where all prime ideals are principal is a principal ideal ring
14+
- `IsPrincipalIdealRing.of_prime`: a ring where all prime ideals are principal is a principal ideal
15+
ring.
1516
-/
1617

17-
open Ideal
18+
variable {R : Type*} [CommSemiring R]
19+
20+
namespace Ideal
21+
22+
/-- `Submodule.IsPrincipal` is an Oka predicate. -/
23+
theorem isOka_isPrincipal : IsOka (Submodule.IsPrincipal (R := R)) where
24+
top := top_isPrincipal
25+
oka {I a} := by
26+
intro ⟨x, hx⟩ ⟨y, hy⟩
27+
refine ⟨x * y, le_antisymm ?_ ?_⟩ <;> rw [submodule_span_eq] at *
28+
· intro i hi
29+
have hisup : i ∈ I ⊔ span {a} := mem_sup_left hi
30+
have hasup : a ∈ I ⊔ span {a} := mem_sup_right (mem_span_singleton_self a)
31+
rw [hx, mem_span_singleton'] at hisup hasup
32+
obtain ⟨u, rfl⟩ := hisup
33+
obtain ⟨v, rfl⟩ := hasup
34+
obtain ⟨z, rfl⟩ : ∃ z, z * y = u := by
35+
rw [← mem_span_singleton', ← hy, mem_colon_singleton, mul_comm v, ← mul_assoc]
36+
exact mul_mem_right _ _ hi
37+
exact mem_span_singleton'.2 ⟨z, by rw [mul_assoc, mul_comm y]⟩
38+
· rw [← span_singleton_mul_span_singleton, ← hx, Ideal.sup_mul, sup_le_iff,
39+
span_singleton_mul_span_singleton, mul_comm a, span_singleton_le_iff_mem]
40+
exact ⟨mul_le_right, mem_colon_singleton.1 <| hy ▸ mem_span_singleton_self y⟩
1841

19-
variable {R : Type*} [CommRing R]
42+
end Ideal
43+
44+
open Ideal
2045

2146
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
2247
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
2348
IsPrincipalIdealRing R := by
24-
-- Suppose the set of `nonPrincipals` is not empty.
25-
rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_notMem]
26-
intro J hJ
27-
-- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
28-
obtain ⟨I, hJI, hI⟩ := zorn_le_nonempty₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
29-
have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
30-
intro K hK
31-
simpa [nonPrincipals] using hI.not_prop_of_gt hK
32-
by_cases hI1 : I = ⊤
33-
· subst hI1
34-
exact hI.prop top_isPrincipal
35-
-- Let `x y : R` with `x * y ∈ I` and suppose WLOG `y ∉ I`.
36-
refine hI.prop (H I ⟨hI1, fun {x y} hxy => or_iff_not_imp_right.mpr fun hy => ?_⟩)
37-
obtain ⟨a, ha⟩ : (I ⊔ span {y}).IsPrincipal :=
38-
Imax' (left_lt_sup.mpr (mt I.span_singleton_le_iff_mem.mp hy))
39-
-- Then `x ∈ I.colon (span {y})`, which is equal to `I` if it's not principal.
40-
suffices He : ¬(I.colon (span {y})).IsPrincipal by
41-
rw [hI.eq_of_le ((nonPrincipals_def R).2 He) fun a ha ↦
42-
Ideal.mem_colon_singleton.2 (mul_mem_right _ _ ha)]
43-
exact Ideal.mem_colon_singleton.2 hxy
44-
-- So suppose for the sake of contradiction that both `I ⊔ span {y}` and `I.colon (span {y})`
45-
-- are principal.
46-
rintro ⟨b, hb⟩
47-
-- We will show `I` is generated by `a * b`.
48-
refine (nonPrincipals_def _).1 hI.prop ⟨a * b, ?_⟩
49-
refine
50-
le_antisymm (α := Ideal R) (fun i hi => ?_) <|
51-
(span_singleton_mul_span_singleton a b).ge.trans ?_
52-
· have hisup : i ∈ I ⊔ span {y} := Ideal.mem_sup_left hi
53-
have : y ∈ I ⊔ span {y} := Ideal.mem_sup_right (Ideal.mem_span_singleton_self y)
54-
rw [ha, Ideal.submodule_span_eq, mem_span_singleton'] at hisup this
55-
obtain ⟨v, rfl⟩ := this
56-
obtain ⟨u, rfl⟩ := hisup
57-
have hucolon : u ∈ I.colon (span {v * a}) := by
58-
rw [Ideal.mem_colon_singleton, mul_comm v, ← mul_assoc]
59-
exact mul_mem_right _ _ hi
60-
rw [hb, Ideal.submodule_span_eq, mem_span_singleton'] at hucolon
61-
obtain ⟨z, rfl⟩ := hucolon
62-
exact mem_span_singleton'.2 ⟨z, by ring⟩
63-
· rw [← Ideal.submodule_span_eq, ← ha, Ideal.sup_mul, sup_le_iff,
64-
span_singleton_mul_span_singleton, mul_comm y, Ideal.span_singleton_le_iff_mem]
65-
exact ⟨mul_le_right, Ideal.mem_colon_singleton.1 <| hb.symm ▸ Ideal.mem_span_singleton_self b⟩
49+
refine ⟨isOka_isPrincipal.forall_of_forall_prime (fun I hI ↦ exists_maximal_not_isPrincipal ?_) H⟩
50+
rw [isPrincipalIdealRing_iff, not_forall]
51+
exact ⟨I, hI⟩

0 commit comments

Comments
 (0)