Skip to content

Commit 86a0d44

Browse files
author
Release Manager
committed
gh-39837: Richcmp for pseudomorphisms This PR implements rich comparison for pseudomorphisms. Fixes #39807 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. URL: #39837 Reported by: Xavier Caruso Reviewer(s): user202729, Xavier Caruso
2 parents 4dfd788 + c888597 commit 86a0d44

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/sage/modules/free_module_pseudomorphism.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# ****************************************************************************
2323

2424
from sage.categories.morphism import Morphism
25-
from sage.structure.richcmp import rich_to_bool, richcmp
25+
from sage.structure.richcmp import richcmp
2626
from sage.modules.free_module_morphism import FreeModuleMorphism
2727

2828

@@ -463,7 +463,7 @@ def side_switch(self):
463463
def __nonzero__(self):
464464
return not (self._derivation is None and self._matrix)
465465

466-
def __eq__(self, other):
466+
def _richcmp_(self, other, op):
467467
r"""
468468
Compare this morphism with ``other``.
469469
@@ -472,7 +472,7 @@ def __eq__(self, other):
472472
sage: Fq.<z> = GF(7^3)
473473
sage: Frob = Fq.frobenius_endomorphism()
474474
sage: V = Fq^2
475-
sage: m = random_matrix(Fq, 2)
475+
sage: m = matrix(2, 2, [z, z^3, z^5, z^7])
476476
477477
sage: f = V.pseudohom(m, Frob)
478478
sage: g = V.pseudohom(m.transpose(), Frob, side="right")
@@ -482,6 +482,12 @@ def __eq__(self, other):
482482
sage: g = V.pseudohom(m.transpose(), Frob)
483483
sage: f == g
484484
False
485+
sage: f < g
486+
True
487+
sage: f > g
488+
False
489+
490+
::
485491
486492
sage: g = V.pseudohom(m, Frob^2)
487493
sage: f == g
@@ -491,14 +497,15 @@ def __eq__(self, other):
491497
sage: h = V.hom(m)
492498
sage: g == h
493499
True
500+
501+
::
502+
503+
sage: f < V
504+
Traceback (most recent call last):
505+
...
506+
TypeError: unsupported operand parent(s) for <: 'Set of Pseudoendomorphisms (twisted by z |--> z^7) of Vector space of dimension 2 over Finite Field in z of size 7^3' and '<class 'sage.modules.free_module.FreeModule_ambient_field_with_category'>'
494507
"""
495-
if isinstance(other, FreeModuleMorphism):
496-
try:
497-
other = self.parent()(other)
498-
except ValueError:
499-
return False
500-
if isinstance(other, FreeModulePseudoMorphism):
501-
return self.parent() is other.parent() and self._matrix == other._matrix
508+
return richcmp(self._matrix, other._matrix, op)
502509

503510
def ore_module(self, names=None):
504511
r"""

0 commit comments

Comments
 (0)