Skip to content

Commit 00f24ed

Browse files
author
Matthias Koeppe
committed
More block tags, docstring cosmetics
1 parent 16cd708 commit 00f24ed

File tree

6 files changed

+128
-111
lines changed

6 files changed

+128
-111
lines changed

src/sage/data_structures/stream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,12 +2526,12 @@ def _approximate_order(self):
25262526
25272527
sage: from sage.data_structures.stream import Stream_function, Stream_cauchy_invert
25282528
sage: f = Stream_function(lambda n: GF(7)(n), True, 0)
2529-
sage: [f[i] for i in range(5)] # needs sage.rings.finite_rings
2529+
sage: [f[i] for i in range(5)]
25302530
[0, 1, 2, 3, 4]
2531-
sage: h = Stream_cauchy_invert(f) # needs sage.rings.finite_rings
2532-
sage: h._approximate_order # needs sage.rings.finite_rings
2531+
sage: h = Stream_cauchy_invert(f)
2532+
sage: h._approximate_order
25332533
-1
2534-
sage: [h[i] for i in range(-2, 5)] # needs sage.rings.finite_rings
2534+
sage: [h[i] for i in range(-2, 5)]
25352535
[0, 1, 5, 1, 0, 0, 0]
25362536
"""
25372537
try:

src/sage/ext/fast_callable.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,23 +2488,24 @@ cdef class Wrapper:
24882488
24892489
EXAMPLES::
24902490
2491+
sage: # needs sage.symbolic
24912492
sage: from sage.ext.fast_callable import ExpressionTreeBuilder, generate_code, InstructionStream
24922493
sage: etb = ExpressionTreeBuilder('x')
24932494
sage: x = etb.var('x')
2494-
sage: expr = (x+pi) * (x+1) # needs sage.symbolic
2495+
sage: expr = (x+pi) * (x+1)
24952496
sage: from sage.ext.interpreters.wrapper_py import metadata, Wrapper_py
24962497
sage: instr_stream = InstructionStream(metadata, 1)
2497-
sage: generate_code(expr, instr_stream) # needs sage.symbolic
2498+
sage: generate_code(expr, instr_stream)
24982499
sage: instr_stream.instr('return')
24992500
sage: v = Wrapper_py(instr_stream.get_current())
2500-
sage: v.get_orig_args() # needs sage.symbolic
2501+
sage: v.get_orig_args()
25012502
{'args': 1,
25022503
'code': [0, 0, 1, 0, 4, 0, 0, 1, 1, 4, 6, 2],
25032504
'constants': [pi, 1],
25042505
'domain': None,
25052506
'py_constants': [],
25062507
'stack': 3}
2507-
sage: v.op_list() # needs sage.symbolic
2508+
sage: v.op_list()
25082509
[('load_arg', 0), ('load_const', pi), 'add', ('load_arg', 0), ('load_const', 1), 'add', 'mul', 'return']
25092510
"""
25102511

