Skip to content

Commit

Permalink
Add characteristic polynomial for a digraph (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
le27 authored and wilfwilson committed Feb 15, 2019
1 parent 3977137 commit 422154c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
27 changes: 27 additions & 0 deletions doc/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,33 @@ gap> Display(mat);
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="CharacteristicPolynomial">
<ManSection>
<Attr Name="CharacteristicPolynomial" Arg="digraph"/>
<Returns>A polynomial with integer coefficients.</Returns>
<Description>
This function returns the characteristic polynomial of the digraph
<A>digraph</A>. That is it returns the characteristic polynomial
of the adjacency matrix of the digraph <A>digraph</A>
<Example><![CDATA[
gap> gr := Digraph([
> [2, 2, 2], [1, 3, 6, 8, 9, 10], [4, 6, 8],
> [1, 2, 3, 9], [3, 3], [3, 5, 6, 10], [1, 2, 7],
> [1, 2, 3, 10, 5, 6, 10], [1, 3, 4, 5, 8, 10],
> [2, 3, 4, 6, 7, 10]]);
<multidigraph with 10 vertices, 44 edges>
gap> CharacteristicPolynomial(gr);
x_1^10-3*x_1^9-7*x_1^8-x_1^7+14*x_1^6+x_1^5-26*x_1^4+51*x_1^3-10*x_1^2\
+18*x_1-30
gap> gr := CompleteDigraph(5);
<digraph with 5 vertices, 20 edges>
gap> CharacteristicPolynomial(gr);
x_1^5-10*x_1^3-20*x_1^2-15*x_1-4
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="BooleanAdjacencyMatrix">
<ManSection>
<Attr Name="BooleanAdjacencyMatrix" Arg="digraph"/>
Expand Down
5 changes: 3 additions & 2 deletions doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<Section><Heading>Neighbours and degree</Heading>
<#Include Label="AdjacencyMatrix">
<#Include Label="CharacteristicPolynomial">
<#Include Label="BooleanAdjacencyMatrix">
<#Include Label="DigraphAdjacencyFunction">
<#Include Label="RangeSourceDigraph">
Expand Down Expand Up @@ -61,7 +62,7 @@
<#Include Label="DigraphDegeneracyOrdering">
<#Include Label="HamiltonianPath">
</Section>

<Section><Heading>Cayley graphs of groups</Heading>
<#Include Label="GroupOfCayleyDigraph">
<#Include Label="GeneratorsOfCayleyDigraph">
Expand All @@ -70,7 +71,7 @@
<Section><Heading>Associated semigroups</Heading>
<#Include Label="AsSemigroup">
</Section>

<Section><Heading>Planarity</Heading>
<#Include Label="KuratowskiPlanarSubdigraph">
<#Include Label="KuratowskiOuterPlanarSubdigraph">
Expand Down
1 change: 1 addition & 0 deletions gap/attr.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ DeclareAttribute("DigraphTransitiveClosure", IsDigraph);
DeclareGlobalFunction("DigraphTransitiveClosureNC");

DeclareAttribute("ChromaticNumber", IsDigraph);
DeclareAttribute("CharacteristicPolynomial", IsDigraph);

DeclareAttribute("DigraphAdjacencyFunction", IsDigraph);

Expand Down
7 changes: 7 additions & 0 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,10 @@ function(D)
SetIsAntisymmetricDigraph(out, true);
return out;
end);

InstallMethod(CharacteristicPolynomial,
"for a digraph",
[IsDigraph],
function(gr)
return CharacteristicPolynomial(AdjacencyMatrix(gr));
end);
15 changes: 15 additions & 0 deletions tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,21 @@ gap> OutNeighbours(last);
gap> MaximalAntiSymmetricSubdigraph(CompleteDigraph(10));
<digraph with 10 vertices, 45 edges>

# CharacteristicPolynomial
gap> gr := Digraph([
> [2, 2, 2], [1, 3, 6, 8, 9, 10], [4, 6, 8],
> [1, 2, 3, 9], [3, 3], [3, 5, 6, 10], [1, 2, 7],
> [1, 2, 3, 10, 5, 6, 10], [1, 3, 4, 5, 8, 10],
> [2, 3, 4, 6, 7, 10]]);
<multidigraph with 10 vertices, 44 edges>
gap> CharacteristicPolynomial(gr);
x_1^10-3*x_1^9-7*x_1^8-x_1^7+14*x_1^6+x_1^5-26*x_1^4+51*x_1^3-10*x_1^2+18*x_1-\
30
gap> gr := CompleteDigraph(5);
<digraph with 5 vertices, 20 edges>
gap> CharacteristicPolynomial(gr);
x_1^5-10*x_1^3-20*x_1^2-15*x_1-4

# DIGRAPHS_UnbindVariables
gap> Unbind(adj);
gap> Unbind(adj1);
Expand Down

0 comments on commit 422154c

Please sign in to comment.