From 0c5ba32c8c25d40975a98ef4ec19896af02c20ab Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 08:05:59 +0000 Subject: [PATCH 01/20] 2edgetrans synonym --- doc/prop.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/prop.xml b/doc/prop.xml index 5c293f4a3..0eea03180 100644 --- a/doc/prop.xml +++ b/doc/prop.xml @@ -1665,11 +1665,14 @@ false]]> <#GAPDoc Label="Is2EdgeTransitive"> + true or false. If digraph is a digraph without multiple edges, then Is2EdgeTransitive returns true if digraph is 2-edge transitive, and false - otherwise. If digraph has multiple edges, then Is2EdgeTransitive returns an error. + otherwise. If digraph has multiple edges, then Is2EdgeTransitive returns an error.

+ + is a synonym for .

A digraph is 2-edge transitive if its automorphism group acts transitively on 2-edges via the action From cde46783fffd30d2f0952e8c634ae12f73c982c0 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 08:45:27 +0000 Subject: [PATCH 02/20] cutverts synonym --- doc/attr.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/attr.xml b/doc/attr.xml index 1dd3bb640..23f846615 100644 --- a/doc/attr.xml +++ b/doc/attr.xml @@ -1117,6 +1117,7 @@ gap> DigraphUndirectedGirth(D); <#GAPDoc Label="ArticulationPoints"> + A list of vertices. A connected digraph is biconnected if it is still connected (in the @@ -1143,6 +1144,9 @@ gap> DigraphUndirectedGirth(D); with articulation points, but no bridges.

+ is a synonym for . +

+ See also and . Date: Sun, 25 Oct 2026 09:11:10 +0000 Subject: [PATCH 03/20] smallestlastorder docs --- doc/grahom.xml | 30 ++++++++++++++++++++++++++++++ doc/z-chap6.xml | 1 + 2 files changed, 31 insertions(+) diff --git a/doc/grahom.xml b/doc/grahom.xml index 2e3d1b213..dadcc01b9 100644 --- a/doc/grahom.xml +++ b/doc/grahom.xml @@ -563,6 +563,36 @@ gap> DigraphWelshPowellOrder(Digraph([[4], [9], [9], [], <#/GAPDoc> +<#GAPDoc Label="DigraphSmallestLastOrder"> + + + A list of vertices. + + DigraphSmallestLastOrder returns a list order containing each + of the vertices of digraph in smallest-last order, defined as + follows:

+ + Let D_n be digraph. For i = n, n-1, \ldots, 1, the + vertex order[i] is a vertex of minimum degree in D_i, and + D_{i-1} is the subdigraph of D_i induced by removing + order[i]. The degree of a vertex here is the sum of the number of + out- and in-neighbours.

+ + The result is not unique in general, since there may be several vertices + of minimum degree at any step; DigraphSmallestLastOrder tiebreaks + by taking the smallest such vertex. + D1 := Digraph([[2], [1, 3], [2]]);; +gap> DigraphSmallestLastOrder(D1); +[ 3, 2, 1 ] +gap> D2 := CompleteDigraph(3);; +gap> DigraphSmallestLastOrder(D2); +[ 3, 2, 1 ] +]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphEmbedding"> diff --git a/doc/z-chap6.xml b/doc/z-chap6.xml index f9798b51c..26f5e23bc 100644 --- a/doc/z-chap6.xml +++ b/doc/z-chap6.xml @@ -73,6 +73,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are <#Include Label="DigraphColouring"> <#Include Label="DigraphGreedyColouring"> <#Include Label="DigraphWelshPowellOrder"> + <#Include Label="DigraphSmallestLastOrder"> <#Include Label="ChromaticNumber"> <#Include Label="DigraphCore"> <#Include Label="LatticeDigraphEmbedding"> From 148eb658a38e7383a7fef1b83e4418d8e3ae685b Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 09:21:51 +0000 Subject: [PATCH 04/20] unitedgeweighted docs --- doc/weights.xml | 21 +++++++++++++++++++++ doc/z-chap5.xml | 1 + 2 files changed, 22 insertions(+) diff --git a/doc/weights.xml b/doc/weights.xml index cc569a088..cf25d2612 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -70,6 +70,27 @@ gap> EdgeWeights(g); <#/GAPDoc> +<#GAPDoc Label="UnitEdgeWeightedDigraph"> + + + A digraph + + UnitEdgeWeightedDigraph returns an edge-weighted copy of + digraph, with all edge weights set to 1.

+ + See . + D := Digraph([[2], [1, 3], [1]]); + +gap> D1 := UnitEdgeWeightedDigraph(D); + +gap> EdgeWeights(D1); +[ [ 1 ], [ 1, 1 ], [ 1 ] ] +]]> + + +<#/GAPDoc> + <#GAPDoc Label="EdgeWeightedDigraphTotalWeight"> diff --git a/doc/z-chap5.xml b/doc/z-chap5.xml index f1da97657..361324fc9 100644 --- a/doc/z-chap5.xml +++ b/doc/z-chap5.xml @@ -28,6 +28,7 @@

