1-- Sublattices and the restricted order2-- 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.Sublattice8import LatticeHom9import Set.WellOrder1011predicate IsSublattice (A r B : Set) :=12 IsLattice(A, r) ∧ (B ⊆ A) ∧13 (∀ x ∈ B, ∀ y ∈ B, join(A, r, x, y) ∈ B ∧ meet(A, r, x, y) ∈ B)1415theorem IsSublattice.lattice (A r B : Set)16requires h : IsSublattice(A, r, B)17shows IsLattice(A, r)18proof19simp [IsSublattice]2021theorem IsSublattice.subset (A r B : Set)22requires h : IsSublattice(A, r, B)23shows B ⊆ A24proof25simp [IsSublattice]2627theorem IsSublattice.join_closed (A r B x y : Set)28requires h : IsSublattice(A, r, B)29requires hx : x ∈ B30requires hy : y ∈ B31shows join(A, r, x, y) ∈ B32proof33rcases h with⟨lattice, bounded, closed⟩34have both := closed with x, hx, y, hy35exact both.left3637theorem IsSublattice.meet_closed (A r B x y : Set)38requires h : IsSublattice(A, r, B)39requires hx : x ∈ B40requires hy : y ∈ B41shows meet(A, r, x, y) ∈ B42proof43rcases h with⟨lattice, bounded, closed⟩44have both := closed with x, hx, y, hy45exact both.right4647theorem IsSublattice.whole (A r : Set)48requires lattice : IsLattice(A, r)49shows IsSublattice(A, r, A)50proof51refine⟨lattice, Subset.reflexive at A, ?_⟩52intros x hx y hy53refine⟨(join.member with lattice, hx, hy), (meet.member with lattice, hx,54 hy)⟩5556theorem IsSublattice.intersection (A r B C : Set)57requires hB : IsSublattice(A, r, B)58requires hC : IsSublattice(A, r, C)59shows IsSublattice(A, r, B ∩ C)60proof61have lattice := IsSublattice.lattice with hB62have bounded := Subset.transitive with (intersection.subset_left at B, C),63 (IsSublattice.subset with hB)64refine⟨lattice, bounded, ?_⟩65intros x hx y hy66have xBoth := intersection.membership.forward with hx67have yBoth := intersection.membership.forward with hy68constructor69 . apply intersection.membership.backward70constructor71 . exact IsSublattice.join_closed with hB, xBoth.left, yBoth.left72 . exact IsSublattice.join_closed with hC, xBoth.right, yBoth.right73 . apply intersection.membership.backward74constructor75 . exact IsSublattice.meet_closed with hB, xBoth.left, yBoth.left76 . exact IsSublattice.meet_closed with hC, xBoth.right, yBoth.right7778-- The restriction of a partial order to a subset7980theorem restrictOrder.partial (A r B : Set)81requires order : IsPartialOrder(A, r)82requires hB : B ⊆ A83shows IsPartialOrder(B, restrictOrder(r, B))84proof85have reflexive := IsPartialOrder.reflexive with order86have transitive := IsPartialOrder.transitive with order87have antisymmetric := IsPartialOrder.antisymmetric with order88constructor89 . constructor90 . exact restrictOrder.relation at r, B91 . constructor92 . intros x hx93apply restrictOrder.relates.backward94refine⟨(reflexive with x, (hB with x, hx)), hx, hx⟩95 . intros x hx y hy z hz xy yz96have first := restrictOrder.relates.forward with xy97have second := restrictOrder.relates.forward with yz98apply restrictOrder.relates.backward99refine⟨(transitive with x, (hB with x, hx), y, (hB with y, hy), z,100 (hB with z, hz), first.left, second.left), hx, hz⟩101 . intros x hx y hy xy yx102have first := restrictOrder.relates.forward with xy103have second := restrictOrder.relates.forward with yx104exact antisymmetric with x, (hB with x, hx), y, (hB with y, hy),105 first.left, second.left106107theorem IsSublattice.supremum (A r B x y : Set)108requires h : IsSublattice(A, r, B)109requires hx : x ∈ B110requires hy : y ∈ B111shows Supremum(B, restrictOrder(r, B), {x, y}, join(A, r, x, y))112proof113have lattice := IsSublattice.lattice with h114have bounded := IsSublattice.subset with h115have xA := bounded with x, hx116have yA := bounded with y, hy117have joinB := IsSublattice.join_closed with h, hx, hy118haveleft : relates(restrictOrder(r, B), x, join(A, r, x, y))119apply restrictOrder.relates.backward120refine⟨(join.upper_left with lattice, xA, yA), hx, joinB⟩121haveright : relates(restrictOrder(r, B), y, join(A, r, x, y))122apply restrictOrder.relates.backward123refine⟨(join.upper_right with lattice, xA, yA), hy, joinB⟩124apply Supremum.of_pair with hx, hy, joinB, left, right125intros b hb xb yb126have xbR := restrictOrder.relates.forward with xb127have ybR := restrictOrder.relates.forward with yb128apply restrictOrder.relates.backward129refine⟨(join.least with lattice, xA, yA, (bounded with b, hb), xbR.left,130 ybR.left), joinB, hb⟩131132theorem IsSublattice.infimum (A r B x y : Set)133requires h : IsSublattice(A, r, B)134requires hx : x ∈ B135requires hy : y ∈ B136shows Infimum(B, restrictOrder(r, B), {x, y}, meet(A, r, x, y))137proof138have lattice := IsSublattice.lattice with h139have bounded := IsSublattice.subset with h140have xA := bounded with x, hx141have yA := bounded with y, hy142have meetB := IsSublattice.meet_closed with h, hx, hy143haveleft : relates(restrictOrder(r, B), meet(A, r, x, y), x)144apply restrictOrder.relates.backward145refine⟨(meet.lower_left with lattice, xA, yA), meetB, hx⟩146haveright : relates(restrictOrder(r, B), meet(A, r, x, y), y)147apply restrictOrder.relates.backward148refine⟨(meet.lower_right with lattice, xA, yA), meetB, hy⟩149apply Infimum.of_pair with hx, hy, meetB, left, right150intros b hb bx byBound151have bxR := restrictOrder.relates.forward with bx152have byR := restrictOrder.relates.forward with byBound153apply restrictOrder.relates.backward154refine⟨(meet.greatest with lattice, xA, yA, (bounded with b, hb), bxR.left,155 byR.left), hb, meetB⟩156157theorem IsSublattice.restricted (A r B : Set)158requires h : IsSublattice(A, r, B)159shows IsLattice(B, restrictOrder(r, B))160proof161have lattice := IsSublattice.lattice with h162have order := restrictOrder.partial with (IsLattice.order with lattice),163 (IsSublattice.subset with h)164apply IsLattice.of_pairs with order165 . intros x hx y hy166refine⟨join(A, r, x, y), (IsSublattice.supremum with h, hx, hy)⟩167 . intros x hx y hy168refine⟨meet(A, r, x, y), (IsSublattice.infimum with h, hx, hy)⟩169170theorem IsSublattice.join (A r B x y : Set)171requires h : IsSublattice(A, r, B)172requires hx : x ∈ B173requires hy : y ∈ B174shows join(B, restrictOrder(r, B), x, y) = join(A, r, x, y)175proof176have restricted := IsSublattice.restricted with h177 symm178exact join.of_supremum with restricted, hx, hy, (IsSublattice.supremum with h,179 hx, hy)180181theorem IsSublattice.meet (A r B x y : Set)182requires h : IsSublattice(A, r, B)183requires hx : x ∈ B184requires hy : y ∈ B185shows meet(B, restrictOrder(r, B), x, y) = meet(A, r, x, y)186proof187have restricted := IsSublattice.restricted with h188 symm189exact meet.of_infimum with restricted, hx, hy, (IsSublattice.infimum with h,190 hx, hy)191192-- The image of a lattice homomorphism is a sublattice of its target.193194theorem IsLatticeHom.image_sublattice (f A r B s : Set)195requires h : IsLatticeHom(f, A, r, B, s)196shows IsSublattice(B, s, functionImage(f, A, B))197proof198have source := IsLatticeHom.source with h199have target := IsLatticeHom.target with h200refine⟨target, (functionImage.subset at f, A, B), ?_⟩201intros u hu v hv202obtain⟨uB, x, hx, rfl⟩:= functionImage.membership.forward with hu203obtain⟨vB, y, hy, rfl⟩:= functionImage.membership.forward with hv204have joinA := join.member with source, hx, hy205have meetA := meet.member with source, hx, hy206have joinValue := IsLatticeHom.join with h, hx, hy207have meetValue := IsLatticeHom.meet with h, hx, hy208constructor209 . rw← joinValue210exact functionImage.membership.backward with211⟨(IsLatticeHom.apply_member with h, joinA), join(A, r, x, y), joinA, rfl⟩212 . rw← meetValue213exact functionImage.membership.backward with214⟨(IsLatticeHom.apply_member with h, meetA), meet(A, r, x, y), meetA, rfl⟩215