Skip to content

Commit 41d49e3

Browse files
author
Release Manager
committed
Trac #32888: Feature for sage.groups
Most substantial code in `sage.groups` depends on `libgap`, so `sage.groups` will not be used in small distributions such as '''sagemath-categories''' and '''sagemath-polyhedra'''. We introduce a `Feature` for use in `# optional` annotations for doctests that use groups as examples. We add these annotations in some modules of `sage.structure` and `sage.graphs`. URL: https://trac.sagemath.org/32888 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): Sébastien Labbé
2 parents dcce1d6 + 678ffc8 commit 41d49e3

File tree

7 files changed

+69
-46
lines changed

7 files changed

+69
-46
lines changed

src/sage/features/sagemath.py

+23
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ def __init__(self):
100100
[PythonModule('sage.graphs.graph')])
101101

102102

103+
class sage__groups(JoinFeature):
104+
r"""
105+
A :class:`sage.features.Feature` describing the presence of ``sage.groups``.
106+
107+
EXAMPLES::
108+
109+
sage: from sage.features.sagemath import sage__groups
110+
sage: sage__groups().is_present() # optional - sage.groups
111+
FeatureTestResult('sage.groups', True)
112+
"""
113+
def __init__(self):
114+
r"""
115+
TESTS::
116+
117+
sage: from sage.features.sagemath import sage__groups
118+
sage: isinstance(sage__groups(), sage__groups)
119+
True
120+
"""
121+
JoinFeature.__init__(self, 'sage.groups',
122+
[PythonModule('sage.groups.perm_gps.permgroup')])
123+
124+
103125
class sage__plot(JoinFeature):
104126
r"""
105127
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.plot`.
@@ -236,6 +258,7 @@ def all_features():
236258
sage__combinat(),
237259
sage__geometry__polyhedron(),
238260
sage__graphs(),
261+
sage__groups(),
239262
sage__plot(),
240263
sage__rings__number_field(),
241264
sage__rings__padics(),

src/sage/graphs/generators/families.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2790,8 +2790,8 @@ def HanoiTowerGraph(pegs, disks, labels=True, positions=True):
27902790
27912791
::
27922792
2793-
sage: H = graphs.HanoiTowerGraph(3,4,labels=False,positions=False)
2794-
sage: H.automorphism_group().is_isomorphic(SymmetricGroup(3))
2793+
sage: H = graphs.HanoiTowerGraph(3, 4, labels=False, positions=False)
2794+
sage: H.automorphism_group().is_isomorphic(SymmetricGroup(3)) # optional - sage.groups
27952795
True
27962796
sage: H.chromatic_number()
27972797
3

src/sage/graphs/generic_graph.py

+27-27
Original file line numberDiff line numberDiff line change
@@ -18667,33 +18667,33 @@ def _color_by_label(self, format='hex', as_function=False, default_color="black"
1866718667
We consider the Cayley graph of the symmetric group, whose edges are
1866818668
labelled by the numbers 1,2, and 3::
1866918669

18670-
sage: G = SymmetricGroup(4).cayley_graph()
18671-
sage: set(G.edge_labels())
18670+
sage: G = SymmetricGroup(4).cayley_graph() # optional - sage.groups
18671+
sage: set(G.edge_labels()) # optional - sage.groups
1867218672
{1, 2, 3}
1867318673

1867418674
We first request the coloring as a function::
1867518675

18676-
sage: f = G._color_by_label(as_function=True)
18677-
sage: [f(1), f(2), f(3)]
18676+
sage: f = G._color_by_label(as_function=True) # optional - sage.groups
18677+
sage: [f(1), f(2), f(3)] # optional - sage.groups
1867818678
['#0000ff', '#ff0000', '#00ff00']
18679-
sage: f = G._color_by_label({1: "blue", 2: "red", 3: "green"}, as_function=True)
18680-
sage: [f(1), f(2), f(3)]
18679+
sage: f = G._color_by_label({1: "blue", 2: "red", 3: "green"}, as_function=True) # optional - sage.groups
18680+
sage: [f(1), f(2), f(3)] # optional - sage.groups
1868118681
['blue', 'red', 'green']
18682-
sage: f = G._color_by_label({1: "red"}, as_function=True)
18683-
sage: [f(1), f(2), f(3)]
18682+
sage: f = G._color_by_label({1: "red"}, as_function=True) # optional - sage.groups
18683+
sage: [f(1), f(2), f(3)] # optional - sage.groups
1868418684
['red', 'black', 'black']
18685-
sage: f = G._color_by_label({1: "red"}, as_function=True, default_color='blue')
18686-
sage: [f(1), f(2), f(3)]
18685+
sage: f = G._color_by_label({1: "red"}, as_function=True, default_color='blue') # optional - sage.groups
18686+
sage: [f(1), f(2), f(3)] # optional - sage.groups
1868718687
['red', 'blue', 'blue']
1868818688

1868918689
The default output is a dictionary assigning edges to colors::
1869018690

18691-
sage: G._color_by_label()
18691+
sage: G._color_by_label() # optional - sage.groups
1869218692
{'#0000ff': [((), (1,2), 1), ...],
1869318693
'#00ff00': [((), (3,4), 3), ...],
1869418694
'#ff0000': [((), (2,3), 2), ...]}
1869518695

18696-
sage: G._color_by_label({1: "blue", 2: "red", 3: "green"})
18696+
sage: G._color_by_label({1: "blue", 2: "red", 3: "green"}) # optional - sage.groups
1869718697
{'blue': [((), (1,2), 1), ...],
1869818698
'green': [((), (3,4), 3), ...],
1869918699
'red': [((), (2,3), 2), ...]}
@@ -18702,12 +18702,12 @@ def _color_by_label(self, format='hex', as_function=False, default_color="black"
1870218702

1870318703
We check what happens when several labels have the same color::
1870418704

18705-
sage: result = G._color_by_label({1: "blue", 2: "blue", 3: "green"})
18706-
sage: sorted(result)
18705+
sage: result = G._color_by_label({1: "blue", 2: "blue", 3: "green"}) # optional - sage.groups
18706+
sage: sorted(result) # optional - sage.groups
1870718707
['blue', 'green']
18708-
sage: len(result['blue'])
18708+
sage: len(result['blue']) # optional - sage.groups
1870918709
48
18710-
sage: len(result['green'])
18710+
sage: len(result['green']) # optional - sage.groups
1871118711
24
1871218712
"""
1871318713
if format is True:
@@ -21599,10 +21599,10 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c
2159921599
Relabeling using a Sage permutation::
2160021600

