Skip to content

Commit 2a3719e

Browse files
committed
More notes
1 parent e207052 commit 2a3719e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/doc/en/thematic_tutorials/coercion_and_categories.rst

+13-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Outline
4343
must not be overridden. Instead, the actual implementation should be in
4444
*single underscore* methods, such as ``_add_`` or ``_mul_``.
4545

46-
Exceptions are ``__lshift__``, ``__rshift__``, ``__invert__``,
47-
where no default implementation is provided.
46+
Exceptions are ``__lshift__``, ``__rshift__``, ``__and__``, ``__or__``,
47+
``__xor__``, ``__invert__``, where no default implementation is provided.
4848

4949
Also note that if the class is implemented in Cython, currently
5050
SageMath uses a legacy behavior with ``c_api_binop_methods=True``,
@@ -162,7 +162,7 @@ be complemented later.
162162
....: def characteristic(self):
163163
....: return self.base().characteristic()
164164

165-
.. end ouf output
165+
.. end of output
166166
167167
This basic implementation is formed by the following steps:
168168

@@ -189,6 +189,9 @@ This basic implementation is formed by the following steps:
189189
and it is requested to **implement SINGLE underscore methods ``_repr_``, and
190190
similarly ``_add_``, ``_mul_`` etc.**
191191

192+
The double underscore methods that can be implemented by subclasses are
193+
listed above.
194+
192195
- You are encouraged to **make your parent "unique"**. That's to say, parents
193196
should only evaluate equal if they are identical. Sage provides frameworks
194197
to create unique parents. We use here the most easy one: Inheriting from the
@@ -273,6 +276,13 @@ considerations:
273276
etc. **We do not override the default double underscore ``__add__``, ``__mul__``**,
274277
since otherwise, we could not use Sage's coercion model.
275278

279+
The double underscore methods that can be implemented by subclasses are
280+
listed above.
281+
282+
Note that the double-underscore method ``__neg__`` just directly call the
283+
single-underscore method ``_neg_``, the operation is unary so the coercion model
284+
is unnecessary.
285+
276286
- Comparisons can be implemented using ``_richcmp_``.
277287
This automatically makes the relational operators like
278288
``==`` and ``<`` work. Inside this method, you can use

0 commit comments

Comments
 (0)