Skip to content

Commit ff2ff7c

Browse files
authored
Implemented ^ operator for digraphs to delegate to OnDigraphs (issue #580) (#876)
* Implemented ^ operator for digraphs to delegate to OnDigraphs (issue #580) * Added ^ declaration for digraph actions with permutations and transformations * Fixed formating for lint check * Added Tests for digraph operator '^' * Fixed lint formatting for oper.tst file * Made minor changes to formatting * Made minor changes to formatting * Fixed tests formatting * Fixed tests formatting * Defined local varibales * Added documentation * Updated documentation formating for lint * Added label and updated it in the manual * Added a note in documentation for \^ * Made changes based on comments on the PR to the doc and tests
1 parent e453d99 commit ff2ff7c

5 files changed

Lines changed: 82 additions & 0 deletions

File tree

doc/oper.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ true
248248
with <C>OnDigraphs(<A>digraph</A>, AsPermutation(<A>trans</A>))</C>.
249249
<P/>
250250

251+
Note: <C>OnDigraphs</C> for a digraph and a permutation or transformation can also be used via the <C>\^</C> operator. <P/>
252+
251253
The <Ref Oper="DigraphVertexLabels"/> of <A>digraph</A> will not be retained
252254
in the returned digraph. <P/>
253255

@@ -278,6 +280,48 @@ true
278280
</ManSection>
279281
<#/GAPDoc>
280282

283+
<#GAPDoc Label="\^OperatorOnDigraphs">
284+
<ManSection>
285+
<Oper Name="\^" Arg="digraph, permOrTrans" Label="for a digraph and a permutation or transformation"/>
286+
<Returns>A digraph.</Returns>
287+
<Description>
288+
The <C>^</C> operator acts on digraphs with either a permutation or a transformation.
289+
For a digraph <A>digraph</A> and a permutation <A>perm</A>,
290+
<C>digraph ^ perm</C> gives the same result as
291+
<C>OnDigraphs(digraph, perm)</C> — a digraph whose vertices have been relabelled according to the permutation. <P/>
292+
293+
Similarly, if the second argument is a transformation <A>trans</A>,
294+
then <C>digraph ^ trans</C> calls <C>OnDigraphs(digraph, trans)</C>.
295+
This allows a simple way to apply vertex relabelling or transformations directly using the <C>^</C> symbol. <P/>
296+
297+
<Example><![CDATA[
298+
gap> D := CycleDigraph(5);
299+
<immutable cycle digraph with 5 vertices>
300+
gap> p := (1, 5)(2, 4);;
301+
gap> D ^ p = DigraphReverse(D);
302+
true
303+
gap> OnDigraphs(D, p) = D ^ p;
304+
true
305+
gap> idp := ();;
306+
gap> D ^ idp = D;
307+
true
308+
gap> q := (1, 2, 3, 4, 5);;
309+
gap> (D ^ q) ^ (q ^ -1) = D;
310+
true
311+
gap> t := Transformation([2, 3, 4, 5, 1]);;
312+
gap> D ^ t = OnDigraphs(D, t);
313+
true
314+
gap> idt := Transformation([1, 2, 3, 4, 5]);;
315+
gap> D ^ idt = D;
316+
true
317+
gap> M := DigraphMutableCopy(D);;
318+
gap> M ^ p = OnDigraphs(M, p);
319+
true
320+
]]></Example>
321+
</Description>
322+
</ManSection>
323+
<#/GAPDoc>
324+
281325
<#GAPDoc Label="OnMultiDigraphs">
282326
<ManSection>
283327
<Oper Name="OnMultiDigraphs" Arg="digraph, pair"/>

doc/z-chap6.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are
1010

1111
<Section><Heading>Acting on digraphs</Heading>
1212
<#Include Label="OnDigraphs">
13+
<#Include Label="\^OperatorOnDigraphs">
1314
<#Include Label="OnMultiDigraphs">
1415
<#Include Label="OnTuplesDigraphs">
1516
</Section>

gap/oper.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ DeclareOperation("DIGRAPHS_GraphProduct", [IsDigraph, IsDigraph, IsFunction]);
6262
DeclareOperation("SwapDigraphs", [IsMutableDigraph, IsMutableDigraph]);
6363

6464
# 4. Actions . . .
65+
DeclareOperation("^", [IsDigraph, IsPerm]);
66+
DeclareOperation("^", [IsDigraph, IsTransformation]);
6567
DeclareOperation("OnDigraphs", [IsDigraph, IsPerm]);
6668
DeclareOperation("OnDigraphs", [IsDigraph, IsTransformation]);
6769
DeclareOperation("OnDigraphsNC", [IsDigraph, IsPerm]);

gap/oper.gi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,16 @@ InstallMethod(DomainForAction, "for a digraph, list or collection and function",
11381138
[IsDigraph, IsListOrCollection, IsFunction],
11391139
ReturnTrue);
11401140

1141+
# Operator action: D^p and D^t
1142+
# Allow D ^ p (digraph and permutation) to call OnDigraphs(D, p)
1143+
# and D ^ t (digraph and transformation) to call OnDigraphs(D, t)
1144+
1145+
InstallMethod(\^, "digraph acted on by a permutation",
1146+
[IsDigraph, IsPerm], OnDigraphs);
1147+
1148+
InstallMethod(\^, "digraph acted on by a transformation",
1149+
[IsDigraph, IsTransformation], OnDigraphs);
1150+
11411151
#############################################################################
11421152
# 5. Substructures and quotients
11431153
#############################################################################

tst/standard/oper.tst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#@local i1, i2, id, idom, in1, in2, in3, iter, j1, j2, m, m1, m2, mat, n, nbs
1717
#@local out, out1, out2, out3, p1, p2, path, preorder, qr, r, res, rtclosure, t
1818
#@local tclosure, u1, u2, x
19+
#@local p, q, idp, idt, M
1920
gap> START_TEST("Digraphs package: standard/oper.tst");
2021
gap> LoadPackage("digraphs", false);;
2122

@@ -109,6 +110,30 @@ gap> gr := DigraphRemoveEdge(gr, [2, 1]);
109110
gap> DigraphEdges(gr);
110111
[ [ 1, 2 ] ]
111112

113+
# Tests for digraph operator "^" (implements D ^ p and D ^ t using OnDigraphs)
114+
gap> D := CycleDigraph(5);
115+
<immutable cycle digraph with 5 vertices>
116+
gap> p := (1, 5)(2, 4);;
117+
gap> D ^ p = DigraphReverse(D);
118+
true
119+
gap> OnDigraphs(D, p) = D ^ p;
120+
true
121+
gap> idp := ();;
122+
gap> D ^ idp = D;
123+
true
124+
gap> q := (1, 2, 3, 4, 5);;
125+
gap> (D ^ q) ^ (q ^ -1) = D;
126+
true
127+
gap> t := Transformation([2, 3, 4, 5, 1]);;
128+
gap> D ^ t = OnDigraphs(D, t);
129+
true
130+
gap> idt := Transformation([1, 2, 3, 4, 5]);;
131+
gap> D ^ idt = D;
132+
true
133+
gap> M := DigraphMutableCopy(D);;
134+
gap> M ^ p = OnDigraphs(M, p);
135+
true
136+
112137
# OnDigraphs: for a digraph and a perm
113138
gap> gr := Digraph([[2], [1], [3]]);
114139
<immutable digraph with 3 vertices, 3 edges>

0 commit comments

Comments
 (0)