src/sage/structure/coerce.pyx

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,18 @@ cpdef bint is_numpy_type(t):
423423
EXAMPLES::
424424
425425
sage: from sage.structure.coerce import is_numpy_type
426-
sage: import numpy # needs numpy
427-
sage: is_numpy_type(numpy.int16) # needs numpy
426+
427+
sage: # needs numpy
428+
sage: import numpy
429+
sage: is_numpy_type(numpy.int16)
428430
True
429-
sage: is_numpy_type(numpy.floating) # needs numpy
431+
sage: is_numpy_type(numpy.floating)
430432
True
431-
sage: is_numpy_type(numpy.ndarray) # needs numpy
433+
sage: is_numpy_type(numpy.ndarray)
432434
True
433-
sage: is_numpy_type(numpy.matrix) # needs numpy
435+
sage: is_numpy_type(numpy.matrix)
434436
True
437+
435438
sage: is_numpy_type(int)
436439
False
437440
sage: is_numpy_type(Integer)
@@ -923,20 +926,23 @@ cdef class CoercionModel:
923926
cpdef analyse(self, xp, yp, op=mul):
924927
"""
925928
Emulate the process of doing arithmetic between xp and yp, returning
926-
a list of steps and the parent that the result will live in. The
927-
``explain`` function is easier to use, but if one wants access to
929+
a list of steps and the parent that the result will live in.
930+
931+
The :meth:`explain` method is easier to use, but if one wants access to
928932
the actual morphism and action objects (rather than their string
929-
representations) then this is the function to use.
933+
representations), then this is the function to use.
930934
931935
EXAMPLES::
932936
933937
sage: cm = sage.structure.element.get_coercion_model()
934938
sage: GF7 = GF(7)
935939
sage: steps, res = cm.analyse(GF7, ZZ)
936940
sage: steps
937-
['Coercion on right operand via', Natural morphism:
941+
['Coercion on right operand via',
942+
Natural morphism:
938943
From: Integer Ring
939-
To: Finite Field of size 7, 'Arithmetic performed after coercions.']
944+
To: Finite Field of size 7,
945+
'Arithmetic performed after coercions.']
940946
sage: res
941947
Finite Field of size 7
942948
sage: f = steps[1]; type(f)
@@ -1016,9 +1022,10 @@ cdef class CoercionModel:
10161022

10171023
def common_parent(self, *args):
10181024
"""
1019-
Computes a common parent for all the inputs. It's essentially
1020-
an `n`-ary canonical coercion except it can operate on parents
1021-
rather than just elements.
1025+
Compute a common parent for all the inputs.
1026+
1027+
It's essentially an `n`-ary canonical coercion except it can
1028+
operate on parents rather than just elements.
10221029
10231030
INPUT:
10241031
@@ -1027,7 +1034,7 @@ cdef class CoercionModel:
10271034
OUTPUT:
10281035
10291036
A :class:`Parent` into which each input should coerce, or raises a
1030-
``TypeError`` if no such :class:`Parent` can be found.
1037+
:class:`TypeError` if no such :class:`Parent` can be found.
10311038
10321039
EXAMPLES::
10331040
@@ -1122,23 +1129,25 @@ cdef class CoercionModel:
11221129

11231130
cpdef bin_op(self, x, y, op):
11241131
"""
1125-
Execute the operation op on x and y. It first looks for an action
1126-
corresponding to op, and failing that, it tries to coerces x and y
1127-
into a common parent and calls op on them.
1132+
Execute the operation ``op`` on `x` and `y`.
1133+
1134+
It first looks for an action
1135+
corresponding to ``op``, and failing that, it tries to coerce `x` and `y`
1136+
into a common parent and calls ``op`` on them.
11281137
1129-
If it cannot make sense of the operation, a TypeError is raised.
1138+
If it cannot make sense of the operation, a :class:`TypeError` is raised.
11301139
11311140
INPUT:
11321141
1133-
- ``x`` - the left operand
1142+
- ``x`` -- the left operand
11341143
1135-
- ``y`` - the right operand
1144+
- ``y`` -- the right operand
11361145
1137-
- ``op`` - a python function taking 2 arguments
1146+
- ``op`` -- a python function taking 2 arguments
11381147
11391148
.. NOTE::
11401149
1141-
op is often an arithmetic operation, but need not be so.
1150+
``op`` is often an arithmetic operation, but need not be so.
11421151
11431152
EXAMPLES::
11441153
@@ -1268,26 +1277,28 @@ cdef class CoercionModel:
12681277

12691278
cpdef canonical_coercion(self, x, y):
12701279
r"""
1271-
Given two elements x and y, with parents S and R respectively,
1272-
find a common parent Z such that there are coercions
1273-
`f: S \mapsto Z` and `g: R \mapsto Z` and return `f(x), g(y)`
1280+
Given two elements `x` and `y`, with parents `S` and `R` respectively,
1281+
find a common parent `Z` such that there are coercions
1282+
`f: S \to Z` and `g: R \to Z` and return `f(x), g(y)`,
12741283
which will have the same parent.
12751284
1276-
Raises a type error if no such Z can be found.
1285+
Raises a type error if no such `Z` can be found.
12771286
12781287
EXAMPLES::
12791288
12801289
sage: cm = sage.structure.element.get_coercion_model()
12811290
sage: cm.canonical_coercion(mod(2, 10), 17)
12821291
(2, 7)
1283-
sage: x, y = cm.canonical_coercion(1/2, matrix(ZZ, 2, 2, range(4))) # needs sage.modules
1284-
sage: x # needs sage.modules
1292+
1293+
sage: # needs sage.modules
1294+
sage: x, y = cm.canonical_coercion(1/2, matrix(ZZ, 2, 2, range(4)))
1295+
sage: x
12851296
[1/2 0]
12861297
[ 0 1/2]
1287-
sage: y # needs sage.modules
1298+
sage: y
12881299
[0 1]
12891300
[2 3]
1290-
sage: parent(x) is parent(y) # needs sage.modules
1301+
sage: parent(x) is parent(y)
12911302
True
12921303
12931304
There is some support for non-Sage datatypes as well::
@@ -1296,7 +1307,6 @@ cdef class CoercionModel:
12961307
sage: type(x), type(y)
12971308
(<class 'sage.rings.integer.Integer'>, <class 'sage.rings.integer.Integer'>)
12981309
1299-
13001310
sage: x, y = cm.canonical_coercion(int(5), complex(3))
13011311
sage: type(x), type(y)
13021312
(<class 'complex'>, <class 'complex'>)
@@ -1411,7 +1421,6 @@ cdef class CoercionModel:
14111421

