Skip to content

Implement IsBetweenCoverAndLattice#920

Open
ThatOtherAndrew wants to merge 7 commits intodigraphs:mainfrom
ThatOtherAndrew:pr/isbetweencoverandlattice
Open

Implement IsBetweenCoverAndLattice#920
ThatOtherAndrew wants to merge 7 commits intodigraphs:mainfrom
ThatOtherAndrew:pr/isbetweencoverandlattice

Conversation

@ThatOtherAndrew
Copy link
Copy Markdown

Prompted by conversation in #714, I believe this is a functional implementation of the IsBetweenCoverAndLattice function. My implementation is based on the three-step outline given by @Joseph-Edwards and also implements DIGRAPHS_MeetJoinTableBetweenCover (as a slightly modified/generalised version of DIGRAPHS_MeetJoinTable) in order to make this possible. I've thrown in some tests as well (due to my limited understanding of the maths I'm unsure how comprehensive they are though!) and they do appear to pass when building and running locally. (hopefully CI/CD can validate if they still work!)

Copilot AI review requested due to automatic review settings April 22, 2026 14:56
@ThatOtherAndrew
Copy link
Copy Markdown
Author

gaplint should be satisfied now :>

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new predicate to determine whether a digraph lies between the cover relation of some lattice and a lattice digraph (without constructing the reflexive transitive closure), motivated by #714.

Changes:

  • Introduces IsBetweenCoverAndLattice as a declared property and implements its method in gap/prop.gi.
  • Adds DIGRAPHS_MeetJoinTableBetweenCover, a meet/join table builder that avoids relying on transitive edges being present.
  • Adds standard tests covering basic positive/negative cases for IsBetweenCoverAndLattice.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
