1-- Two-sided ideals over separate pieces: the engine under Ideal, with the2-- proper and maximal ideals and the closure results, 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.IdealCore9import Core10import Set.Order1112-- IsIdeal(A, add, zero, neg, mul, I) is the two-sided ideal over separate13-- pieces; the bundled Ideal(R, I) under a ring hypothesis is defined in14-- Ideal and bridged to this form. Ring laws appear as hypotheses of the15-- ring-specific results.16predicate IsIdeal (A add zero neg mul I : Set) :=17 I ⊆ A ∧ zero ∈ I ∧18 (∀ x ∈ I, ∀ y ∈ I, call2(add, x, y) ∈ I) ∧19 (∀ x ∈ I, neg(x) ∈ I) ∧20 (∀ a ∈ A, ∀ x ∈ I, call2(mul, a, x) ∈ I ∧ call2(mul, x, a) ∈ I)21predicate IsProperIdeal (A add zero neg mul one I : Set) :=22 IsIdeal(A, add, zero, neg, mul, I) ∧¬(one ∈ I)23predicate IsMaximalIdeal (A add zero neg mul one M : Set) :=24 IsProperIdeal(A, add, zero, neg, mul, one, M) ∧25 (∀ J, IsProperIdeal(A, add, zero, neg, mul, one, J) → M ⊆ J → J = M)2627notationscoped IsIdeal(R, I) => IsIdeal(R.carrier, R.add, R.zero, R.neg, R.mul, I)2829notationscoped IsProperIdeal(R, I) => IsProperIdeal(R.carrier, R.add, R.zero, R.neg, R.mul, R.one, I)3031notationscoped IsMaximalIdeal(R, M) => IsMaximalIdeal(R.carrier, R.add, R.zero, R.neg, R.mul, R.one, M)323334theorem IsMaximalIdeal.proper (A add zero neg mul one I : Set)35requires h : IsMaximalIdeal(A, add, zero, neg, mul, one, I)36shows IsProperIdeal(A, add, zero, neg, mul, one, I)37proof38exact h.left3940theorem IsMaximalIdeal.ideal (A add zero neg mul one I : Set)41requires h : IsMaximalIdeal(A, add, zero, neg, mul, one, I)42shows IsIdeal(A, add, zero, neg, mul, I)43proof44have proper := IsMaximalIdeal.proper with h45exact proper.left4647theorem IsIdeal.subset_carrier (A add zero neg mul I : Set)48requires ideal : IsIdeal(A, add, zero, neg, mul, I)49shows I ⊆ A50proof51simp [IsIdeal]5253theorem IsIdeal.zero_closed (A add zero neg mul I : Set)54requires ideal : IsIdeal(A, add, zero, neg, mul, I)55shows zero ∈ I56proof57simp [IsIdeal]5859theorem IsIdeal.add_closed (A add zero neg mul I x y : Set)60requires ideal : IsIdeal(A, add, zero, neg, mul, I)61requires hx : x ∈ I62requires hy : y ∈ I63shows call2(add, x, y) ∈ I64proof65exact ideal.right.right.left with x, hx, y, hy6667theorem IsIdeal.neg_closed (A add zero neg mul I x : Set)68requires ideal : IsIdeal(A, add, zero, neg, mul, I)69requires hx : x ∈ I70shows neg(x) ∈ I71proof72exact ideal.right.right.right.left with x, hx7374theorem IsIdeal.mul_left_closed (A add zero neg mul I a x : Set)75requires ideal : IsIdeal(A, add, zero, neg, mul, I)76requires ha : a ∈ A77requires hx : x ∈ I78shows call2(mul, a, x) ∈ I79proof80have products := ideal.right.right.right.right with a, ha, x, hx81exact products.left8283theorem IsIdeal.mul_right_closed (A add zero neg mul I a x : Set)84requires ideal : IsIdeal(A, add, zero, neg, mul, I)85requires ha : a ∈ A86requires hx : x ∈ I87shows call2(mul, x, a) ∈ I88proof89have products := ideal.right.right.right.right with a, ha, x, hx90exact products.right9192theorem IsIdeal.union_chain (A add zero neg mul S : Set)93requires inhabited : Nonempty(S)94requires ideals : ∀ I ∈ S, IsIdeal(A, add, zero, neg, mul, I)95requires nested : ∀ I ∈ S, ∀ J ∈ S, I ⊆ J ∨ J ⊆ I96shows IsIdeal(A, add, zero, neg, mul, ⋃(S))97proof98obtain⟨I0, hI0⟩:= inhabited99obtain⟨subset0, zero0, add0, neg0, mul0⟩:= ideals with I0, hI0100have bounded : ⋃(S) ⊆ A101apply union.subset102intros B hB103obtain⟨subsetI, restI⟩:= ideals with B, hB104exact subsetI105have zeroIn : zero ∈⋃(S) :=set.union.backward with⟨I0, hI0, zero0⟩106constructor107 . exact bounded108 . constructor109 . exact zeroIn110 . constructor111 . intros x hx y hy112obtain⟨I, hI, xI⟩:=set.union.forward with hx113obtain⟨J, hJ, yJ⟩:=set.union.forward with hy114have alternatives := nested with I, hI, J, hJ115cases alternatives with ij | ji116have xJ := ij with x, xI117obtain⟨boundedJ, zeroJ, addJ, negJ, mulJ⟩:= ideals with J, hJ118have sum := addJ with x, xJ, y, yJ119exactset.union.backward with⟨J, hJ, sum⟩120have yI := ji with y, yJ121obtain⟨boundedI, zeroI, addI, negI, mulI⟩:= ideals with I, hI122have sum := addI with x, xI, y, yI123exactset.union.backward with⟨I, hI, sum⟩124 . constructor125 . intros x hx126obtain⟨N, hI, xI⟩:=set.union.forward with hx127obtain⟨boundedI, zeroI, addI, negI, mulI⟩:= ideals with N, hI128have negative := negI with x, xI129exactset.union.backward with⟨N, hI, negative⟩130 . intros a ha x hx131obtain⟨P, hI, xI⟩:=set.union.forward with hx132obtain⟨boundedI, zeroI, addI, negI, mulI⟩:= ideals with P, hI133obtain⟨leftProduct, rightProduct⟩:= mulI with a, ha, x, xI134constructor135 . applyset.union.backward at S, call2(mul, a, x)136refine⟨P, hI, leftProduct⟩137 . applyset.union.backward at S, call2(mul, x, a)138refine⟨P, hI, rightProduct⟩139140theorem IsProperIdeal.union_chain (A add zero neg mul one S : Set)141requires inhabited : Nonempty(S)142requires ideals : ∀ I ∈ S, IsProperIdeal(A, add, zero, neg, mul, one, I)143requires nested : ∀ I ∈ S, ∀ J ∈ S, I ⊆ J ∨ J ⊆ I144shows IsProperIdeal(A, add, zero, neg, mul, one, ⋃(S))145proof146have underlying : ∀ I ∈ S, IsIdeal(A, add, zero, neg, mul, I)147intros B hB148obtain⟨idealI, absent⟩:= ideals with B, hB149exact idealI150have unionIdeal := IsIdeal.union_chain with inhabited, underlying, nested151constructor152 . exact unionIdeal153 . intro oneIn154obtain⟨I, hI, oneI⟩:=set.union.forward with oneIn155obtain⟨idealI, absent⟩:= ideals with I, hI156exact absent with oneI157158theorem IsIdeal.whole_of_one (A add zero neg mul one I : Set)159requiresring : IsRing(A, add, zero, neg, mul, one)160requires ideal : IsIdeal(A, add, zero, neg, mul, I)161requires contains : one ∈ I162shows I = A163proof164rcases ideal with⟨bounded, zeroIn, addClosed, negClosed, absorbs⟩165have monoid := IsRing.multiplicative withring166apply Subset.antisymmetric with bounded167intros x hx168obtain⟨product, unused⟩:= absorbs with x, hx, one, contains169have identity := IsMonoid.right_identity with monoid, hx170 rwa identity at product171172theorem IsIdeal.zero_ideal (A add zero neg mul one : Set)173requiresring : IsRing(A, add, zero, neg, mul, one)174shows IsIdeal(A, add, zero, neg, mul, {zero})175proof176have zeroIn := IsRing.zero_in_carrier withring177have additive := IsRing.additive withring178have group := IsAbelianGroup.group with additive179have negZero := IsGroup.inverse_unit with group180have addZero := IsRing.add_left_identity withring, zeroIn181constructor182intros x hx183have equal := singleton.membership.forward with hx184 rwa equal185 . constructor186 . exact singleton.self at zero187 . constructor188 . intros x hx y hy189have ex := singleton.membership.forward with hx190have ey := singleton.membership.forward with hy191rw [ex, ey, addZero]192exact singleton.self193 . constructor194 . intros x hx195have ex := singleton.membership.forward with hx196rw [ex, negZero]197exact singleton.self198 . intros a ha x hx199have ex := singleton.membership.forward with hx200rw ex201have leftZero := IsRing.mul_zero withring, ha202have rightZero := IsRing.zero_mul withring, ha203constructor204 . rw leftZero205exact singleton.self206 . rw rightZero207exact singleton.self208209theorem IsProperIdeal.zero_ideal (A add zero neg mul one : Set)210requiresring : IsRing(A, add, zero, neg, mul, one)211requires nontrivial : Nontrivial(A, zero, one)212shows IsProperIdeal(A, add, zero, neg, mul, one, {zero})213proof214have ideal := IsIdeal.zero_ideal withring215rcases nontrivial with⟨zeroIn, oneIn, distinct⟩216constructor217 . exact ideal218 . intro member219have equal := singleton.membership.forward with member220apply distinct221 symm222exact equal223224theorem IsProperIdeal.iff_ne_whole (A add zero neg mul one I : Set)225requiresring : IsRing(A, add, zero, neg, mul, one)226requires ideal : IsIdeal(A, add, zero, neg, mul, I)227shows IsProperIdeal(A, add, zero, neg, mul, one, I) ↔ I ≠ A228proof229constructor230 . intros proper equal231rcases proper with⟨underlying, absent⟩232have monoid := IsRing.multiplicative withring233have oneIn := IsMonoid.unit_in_carrier with monoid234rw← equal at oneIn235exact absent with oneIn236 . intro distinct237constructor238 . exact ideal239 . intro oneIn240have equal := IsIdeal.whole_of_one withring, ideal, oneIn241exact distinct with equal242243theorem IsMaximalIdeal.eq_or_whole (A add zero neg mul one M J : Set)244requiresring : IsRing(A, add, zero, neg, mul, one)245requires maximal : IsMaximalIdeal(A, add, zero, neg, mul, one, M)246requires ideal : IsIdeal(A, add, zero, neg, mul, J)247requires contains : M ⊆ J248shows J = M ∨ J = A249proof250have alternatives : one ∈ J ∨¬(one ∈ J) bytauto251cases alternatives with oneIn | absent252 . right253exact IsIdeal.whole_of_one withring, ideal, oneIn254 . left255rcases maximal with⟨properM, largest⟩256have properJ : IsProperIdeal(A, add, zero, neg, mul, one, J)257unfold IsProperIdeal258refine⟨ideal, absent⟩259exact largest with J, properJ, contains260