14121422
raise TypeError("no common canonical parent for objects with parents: '%s' and '%s'"%(xp, yp))
14131423

1414-
14151424
cpdef coercion_maps(self, R, S):
14161425
r"""
14171426
Give two parents `R` and `S`, return a pair of coercion maps
@@ -1471,12 +1480,14 @@ cdef class CoercionModel:
14711480
False
14721481
sage: cm = sage.structure.element.get_coercion_model()
14731482
sage: cm.coercion_maps(V, W)
1474-
(None, (map internal to coercion system -- copy before use)
1483+
(None,
1484+
(map internal to coercion system -- copy before use)
14751485
Coercion map:
14761486
From: Vector space of dimension 3 over Rational Field
14771487
To: Vector space of dimension 3 over Rational Field)
14781488
sage: cm.coercion_maps(W, V)
1479-
(None, (map internal to coercion system -- copy before use)
1489+
(None,
1490+
(map internal to coercion system -- copy before use)
14801491
Coercion map:
14811492
From: Vector space of dimension 3 over Rational Field
14821493
To: Vector space of dimension 3 over Rational Field)
@@ -1495,15 +1506,15 @@ cdef class CoercionModel:
14951506
sage: # needs sage.libs.pari
14961507
sage: import gc
14971508
sage: T = type(GF(2))
1498-
sage: gc.collect() #random
1509+
sage: gc.collect() # random
14991510
852
15001511
sage: N0 = len(list(o for o in gc.get_objects() if type(o) is T))
15011512
sage: L = [ZZ(1) + GF(p)(1) for p in prime_range(2, 50)]
15021513
sage: N1 = len(list(o for o in gc.get_objects() if type(o) is T))
15031514
sage: N1 > N0
15041515
True
15051516
sage: del L
1506-
sage: gc.collect() #random
1517+
sage: gc.collect() # random
15071518
3939
15081519
sage: N2 = len(list(o for o in gc.get_objects() if type(o) is T))
15091520
sage: N2 - N0
@@ -1561,7 +1572,7 @@ cdef class CoercionModel:
15611572

15621573
cpdef verify_coercion_maps(self, R, S, homs, bint fix=False):
15631574
"""
1564-
Make sure this is a valid pair of homomorphisms from R and S to a common parent.
1575+
Make sure this is a valid pair of homomorphisms from `R` and `S` to a common parent.
15651576
This function is used to protect the user against buggy parents.
15661577
15671578
EXAMPLES::
@@ -1631,7 +1642,7 @@ cdef class CoercionModel:
16311642
cpdef discover_coercion(self, R, S):
16321643
"""
16331644
This actually implements the finding of coercion maps as described in
1634-
the ``coercion_maps`` method.
1645+
the :meth:`coercion_maps` method.
16351646
16361647
EXAMPLES::
16371648
@@ -1811,15 +1822,15 @@ cdef class CoercionModel:
18111822
"""
18121823
INPUT:
18131824
1814-
- ``R`` - the left Parent (or type)
1815-
- ``S`` - the right Parent (or type)
1816-
- ``op`` - the operand, typically an element of the operator module
1817-
- ``r`` - (optional) element of R
1818-
- ``s`` - (optional) element of S.
1825+
- ``R`` -- the left :class:`Parent` (or type)
1826+
- ``S`` -- the right :class:`Parent` (or type)
1827+
- ``op`` -- the operand, typically an element of the :mod:`operator` module
1828+
- ``r`` -- (optional) element of `R`
1829+
- ``s`` -- (optional) element of `S`.
18191830
18201831
OUTPUT:
18211832
1822-
- An action A such that s op r is given by A(s,r).
1833+
- An action `A` such that `s` ``op`` `r` is given by `A(s,r)`.
18231834
18241835
The steps taken are illustrated below.
18251836
@@ -1833,13 +1844,14 @@ cdef class CoercionModel:
18331844
True
18341845
sage: cm = sage.structure.element.get_coercion_model()
18351846
1836-
If R or S is a Parent, ask it for an action by/on R::
1847+
If `R` or `S` is a :class:`Parent`, ask it for an action by/on `R`::
18371848
18381849
sage: cm.discover_action(ZZ, P, operator.mul)
18391850
Left scalar multiplication by Integer Ring on
18401851
Univariate Polynomial Ring in x over Integer Ring
18411852
1842-
If R or S a type, recursively call get_action with the Sage versions of R and/or S::
1853+
If `R` or `S` a type, recursively call :meth:`get_action`
1854+
with the Sage versions of `R` and/or `S`::
18431855
18441856
sage: cm.discover_action(P, int, operator.mul)
18451857
Right scalar multiplication by Integer Ring on
@@ -1848,7 +1860,7 @@ cdef class CoercionModel:
18481860
From: Set of Python objects of class 'int'
18491861
To: Integer Ring
18501862
1851-
If op is division, look for action on right by inverse::
1863+
If ``op`` is division, look for action on ``right`` by inverse::
18521864
18531865
sage: cm.discover_action(P, ZZ, operator.truediv)
18541866
Right inverse action by Rational Field on