2160121601
sage: G = graphs.PathGraph(3)
21602-
sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup
21603-
sage: S = SymmetricGroup(3)
21604-
sage: gamma = S('(1,2)')
21605-
sage: G.relabel(gamma, inplace=False).am()
21602+
sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup # optional - sage.groups
21603+
sage: S = SymmetricGroup(3) # optional - sage.groups
21604+
sage: gamma = S('(1,2)') # optional - sage.groups
21605+
sage: G.relabel(gamma, inplace=False).am() # optional - sage.groups
2160621606
[0 0 1]
2160721607
[0 0 1]
2160821608
[1 1 0]
@@ -22537,21 +22537,21 @@ def is_isomorphic(self, other, certificate=False, verbosity=0, edge_labels=False
2253722537

2253822538
Graphs::
2253922539

22540-
sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup
22540+
sage: from sage.groups.perm_gps.permgroup_named import SymmetricGroup # optional - sage.groups
2254122541
sage: D = graphs.DodecahedralGraph()
2254222542
sage: E = copy(D)
22543-
sage: gamma = SymmetricGroup(20).random_element()
22544-
sage: E.relabel(gamma)
22543+
sage: gamma = SymmetricGroup(20).random_element() # optional - sage.groups
22544+
sage: E.relabel(gamma) # optional - sage.groups
2254522545
sage: D.is_isomorphic(E)
2254622546
True
2254722547

2254822548
::
2254922549

2255022550
sage: D = graphs.DodecahedralGraph()
22551-
sage: S = SymmetricGroup(20)
22552-
sage: gamma = S.random_element()
22553-
sage: E = copy(D)
22554-
sage: E.relabel(gamma)
22551+
sage: S = SymmetricGroup(20) # optional - sage.groups
22552+
sage: gamma = S.random_element() # optional - sage.groups
22553+
sage: E = copy(D) # optional - sage.groups
22554+
sage: E.relabel(gamma) # optional - sage.groups
2255522555
sage: a,b = D.is_isomorphic(E, certificate=True); a
2255622556
True
2255722557
sage: from sage.graphs.generic_graph_pyx import spring_layout_fast

src/sage/graphs/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ class Graph(GenericGraph):
601601
'out' is the label for the edge on 2 and 5. Labels can be used as
602602
weights, if all the labels share some common parent.::
603603
604-
sage: a,b,c,d,e,f = sorted(SymmetricGroup(3))
605-
sage: Graph({b:{d:'c',e:'p'}, c:{d:'p',e:'c'}})
604+
sage: a, b, c, d, e, f = sorted(SymmetricGroup(3)) # optional - sage.groups
605+
sage: Graph({b: {d: 'c', e: 'p'}, c: {d: 'p', e: 'c'}}) # optional - sage.groups
606606
Graph on 4 vertices
607607
608608
#. A dictionary of lists::

src/sage/structure/coerce.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ cdef class CoercionModel:
10851085
sage: Zmod100 = Integers(100)
10861086
sage: cm.division_parent(Zmod100)
10871087
Ring of integers modulo 100
1088-
sage: S5 = SymmetricGroup(5)
1089-
sage: cm.division_parent(S5)
1088+
sage: S5 = SymmetricGroup(5) # optional - sage.groups
1089+
sage: cm.division_parent(S5) # optional - sage.groups
10901090
Symmetric group of order 5! as a permutation group
10911091
"""
10921092
try:

src/sage/structure/coerce_actions.pyx

+10-10
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ cdef class GenericAction(Action):
9797
sage: A.codomain()
9898
Set P^1(QQ) of all cusps
9999
100-
sage: S3 = SymmetricGroup(3)
101-
sage: QQxyz = QQ['x,y,z']
102-
sage: A = sage.structure.coerce_actions.ActOnAction(S3, QQxyz, False)
103-
sage: A.codomain()
100+
sage: S3 = SymmetricGroup(3) # optional - sage.groups
101+
sage: QQxyz = QQ['x,y,z'] # optional - sage.groups
102+
sage: A = sage.structure.coerce_actions.ActOnAction(S3, QQxyz, False) # optional - sage.groups
103+
sage: A.codomain() # optional - sage.groups
104104
Multivariate Polynomial Ring in x, y, z over Rational Field
105105
106106
"""
@@ -118,15 +118,15 @@ cdef class ActOnAction(GenericAction):
118118
"""
119119
TESTS::
120120
121-
sage: G = SymmetricGroup(3)
122-
sage: R.<x,y,z> = QQ[]
123-
sage: A = sage.structure.coerce_actions.ActOnAction(G, R, False)
124-
sage: A(x^2 + y - z, G((1,2)))
121+
sage: G = SymmetricGroup(3) # optional - sage.groups
122+
sage: R.<x,y,z> = QQ[] # optional - sage.groups
123+
sage: A = sage.structure.coerce_actions.ActOnAction(G, R, False) # optional - sage.groups
124+
sage: A(x^2 + y - z, G((1,2))) # optional - sage.groups
125125
y^2 + x - z
126-
sage: A(x+2*y+3*z, G((1,3,2)))
126+
sage: A(x+2*y+3*z, G((1,3,2))) # optional - sage.groups
127127
2*x + 3*y + z
128128
129-
sage: type(A)
129+
sage: type(A) # optional - sage.groups
130130
<... 'sage.structure.coerce_actions.ActOnAction'>
131131
"""
132132
return (<Element>g)._act_on_(x, self._is_left)

src/sage/structure/element.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2549,9 +2549,9 @@ cdef class MonoidElement(Element):
25492549
25502550
EXAMPLES::
25512551
2552-
sage: G = SymmetricGroup(4)
2553-
sage: g = G([2, 3, 4, 1])
2554-
sage: g.powers(4)
2552+
sage: G = SymmetricGroup(4) # optional - sage.groups
2553+
sage: g = G([2, 3, 4, 1]) # optional - sage.groups
2554+
sage: g.powers(4) # optional - sage.groups
25552555
[(), (1,2,3,4), (1,3)(2,4), (1,4,3,2)]
25562556
"""
25572557
if n < 0:

0 commit comments

Comments
 (0)