gap/prop.gi Implements IsBetweenCoverAndLattice and adds the new meet/join table helper used by it.
gap/prop.gd Declares the IsBetweenCoverAndLattice property and installs a trivial-true implication for lattice digraphs.
tst/standard/prop.tst Adds regression tests for IsBetweenCoverAndLattice across several small digraph examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gap/prop.gi
Comment thread gap/prop.gi Outdated
Comment thread gap/prop.gi
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 95.23810% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.37%. Comparing base (1f56fb0) to head (d2c54bc).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
gap/prop.gi 95.08% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (95.23%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #920      +/-   ##
==========================================
+ Coverage   97.35%   97.37%   +0.02%     
==========================================
  Files          50       50              
  Lines       21045    21256     +211     
  Branches      639      639              
==========================================
+ Hits        20489    20699     +210     
- Misses        491      492       +1     
  Partials       65       65              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@reiniscirpons reiniscirpons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the commit! I have suggested some changes. One larger change I would like is for you to modify DIGRAPHS_MeetJoinTable to have the behavior of DIGRAPHS_MeetJoinTableBetweenCover depending on a switch.

One other thing: The function is currently missing documentation. To add this you should modify the doc/prop.xml file and add an entry to this file for the IsBetweenCoverAndLattice function, see the doc for IsMeetSemilatticeDigraph function doc for an example:

Digraphs/doc/prop.xml

Lines 1295 to 1349 in 313228b

<#GAPDoc Label="IsMeetSemilatticeDigraph">
<ManSection>
<Prop Name="IsMeetSemilatticeDigraph" Arg="digraph"/>
<Prop Name="IsJoinSemilatticeDigraph" Arg="digraph"/>
<Prop Name="IsLatticeDigraph" Arg="digraph"/>
<Returns><K>true</K> or <K>false</K>.</Returns>
<Description>
<C>IsMeetSemilatticeDigraph</C> returns <K>true</K> if the digraph
<A>digraph</A> is a meet semilattice; <C>IsJoinSemilatticeDigraph</C>
returns <K>true</K> if the digraph <A>digraph</A> is a join semilattice;
and <C>IsLatticeDigraph</C> returns <K>true</K> if the digraph
<A>digraph</A> is both a meet and a join semilattice.
<P/>
For a partial order digraph <Ref Prop="IsPartialOrderDigraph"/> the
corresponding partial order is the relation <M>\leq</M>, defined by
<M>x \leq y</M> if and only if <C>[x, y]</C> is an edge.
A digraph is a <E>meet semilattice</E> if it is a partial order and every
pair of vertices has a greatest lower bound (meet) with respect to the
aforementioned relation. A <E>join semilattice</E> is a partial order where
every pair of vertices has a least upper bound (join) with respect to
the relation.
<P/>
&MUTABLE_RECOMPUTED_PROP;
<Example><![CDATA[
gap> D := Digraph([[1, 3], [2, 3], [3]]);
<immutable digraph with 3 vertices, 5 edges>
gap> IsMeetSemilatticeDigraph(D);
false
gap> IsJoinSemilatticeDigraph(D);
true
gap> IsLatticeDigraph(D);
false
gap> D := Digraph([[1], [2], [1 .. 3]]);
<immutable digraph with 3 vertices, 5 edges>
gap> IsJoinSemilatticeDigraph(D);
false
gap> IsMeetSemilatticeDigraph(D);
true
gap> IsLatticeDigraph(D);
false
gap> D := Digraph([[1 .. 4], [2, 4], [3, 4], [4]]);
<immutable digraph with 4 vertices, 9 edges>
gap> IsMeetSemilatticeDigraph(D);
true
gap> IsJoinSemilatticeDigraph(D);
true
gap> IsLatticeDigraph(D);
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

You then want to include the function doc in the manual, the doc/z-chap5.xml file in the orders section after IsMeetSemilatticeDigraph is probably the right place for this:

Digraphs/doc/z-chap5.xml

Lines 41 to 51 in 313228b

<Section><Heading>Orders</Heading>
<#Include Label="IsPreorderDigraph">
<#Include Label="IsPartialOrderDigraph">
<#Include Label="IsMeetSemilatticeDigraph">
<#Include Label="DigraphMeetTable">
<#Include Label="IsOrderIdeal">
<#Include Label="IsOrderFilter">
<#Include Label="IsUpperSemimodularDigraph">
<#Include Label="IsDistributiveLatticeDigraph">
<#Include Label="IsModularLatticeDigraph">
</Section>

Otherwise looks good in the first instance!

Comment thread gap/prop.gi
Comment on lines +132 to +137
# the below conditions are the only part that
# differs from MeetJoinTable above
if join and tab[q, z] <> z then
return fail;
elif not join and tab[z, q] <> z then
return fail;
Copy link
Copy Markdown
Collaborator

@reiniscirpons reiniscirpons Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is the only difference, would it be feasible to modify DIGRAPHS_MeetJoinTable to have both functionalities e.g. by adding an extra boolean parameter check_edges, which makes the DIGRAPHS_MeetJoinTable behave the same as before if set to true and otherwise make it behave like DIGRAPHS_MeetJoinTableBetweenCover?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it! Would doing a text search for "DIGRAPHS_MeetJoinTable" be sufficient to ensure that all places affected by the function signature breaking change are covered?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think so! It would also be nice if you could add a comment describing what each of the input parameters D, P, U, join and the new one you add is expected to be, and how using them affects the output. The DIGRAPHS_ prefix functions are for internal use only, so they don't get an official documentation entry, but it might be useful for the next person who touches the code.

Comment thread gap/prop.gi Outdated
Comment thread gap/prop.gi Outdated
Copy link
Copy Markdown
Collaborator

@reiniscirpons reiniscirpons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things I noticed. We should discuss next meeting, but overall looks good.

Comment thread gap/prop.gi
Comment on lines +220 to +226
neighbours := OutNeighbours(hasse);
table := DIGRAPHS_MeetJoinTableBetweenCover(
DigraphNrVertices(copy),
order,
neighbours,
true);
return table <> fail;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the similarity of this line to the previous one, would it might make more sense to have two functions IsBetweenCoverAndMeetSemilattice and IsBetweenCoverAndJoinSemilattice which to this check with the meet and join table respectively and then make IsBetweenCoverAndLattice to simply return true when both IsBetweenCoverAndMeetSemilattice and IsBetweenCoverAndJoinSemilattice are true, like we do for IsLatticeDigraph.

Comment thread gap/prop.gi
if table = fail then
return false;
fi;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if IsImmutableDigraph(D) then
SetDigraphMeetTable(D, tab);
fi;

We can save the result as the meet table here, since we already did all that work to compute it. The same should be done for the join table below.

ThatOtherAndrew and others added 2 commits April 22, 2026 17:25
Co-authored-by: Reinis Cirpons <43414125+reiniscirpons@users.noreply.github.com>
Co-authored-by: Reinis Cirpons <43414125+reiniscirpons@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants