Skip to content

Commit

Permalink
Merge branch 'bellmanford' of https://github.com/baydrea/Digraphs int…
Browse files Browse the repository at this point in the history
…o bellmanford
  • Loading branch information
baydrea committed Jan 19, 2022
2 parents a0298d5 + 6eb2b82 commit 246ed12
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 24 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# You can adjust the behavior by modifying this file.
# For more information, see:
# https://github.com/actions/stale
name: Mark stale issues and pull requests

on:
schedule:
- cron: '42 0 * * *'

jobs:
stale:

runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
days-before-close: -1
37 changes: 37 additions & 0 deletions doc/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2430,3 +2430,40 @@ gap> Length(M);
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="NonUpperSemimodularPair">
<ManSection>
<Attr Name="NonUpperSemimodularPair" Arg="D"/>
<Attr Name="NonLowerSemimodularPair" Arg="D"/>
<Returns>A pair of vertices or <K>fail</K>.</Returns>
<Description>
<C>NonUpperSemimodularPair</C> returns a pair of vertices in the digraph
<A>D</A> that witnesses the fact that <A>D</A> does not represent an upper
semimodular lattice, if such a pair exists. <P/>

If the digraph <A>D</A> does not satisfy <Ref
Prop="IsLatticeDigraph"/>, then an error is given. Otherwise if the
digraph <A>D</A> does satisfy <Ref
Prop="IsLatticeDigraph"/>, then either a non-upper semimodular pair of
vertices is returned, or <K>fail</K> is returned if no such pair exists
(meaning that <A>D</A> is an upper semimodular lattice. <P/>

<C>NonLowerSemimodularPair</C> behaves in the analogous way to
<C>NonUpperSemimodularPair</C> with respect to lower semimodularity. <P/>

See <Ref Prop="IsUpperSemimodularDigraph"/> and <Ref
Prop="IsLowerSemimodularDigraph"/> for the definition of upper
semimodularity of a lattice.

<Example><![CDATA[
gap> D := DigraphFromDigraph6String(
> "&M~~sc`lYUZO__KIBboC_@h?U_?_GL?A_?c");
<immutable digraph with 14 vertices, 66 edges>
gap> NonLowerSemimodularPair(D);
[ 10, 9 ]
gap> NonUpperSemimodularPair(D);
fail
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
63 changes: 41 additions & 22 deletions doc/digraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,33 +421,52 @@ gap> D := DigraphByInNeighbours(IsMutableDigraph,

<#GAPDoc Label="AsDigraph">
<ManSection>
<Oper Name="AsDigraph" Arg="[filt, ]f[, n]"
Label="for a transformation or perm"/>
<Oper Name="AsDigraph" Arg="[filt, ]f[, n]" Label="for a binary relation"/>
<Returns>A digraph, or <K>fail</K>.</Returns>
<Description>
If <A>f</A> is a transformation or permutation,
and <A>n</A> is a non-negative integer
such that the restriction of <A>f</A> to <C>[1..<A>n</A>]</C> defines
a function of <C>[1..<A>n</A>]</C>, then <C>AsDigraph</C>
returns the functional digraph with <A>n</A> vertices defined by
<A>f</A>. See <Ref Prop="IsFunctionalDigraph"/>.
<P/>

Specifically, the digraph returned by <C>AsDigraph</C> has <A>n</A> edges:
for each vertex <C>v</C> in <C>[1..<A>n</A>]</C>, there is a unique edge
with source <C>v</C>; this edge has range <C>v^<A>f</A></C>.
<P/>

If the optional second argument <A>n</A> is not supplied, then
the degree of the transformation <A>f</A>,
or the largest moved point of the permutation <A>f</A>,
as applicable, is used by default. If the restriction of
<A>f</A> to <C>[1..<A>n</A>]</C> does not define a function of
<C>[1..<A>n</A>]</C>, then <C>AsDigraph(<A>f</A>, <A>n</A>)</C>
returns <K>fail</K>.
If <A>f</A> is a binary relation represented as one of the following in
&GAP;:
<List>
<Mark>
a transformation
</Mark>
<Item>
satisfying <Ref Filt="IsTransformation" BookName="ref"/>;
</Item>
<Mark>
a permutation
</Mark>
<Item>
satisfying <Ref Filt="IsPerm" BookName="ref"/>;
</Item>
<Mark>
a partial perm
</Mark>
<Item>
satisfying <Ref Filt="IsPartialPerm" BookName="ref"/>;
</Item>
<Mark>
a binary relation
</Mark>
<Item>
satisfying <Ref Filt="IsBinaryRelation" BookName="ref"/>;
</Item>
</List>
and <A>n</A> is a non-negative integer, then <C>AsDigraph</C> attempts
to construct a digraph with <A>n</A> vertices whose edges are determined
by <A>f</A>.<P/>

The digraph returned by <C>AsDigraph</C> has for each vertex
<C>v</C> in <C>[1 .. <A>n</A>]</C>, an edge with source <C>v</C> and range
<C>v ^ <A>f</A></C>. If <C>v ^ <A>f</A></C> is greater than <A>n</A> for any
<C>v</C>, then <K>fail</K> is returned.
<P/>

See also <Ref Attr="AsTransformation"/>.
If the optional second argument <A>n</A> is not supplied, then the degree
of the transformation <A>f</A>, the largest moved point of the permutation
<A>f</A>, the maximum of the degree and the codegree of the partial perm
<A>f</A>, or as applicable, is used by default.
<P/>

&STANDARD_FILT_TEXT;
Expand Down
36 changes: 36 additions & 0 deletions doc/prop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1459,3 +1459,39 @@ true
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IsUpperSemimodularDigraph">
<ManSection>
<Prop Name="IsUpperSemimodularDigraph" Arg="D"/>
<Prop Name="IsLowerSemimodularDigraph" Arg="D"/>
<Returns><K>true</K> or <K>false</K>.</Returns>
<Description>
<C>IsUpperSemimodularDigraph</C> returns <K>true</K> if the digraph
<A>D</A> represents an upper semimodular lattice and <K>false</K> if it
does not. Similarly, <C>IsLowerSemimodularDigraph</C> returns <K>true</K>
if <A>D</A> represents a lower semimodular lattice and <K>false</K> if
it does not. <P/>

In a lattice we say that a vertex <C>a</C> <E>covers</E> a vertex <C>b</C>
if <C>a</C> is greater than <C>b</C>, and there are no further vertices
between <C>a</C> and <C>b</C>. A lattice is <E>upper semimodular</E> if
whenever the meet of <C>a</C> and <C>b</C> is covered by <C>a</C>, the join
of <C>a</C> and <C>b</C> covers <C>b</C>. <E>Lower semimodularity</E> is
defined analogously. <P/>

See also <Ref Prop="IsLatticeDigraph"/>, <Ref Oper="NonUpperSemimodularPair"/>,
and <Ref Oper="NonLowerSemimodularPair"/>.

&MUTABLE_RECOMPUTED_PROP;

<Example><![CDATA[
gap> D := DigraphFromDigraph6String(
> "&M~~sc`lYUZO__KIBboC_@h?U_?_GL?A_?c");
<immutable digraph with 14 vertices, 66 edges>
gap> IsUpperSemimodularDigraph(D);
true
gap> IsLowerSemimodularDigraph(D);
false]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
6 changes: 5 additions & 1 deletion doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@
<#Include Label="InDegreeOfVertex">
<#Include Label="InNeighboursOfVertex">
<#Include Label="DigraphLoops">
<#Include Label="PartialOrderDigraphMeetOfVertices">
<#Include Label="DegreeMatrix">
<#Include Label="LaplacianMatrix">
</Section>

<Section><Heading>Orders</Heading>
<#Include Label="PartialOrderDigraphMeetOfVertices">
<#Include Label="NonUpperSemimodularPair">
</Section>

<Section><Heading>Reachability and connectivity</Heading>
<#Include Label="DigraphDiameter">
Expand Down
4 changes: 4 additions & 0 deletions doc/z-chap5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
<#Include Label="IsSymmetricDigraph">
<#Include Label="IsTournament">
<#Include Label="IsTransitiveDigraph">
</Section>

<Section><Heading>Orders</Heading>
<#Include Label="IsPreorderDigraph">
<#Include Label="IsPartialOrderDigraph">
<#Include Label="IsMeetSemilatticeDigraph">
<#Include Label="IsUpperSemimodularDigraph">
</Section>

<Section><Heading>Regularity</Heading>
Expand Down
6 changes: 6 additions & 0 deletions gap/attr.gd
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ DeclareAttribute("DigraphMaximumMatching", IsDigraph);

DeclareAttribute("Bridges", IsDigraph);
DeclareAttributeThatReturnsDigraph("StrongOrientation", IsDigraph);

DeclareAttribute("NonUpperSemimodularPair", IsDigraph);
DeclareAttribute("NonLowerSemimodularPair", IsDigraph);

DeclareProperty("IsUpperSemimodularDigraph", IsDigraph);
DeclareProperty("IsLowerSemimodularDigraph", IsDigraph);
70 changes: 70 additions & 0 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2655,3 +2655,73 @@ function(D)
M := List(DigraphLoops(D), x -> [x, x]);
return Union(M, DIGRAPHS_MateToMatching(D, mateD));
end);

# The following function is a transliteration from python to GAP of
# the function find_nonsemimodular_pair
# in sage/src/sage/combinat/posets/hasse_diagram.py

BindGlobal("DIGRAPHS_NonSemimodularPair",
function(nbs)
local n, covers, covers_len, a, covers_a, b, e, a_i, b_i;
n := Length(nbs);

for e in [1 .. n] do
covers := nbs[e];
covers_len := Length(covers);
if covers_len < 2 then
continue;
fi;
for a_i in [1 .. covers_len] do
a := covers[a_i];
covers_a := nbs[a];
for b_i in [1 .. a_i] do
b := covers[b_i];
if not ForAny(nbs[b], j -> j in covers_a) then
return [a, b];
fi;
od;
od;
od;

return fail;
end);

InstallMethod(NonUpperSemimodularPair, "for a digraph",
[IsDigraphByOutNeighboursRep],
function(D)
if not IsLatticeDigraph(D) then
ErrorNoReturn("the argument (a digraph) is not a lattice");
fi;
D := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D));
return DIGRAPHS_NonSemimodularPair(OutNeighbours(D));
end);

InstallMethod(NonLowerSemimodularPair, "for a digraph",
[IsDigraphByOutNeighboursRep],
function(D)
if not IsLatticeDigraph(D) then
ErrorNoReturn("the argument (a digraph) is not a lattice");
fi;
D := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D));
return DIGRAPHS_NonSemimodularPair(InNeighbours(D));
end);

