1-- Prime ideals over separate pieces: the engine under PrimeIdeal, with2-- the colon ideals of a commutative ring, all in ZF3-- Part of Cumulus, the Grace17 mathematics library.4-- Copyright (c) 2026 Grant Passmore.5-- Released under the Apache License 2.0. See LICENSE in the repository root.6-- Authors: Grant Passmore78module Grace.Cumulus.Algebra.Ring.PrimeIdealCore9import IdealCore1011-- IsPrimeIdeal(A, add, zero, neg, mul, one, I) is the prime ideal over12-- separate pieces; the bundled PrimeIdeal(R, I) is defined in PrimeIdeal13-- and bridged to this form.14predicate IsPrimeIdeal (A add zero neg mul one I : Set) :=15 IsProperIdeal(A, add, zero, neg, mul, one, I) ∧16 (∀ x ∈ A, ∀ y ∈ A, call2(mul, x, y) ∈ I → x ∈ I ∨ y ∈ I)1718notationscoped IsPrimeIdeal(R, I) => IsPrimeIdeal(R.carrier, R.add, R.zero, R.neg, R.mul, R.one, I)1920-- The colon ideal (I : y), with its ambient carrier explicit.21def colonIdeal (A mul I y : Set) : Set:= {x ∈ A | call2(mul, x, y) ∈ I}2223theorem colonIdeal.contains (A add zero neg mul I y : Set)24requires ideal : IsIdeal(A, add, zero, neg, mul, I)25requires hy : y ∈ A26shows I ⊆ colonIdeal(A, mul, I, y)27proof28rcases ideal with⟨bounded, zeroIn, sums, negatives, products⟩29intros x hx30have xInA := bounded with x, hx31obtain⟨leftProduct, rightProduct⟩:= products with y, hy, x, hx32exact colonIdeal.membership.backward with⟨xInA, rightProduct⟩3334theorem colonIdeal.ideal (A add zero neg mul one I y : Set)35requires commRing : IsCommRing(A, add, zero, neg, mul, one)36requires ideal : IsIdeal(A, add, zero, neg, mul, I)37requires hy : y ∈ A38shows IsIdeal(A, add, zero, neg, mul, colonIdeal(A, mul, I, y))39proof40havering:= IsCommRing.ring with commRing41rcases ideal with⟨boundedI, zeroIn, sums, negatives, products⟩42constructor43 . settlewith Subset, colonIdeal.membership44 . constructor45 . have zeroInA := IsRing.zero_in_carrier withring46have zeroProduct := IsRing.zero_mul at A, add, zero, neg, mul, one,47 y with*48apply colonIdeal.membership.backward49constructor50 . exact zeroInA51 . rw zeroProduct52exact zeroIn53 . constructor54 . intros x hx z hz55have xData := colonIdeal.membership.forward with hx56have zData := colonIdeal.membership.forward with hz57rcases xData with⟨xInA, xyIn⟩58rcases zData with⟨zInA, zyIn⟩59have sumInA := IsRing.add_closed at A, add, zero, neg, mul, one, x, z with*60have sumIn := sums with call2(mul, x, y), xyIn, call2(mul, z, y), zyIn61have distribute := IsCommRing.add_mul at A, add, zero, neg, mul, one, x, z, y with*62apply colonIdeal.membership.backward63constructor64 . exact sumInA65 . rw distribute66exact sumIn67 . constructor68 . intros x hx69obtain⟨xInA, xyIn⟩:= colonIdeal.membership.forward with hx70have negInA := IsRing.neg_closed withring, xInA71have negIn := negatives with call2(mul, x, y), xyIn72have distribute := IsRing.neg_mul at A, add, zero, neg, mul, one, x, y with*73apply colonIdeal.membership.backward74constructor75 . exact negInA76 . rw distribute77exact negIn78 . intros a ha x hx79obtain⟨xInA, xyIn⟩:= colonIdeal.membership.forward with hx80have axInA := IsRing.mul_closed at A, add, zero, neg, mul, one, a, x with*81have xaInA := IsRing.mul_closed at A, add, zero, neg, mul, one, x, a with*82obtain⟨leftProduct, rightProduct⟩:= products with a, ha, call2(mul, x, y), xyIn83have associate := IsCommRing.mul_assoc at A, add, zero, neg, mul, one, a, x, y with*84have commute := IsCommRing.mul_comm at A, add, zero, neg, mul, one, x, a with*85constructor86 . apply colonIdeal.membership.backward at87 A, mul, I, y, call2(mul, a, x)88constructor89 . exact axInA90 . rw associate91exact leftProduct92 . apply colonIdeal.membership.backward at93 A, mul, I, y, call2(mul, x, a)94constructor95 . exact xaInA96 . rw [commute, associate]97exact leftProduct9899theorem colonIdeal.proper (A add zero neg mul one I y : Set)100requires commRing : IsCommRing(A, add, zero, neg, mul, one)101requires ideal : IsIdeal(A, add, zero, neg, mul, I)102requires hy : y ∈ A103requires absent : ¬(y ∈ I)104shows IsProperIdeal(A, add, zero, neg, mul, one, colonIdeal(A, mul, I, y))105proof106have colon := colonIdeal.ideal with*107have identity := IsCommRing.one_left with*108constructor109 . exact colon110 . intro member111obtain⟨oneInA, productIn⟩:= colonIdeal.membership.forward with member112rw identity at productIn113exact absent with productIn114115theorem IsMaximalIdeal.is_prime (A add zero neg mul one M : Set)116requires commRing : IsCommRing(A, add, zero, neg, mul, one)117requires maximal : IsMaximalIdeal(A, add, zero, neg, mul, one, M)118shows IsPrimeIdeal(A, add, zero, neg, mul, one, M)119proof120rcases maximal with⟨proper, largest⟩121have ideal : IsIdeal(A, add, zero, neg, mul, M) bysimp [IsProperIdeal]122constructor123 . exact proper124 . intros x hx y hy productIn125have alternatives : y ∈ M ∨¬(y ∈ M) bytauto126cases alternatives with yIn | yOut127 . right128exact yIn129 . left130have colonProper := colonIdeal.proper with*131have contains := colonIdeal.contains with ideal, hy132have equal := largest with colonIdeal(A, mul, M, y), colonProper, contains133have xInColon : x ∈ colonIdeal(A, mul, M, y) := colonIdeal.membership.backward with⟨hx, productIn⟩134 rwa equal at xInColon135136theorem IsPrimeIdeal.proper (A add zero neg mul one I : Set)137requires prime : IsPrimeIdeal(A, add, zero, neg, mul, one, I)138shows IsProperIdeal(A, add, zero, neg, mul, one, I)139proof140simp [IsPrimeIdeal]141142theorem IsPrimeIdeal.ideal (A add zero neg mul one I : Set)143requires h : IsPrimeIdeal(A, add, zero, neg, mul, one, I)144shows IsIdeal(A, add, zero, neg, mul, I)145proof146have proper := IsPrimeIdeal.proper with h147exact proper.left148149theorem IsPrimeIdeal.left_of_mul (A add zero neg mul one I x y : Set)150requires prime : IsPrimeIdeal(A, add, zero, neg, mul, one, I)151requires hx : x ∈ A152requires hy : y ∈ A153requires productIn : call2(mul, x, y) ∈ I154requires absent : ¬(y ∈ I)155shows x ∈ I156proof157rcases prime with⟨proper, factors⟩158have alternatives := factors with x, hx, y, hy, productIn159cases alternatives with xIn | yIn160 . exact xIn161 . exfalso162exact absent with yIn163164theorem IsPrimeIdeal.colon_eq (A add zero neg mul one I y : Set)165requires prime : IsPrimeIdeal(A, add, zero, neg, mul, one, I)166requires hy : y ∈ A167requires absent : ¬(y ∈ I)168shows colonIdeal(A, mul, I, y) = I169proof170obtain⟨ideal, oneOut⟩:= IsPrimeIdeal.proper with prime171have contains := colonIdeal.contains with*172apply Subset.antisymmetric173intros x hx174obtain⟨xInA, productIn⟩:= colonIdeal.membership.forward with hx175exact IsPrimeIdeal.left_of_mul with*176 . exact contains177178theorem IsIntegralDomain.zero_prime (A add zero neg mul one : Set)179requires domain : IsIntegralDomain(A, add, zero, neg, mul, one)180shows IsPrimeIdeal(A, add, zero, neg, mul, one, {zero})181proof182have commRing := IsIntegralDomain.comm_ring with domain183havering:= IsCommRing.ring with commRing184have nontrivial := IsIntegralDomain.nontrivial with domain185have noZeroDivisors := IsIntegralDomain.no_zero_divisors with domain186have proper := IsProperIdeal.zero_ideal with*187constructor188 . exact proper189 . intros x hx y hy productIn190have zeroProduct := singleton.membership.forward with productIn191have alternatives := noZeroDivisors with x, hx, y, hy, zeroProduct192cases alternatives with xZero | yZero193 . left194exact singleton.membership.backward with xZero195 . right196exact singleton.membership.backward with yZero197198theorem IsPrimeIdeal.zero_iff_domain (A add zero neg mul one : Set)199requires commRing : IsCommRing(A, add, zero, neg, mul, one)200shows IsPrimeIdeal(A, add, zero, neg, mul, one, {zero}) ↔201 IsIntegralDomain(A, add, zero, neg, mul, one)202proof203constructor204 . intro prime205havering:= IsCommRing.ring with commRing206have zeroInA := IsRing.zero_in_carrier withring207have monoid := IsRing.multiplicative withring208have oneInA := IsMonoid.unit_in_carrier with monoid209rcases prime with⟨proper, factors⟩210rcases proper with⟨ideal, oneOut⟩211have distinct : zero ≠ one212intro equal213apply oneOut214apply singleton.membership.backward215 symm216exact equal217have nontrivial : Nontrivial(A, zero, one)218unfold Nontrivial219refine⟨zeroInA, oneInA, distinct⟩220have noZeroDivisors : NoZeroDivisors(A, mul, zero)221intros x hx y hy productZero222have productIn := singleton.membership.backward with productZero223have alternatives := factors with x, hx, y, hy, productIn224cases alternatives with xIn | yIn225 . left226exact singleton.membership.forward with xIn227 . right228exact singleton.membership.forward with yIn229unfold IsIntegralDomain230refine⟨commRing, nontrivial, noZeroDivisors⟩231 . intro domain232exact IsIntegralDomain.zero_prime with domain233