Edge Weights <#Include Label="EdgeWeights"> <#Include Label="EdgeWeightedDigraph"> + <#Include Label="UnitEdgeWeightedDigraph"> <#Include Label="EdgeWeightedDigraphTotalWeight"> <#Include Label="EdgeWeightedDigraphMinimumSpanningTree"> <#Include Label="EdgeWeightedDigraphShortestPaths"> From 6712150db57a984293b63234173c84c6471edcef Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 09:35:42 +0000 Subject: [PATCH 05/20] product synonyms --- doc/oper.xml | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/oper.xml b/doc/oper.xml index 9213ec1b4..758489b05 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -2290,6 +2290,7 @@ gap> DigraphDijkstra(D, 1, 2); <#GAPDoc Label="ModularProduct"> + A digraph. If D1 and D2 are digraphs without multiple edges, then @@ -2313,7 +2314,10 @@ gap> DigraphDijkstra(D, 1, 2); Notably, the complete (with loops) subdigraphs of MPD are - precisely the partial isomorphisms from D1 to D2. + precisely the partial isomorphisms from D1 to D2.

+ + is a synonym for + . ModularProduct(Digraph([[1], [1, 2]]), Digraph([[], [2]])); @@ -2333,6 +2337,7 @@ gap> ModularProduct(NullDigraph(0), CompleteDigraph(10)); <#GAPDoc Label="StrongProduct"> + A digraph. If D1 and D2 are digraphs without multiple edges, @@ -2360,7 +2365,10 @@ gap> ModularProduct(NullDigraph(0), CompleteDigraph(10)); The SPD of two paths of lengths m and n is also the king's graph - for an m by n board. + for an m by n board.

