1-- Ideals, filters, and prime ideals of a lattice2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Lattice.Ideal8import Bounded9import Set.WellOrder1011-- An ideal is a nonempty lower set closed under joins; a filter is a12-- nonempty upper set closed under meets.13predicate IsLatticeIdeal (A r I : Set) :=14 IsLattice(A, r) ∧ (I ⊆ A) ∧ Nonempty(I) ∧15 (∀ x ∈ I, ∀ y ∈ I, join(A, r, x, y) ∈ I) ∧16 (∀ x ∈ I, ∀ y ∈ A, relates(r, y, x) → y ∈ I)1718predicate IsLatticeFilter (A r F : Set) :=19 IsLattice(A, r) ∧ (F ⊆ A) ∧ Nonempty(F) ∧20 (∀ x ∈ F, ∀ y ∈ F, meet(A, r, x, y) ∈ F) ∧21 (∀ x ∈ F, ∀ y ∈ A, relates(r, x, y) → y ∈ F)2223predicate IsLatticePrimeIdeal (A r I : Set) :=24 IsLatticeIdeal(A, r, I) ∧ I ≠ A ∧25 (∀ x ∈ A, ∀ y ∈ A, meet(A, r, x, y) ∈ I → x ∈ I ∨ y ∈ I)2627-- The upper set of a point, dual to the initial segment below it.28def upperSegment (A r a : Set) : Set:= { x ∈ A | relates(r, a, x) }2930theorem upperSegment.subset (A r a : Set)31shows upperSegment(A, r, a) ⊆ A32proof33intros x hx34have member := upperSegment.membership.forward with hx35exact member.left3637-- Projections3839theorem IsLatticeIdeal.lattice (A r I : Set)40requires h : IsLatticeIdeal(A, r, I)41shows IsLattice(A, r)42proof43simp [IsLatticeIdeal]4445theorem IsLatticeIdeal.subset (A r I : Set)46requires h : IsLatticeIdeal(A, r, I)47shows I ⊆ A48proof49simp [IsLatticeIdeal]5051theorem IsLatticeIdeal.nonempty (A r I : Set)52requires h : IsLatticeIdeal(A, r, I)53shows Nonempty(I)54proof55simp [IsLatticeIdeal]5657theorem IsLatticeIdeal.join_closed (A r I x y : Set)58requires h : IsLatticeIdeal(A, r, I)59requires hx : x ∈ I60requires hy : y ∈ I61shows join(A, r, x, y) ∈ I62proof63rcases h with⟨lattice, bounded, nonempty, joins, downward⟩64exact joins with x, hx, y, hy6566theorem IsLatticeIdeal.downward (A r I x y : Set)67requires h : IsLatticeIdeal(A, r, I)68requires hx : x ∈ I69requires hy : y ∈ A70requires hyx : relates(r, y, x)71shows y ∈ I72proof73rcases h with⟨lattice, bounded, nonempty, joins, downward⟩74exact downward with x, hx, y, hy, hyx7576theorem IsLatticeFilter.lattice (A r F : Set)77requires h : IsLatticeFilter(A, r, F)78shows IsLattice(A, r)79proof80simp [IsLatticeFilter]8182theorem IsLatticeFilter.subset (A r F : Set)83requires h : IsLatticeFilter(A, r, F)84shows F ⊆ A85proof86simp [IsLatticeFilter]8788theorem IsLatticeFilter.nonempty (A r F : Set)89requires h : IsLatticeFilter(A, r, F)90shows Nonempty(F)91proof92simp [IsLatticeFilter]9394theorem IsLatticeFilter.meet_closed (A r F x y : Set)95requires h : IsLatticeFilter(A, r, F)96requires hx : x ∈ F97requires hy : y ∈ F98shows meet(A, r, x, y) ∈ F99proof100rcases h with⟨lattice, bounded, nonempty, meets, upward⟩101exact meets with x, hx, y, hy102103theorem IsLatticeFilter.upward (A r F x y : Set)104requires h : IsLatticeFilter(A, r, F)105requires hx : x ∈ F106requires hy : y ∈ A107requires hxy : relates(r, x, y)108shows y ∈ F109proof110rcases h with⟨lattice, bounded, nonempty, meets, upward⟩111exact upward with x, hx, y, hy, hxy112113theorem IsLatticePrimeIdeal.ideal (A r I : Set)114requires h : IsLatticePrimeIdeal(A, r, I)115shows IsLatticeIdeal(A, r, I)116proof117simp [IsLatticePrimeIdeal]118119theorem IsLatticePrimeIdeal.proper (A r I : Set)120requires h : IsLatticePrimeIdeal(A, r, I)121shows I ≠ A122proof123simp [IsLatticePrimeIdeal]124125theorem IsLatticePrimeIdeal.prime (A r I x y : Set)126requires h : IsLatticePrimeIdeal(A, r, I)127requires hx : x ∈ A128requires hy : y ∈ A129requires hxy : meet(A, r, x, y) ∈ I130shows x ∈ I ∨ y ∈ I131proof132rcases h with⟨ideal, proper, prime⟩133exact prime with x, hx, y, hy, hxy134135-- Closure properties136137theorem IsLatticeIdeal.meet_closed (A r I x y : Set)138requires h : IsLatticeIdeal(A, r, I)139requires hx : x ∈ I140requires hy : y ∈ A141shows meet(A, r, x, y) ∈ I142proof143have lattice := IsLatticeIdeal.lattice with h144have xA := IsLatticeIdeal.subset with h, x, hx145have meetA := meet.member with lattice, xA, hy146have below := meet.lower_left with lattice, xA, hy147exact IsLatticeIdeal.downward with h, hx, meetA, below148149theorem IsLatticeFilter.join_closed (A r F x y : Set)150requires h : IsLatticeFilter(A, r, F)151requires hx : x ∈ F152requires hy : y ∈ A153shows join(A, r, x, y) ∈ F154proof155have lattice := IsLatticeFilter.lattice with h156have xA := IsLatticeFilter.subset with h, x, hx157have joinA := join.member with lattice, xA, hy158have above := join.upper_left with lattice, xA, hy159exact IsLatticeFilter.upward with h, hx, joinA, above160161theorem IsLatticeIdeal.join_iff (A r I x y : Set)162requires h : IsLatticeIdeal(A, r, I)163requires hx : x ∈ A164requires hy : y ∈ A165shows join(A, r, x, y) ∈ I ↔ x ∈ I ∧ y ∈ I166proof167have lattice := IsLatticeIdeal.lattice with h168constructor169 . intro joined170constructor171 . exact IsLatticeIdeal.downward with h, joined, hx,172 (join.upper_left with lattice, hx, hy)173 . exact IsLatticeIdeal.downward with h, joined, hy,174 (join.upper_right with lattice, hx, hy)175 . intro both176exact IsLatticeIdeal.join_closed with h, both.left, both.right177178theorem IsLatticeFilter.meet_iff (A r F x y : Set)179requires h : IsLatticeFilter(A, r, F)180requires hx : x ∈ A181requires hy : y ∈ A182shows meet(A, r, x, y) ∈ F ↔ x ∈ F ∧ y ∈ F183proof184have lattice := IsLatticeFilter.lattice with h185constructor186 . intro met187constructor188 . exact IsLatticeFilter.upward with h, met, hx,189 (meet.lower_left with lattice, hx, hy)190 . exact IsLatticeFilter.upward with h, met, hy,191 (meet.lower_right with lattice, hx, hy)192 . intro both193exact IsLatticeFilter.meet_closed with h, both.left, both.right194195theorem IsLatticeIdeal.bottom (A r bot top I : Set)196requires bounded : IsBoundedLattice(A, r, bot, top)197requires h : IsLatticeIdeal(A, r, I)198shows bot ∈ I199proof200obtain⟨x, hx⟩:= IsLatticeIdeal.nonempty with h201have xA := IsLatticeIdeal.subset with h, x, hx202have botA := IsBoundedLattice.bottom_member with bounded203exact IsLatticeIdeal.downward with h, hx, botA,204 (IsBoundedLattice.bottom_le with bounded, xA)205206theorem IsLatticeFilter.top (A r bot top F : Set)207requires bounded : IsBoundedLattice(A, r, bot, top)208requires h : IsLatticeFilter(A, r, F)209shows top ∈ F210proof211obtain⟨x, hx⟩:= IsLatticeFilter.nonempty with h212have xA := IsLatticeFilter.subset with h, x, hx213have topA := IsBoundedLattice.top_member with bounded214exact IsLatticeFilter.upward with h, hx, topA,215 (IsBoundedLattice.le_top with bounded, xA)216217-- Examples: the whole lattice, principal ideals and filters, intersections218219theorem IsLatticeIdeal.whole (A r : Set)220requires lattice : IsLattice(A, r)221requires nonempty : Nonempty(A)222shows IsLatticeIdeal(A, r, A)223proof224refine⟨lattice, Subset.reflexive at A, nonempty, ?_, ?_⟩225 . intros x hx y hy226exact join.member with lattice, hx, hy227 . intros x hx y hy hyx228exact hy229230theorem IsLatticeFilter.whole (A r : Set)231requires lattice : IsLattice(A, r)232requires nonempty : Nonempty(A)233shows IsLatticeFilter(A, r, A)234proof235refine⟨lattice, Subset.reflexive at A, nonempty, ?_, ?_⟩236 . intros x hx y hy237exact meet.member with lattice, hx, hy238 . intros x hx y hy hxy239exact hy240241theorem IsLatticeIdeal.principal (A r a : Set)242requires lattice : IsLattice(A, r)243requires ha : a ∈ A244shows IsLatticeIdeal(A, r, segment(A, r, a))245proof246have reflexive := IsLattice.reflexive with lattice247have transitive := IsLattice.transitive with lattice248haveself : a ∈ segment(A, r, a) :=249 segment.membership.backward with⟨ha, (reflexive with a, ha)⟩250have nonempty : Nonempty(segment(A, r, a)) :=⟨a, self⟩251refine⟨lattice, (segment.subset at A, r, a), nonempty, ?_, ?_⟩252 . intros x hx y hy253have xS := segment.membership.forward with hx254have yS := segment.membership.forward with hy255have joinA := join.member with lattice, xS.left, yS.left256have below := join.least with lattice, xS.left, yS.left, ha, xS.right,257 yS.right258exact segment.membership.backward with⟨joinA, below⟩259 . intros x hx y hy hyx260have xS := segment.membership.forward with hx261have below := transitive with y, hy, x, xS.left, a, ha, hyx, xS.right262exact segment.membership.backward with⟨hy, below⟩263264theorem IsLatticeFilter.principal (A r a : Set)265requires lattice : IsLattice(A, r)266requires ha : a ∈ A267shows IsLatticeFilter(A, r, upperSegment(A, r, a))268proof269have reflexive := IsLattice.reflexive with lattice270have transitive := IsLattice.transitive with lattice271haveself : a ∈ upperSegment(A, r, a) :=272 upperSegment.membership.backward with⟨ha, (reflexive with a, ha)⟩273have nonempty : Nonempty(upperSegment(A, r, a)) :=⟨a, self⟩274refine⟨lattice, (upperSegment.subset at A, r, a), nonempty, ?_, ?_⟩275 . intros x hx y hy276have xS := upperSegment.membership.forward with hx277have yS := upperSegment.membership.forward with hy278have meetA := meet.member with lattice, xS.left, yS.left279have above := meet.greatest with lattice, xS.left, yS.left, ha, xS.right,280 yS.right281exact upperSegment.membership.backward with⟨meetA, above⟩282 . intros x hx y hy hxy283have xS := upperSegment.membership.forward with hx284have above := transitive with a, ha, x, xS.left, y, hy, xS.right, hxy285exact upperSegment.membership.backward with⟨hy, above⟩286287theorem IsLatticeIdeal.intersection (A r I J : Set)288requires hI : IsLatticeIdeal(A, r, I)289requires hJ : IsLatticeIdeal(A, r, J)290shows IsLatticeIdeal(A, r, I ∩ J)291proof292have lattice := IsLatticeIdeal.lattice with hI293have bounded := Subset.transitive with (intersection.subset_left at I, J),294 (IsLatticeIdeal.subset with hI)295have nonempty : Nonempty(I ∩ J)296obtain⟨x, hx⟩:= IsLatticeIdeal.nonempty with hI297obtain⟨y, hy⟩:= IsLatticeIdeal.nonempty with hJ298have xA := IsLatticeIdeal.subset with hI, x, hx299have yA := IsLatticeIdeal.subset with hJ, y, hy300have inI := IsLatticeIdeal.meet_closed with hI, hx, yA301have swap := meet.commutative with lattice, xA, yA302have inJ := IsLatticeIdeal.meet_closed with hJ, hy, xA303rw← swap at inJ304refine⟨meet(A, r, x, y), (intersection.membership.backward with⟨inI,305 inJ⟩)⟩306refine⟨lattice, bounded, nonempty, ?_, ?_⟩307 . intros x hx y hy308have xBoth := intersection.membership.forward with hx309have yBoth := intersection.membership.forward with hy310apply intersection.membership.backward311constructor312 . exact IsLatticeIdeal.join_closed with hI, xBoth.left, yBoth.left313 . exact IsLatticeIdeal.join_closed with hJ, xBoth.right, yBoth.right314 . intros x hx y hy hyx315have xBoth := intersection.membership.forward with hx316apply intersection.membership.backward317constructor318 . exact IsLatticeIdeal.downward with hI, xBoth.left, hy, hyx319 . exact IsLatticeIdeal.downward with hJ, xBoth.right, hy, hyx320321-- Duality: ideals of the converse order are filters.322323theorem IsLatticeIdeal.converse (A r I : Set)324requires h : IsLatticeIdeal(A, r, I)325shows IsLatticeFilter(A, converse(r, A, A), I)326proof327have lattice := IsLatticeIdeal.lattice with h328have bounded := IsLatticeIdeal.subset with h329refine⟨(IsLattice.converse with lattice), bounded,330 (IsLatticeIdeal.nonempty with h), ?_, ?_⟩331 . intros x hx y hy332have swap := meet.converse with lattice, (bounded with x, hx),333 (bounded with y, hy)334rw swap335exact IsLatticeIdeal.join_closed with h, hx, hy336 . intros x hx y hy hxy337have reversed := converse.reflects with hxy338exact IsLatticeIdeal.downward with h, hx, hy, reversed339340theorem IsLatticeFilter.converse (A r F : Set)341requires h : IsLatticeFilter(A, r, F)342shows IsLatticeIdeal(A, converse(r, A, A), F)343proof344have lattice := IsLatticeFilter.lattice with h345have bounded := IsLatticeFilter.subset with h346refine⟨(IsLattice.converse with lattice), bounded,347 (IsLatticeFilter.nonempty with h), ?_, ?_⟩348 . intros x hx y hy349have swap := join.converse with lattice, (bounded with x, hx),350 (bounded with y, hy)351rw swap352exact IsLatticeFilter.meet_closed with h, hx, hy353 . intros x hx y hy hyx354have reversed := converse.reflects with hyx355exact IsLatticeFilter.upward with h, hx, hy, reversed356