Skip to content

Commit a247fc7

Browse files
author
Release Manager
committed
sagemathgh-39137: Minor refactor for is_exact The method is unnecessarily duplicated, which this pull request removes. Besides, it wasn't originally correctly implemented for modules and matrix spaces. Fixed now. Side note: technically a matrix space over R is a (usually noncommutative) R-algebra, which is in turn a R-module. Yet MatrixSpace doesn't inherit from Module? ### 📝 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 created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39137 Reported by: user202729 Reviewer(s): Frédéric Chapoton
2 parents fad9f15 + 06bd6f4 commit a247fc7

File tree

5 files changed

+52
-26
lines changed

5 files changed

+52
-26
lines changed

src/sage/matrix/matrix_space.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,24 @@ def characteristic(self):
955955
"""
956956
return self.base_ring().characteristic()
957957

958+
def is_exact(self):
959+
"""
960+
Test whether elements of this matrix space are represented exactly.
961+
962+
OUTPUT:
963+
964+
Return ``True`` if elements of this matrix space are represented exactly, i.e.,
965+
there is no precision loss when doing arithmetic.
966+
967+
EXAMPLES::
968+
969+
sage: MatrixSpace(ZZ, 3).is_exact()
970+
True
971+
sage: MatrixSpace(RR, 3).is_exact()
972+
False
973+
"""
974+
return self._base.is_exact()
975+
958976
def _has_default_implementation(self):
959977
r"""
960978
EXAMPLES::

src/sage/modules/free_module.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,24 @@ def is_sparse(self):
998998
"""
999999
return self.__is_sparse
10001000

1001+
def is_exact(self):
1002+
"""
1003+
Test whether elements of this module are represented exactly.
1004+
1005+
OUTPUT:
1006+
1007+
Return ``True`` if elements of this module are represented exactly, i.e.,
1008+
there is no precision loss when doing arithmetic.
1009+
1010+
EXAMPLES::
1011+
1012+
sage: (ZZ^2).is_exact()
1013+
True
1014+
sage: (RR^2).is_exact()
1015+
False
1016+
"""
1017+
return self._base.is_exact()
1018+
10011019
def _an_element_(self):
10021020
"""
10031021
Return an arbitrary element of a free module.

src/sage/rings/ring.pyx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,29 +518,6 @@ cdef class Ring(ParentWithGens):
518518
else:
519519
return False
520520

521-
cpdef bint is_exact(self) except -2:
522-
"""
523-
Return ``True`` if elements of this ring are represented exactly, i.e.,
524-
there is no precision loss when doing arithmetic.
525-
526-
.. NOTE::
527-
528-
This defaults to ``True``, so even if it does return ``True`` you
529-
have no guarantee (unless the ring has properly overloaded this).
530-
531-
EXAMPLES::
532-
533-
sage: QQ.is_exact() # indirect doctest
534-
True
535-
sage: ZZ.is_exact()
536-
True
537-
sage: Qp(7).is_exact() # needs sage.rings.padics
538-
False
539-
sage: Zp(7, type='capped-abs').is_exact() # needs sage.rings.padics
540-
False
541-
"""
542-
return True
543-
544521
def order(self):
545522
"""
546523
The number of elements of ``self``.

src/sage/schemes/elliptic_curves/ell_generic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,19 @@ def is_on_curve(self, x, y):
10761076
a = self.ainvs()
10771077
return y**2 + a[0]*x*y + a[2]*y == x**3 + a[1]*x**2 + a[3]*x + a[4]
10781078

1079+
def is_exact(self):
1080+
"""
1081+
Test whether elements of this elliptic curve are represented exactly.
1082+
1083+
EXAMPLES::
1084+
1085+
sage: EllipticCurve(QQ, [1, 2]).is_exact()
1086+
True
1087+
sage: EllipticCurve(RR, [1, 2]).is_exact()
1088+
False
1089+
"""
1090+
return self.__base_ring.is_exact()
1091+
10791092
def a_invariants(self):
10801093
r"""
10811094
The `a`-invariants of this elliptic curve, as a tuple.

src/sage/structure/parent.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,17 +2863,17 @@ cdef class Parent(sage.structure.category_object.CategoryObject):
28632863

28642864
cpdef bint is_exact(self) except -2:
28652865
"""
2866-
Test whether the ring is exact.
2866+
Test whether elements of this parent are represented exactly.
28672867
28682868
.. NOTE::
28692869
28702870
This defaults to true, so even if it does return ``True``
2871-
you have no guarantee (unless the ring has properly
2871+
you have no guarantee (unless the parent has properly
28722872
overloaded this).
28732873
28742874
OUTPUT:
28752875
2876-
Return ``True`` if elements of this ring are represented exactly, i.e.,
2876+
Return ``True`` if elements of this parent are represented exactly, i.e.,
28772877
there is no precision loss when doing arithmetic.
28782878
28792879
EXAMPLES::

0 commit comments

Comments
 (0)