+ + is a synonym for + . D1 := Digraph([[2], [1, 3, 4], [2, 5], [2, 5], [3, 4]]); @@ -2380,6 +2388,7 @@ gap> StrongProduct(DigraphSymmetricClosure(ChainDigraph(3)), <#GAPDoc Label="ConormalProduct"> + A digraph. If D1 and D2 are digraphs without multiple edges, @@ -2398,7 +2407,10 @@ gap> StrongProduct(DigraphSymmetricClosure(ChainDigraph(3)), There is an edge from b to d in D2. - +

+ + is a synonym for + . ConormalProduct(DigraphSymmetricClosure(CycleDigraph(7)), @@ -2414,6 +2426,7 @@ gap> ConormalProduct(NullDigraph(0), CompleteDigraph(10)); <#GAPDoc Label="HomomorphicProduct"> + A digraph. If D1 and D2 are digraphs without multiple edges, @@ -2433,7 +2446,10 @@ gap> ConormalProduct(NullDigraph(0), CompleteDigraph(10)); There is an edge from a to c in D1 and no edge from b to d in D2. - +

+ + is a synonym for + . HomomorphicProduct(PetersenGraph(), @@ -2476,6 +2492,7 @@ gap> OutNeighbours(D1); <#GAPDoc Label="LexicographicProduct"> + A digraph. If D1 and D2 are digraphs without multiple edges, @@ -2495,7 +2512,10 @@ gap> OutNeighbours(D1); The vertices a and c of D1 are equal and there is an edge from b to d in D2. - +

+ + is a synonym for + . LexicographicProduct(DigraphSymmetricClosure(CycleDigraph(3)), From 958501fb057e1686d32320f5ac31b8c60f960bae Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 09:36:07 +0000 Subject: [PATCH 06/20] dominatingset synonym --- doc/oper.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/oper.xml b/doc/oper.xml index 758489b05..4231b0614 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -1957,6 +1957,7 @@ rec( idom := [ 2, fail, 2, 2, 2 ], preorder := [ 2, 1, 3, 4, 5 ] ) <#GAPDoc Label="IsDigraphOutDominatingSet"> + true or false. @@ -1973,7 +1974,10 @@ rec( idom := [ 2, fail, 2, 2, 2 ], preorder := [ 2, 1, 3, 4, 5 ] ) either in S or an out-neighbour of a vertex in S. An in-dominating set of digraph is a subset S of vertices of digraph such that every vertex of digraph is - either in S or an in-neighbour of a vertex in S. + either in S or an in-neighbour of a vertex in S.

+ + is a synonym for + . D := Digraph([[2, 4], [3], [1, 5], [3], [4]]);; From 225463dfd58a9cfdfc4f4de4544f69946794da21 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 09:43:54 +0000 Subject: [PATCH 07/20] isnegativeedgeweight docs --- doc/weights.xml | 18 ++++++++++++++++++ doc/z-chap5.xml | 1 + 2 files changed, 19 insertions(+) diff --git a/doc/weights.xml b/doc/weights.xml index cf25d2612..502d8ff9f 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -112,6 +112,24 @@ gap> EdgeWeightedDigraphTotalWeight(D); <#/GAPDoc> +<#GAPDoc Label="IsNegativeEdgeWeightedDigraph"> + + + A boolean. + + This returns true if digraph contains at least one edge + with negative weight, and false otherwise. + D := EdgeWeightedDigraph([[2], [1]], [[5], [10]]);; +gap> IsNegativeEdgeWeightedDigraph(D); +false +gap> D := EdgeWeightedDigraph([[2], [1]], [[-5], [10]]);; +gap> IsNegativeEdgeWeightedDigraph(D); +true]]> + + +<#/GAPDoc> + <#GAPDoc Label="EdgeWeightedDigraphMinimumSpanningTree"> diff --git a/doc/z-chap5.xml b/doc/z-chap5.xml index 361324fc9..bf322b769 100644 --- a/doc/z-chap5.xml +++ b/doc/z-chap5.xml @@ -30,6 +30,7 @@ <#Include Label="EdgeWeightedDigraph"> <#Include Label="UnitEdgeWeightedDigraph"> <#Include Label="EdgeWeightedDigraphTotalWeight"> + <#Include Label="IsNegativeEdgeWeightedDigraph"> <#Include Label="EdgeWeightedDigraphMinimumSpanningTree"> <#Include Label="EdgeWeightedDigraphShortestPaths"> <#Include Label="EdgeWeightedDigraphShortestPath"> From dd7f7101251498b65ff1794c72fc5c43726de354 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:33:16 +0000 Subject: [PATCH 08/20] doc syntax --- doc/oper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/oper.xml b/doc/oper.xml index 4231b0614..c7cf5d218 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -2411,7 +2411,7 @@ gap> StrongProduct(DigraphSymmetricClosure(ChainDigraph(3)), There is an edge from b to d in D2. -

+

is a synonym for . From 8b8e02117baaf08f16c9107032056532a041de07 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Mon, 26 Oct 2026 14:50:49 +0000 Subject: [PATCH 09/20] wrong declaration --- gap/weights.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gap/weights.gd b/gap/weights.gd index 423950b61..77d8823a4 100644 --- a/gap/weights.gd +++ b/gap/weights.gd @@ -14,7 +14,7 @@ DeclareGlobalFunction("EdgeWeightedDigraph"); DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights); DeclareAttribute("EdgeWeightedDigraphTotalWeight", IsDigraph and HasEdgeWeights); -DeclareAttribute("UnitEdgeWeightedDigraph", IsDigraph); +DeclareOperation("UnitEdgeWeightedDigraph", [IsDigraph]); # 2. Edge Weight Copies DeclareOperation("EdgeWeightsMutableCopy", [IsDigraph and HasEdgeWeights]); From b2592a18ee3a9e3ee8c3633b3fd16d2fe48a2eb5 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Mon, 26 Oct 2026 14:50:59 +0000 Subject: [PATCH 10/20] fixes --- doc/weights.xml | 18 ++++++++++++++---- gap/grahom.gd | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/weights.xml b/doc/weights.xml index 502d8ff9f..be0fda438 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -75,10 +75,14 @@ gap> EdgeWeights(g); A digraph - UnitEdgeWeightedDigraph returns an edge-weighted copy of - digraph, with all edge weights set to 1.

+ + If digraph is immutable, UnitEdgeWeightedDigraph returns + an immutable edge-weighted copy of digraph, with all edge weights + set to 1. If digraph is mutable, the returned digraph will be + mutable, but will not have edge weights.

See . + D := Digraph([[2], [1, 3], [1]]); @@ -86,6 +90,11 @@ gap> D1 := UnitEdgeWeightedDigraph(D); gap> EdgeWeights(D1); [ [ 1 ], [ 1, 1 ], [ 1 ] ] +gap> D2 := Digraph(IsMutableDigraph, [[2], [1, 3], [1]]);; +gap> UnitEdgeWeightedDigraph(D2); + +gap> HasEdgeWeights(D2); +false ]]> @@ -117,8 +126,9 @@ gap> EdgeWeightedDigraphTotalWeight(D); A boolean. - This returns true if digraph contains at least one edge - with negative weight, and false otherwise. + If digraph has edge weights, then this returns true if + at least one edge has negative weight, and false otherwise. If + digraph has no edge weights, then an error is raised. D := EdgeWeightedDigraph([[2], [1]], [[5], [10]]);; gap> IsNegativeEdgeWeightedDigraph(D); diff --git a/gap/grahom.gd b/gap/grahom.gd index b18ecce70..8e970feb7 100644 --- a/gap/grahom.gd +++ b/gap/grahom.gd @@ -42,7 +42,7 @@ DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsHomogeneousList]); DeclareOperation("DigraphGreedyColouringNC", [IsDigraph, IsHomogeneousList]); DeclareAttribute("DigraphWelshPowellOrder", IsDigraph); -DeclareAttribute("DigraphSmallestLastOrder", IsDigraph); # TODO: document +DeclareAttribute("DigraphSmallestLastOrder", IsDigraph); DeclareOperation("IsDigraphEndomorphism", [IsDigraph, IsTransformation]); DeclareOperation("IsDigraphHomomorphism", From f15f1b294ce40c598a50df3041fe510ae0927bd0 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:47:38 +0000 Subject: [PATCH 11/20] unitedgeweight check immutable --- gap/weights.gi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gap/weights.gi b/gap/weights.gi index dc1081fcf..70bbd61eb 100644 --- a/gap/weights.gi +++ b/gap/weights.gi @@ -80,7 +80,7 @@ InstallMethod(EdgeWeightedDigraphTotalWeight, D -> Sum(EdgeWeights(D), Sum)); InstallMethod(UnitEdgeWeightedDigraph, "for a digraph", -[IsDigraph], +[IsDigraph and IsImmutableDigraph], D -> EdgeWeightedDigraph(D, List(OutNeighbours(D), l -> ListWithIdenticalEntries(Length(l), 1)))); From 29e5a39772fcdb5d2b756c2b5883a626c2a905f0 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:58:42 +0000 Subject: [PATCH 12/20] edgeweights check immutable, refactor --- gap/weights.gd | 4 +++- gap/weights.gi | 26 ++++++++++++++------------ tst/standard/weights.tst | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/gap/weights.gd b/gap/weights.gd index 77d8823a4..630a89e0f 100644 --- a/gap/weights.gd +++ b/gap/weights.gd @@ -10,7 +10,9 @@ # 1. Edge Weights DeclareAttribute("EdgeWeights", IsDigraph); -DeclareGlobalFunction("EdgeWeightedDigraph"); +DeclareOperation("EdgeWeightedDigraph", + [IsDigraph and IsImmutableDigraph, IsList]); +DeclareOperation("EdgeWeightedDigraph", [IsList, IsList]); DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights); DeclareAttribute("EdgeWeightedDigraphTotalWeight", IsDigraph and HasEdgeWeights); diff --git a/gap/weights.gi b/gap/weights.gi index 70bbd61eb..e6b88613f 100644 --- a/gap/weights.gi +++ b/gap/weights.gi @@ -12,19 +12,15 @@ # 1. Edge Weights ############################################################################# -InstallGlobalFunction(EdgeWeightedDigraph, +InstallMethod(EdgeWeightedDigraph, +"for a digraph and a list", +[IsDigraph and IsImmutableDigraph, IsList], function(D, weights) - local outNeighbours, outNeighbourWeights, u, i; - - if IsDigraph(D) then - D := DigraphCopy(D); - else - D := Digraph(D); - fi; + local outNeighbours, outNeighbourWeights, u, i, newD; # check all elements of weights is a list - if not ForAll(weights, IsListOrCollection) then - ErrorNoReturn("the 2nd argument (list) must be a list of lists,"); + if not ForAll(weights, IsList) then + ErrorNoReturn("the 2nd argument must be a list of lists,"); fi; # check number there is an edge weight list for vertex u @@ -54,10 +50,16 @@ function(D, weights) od; od; - SetEdgeWeights(D, weights); - return D; + newD := DigraphCopy(D); + SetEdgeWeights(newD, weights); + return newD; end); +InstallMethod(EdgeWeightedDigraph, +"for a list and a list", +[IsList, IsList], +{D, weights} -> EdgeWeightedDigraph(Digraph(D), weights)); + InstallMethod(IsNegativeEdgeWeightedDigraph, "for a digraph with edge weights", [IsDigraph and HasEdgeWeights], function(D) diff --git a/tst/standard/weights.tst b/tst/standard/weights.tst index 036dac4d0..1e9dd3055 100644 --- a/tst/standard/weights.tst +++ b/tst/standard/weights.tst @@ -39,7 +39,7 @@ ceeding the length of the argument, # check all elements of weights are list gap> d := EdgeWeightedDigraph([[1], []], [5, []]); -Error, the 2nd argument (list) must be a list of lists, +Error, the 2nd argument must be a list of lists, # string for digraphs gap> d := EdgeWeightedDigraph([["a"], []], [[2], []]); From af7d7229b3020e60bb364e2746e828c586857c3c Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Tue, 27 Oct 2026 23:18:11 +0000 Subject: [PATCH 13/20] docs --- doc/weights.xml | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/doc/weights.xml b/doc/weights.xml index be0fda438..d841563ed 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -24,7 +24,7 @@ of EdgeWeights which is a mutable list of mutable lists.

