1-- Fixed points of monotone maps on a complete 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.Tarski8import Monotone910def latticePrefixed (f A r : Set) : Set:= { x ∈ A | relates(r, f(x), x) }11def latticePostfixed (f A r : Set) : Set:= { x ∈ A | relates(r, x, f(x)) }12def latticeFixedPoints (f A : Set) : Set:= { x ∈ A | f(x) = x }1314-- The least fixed point is the infimum of the prefixed points, and the15-- greatest fixed point is the supremum of the postfixed points.16def latticeLeastFixed (f A r : Set) : Set:=17 infimum(A, r, latticePrefixed(f, A, r))18def latticeGreatestFixed (f A r : Set) : Set:=19 supremum(A, r, latticePostfixed(f, A, r))2021theorem latticeLeastFixed.value (f A r : Set)22shows latticeLeastFixed(f, A, r) = infimum(A, r, latticePrefixed(f, A, r))23proof24simp [latticeLeastFixed]2526theorem latticeGreatestFixed.value (f A r : Set)27shows28 latticeGreatestFixed(f, A, r) = supremum(A, r, latticePostfixed(f, A, r))29proof30simp [latticeGreatestFixed]3132theorem latticePrefixed.subset (f A r : Set)33shows latticePrefixed(f, A, r) ⊆ A34proof35intros x hx36have member := latticePrefixed.membership.forward with hx37exact member.left3839theorem latticePostfixed.subset (f A r : Set)40shows latticePostfixed(f, A, r) ⊆ A41proof42intros x hx43have member := latticePostfixed.membership.forward with hx44exact member.left4546theorem latticeFixedPoints.subset (f A : Set)47shows latticeFixedPoints(f, A) ⊆ A48proof49intros x hx50have member := latticeFixedPoints.membership.forward with hx51exact member.left5253-- The least fixed point5455theorem latticeLeastFixed.member (f A r : Set)56requires complete : IsCompleteLattice(A, r)57shows latticeLeastFixed(f, A, r) ∈ A58proof59have value := latticeLeastFixed.value at f, A, r60rw value61exact infimum.member with complete, (latticePrefixed.subset at f, A, r)6263theorem latticeLeastFixed.below (f A r x : Set)64requires complete : IsCompleteLattice(A, r)65requires hx : x ∈ A66requires prefixed : relates(r, f(x), x)67shows relates(r, latticeLeastFixed(f, A, r), x)68proof69have value := latticeLeastFixed.value at f, A, r70rw value71have member : x ∈ latticePrefixed(f, A, r) :=72 latticePrefixed.membership.backward with⟨hx, prefixed⟩73exact infimum.below with complete, (latticePrefixed.subset at f, A, r), member7475theorem latticeLeastFixed.prefixed (f A r : Set)76requires complete : IsCompleteLattice(A, r)77requires monotone : IsMonotoneMap(f, A, r, A, r)78shows relates(r, f(latticeLeastFixed(f, A, r)), latticeLeastFixed(f, A, r))79proof80have order := IsCompleteLattice.order with complete81have transitive := IsPartialOrder.transitive with order82have bounded := latticePrefixed.subset at f, A, r83have leastA := latticeLeastFixed.member at f, A, r with complete84have valueA := IsMonotoneMap.apply_member with monotone, leastA85have lower : LowerBound(A, r, latticePrefixed(f, A, r),86 f(latticeLeastFixed(f, A, r)))87refine⟨valueA, bounded, ?_⟩88intros x hx89have member := latticePrefixed.membership.forward with hx90have below := latticeLeastFixed.below with complete, member.left,91 member.right92have mapped := IsMonotoneMap.preserves with monotone, leastA, member.left,93 below94have fxA := IsMonotoneMap.apply_member with monotone, member.left95exact transitive with f(latticeLeastFixed(f, A, r)), valueA, f(x), fxA, x,96 member.left, mapped, member.right97have value := latticeLeastFixed.value at f, A, r98rw value99rw value at lower100rw value at valueA101exact infimum.greatest with complete, bounded, valueA, lower102103theorem latticeLeastFixed.fixed (f A r : Set)104requires complete : IsCompleteLattice(A, r)105requires monotone : IsMonotoneMap(f, A, r, A, r)106shows f(latticeLeastFixed(f, A, r)) = latticeLeastFixed(f, A, r)107proof108have order := IsCompleteLattice.order with complete109have antisymmetric := IsPartialOrder.antisymmetric with order110have leastA := latticeLeastFixed.member at f, A, r with complete111have valueA := IsMonotoneMap.apply_member with monotone, leastA112have prefixed := latticeLeastFixed.prefixed with complete, monotone113have mapped := IsMonotoneMap.preserves with monotone, valueA, leastA, prefixed114have above := latticeLeastFixed.below with complete, valueA, mapped115exact antisymmetric with f(latticeLeastFixed(f, A, r)), valueA,116 latticeLeastFixed(f, A, r), leastA, prefixed, above117118theorem latticeLeastFixed.least (f A r x : Set)119requires complete : IsCompleteLattice(A, r)120requires hx : x ∈ A121requires fixed : f(x) = x122shows relates(r, latticeLeastFixed(f, A, r), x)123proof124have reflexive := IsPartialOrder.reflexive with125 (IsCompleteLattice.order with complete)126have prefixed : relates(r, f(x), x)127rw fixed128exact reflexive with x, hx129exact latticeLeastFixed.below with complete, hx, prefixed130131theorem latticeLeastFixed.least_fixed (f A r : Set)132requires complete : IsCompleteLattice(A, r)133requires monotone : IsMonotoneMap(f, A, r, A, r)134shows Least(A, r, latticeFixedPoints(f, A), latticeLeastFixed(f, A, r))135proof136have leastA := latticeLeastFixed.member at f, A, r with complete137have fixed := latticeLeastFixed.fixed with complete, monotone138constructor139 . exact latticeFixedPoints.membership.backward with⟨leastA, fixed⟩140 . refine⟨leastA, (latticeFixedPoints.subset at f, A), ?_⟩141intros x hx142have member := latticeFixedPoints.membership.forward with hx143exact latticeLeastFixed.least with complete, member.left, member.right144145-- The greatest fixed point146147theorem latticeGreatestFixed.member (f A r : Set)148requires complete : IsCompleteLattice(A, r)149shows latticeGreatestFixed(f, A, r) ∈ A150proof151have value := latticeGreatestFixed.value at f, A, r152rw value153exact supremum.member with complete, (latticePostfixed.subset at f, A, r)154155theorem latticeGreatestFixed.above (f A r x : Set)156requires complete : IsCompleteLattice(A, r)157requires hx : x ∈ A158requires postfixed : relates(r, x, f(x))159shows relates(r, x, latticeGreatestFixed(f, A, r))160proof161have value := latticeGreatestFixed.value at f, A, r162rw value163have member : x ∈ latticePostfixed(f, A, r) :=164 latticePostfixed.membership.backward with⟨hx, postfixed⟩165exact supremum.above with complete, (latticePostfixed.subset at f, A, r),166 member167168theorem latticeGreatestFixed.postfixed (f A r : Set)169requires complete : IsCompleteLattice(A, r)170requires monotone : IsMonotoneMap(f, A, r, A, r)171shows172 relates(r, latticeGreatestFixed(f, A, r), f(latticeGreatestFixed(f, A, r)))173proof174have order := IsCompleteLattice.order with complete175have transitive := IsPartialOrder.transitive with order176have bounded := latticePostfixed.subset at f, A, r177have greatestA := latticeGreatestFixed.member at f, A, r with complete178have valueA := IsMonotoneMap.apply_member with monotone, greatestA179have upper : UpperBound(A, r, latticePostfixed(f, A, r),180 f(latticeGreatestFixed(f, A, r)))181refine⟨valueA, bounded, ?_⟩182intros x hx183have member := latticePostfixed.membership.forward with hx184have above := latticeGreatestFixed.above with complete, member.left,185 member.right186have mapped := IsMonotoneMap.preserves with monotone, member.left,187 greatestA, above188have fxA := IsMonotoneMap.apply_member with monotone, member.left189exact transitive with x, member.left, f(x), fxA, f(latticeGreatestFixed(f,190 A, r)), valueA, member.right, mapped191have value := latticeGreatestFixed.value at f, A, r192rw value193rw value at upper194rw value at valueA195exact supremum.least with complete, bounded, valueA, upper196197theorem latticeGreatestFixed.fixed (f A r : Set)198requires complete : IsCompleteLattice(A, r)199requires monotone : IsMonotoneMap(f, A, r, A, r)200shows f(latticeGreatestFixed(f, A, r)) = latticeGreatestFixed(f, A, r)201proof202have order := IsCompleteLattice.order with complete203have antisymmetric := IsPartialOrder.antisymmetric with order204have greatestA := latticeGreatestFixed.member at f, A, r with complete205have valueA := IsMonotoneMap.apply_member with monotone, greatestA206have postfixed := latticeGreatestFixed.postfixed with complete, monotone207have mapped := IsMonotoneMap.preserves with monotone, greatestA, valueA,208 postfixed209have below := latticeGreatestFixed.above with complete, valueA, mapped210exact antisymmetric with f(latticeGreatestFixed(f, A, r)), valueA,211 latticeGreatestFixed(f, A, r), greatestA, below, postfixed212213theorem latticeGreatestFixed.greatest (f A r x : Set)214requires complete : IsCompleteLattice(A, r)215requires hx : x ∈ A216requires fixed : f(x) = x217shows relates(r, x, latticeGreatestFixed(f, A, r))218proof219have reflexive := IsPartialOrder.reflexive with220 (IsCompleteLattice.order with complete)221have postfixed : relates(r, x, f(x))222rw fixed223exact reflexive with x, hx224exact latticeGreatestFixed.above with complete, hx, postfixed225226theorem latticeGreatestFixed.greatest_fixed (f A r : Set)227requires complete : IsCompleteLattice(A, r)228requires monotone : IsMonotoneMap(f, A, r, A, r)229shows Greatest(A, r, latticeFixedPoints(f, A), latticeGreatestFixed(f, A, r))230proof231have greatestA := latticeGreatestFixed.member at f, A, r with complete232have fixed := latticeGreatestFixed.fixed with complete, monotone233constructor234 . exact latticeFixedPoints.membership.backward with⟨greatestA, fixed⟩235 . refine⟨greatestA, (latticeFixedPoints.subset at f, A), ?_⟩236intros x hx237have member := latticeFixedPoints.membership.forward with hx238exact latticeGreatestFixed.greatest with complete, member.left, member.right239240-- Consequences241242theorem IsMonotoneMap.exists_fixed_point (f A r : Set)243requires complete : IsCompleteLattice(A, r)244requires monotone : IsMonotoneMap(f, A, r, A, r)245shows∃ x ∈ A, f(x) = x246proof247refine⟨latticeLeastFixed(f, A, r), (latticeLeastFixed.member at f, A,248 r with complete), (latticeLeastFixed.fixed with complete, monotone)⟩249250theorem latticeFixedPoints.nonempty (f A r : Set)251requires complete : IsCompleteLattice(A, r)252requires monotone : IsMonotoneMap(f, A, r, A, r)253shows Nonempty(latticeFixedPoints(f, A))254proof255have least := latticeLeastFixed.least_fixed with complete, monotone256refine⟨latticeLeastFixed(f, A, r), Least.member with least⟩257258theorem latticeLeastFixed.le_greatest (f A r : Set)259requires complete : IsCompleteLattice(A, r)260requires monotone : IsMonotoneMap(f, A, r, A, r)261shows relates(r, latticeLeastFixed(f, A, r), latticeGreatestFixed(f, A, r))262proof263have greatestA := latticeGreatestFixed.member at f, A, r with complete264have fixed := latticeGreatestFixed.fixed with complete, monotone265exact latticeLeastFixed.least with complete, greatestA, fixed266267theorem latticeFixedPoints.unique_of_eq (f A r : Set)268requires complete : IsCompleteLattice(A, r)269requires monotone : IsMonotoneMap(f, A, r, A, r)270requires same : latticeLeastFixed(f, A, r) = latticeGreatestFixed(f, A, r)271shows∀ x ∈ A, f(x) = x → x = latticeLeastFixed(f, A, r)272proof273have antisymmetric := IsPartialOrder.antisymmetric with274 (IsCompleteLattice.order with complete)275have leastA := latticeLeastFixed.member at f, A, r with complete276intros x hx fixed277have below := latticeLeastFixed.least with complete, hx, fixed278have above := latticeGreatestFixed.greatest with complete, hx, fixed279rw← same at above280exact antisymmetric with x, hx, latticeLeastFixed(f, A, r), leastA, above,281 below282