src/sage/structure/coerce_actions.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ cdef class ActOnAction(GenericAction):
130130
y^2 + x - z
131131
sage: A(x + 2*y + 3*z, G((1,3,2)))
132132
2*x + 3*y + z
133-
134-
sage: type(A) # needs sage.groups
133+
sage: type(A)
135134
<... 'sage.structure.coerce_actions.ActOnAction'>
136135
"""
137136
return (<Element>g)._act_on_(x, self._is_left)
@@ -152,8 +151,7 @@ cdef class ActedUponAction(GenericAction):
152151
Infinity
153152
sage: A(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2))
154153
Infinity
155-
156-
sage: type(A) # needs sage.modular sage.modules
154+
sage: type(A)
157155
<... 'sage.structure.coerce_actions.ActedUponAction'>
158156
"""
159157
return (<Element>x)._acted_upon_(g, not self._is_left)

src/sage/structure/element.pyx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,25 +3243,31 @@ cdef class CommutativeRingElement(RingElement):
32433243

32443244
def sqrt(self, extend=True, all=False, name=None):
32453245
"""
3246-
It computes the square root.
3246+
Compute the square root.
32473247
32483248
INPUT:
32493249
3250-
- ``extend`` -- Whether to make a ring extension containing a square root if ``self`` is not a square (default: ``True``)
3250+
- ``extend`` -- boolean (default: ``True``); whether to make a ring
3251+
extension containing a square root if ``self`` is not a square
32513252
3252-
- ``all`` -- Whether to return a list of all square roots or just a square root (default: False)
3253+
- ``all`` -- boolean (default: ``False``); whether to return a list of
3254+
all square roots or just a square root
32533255
3254-
- ``name`` -- Required when ``extend=True`` and ``self`` is not a square. This will be the name of the generator extension.
3256+
- ``name`` -- required when ``extend=True`` and ``self`` is not a
3257+
square. This will be the name of the generator of the extension.
32553258
32563259
OUTPUT:
32573260
3258-
- if ``all=False`` it returns a square root. (throws an error if ``extend=False`` and ``self`` is not a square)
3261+
- if ``all=False``, a square root; raises an error if ``extend=False``
3262+
and ``self`` is not a square
32593263
3260-
- if ``all=True`` it returns a list of all the square roots (could be empty if ``extend=False`` and ``self`` is not a square)
3264+
- if ``all=True``, a list of all the square roots (empty if
3265+
``extend=False`` and ``self`` is not a square)
32613266
32623267
ALGORITHM:
32633268
3264-
It uses ``is_square(root=true)`` for the hard part of the work, the rest is just wrapper code.
3269+
It uses ``is_square(root=true)`` for the hard part of the work, the rest
3270+
is just wrapper code.
32653271
32663272
EXAMPLES::
32673273
@@ -3320,9 +3326,9 @@ cdef class CommutativeRingElement(RingElement):
33203326
y
33213327
sage: sqrtx^2
33223328
1/x
3323-
sage: (1/x).sqrt(all=true,name="y")
3329+
sage: (1/x).sqrt(all=true, name="y")
33243330
[y, -y]
3325-
sage: (1/x).sqrt(extend=False,all=True)
3331+
sage: (1/x).sqrt(extend=False, all=True)
33263332
[]
33273333
sage: (1/(x^2-1)).sqrt()
33283334
Traceback (most recent call last):

0 commit comments

Comments
 (0)