InstallMethod(IsUpperSemimodularDigraph, "for a digraph",
[IsDigraphByOutNeighboursRep],
function(D)
if not IsLatticeDigraph(D) then
return false;
fi;
D := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D));
return DIGRAPHS_NonSemimodularPair(OutNeighbours(D)) = fail;
end);

InstallMethod(IsLowerSemimodularDigraph, "for a digraph",
[IsDigraphByOutNeighboursRep],
function(D)
if not IsLatticeDigraph(D) then
return false;
fi;
D := DigraphReflexiveTransitiveReduction(DigraphMutableCopyIfMutable(D));
return DIGRAPHS_NonSemimodularPair(InNeighbours(D)) = fail;
end);
6 changes: 6 additions & 0 deletions gap/digraph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,24 @@ DeclareSynonym("DigraphByInNeighbors", DigraphByInNeighbours);
DeclareConstructor("AsDigraphCons", [IsDigraph, IsBinaryRelation]);
DeclareConstructor("AsDigraphCons", [IsDigraph, IsTransformation]);
DeclareConstructor("AsDigraphCons", [IsDigraph, IsTransformation, IsInt]);
DeclareConstructor("AsDigraphCons", [IsDigraph, IsPartialPerm]);
DeclareConstructor("AsDigraphCons", [IsDigraph, IsPartialPerm, IsInt]);

