Skip to content

Commit e23375f

Browse files
committed
Minor refactor for is_exact
1 parent e7477f8 commit e23375f

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-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 is exact.
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
@@ -1008,6 +1008,24 @@ def is_sparse(self):
10081008
"""
10091009
return self.__is_sparse
10101010

1011+
def is_exact(self):
1012+
"""
1013+
Test whether elements of this module is exact.
1014+
1015+
OUTPUT:
1016+
1017+
Return ``True`` if elements of this module are represented exactly, i.e.,
1018+
there is no precision loss when doing arithmetic.
1019+
1020+
EXAMPLES::
1021+
1022+
sage: (ZZ^2).is_exact()
1023+
True
1024+
sage: (RR^2).is_exact()
1025+
False
1026+
"""
1027+
return self._base.is_exact()
1028+
10111029
def _an_element_(self):
10121030
"""
10131031
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
@@ -520,29 +520,6 @@ cdef class Ring(ParentWithGens):
520520
else:
521521
return False
522522

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

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 is exact.
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)