-
Notifications
You must be signed in to change notification settings - Fork 64
Implement IsJoinIrreducible and IsMeetIrreducible #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
46836b9
3bb2bb8
7b7d883
6c07453
8cf99ca
2c37a4b
8ae6cba
d2fd4fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2720,6 +2720,38 @@ function(D, i, j) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InstallMethod(IsJoinIrreducible, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "for a digraph and a positive integer", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [IsDigraph, IsPosInt], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function(D, v) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local hasse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not IsPartialOrderDigraph(D) then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorNoReturn("the 1st argument <D> must satisfy IsPartialOrderDigraph,"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif not v in DigraphVertices(D) then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorNoReturn("the 2nd argument <v> must be a vertex of the ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "1st argument <D>,"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasse := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # join-irreducible iff at most one lower cover in the Hasse diagram | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return InDegrees(hasse)[v] <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2727
to
+2736
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local hasse; | |
| if not IsPartialOrderDigraph(D) then | |
| ErrorNoReturn("the 1st argument <D> must satisfy IsPartialOrderDigraph,"); | |
| elif not v in DigraphVertices(D) then | |
| ErrorNoReturn("the 2nd argument <v> must be a vertex of the ", | |
| "1st argument <D>,"); | |
| fi; | |
| hasse := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D)); | |
| # join-irreducible iff at most one lower cover in the Hasse diagram | |
| return InDegrees(hasse)[v] <= 1; | |
| local verts, i, j, x, y, join; | |
| if not IsPartialOrderDigraph(D) then | |
| ErrorNoReturn("the 1st argument <D> must satisfy IsPartialOrderDigraph,"); | |
| elif not v in DigraphVertices(D) then | |
| ErrorNoReturn("the 2nd argument <v> must be a vertex of the ", | |
| "1st argument <D>,"); | |
| fi; | |
| # An element v is join-irreducible if it is not the join of | |
| # two distinct strictly smaller elements. We check all unordered | |
| # pairs of vertices (x, y) with x <> y and neither equal to v. | |
| verts := DigraphVertices(D); | |
| for i in [1 .. Length(verts) - 1] do | |
| x := verts[i]; | |
| if x = v then | |
| continue; | |
| fi; | |
| for j in [i + 1 .. Length(verts)] do | |
| y := verts[j]; | |
| if y = v then | |
| continue; | |
| fi; | |
| join := PartialOrderDigraphJoinOfVertices(D, x, y); | |
| if join = v then | |
| # v can be expressed as the join of two distinct smaller elements | |
| return false; | |
| fi; | |
| od; | |
| od; | |
| # No such pair found; v is join-irreducible. | |
| return true; |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsJoinIrreducible uses InDegrees(hasse)[v], which computes indegrees for all vertices even though only one value is needed. Using InDegreeOfVertexNC(hasse, v) (mirroring the OutDegreeOfVertexNC usage below) avoids the extra O(|V|+|E|) work per call on large digraphs.
| return InDegrees(hasse)[v] <= 1; | |
| return InDegreeOfVertexNC(hasse, v) <= 1; |
ThatOtherAndrew marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsMeetIrreducible relies on “at most one upper cover in the Hasse diagram”, which (like the join case) is only equivalent to “not a meet of two distinct larger elements” when meets exist appropriately (e.g. meet-semilattices/lattices). For arbitrary partial orders, vertices can have multiple upper covers while no such meet representation exists. Either restrict the accepted digraphs to IsMeetSemilatticeDigraph/IsLatticeDigraph, or compute using the actual meet operation to match the documented semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only explicit precondition checked is
IsPartialOrderDigraph(D), butIsPartialOrderDigraphdoes not exclude multidigraphs. IfDhas multiple edges,DigraphReflexiveTransitiveReductionwill throw a different error (“must be a digraph with no multiple edges”) from inside this method. Consider either rejecting multidigraphs up front with a clear error, or normalizing the copied digraph by removing multiple edges before computing the reduction.