1-- Lattice homomorphisms2-- 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.LatticeHom8import Monotone910predicate IsLatticeHom (f A r B s : Set) :=11 IsLattice(A, r) ∧ IsLattice(B, s) ∧ FunctionBetween(f, A, B) ∧12 (∀ x ∈ A, ∀ y ∈ A, f(join(A, r, x, y)) = join(B, s, f(x), f(y))) ∧13 (∀ x ∈ A, ∀ y ∈ A, f(meet(A, r, x, y)) = meet(B, s, f(x), f(y)))1415theorem IsLatticeHom.source (f A r B s : Set)16requires h : IsLatticeHom(f, A, r, B, s)17shows IsLattice(A, r)18proof19simp [IsLatticeHom]2021theorem IsLatticeHom.target (f A r B s : Set)22requires h : IsLatticeHom(f, A, r, B, s)23shows IsLattice(B, s)24proof25simp [IsLatticeHom]2627theorem IsLatticeHom.function (f A r B s : Set)28requires h : IsLatticeHom(f, A, r, B, s)29shows f : A → B30proof31simp [IsLatticeHom]3233theorem IsLatticeHom.join (f A r B s x y : Set)34requires h : IsLatticeHom(f, A, r, B, s)35requires hx : x ∈ A36requires hy : y ∈ A37shows f(join(A, r, x, y)) = join(B, s, f(x), f(y))38proof39rcases h with⟨source, target, function, joins, meets⟩40exact joins with x, hx, y, hy4142theorem IsLatticeHom.meet (f A r B s x y : Set)43requires h : IsLatticeHom(f, A, r, B, s)44requires hx : x ∈ A45requires hy : y ∈ A46shows f(meet(A, r, x, y)) = meet(B, s, f(x), f(y))47proof48rcases h with⟨source, target, function, joins, meets⟩49exact meets with x, hx, y, hy5051theorem IsLatticeHom.apply_member (f A r B s x : Set)52requires h : IsLatticeHom(f, A, r, B, s)53requires hx : x ∈ A54shows f(x) ∈ B55proof56exact FunctionBetween.apply_closed with (IsLatticeHom.function with h), hx5758theorem IsLatticeHom.monotone (f A r B s : Set)59requires h : IsLatticeHom(f, A, r, B, s)60shows IsMonotoneMap(f, A, r, B, s)61proof62have source := IsLatticeHom.source with h63have target := IsLatticeHom.target with h64constructor65 . exact IsLatticeHom.function with h66 . intros x hx y hy hxy67have fxB := IsLatticeHom.apply_member with h, hx68have fyB := IsLatticeHom.apply_member with h, hy69have joined := join.of_le with source, hx, hy, hxy70have preserved := IsLatticeHom.join with h, hx, hy71rw joined at preserved72 symm at preserved73exact join.eq_right_iff.backward with target, fxB, fyB, preserved7475theorem IsLatticeHom.identity (A r : Set)76requires lattice : IsLattice(A, r)77shows IsLatticeHom(identity(A), A, r, A, r)78proof79refine⟨lattice, lattice, identity.function at A, ?_, ?_⟩80 . intros x hx y hy81have valueX := identity.apply with hx82have valueY := identity.apply with hy83have valueJoin := identity.apply with (join.member with lattice, hx, hy)84rw [valueX, valueY, valueJoin]85rfl86 . intros x hx y hy87have valueX := identity.apply with hx88have valueY := identity.apply with hy89have valueMeet := identity.apply with (meet.member with lattice, hx, hy)90rw [valueX, valueY, valueMeet]91rfl9293theorem IsLatticeHom.compose (f g A r B s C t : Set)94requires hf : IsLatticeHom(f, A, r, B, s)95requires hg : IsLatticeHom(g, B, s, C, t)96shows IsLatticeHom(compose(g, f, A, B, C), A, r, C, t)97proof98have source := IsLatticeHom.source with hf99have middle := IsLatticeHom.target with hf100have target := IsLatticeHom.target with hg101have fFunction := IsLatticeHom.function with hf102have gFunction := IsLatticeHom.function with hg103refine⟨source, target, (compose.function with fFunction, gFunction), ?_, ?_⟩104 . intros x hx y hy105have joinA := join.member with source, hx, hy106have fxB := IsLatticeHom.apply_member with hf, hx107have fyB := IsLatticeHom.apply_member with hf, hy108have valueX := compose.apply with fFunction, gFunction, hx109have valueY := compose.apply with fFunction, gFunction, hy110have valueJoin := compose.apply with fFunction, gFunction, joinA111have innerJoin := IsLatticeHom.join with hf, hx, hy112have outerJoin := IsLatticeHom.join with hg, fxB, fyB113rw [valueX, valueY, valueJoin, innerJoin]114exact outerJoin115 . intros x hx y hy116have meetA := meet.member with source, hx, hy117have fxB := IsLatticeHom.apply_member with hf, hx118have fyB := IsLatticeHom.apply_member with hf, hy119have valueX := compose.apply with fFunction, gFunction, hx120have valueY := compose.apply with fFunction, gFunction, hy121have valueMeet := compose.apply with fFunction, gFunction, meetA122have innerMeet := IsLatticeHom.meet with hf, hx, hy123have outerMeet := IsLatticeHom.meet with hg, fxB, fyB124rw [valueX, valueY, valueMeet, innerMeet]125exact outerMeet126127-- An order isomorphism between lattices preserves joins and meets.128129theorem OrderIsomorphism.join (f A r B s x y : Set)130requires h : OrderIsomorphism(f, A, r, B, s)131requires source : IsLattice(A, r)132requires target : IsLattice(B, s)133requires hx : x ∈ A134requires hy : y ∈ A135shows f(join(A, r, x, y)) = join(B, s, f(x), f(y))136proof137have embedding := OrderIsomorphism.embedding with h138have monotone := OrderEmbedding.monotone with embedding139have surjective := Bijective.surjective with140 (OrderIsomorphism.bijective with h)141have joinA := join.member with source, hx, hy142have fxB := IsMonotoneMap.apply_member with monotone, hx143have fyB := IsMonotoneMap.apply_member with monotone, hy144have fJ := IsMonotoneMap.apply_member with monotone, joinA145have xJ := IsMonotoneMap.preserves with monotone, hx, joinA,146 (join.upper_left with source, hx, hy)147have yJ := IsMonotoneMap.preserves with monotone, hy, joinA,148 (join.upper_right with source, hx, hy)149have supremum : Supremum(B, s, {f(x), f(y)}, f(join(A, r, x, y)))150apply Supremum.of_pair with fxB, fyB, fJ, xJ, yJ151intros b hb xb yb152rcases surjective with⟨function, onto⟩153obtain⟨a, ha, mapped⟩:= onto with b, hb154have value := FunctionBetween.apply_value with function, ha, mapped155rw← value at xb156rw← value at yb157rw← value158have xa := OrderEmbedding.reflects with embedding, hx, ha, xb159have ya := OrderEmbedding.reflects with embedding, hy, ha, yb160have below := join.least with source, hx, hy, ha, xa, ya161exact IsMonotoneMap.preserves with monotone, joinA, ha, below162exact join.of_supremum with target, fxB, fyB, supremum163164theorem OrderIsomorphism.meet (f A r B s x y : Set)165requires h : OrderIsomorphism(f, A, r, B, s)166requires source : IsLattice(A, r)167requires target : IsLattice(B, s)168requires hx : x ∈ A169requires hy : y ∈ A170shows f(meet(A, r, x, y)) = meet(B, s, f(x), f(y))171proof172have embedding := OrderIsomorphism.embedding with h173have monotone := OrderEmbedding.monotone with embedding174have surjective := Bijective.surjective with175 (OrderIsomorphism.bijective with h)176have meetA := meet.member with source, hx, hy177have fxB := IsMonotoneMap.apply_member with monotone, hx178have fyB := IsMonotoneMap.apply_member with monotone, hy179have fM := IsMonotoneMap.apply_member with monotone, meetA180have mX := IsMonotoneMap.preserves with monotone, meetA, hx,181 (meet.lower_left with source, hx, hy)182have mY := IsMonotoneMap.preserves with monotone, meetA, hy,183 (meet.lower_right with source, hx, hy)184have infimum : Infimum(B, s, {f(x), f(y)}, f(meet(A, r, x, y)))185apply Infimum.of_pair with fxB, fyB, fM, mX, mY186intros b hb bx byBound187rcases surjective with⟨function, onto⟩188obtain⟨a, ha, mapped⟩:= onto with b, hb189have value := FunctionBetween.apply_value with function, ha, mapped190rw← value at bx191rw← value at byBound192rw← value193have ax := OrderEmbedding.reflects with embedding, ha, hx, bx194have ay := OrderEmbedding.reflects with embedding, ha, hy, byBound195have above := meet.greatest with source, hx, hy, ha, ax, ay196exact IsMonotoneMap.preserves with monotone, ha, meetA, above197exact meet.of_infimum with target, fxB, fyB, infimum198199theorem OrderIsomorphism.lattice_hom (f A r B s : Set)200requires h : OrderIsomorphism(f, A, r, B, s)201requires source : IsLattice(A, r)202requires target : IsLattice(B, s)203shows IsLatticeHom(f, A, r, B, s)204proof205have function := Injective.function with206 (Bijective.injective with (OrderIsomorphism.bijective with h))207refine⟨source, target, function, ?_, ?_⟩208 . intros x hx y hy209exact OrderIsomorphism.join with h, source, target, hx, hy210 . intros x hx y hy211exact OrderIsomorphism.meet with h, source, target, hx, hy212