The edge weights of a digraph cannot be computed and must be set either - using SetEdgeWeights or .

+ using SetEdgeWeights or .

gr := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [15]]); @@ -47,15 +47,18 @@ Error, List Assignment: must be a mutable list <#GAPDoc Label="EdgeWeightedDigraph"> - + A digraph or fail - The argument digraph may be a digraph or a list of lists of integers, floats or rationals.

+ This function returns an immutable digraph with EdgeWeights set to + weights.

- weights must be a list of lists of integers, floats or rationals - of an equal size and shape to OutNeighbours(digraph), otherwise it will fail.

+ The argument digraph must be an immutable digraph, or a list of + lists of positive integers representing outneighbours.

- This will create a digraph and set the EdgeWeights to weights.

+ The argument weights must be a list of lists of integers, floats + or rationals, of an equal size and shape to + OutNeighbours(digraph).

See . EdgeWeights(g); <#GAPDoc Label="UnitEdgeWeightedDigraph"> - + A digraph - - If digraph is immutable, UnitEdgeWeightedDigraph returns - an immutable edge-weighted copy of digraph, with all edge weights - set to 1. If digraph is mutable, the returned digraph will be - mutable, but will not have edge weights.

+ If digraph is an immutable digraph, + UnitEdgeWeightedDigraph returns an immutable edge-weighted copy + of digraph, with all edge weights set to 1.