DeclareOperation("AsDigraph", [IsFunction, IsBinaryRelation]);
DeclareOperation("AsDigraph", [IsFunction, IsTransformation]);
DeclareOperation("AsDigraph", [IsFunction, IsTransformation, IsInt]);
DeclareOperation("AsDigraph", [IsFunction, IsPerm]);
DeclareOperation("AsDigraph", [IsFunction, IsPerm, IsInt]);
DeclareOperation("AsDigraph", [IsFunction, IsPartialPerm]);
DeclareOperation("AsDigraph", [IsFunction, IsPartialPerm, IsInt]);

DeclareOperation("AsDigraph", [IsBinaryRelation]);
DeclareOperation("AsDigraph", [IsTransformation]);
DeclareOperation("AsDigraph", [IsTransformation, IsInt]);
DeclareOperation("AsDigraph", [IsPerm]);
DeclareOperation("AsDigraph", [IsPerm, IsInt]);
DeclareOperation("AsDigraph", [IsPartialPerm]);
DeclareOperation("AsDigraph", [IsPartialPerm, IsInt]);

DeclareOperation("AsBinaryRelation", [IsDigraph]);
DeclareOperation("AsSemigroup", [IsFunction, IsDigraph]);
Expand Down
52 changes: 52 additions & 0 deletions gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,58 @@ InstallMethod(AsDigraph, "for a function and a perm",
InstallMethod(AsDigraph, "for a perm", [IsPerm],
p -> AsDigraph(AsTransformation(p)));

InstallMethod(AsDigraphCons,
"for IsMutableDigraph, a partial perm, and an integer",
[IsMutableDigraph, IsPartialPerm, IsInt],
function(filt, f, n)
local list, x, i;
if n < 0 then
ErrorNoReturn("the 2nd argument <n> should be a non-negative integer,");
fi;

list := EmptyPlist(n);
for i in [1 .. n] do
x := i ^ f;
if x > n then
return fail;
elif x <> 0 then
list[i] := [x];
else
list[i] := [];
fi;
od;
return DigraphNC(IsMutableDigraph, list);
end);

InstallMethod(AsDigraphCons,
"for IsImmutableDigraph, a partial perm, and an integer",
[IsImmutableDigraph, IsPartialPerm, IsInt],
function(filt, f, n)
local D;
D := AsDigraph(IsMutableDigraph, f, n);
if D <> fail then
D := MakeImmutable(D);
SetIsMultiDigraph(D, false);
fi;
return D;
end);

InstallMethod(AsDigraph, "for a function, a partial perm, and an integer",
[IsFunction, IsPartialPerm, IsInt], AsDigraphCons);

InstallMethod(AsDigraph, "for a partial perm and an integer",
[IsPartialPerm, IsInt],
{t, n} -> AsDigraphCons(IsImmutableDigraph, t, n));

InstallMethod(AsDigraph, "for a function and a partial perm",
[IsFunction, IsPartialPerm],
{func, t} -> AsDigraphCons(func, t, Maximum(DegreeOfPartialPerm(t),
CodegreeOfPartialPerm(t))));

InstallMethod(AsDigraph, "for a partial perm", [IsPartialPerm],
t -> AsDigraphCons(IsImmutableDigraph, t, Maximum(DegreeOfPartialPerm(t),
CodegreeOfPartialPerm(t))));

InstallMethod(AsBinaryRelation, "for a digraph", [IsDigraphByOutNeighboursRep],
function(D)
local rel;
Expand Down
Loading

0 comments on commit 246ed12

Please sign in to comment.