Skip to content

Commit

Permalink
Add BookDigraph (PR #445)
Browse files Browse the repository at this point in the history
  • Loading branch information
LRacine authored Apr 12, 2021
1 parent 3026304 commit 781960a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
37 changes: 37 additions & 0 deletions doc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,40 @@ true
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="BookDigraph">
<ManSection>
<Oper Name="BookDigraph" Arg="[filt, ]m"/>
<Returns>A digraph.</Returns>
<Description>
The <E>Book digraph</E> is the Cartesian product of a complete digraph with 2 vertices
(as the "Book Spine") and the <M><A>m</A>+1</M> star digraph (as the "Pages").
For more details on the Book digraph please refer to <URL>https://mathworld.wolfram.com/BookGraph.html</URL>.<P/>

See <Ref Func="DigraphCartesianProduct" Label="for a positive number of digraphs"/>,
<Ref Oper="CompleteDigraph"/>, and <Ref Oper="StarDigraph"/>. <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> BookDigraph(1);
<immutable bipartite symmetric digraph with bicomponent sizes 2 and 2>
gap> BookDigraph(2);
<immutable bipartite symmetric digraph with bicomponent sizes 3 and 3>
gap> BookDigraph(IsMutable, 12);
<mutable digraph with 26 vertices, 74 edges>
gap> BookDigraph(7);
<immutable bipartite symmetric digraph with bicomponent sizes 8 and 8>
gap> IsSymmetricDigraph(BookDigraph(24));
true
gap> IsBipartiteDigraph(BookDigraph(24));
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 @@ -97,6 +97,7 @@
<#Include Label="KnightsGraph">
<#Include Label="StarDigraph">
<#Include Label="TadpoleDigraph">
<#Include Label="BookDigraph">
</Section>

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

DeclareConstructor("BookDigraphCons", [IsDigraph, IsPosInt]);
DeclareOperation("BookDigraph", [IsPosInt]);
DeclareOperation("BookDigraph", [IsFunction, IsPosInt]);
28 changes: 28 additions & 0 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,31 @@ function(filt, m, n)
SetIsSymmetricDigraph(D, true);
return D;
end);

InstallMethod(BookDigraphCons,
"for IsMutableDigraph and one positive integer",
[IsMutableDigraph, IsPosInt],
function(filt, m)
local book;
book := CompleteDigraph(IsMutable, 2);
return DigraphCartesianProduct(book, StarDigraph(IsMutable, m + 1));
end);

InstallMethod(BookDigraph, "for a function and one positive integer",
[IsFunction, IsPosInt],
BookDigraphCons);

InstallMethod(BookDigraph, "for one positive integer", [IsPosInt],
{m} -> BookDigraphCons(IsImmutableDigraph, m));

InstallMethod(BookDigraphCons,
"for IsImmutableDigraph and one positive integer",
[IsImmutableDigraph, IsPosInt],
function(filt, m)
local D;
D := MakeImmutable(BookDigraph(IsMutableDigraph, m));
SetIsMultiDigraph(D, false);
SetIsSymmetricDigraph(D, true);
SetIsBipartiteDigraph(D, true);
return D;
end);
16 changes: 16 additions & 0 deletions tst/standard/examples.tst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ true
gap> TadpoleDigraph(3, 1);
<immutable symmetric digraph with 4 vertices, 8 edges>
# BookDigraph
gap> BookDigraph(1);
<immutable bipartite symmetric digraph with bicomponent sizes 2 and 2>
gap> BookDigraph(2);
<immutable bipartite symmetric digraph with bicomponent sizes 3 and 3>
gap> BookDigraph(7);
<immutable bipartite symmetric digraph with bicomponent sizes 8 and 8>
gap> BookDigraph(12);
<immutable bipartite symmetric digraph with bicomponent sizes 13 and 13>
gap> BookDigraph(IsMutable, 12);
<mutable digraph with 26 vertices, 74 edges>
gap> IsSymmetricDigraph(BookDigraph(24));
true
gap> IsBipartiteDigraph(BookDigraph(32));
true
#
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: standard/examples.tst", 0);

0 comments on commit 781960a

Please sign in to comment.