See . - D := Digraph([[2], [1, 3], [1]]); @@ -90,11 +90,6 @@ gap> D1 := UnitEdgeWeightedDigraph(D); gap> EdgeWeights(D1); [ [ 1 ], [ 1, 1 ], [ 1 ] ] -gap> D2 := Digraph(IsMutableDigraph, [[2], [1, 3], [1]]);; -gap> UnitEdgeWeightedDigraph(D2); - -gap> HasEdgeWeights(D2); -false ]]> @@ -309,7 +304,7 @@ fail]]> the number of vertices of the digraph, and e is the number of edges.

- See . + See . g := EdgeWeightedDigraph([[2, 2], [3], []], [[3, 2], [1], []]); @@ -339,7 +334,7 @@ gap> Sum(flow[1]); This attribute is computed by using and the max-cut min-flow theorem.

- See . + See . g := EdgeWeightedDigraph([[2, 2], [3], []], [[3, 2], [1], []]); @@ -368,7 +363,7 @@ gap> DigraphMinimumCut(g, 1, 3); This attribute is computed by using .

- See . + See . g := EdgeWeightedDigraph([[2, 2], [3], []], [[3, 2], [1], []]); From 114e2da6fcbd9546b48e826c010c65d2b13af3aa Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:17:09 +0000 Subject: [PATCH 14/20] docs --- doc/weights.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/weights.xml b/doc/weights.xml index d841563ed..cffd36f18 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -50,7 +50,7 @@ Error, List Assignment: must be a mutable list A digraph or fail - This function returns an immutable digraph with EdgeWeights set to + This function returns an immutable digraph with edge weights set to weights.

