Skip to content

Commit

Permalink
gh-35422: sage.categories: Add # optional for modularization; refor…
Browse files Browse the repository at this point in the history
…mat doctests

    
<!-- Please provide a concise, informative and self-explanatory title.
-->
<!-- Don't put issue numbers in the title. Put it in the Description
below. -->
<!-- For example, instead of "Fixes #12345", use "Add a new method to
multiply two integers" -->

### 📚 Description

<!-- Describe your changes here in detail. -->
Adding doctest tags `# optional - sage.rings.finite_rings`,
`...number_field`, `...padics` etc. for modularization purposes.

Also:
- some coding style fixes in the doctests (such as adding spaces around
some operators and after commas, following PEP 8)
- improved the readability of doctests in the HTML format by breaking
long lines to avoid having to scroll horizontally
<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

This is:
- Part of #29705
- Split out & squashed from #34998

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #35422
Reported by: Matthias Köppe
Reviewer(s): Gonzalo Tornaría, Kwankyu Lee, Matthias Köppe
  • Loading branch information
Release Manager committed May 21, 2023
2 parents 2828993 + e02b79e commit b378119
Show file tree
Hide file tree
Showing 137 changed files with 6,439 additions and 5,742 deletions.
67 changes: 38 additions & 29 deletions src/sage/categories/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ A group action `G \times S \rightarrow S` is a functor from `G` to Sets.
sage: import gc
sage: _ = gc.collect()
sage: A
<repr(<sage.categories.action.Action at 0x...>) failed: RuntimeError: This action acted on a set that became garbage collected>
<repr(<sage.categories.action.Action at 0x...>) failed:
RuntimeError: This action acted on a set that became garbage collected>
To avoid garbage collection of the underlying set, it is sufficient to
create a strong reference to it before the action is created.
Expand Down Expand Up @@ -265,15 +266,17 @@ cdef class Action(Functor):
sage: R = (ZZ['x'])['y']
sage: A = R.get_action(P,operator.mul,True)
sage: A # indirect doctest
Right scalar multiplication by Univariate Polynomial Ring in x over
Rational Field on Univariate Polynomial Ring in y over Univariate
Polynomial Ring in x over Integer Ring
Right scalar multiplication
by Univariate Polynomial Ring in x over Rational Field
on Univariate Polynomial Ring in y over
Univariate Polynomial Ring in x over Integer Ring
In this example, the underlying set is the ring ``R``. This is the same
as the left domain, which is different from the codomain of the action::
sage: A.codomain()
Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field
Univariate Polynomial Ring in y
over Univariate Polynomial Ring in x over Rational Field
sage: A.codomain() == R
False
sage: A.left_domain() is R
Expand All @@ -294,7 +297,8 @@ cdef class Action(Functor):
sage: import gc
sage: _ = gc.collect()
sage: A
<repr(<sage.categories.action.Action at 0x...>) failed: RuntimeError: This action acted on a set that became garbage collected>
<repr(<sage.categories.action.Action at 0x...>) failed:
RuntimeError: This action acted on a set that became garbage collected>
"""
S = self.US()
if S is None:
Expand Down Expand Up @@ -329,24 +333,28 @@ cdef class InverseAction(Action):
EXAMPLES::
sage: V = QQ^3
sage: v = V((1, 2, 3))
sage: V = QQ^3 # optional - sage.modules
sage: v = V((1, 2, 3)) # optional - sage.modules
sage: cm = get_coercion_model()
sage: a = cm.get_action(V, QQ, operator.mul)
sage: a
Right scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field
sage: ~a
Right inverse action by Rational Field on Vector space of dimension 3 over Rational Field
sage: (~a)(v, 1/3)
sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules
sage: a # optional - sage.modules
Right scalar multiplication by Rational Field
on Vector space of dimension 3 over Rational Field
sage: ~a # optional - sage.modules
Right inverse action by Rational Field
on Vector space of dimension 3 over Rational Field
sage: (~a)(v, 1/3) # optional - sage.modules
(3, 6, 9)
sage: b = cm.get_action(QQ, V, operator.mul)
sage: b
Left scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field
sage: ~b
Left inverse action by Rational Field on Vector space of dimension 3 over Rational Field
sage: (~b)(1/3, v)
sage: b = cm.get_action(QQ, V, operator.mul) # optional - sage.modules
sage: b # optional - sage.modules
Left scalar multiplication by Rational Field
on Vector space of dimension 3 over Rational Field
sage: ~b # optional - sage.modules
Left inverse action by Rational Field
on Vector space of dimension 3 over Rational Field
sage: (~b)(1/3, v) # optional - sage.modules
(3, 6, 9)
sage: c = cm.get_action(ZZ, list, operator.mul)
Expand Down Expand Up @@ -390,11 +398,11 @@ cdef class InverseAction(Action):
Check that this action can be pickled (:trac:`29031`)::
sage: V = QQ^3
sage: v = V((1, 2, 3))
sage: cm = get_coercion_model()
sage: a = cm.get_action(V, QQ, operator.mul)
sage: loads(dumps(~a)) is not None
sage: V = QQ^3 # optional - sage.modules
sage: v = V((1, 2, 3)) # optional - sage.modules
sage: cm = get_coercion_model() # optional - sage.modules
sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules
sage: loads(dumps(~a)) is not None # optional - sage.modules
True
"""
return (type(self), (self._action,))
Expand Down Expand Up @@ -434,8 +442,9 @@ cdef class PrecomposedAction(Action):
sage: c,x = v[0]
sage: y = x.modular_symbol_rep()
sage: coercion_model.get_action(QQ, parent(y), op=operator.mul)
Left scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field
with precomposition on right by Coercion map:
Left scalar multiplication by Rational Field
on Abelian Group of all Formal Finite Sums over Rational Field
with precomposition on right by Coercion map:
From: Abelian Group of all Formal Finite Sums over Integer Ring
To: Abelian Group of all Formal Finite Sums over Rational Field
"""
Expand Down Expand Up @@ -542,8 +551,8 @@ cdef class ActionEndomorphism(Morphism):
sage: A = ZZ['x'].get_action(QQ, self_on_left=False, op=operator.mul)
sage: A
Left scalar multiplication by Rational Field on Univariate Polynomial
Ring in x over Integer Ring
Left scalar multiplication by Rational Field
on Univariate Polynomial Ring in x over Integer Ring
sage: A(1/2)
Action of 1/2 on Univariate Polynomial Ring in x over Integer Ring
under Left scalar multiplication by Rational Field on Univariate
Expand Down
Loading

0 comments on commit b378119

Please sign in to comment.