Skip to content
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

Add TadpoleDigraph #423

Merged
merged 17 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions doc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,40 @@ gap> D := BananaTree(3, 4);
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="TadpoleDigraph">
<ManSection>
<Oper Name="TadpoleDigraph" Arg="[filt, ]m, n"/>
<Returns>A digraph.</Returns>
<Description>
The <E>Tadpole digraph</E> is the symmetric closure of the disjoint union
of the cycle digraph on <C>[1..<A>m</A>]</C> (the 'head' of the tadpole)
and the chain digraph on <C>[<A>m</A>+1..<A>m</A>+<A>n</A>]</C>
(the 'tail' of the tadpole), along with the additional
edges <C>[1, <A>m</A>+1]</C> and <C>[1, <A>m</A>+1]</C>
which connect the 'head' and the 'tail'. For more details on the Tadpole digraph
please refer to <URL>https://en.wikipedia.org/wiki/Tadpole_graph</URL>.<P/>

See <Ref Oper="DigraphSymmetricClosure"/>, <Ref Oper="DigraphDisjointUnion"/>,
<Ref Oper="CycleDigraph"/>, and <Ref Oper="ChainDigraph"/>. <P/>

If the optional first argument <A>filt</A> is present, then this should
specify the category or representation the digraph being created will
belong to. For example, if <A>filt</A> is <Ref Filt="IsMutableDigraph"/>,
then the digraph being created will be mutable, if <A>filt</A> is <Ref
Filt="IsImmutableDigraph"/>, then the digraph will be immutable.
If the optional first argument <A>filt</A> is not present, then <Ref
Filt="IsImmutableDigraph"/> is used by default.<P/>

<Example><![CDATA[
gap> TadpoleDigraph(10, 15);
<immutable symmetric digraph with 25 vertices, 50 edges>
gap> TadpoleDigraph(IsMutableDigraph, 5, 6);
<mutable digraph with 11 vertices, 22 edges>
gap> IsSymmetricDigraph(TadpoleDigraph(3, 5));
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

1 change: 1 addition & 0 deletions doc/z-chap2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<#Include Label="KingsGraph">
<#Include Label="KnightsGraph">
<#Include Label="StarDigraph">
<#Include Label="TadpoleDigraph">
</Section>

</Chapter>
4 changes: 4 additions & 0 deletions gap/examples.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ DeclareOperation("HaarGraph", [IsFunction, IsPosInt]);
DeclareConstructor("BananaTreeCons", [IsDigraph, IsPosInt, IsPosInt]);
DeclareOperation("BananaTree", [IsPosInt, IsPosInt]);
DeclareOperation("BananaTree", [IsFunction, IsPosInt, IsPosInt]);

DeclareConstructor("TadpoleDigraphCons", [IsDigraph, IsPosInt, IsPosInt]);
DeclareOperation("TadpoleDigraph", [IsInt, IsPosInt]);
DeclareOperation("TadpoleDigraph", [IsFunction, IsPosInt, IsPosInt]);
37 changes: 35 additions & 2 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,43 @@ function(filt, m, n)
return D;
end);

InstallMethod(BananaTree, "for a function and two pos ints",
InstallMethod(BananaTree, "for a function and two positive integers",
[IsPosInt, IsPosInt],
{m, n} -> BananaTreeCons(IsImmutableDigraph, m, n));

InstallMethod(BananaTree, "for a function and two pos ints",
InstallMethod(BananaTree, "for a function and two positive integers",
[IsFunction, IsPosInt, IsPosInt],
{filt, m, n} -> BananaTreeCons(filt, m, n));

InstallMethod(TadpoleDigraphCons,
"for IsMutableDigraph and two positive integers",
[IsMutableDigraph, IsPosInt, IsPosInt],
function(filt, m, n)
local tail, graph;
if m < 3 then
ErrorNoReturn("the first argument <m> must be an integer greater than 2");
fi;
graph := DigraphSymmetricClosure(CycleDigraph(IsMutableDigraph, m));
tail := DigraphSymmetricClosure(ChainDigraph(IsMutable, n));
DigraphDisjointUnion(graph, tail);
DigraphAddEdges(graph, [[m, n + m], [n + m, m]]);
return graph;
end);

InstallMethod(TadpoleDigraph, "for a function and two positive integers",
[IsFunction, IsPosInt, IsPosInt],
TadpoleDigraphCons);

InstallMethod(TadpoleDigraph, "for two positive integers", [IsPosInt, IsPosInt],
{m, n} -> TadpoleDigraphCons(IsImmutableDigraph, m, n));

InstallMethod(TadpoleDigraphCons,
"for IsImmutableDigraph and two positive integers",
[IsImmutableDigraph, IsPosInt, IsPosInt],
function(filt, m, n)
local D;
D := MakeImmutable(TadpoleDigraph(IsMutableDigraph, m, n));
SetIsMultiDigraph(D, false);
SetIsSymmetricDigraph(D, true);
return D;
end);
12 changes: 12 additions & 0 deletions tst/standard/examples.tst
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ gap> D := BananaTree(IsMutableDigraph, 5, 3);
gap> BananaTree(3, 1);
Error, The second argument must be an integer greater than one

# TadPoleDigraph
gap> TadpoleDigraph(2, 2);
Error, the first argument <m> must be an integer greater than 2
gap> TadpoleDigraph(10, 15);
<immutable symmetric digraph with 25 vertices, 50 edges>
gap> TadpoleDigraph(IsMutableDigraph, 5, 6);
<mutable digraph with 11 vertices, 22 edges>
gap> IsSymmetricDigraph(TadpoleDigraph(3, 5));
true
gap> TadpoleDigraph(3, 1);
<immutable symmetric digraph with 4 vertices, 8 edges>

#
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: standard/examples.tst", 0);