The argument digraph must be an immutable digraph, or a list of From b46f4c22a5ab23beb94ea2ed2395d13737808c9d Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:18:06 +0000 Subject: [PATCH 15/20] new constructor for mutable --- gap/weights.gd | 2 ++ gap/weights.gi | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gap/weights.gd b/gap/weights.gd index 630a89e0f..042ad034c 100644 --- a/gap/weights.gd +++ b/gap/weights.gd @@ -10,6 +10,8 @@ # 1. Edge Weights DeclareAttribute("EdgeWeights", IsDigraph); +DeclareOperation("EdgeWeightedDigraph", + [IsDigraph and IsMutableDigraph, IsList]); DeclareOperation("EdgeWeightedDigraph", [IsDigraph and IsImmutableDigraph, IsList]); DeclareOperation("EdgeWeightedDigraph", [IsList, IsList]); diff --git a/gap/weights.gi b/gap/weights.gi index e6b88613f..02e1ab441 100644 --- a/gap/weights.gi +++ b/gap/weights.gi @@ -13,10 +13,10 @@ ############################################################################# InstallMethod(EdgeWeightedDigraph, -"for a digraph and a list", -[IsDigraph and IsImmutableDigraph, IsList], +"for a mutable digraph and a list", +[IsDigraph and IsMutableDigraph, IsList], function(D, weights) - local outNeighbours, outNeighbourWeights, u, i, newD; + local outNeighbours, outNeighbourWeights, u, i; # check all elements of weights is a list if not ForAll(weights, IsList) then @@ -50,15 +50,22 @@ function(D, weights) od; od; - newD := DigraphCopy(D); - SetEdgeWeights(newD, weights); - return newD; + SetEdgeWeights(D, weights); + MakeImmutable(D); + return D; end); +InstallMethod(EdgeWeightedDigraph, +"for an immutable digraph and a list", +[IsDigraph and IsImmutableDigraph, IsList], +{D, weights} -> EdgeWeightedDigraph(DigraphMutableCopy(D), weights)); + InstallMethod(EdgeWeightedDigraph, "for a list and a list", [IsList, IsList], -{D, weights} -> EdgeWeightedDigraph(Digraph(D), weights)); +{outneighbours, weights} -> EdgeWeightedDigraph(Digraph(IsMutableDigraph, + outneighbours), + weights)); InstallMethod(IsNegativeEdgeWeightedDigraph, "for a digraph with edge weights", [IsDigraph and HasEdgeWeights], From 5f837866202c539429260e575074dc401f1286f9 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:51:24 +0000 Subject: [PATCH 16/20] fix bug and add test --- gap/weights.gi | 2 +- tst/standard/weights.tst | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gap/weights.gi b/gap/weights.gi index 02e1ab441..86164f149 100644 --- a/gap/weights.gi +++ b/gap/weights.gi @@ -50,8 +50,8 @@ function(D, weights) od; od; - SetEdgeWeights(D, weights); MakeImmutable(D); + SetEdgeWeights(D, weights); return D; end); diff --git a/tst/standard/weights.tst b/tst/standard/weights.tst index 1e9dd3055..43ae64439 100644 --- a/tst/standard/weights.tst +++ b/tst/standard/weights.tst @@ -28,6 +28,13 @@ gap> d := EdgeWeightedDigraph(Digraph([[2], []]), [[5], []]); gap> EdgeWeightedDigraphTotalWeight(d); 5 +# mutable converted to immutable +gap> d := Digraph(IsMutableDigraph, [[2], []]); + +gap> EdgeWeightedDigraph(d, [[5], []]);; +gap> d; + + # weight not valid gap> d := EdgeWeightedDigraph([[2], []], [["a"], []]); Error, out-neighbour weights must be integers, floats, or rationals, From f163c50722758378a123337a54bc09dfdc68a758 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:42:13 +0000 Subject: [PATCH 17/20] move tests --- tst/standard/weights.tst | 22 ++++++++++++++++++++++ tst/testinstall.tst | 18 ------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tst/standard/weights.tst b/tst/standard/weights.tst index 43ae64439..7d402fd49 100644 --- a/tst/standard/weights.tst +++ b/tst/standard/weights.tst @@ -72,6 +72,28 @@ gap> d := EdgeWeightedDigraph([[2], []], [[5, 10], []]); Error, the number of out-neighbours and weights for the vertex 1 must be equal\ , +# UnitEdgeWeightedDigraph +gap> D := UnitEdgeWeightedDigraph(Digraph([[2], [1, 3], [1]])); + +gap> EdgeWeights(D); +[ [ 1 ], [ 1, 1 ], [ 1 ] ] +gap> D := UnitEdgeWeightedDigraph(Digraph([[3, 4], [1, 3, 4], [2, 4], [1, 2, 3]])); + +gap> EdgeWeights(D); +[ [ 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1, 1 ] ] +gap> D := UnitEdgeWeightedDigraph(EmptyDigraph(4)); + +gap> EdgeWeights(D); +[ [ ], [ ], [ ], [ ] ] +gap> D := UnitEdgeWeightedDigraph(EdgeWeightedDigraph([[2], []], [[5], []])); + +gap> EdgeWeights(D); +[ [ 1 ], [ ] ] +gap> D := Digraph(IsMutable, [[2], [1, 3], [1]]);; +gap> UnitEdgeWeightedDigraph(D);; +gap> D; + + ############################################################################# # 2. Copies of edge weights ############################################################################# diff --git a/tst/testinstall.tst b/tst/testinstall.tst index 7ee79de9f..25b0463bd 100644 --- a/tst/testinstall.tst +++ b/tst/testinstall.tst @@ -541,24 +541,6 @@ gap> AutomorphismGroup(D) > = Group([(1, 2, 3), (1, 2), (4, 5, 6), (4, 5), (1, 4)(2, 5)(3, 6)]); true -# UnitEdgeWeightedDigraph -gap> D := UnitEdgeWeightedDigraph(Digraph([[2], [1, 3], [1]])); - -gap> EdgeWeights(D); -[ [ 1 ], [ 1, 1 ], [ 1 ] ] -gap> D := UnitEdgeWeightedDigraph(Digraph([[3, 4], [1, 3, 4], [2, 4], [1, 2, 3]])); - -gap> EdgeWeights(D); -[ [ 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1, 1 ] ] -gap> D := UnitEdgeWeightedDigraph(EmptyDigraph(4)); - -gap> EdgeWeights(D); -[ [ ], [ ], [ ], [ ] ] -gap> D := UnitEdgeWeightedDigraph(EdgeWeightedDigraph([[2], []], [[5], []])); - -gap> EdgeWeights(D); -[ [ 1 ], [ ] ] - # SwapDigraphs gap> C := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);; gap> D := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);; From 6fdf8b335ce79129613c65c602bda635c4fa00f5 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:47:38 +0000 Subject: [PATCH 18/20] mutability, docs --- doc/weights.xml | 18 ++++++++++-------- gap/weights.gi | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/weights.xml b/doc/weights.xml index cffd36f18..a1f749aed 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -23,8 +23,8 @@ lists, whereas the function EdgeWeightsMutableCopy returns a copy of EdgeWeights which is a mutable list of mutable lists.

- The edge weights of a digraph cannot be computed and must be set either - using SetEdgeWeights or .

+ The edge weights of a digraph are set upon construction with + .

gr := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [15]]); @@ -53,8 +53,11 @@ Error, List Assignment: must be a mutable list This function returns an immutable digraph with edge weights set to weights.

- The argument digraph must be an immutable digraph, or a list of - lists of positive integers representing outneighbours.

+ If the argument digraph is a mutable digraph, then it is also + modified in place.

+ + If the argument digraph is a list of lists of positive integers, + these are interpreted as out-neighbours for a digraph.

The argument weights must be a list of lists of integers, floats or rationals, of an equal size and shape to @@ -78,10 +81,9 @@ gap> EdgeWeights(g); A digraph - If digraph is an immutable digraph, - UnitEdgeWeightedDigraph returns an immutable edge-weighted copy - of digraph, with all edge weights set to 1.

- + This function returns an immutable digraph with all edge weights + set to 1. If digraph is a mutable digraph, + then it is also modified in place.

See . D := Digraph([[2], [1, 3], [1]]); diff --git a/gap/weights.gi b/gap/weights.gi index 86164f149..cb2fab712 100644 --- a/gap/weights.gi +++ b/gap/weights.gi @@ -89,7 +89,7 @@ InstallMethod(EdgeWeightedDigraphTotalWeight, D -> Sum(EdgeWeights(D), Sum)); InstallMethod(UnitEdgeWeightedDigraph, "for a digraph", -[IsDigraph and IsImmutableDigraph], +[IsDigraph], D -> EdgeWeightedDigraph(D, List(OutNeighbours(D), l -> ListWithIdenticalEntries(Length(l), 1)))); From 6f8eafbed9a40e8e8ad08c7dab3c2b3f773ce64f Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Wed, 4 Nov 2026 15:21:53 +0000 Subject: [PATCH 19/20] Apply batched suggestions from code review Co-authored-by: James Mitchell --- doc/weights.xml | 2 +- gap/weights.gi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/weights.xml b/doc/weights.xml index a1f749aed..524167181 100644 --- a/doc/weights.xml +++ b/doc/weights.xml @@ -82,7 +82,7 @@ gap> EdgeWeights(g); A digraph This function returns an immutable digraph with all edge weights - set to 1. If digraph is a mutable digraph, + set to 1. If digraph is a mutable digraph, then it is also modified in place.

See . must be a list of lists,"); + ErrorNoReturn("the 2nd argument must be a list of lists"); fi; # check number there is an edge weight list for vertex u From b61bed020991a43fb9170b1f9d88160f415d5352 Mon Sep 17 00:00:00 2001 From: William-Kenyon <115789274+William-Kenyon@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:33:40 +0000 Subject: [PATCH 20/20] refactor, fix test --- gap/weights.gd | 6 ++---- tst/standard/weights.tst | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/gap/weights.gd b/gap/weights.gd index 042ad034c..42e09e754 100644 --- a/gap/weights.gd +++ b/gap/weights.gd @@ -10,10 +10,8 @@ # 1. Edge Weights DeclareAttribute("EdgeWeights", IsDigraph); -DeclareOperation("EdgeWeightedDigraph", - [IsDigraph and IsMutableDigraph, IsList]); -DeclareOperation("EdgeWeightedDigraph", - [IsDigraph and IsImmutableDigraph, IsList]); +DeclareOperation("EdgeWeightedDigraph", [IsDigraph, IsList]); + DeclareOperation("EdgeWeightedDigraph", [IsList, IsList]); DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights); DeclareAttribute("EdgeWeightedDigraphTotalWeight", diff --git a/tst/standard/weights.tst b/tst/standard/weights.tst index 7d402fd49..17773c267 100644 --- a/tst/standard/weights.tst +++ b/tst/standard/weights.tst @@ -46,7 +46,7 @@ ceeding the length of the argument, # check all elements of weights are list gap> d := EdgeWeightedDigraph([[1], []], [5, []]); -Error, the 2nd argument must be a list of lists, +Error, the 2nd argument must be a list of lists # string for digraphs gap> d := EdgeWeightedDigraph([["a"], []], [[2], []]);