Skip to content

Commit f32e829

Browse files
committed
Improve documentation of various gap-related methods
1 parent 871ba9d commit f32e829

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

src/sage/libs/gap/util.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,4 @@ cdef initialize()
4242
### Evaluate string in GAP #################################################
4343
############################################################################
4444

45-
# Evaluate a string
4645
cdef Obj gap_eval(str gap_string) except? NULL

src/sage/libs/gap/util.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ cdef Obj gap_eval(str gap_string) except? NULL:
293293
r"""
294294
Evaluate a string in GAP.
295295
296+
This function cannot be used directly from Python, use
297+
:meth:`~sage.libs.gap.libgap.Gap.eval` method on global ``libgap``
298+
variable instead.
299+
296300
INPUT:
297301
298302
- ``gap_string`` -- string; a valid statement in GAP

src/sage/structure/sage_object.pyx

+79
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,96 @@ cdef class SageObject:
741741
return True
742742

743743
def _gap_(self, G=None):
744+
"""
745+
Return a Gap object.
746+
747+
Unlike :meth:`_libgap_`, this method returns an instance of
748+
:class:`sage.interfaces.gap.GapElement`, which wraps an object
749+
in the GAP interpreter spawned as a subprocess of Sage.
750+
751+
Typically you should not need to call this method directly,
752+
instead just call :mod:`~sage.interfaces.gap`
753+
on the object. See example below.
754+
755+
EXAMPLES::
756+
757+
sage: a = gap(2/3); a
758+
2/3
759+
sage: type(a)
760+
<class 'sage.interfaces.gap.GapElement'>
761+
762+
sage: a = (2/3)._gap_(); a
763+
2/3
764+
sage: type(a)
765+
<class 'sage.interfaces.gap.GapElement'>
766+
"""
744767
if G is None:
745768
import sage.interfaces.gap
746769
G = sage.interfaces.gap.gap
747770
return self._interface_(G)
748771

749772
def _gap_init_(self):
773+
"""
774+
Return a string that provides a representation of ``self`` in GAP.
775+
776+
This method is indirectly used by :meth:`_libgap_` and :meth:`_gap_`
777+
by essentially passing their output to
778+
:meth:`libgap.eval <sage.libs.gap.libgap.Gap.eval>`
779+
and :mod:`~sage.interfaces.gap` respectively,
780+
unless the subclass overrides them with more efficient variants.
781+
782+
EXAMPLES::
783+
784+
sage: (2/3)._gap_init_()
785+
'2/3'
786+
sage: Zmod(4)._gap_init_()
787+
'ZmodnZ(4)'
788+
"""
750789
import sage.interfaces.gap
751790
I = sage.interfaces.gap.gap
752791
return self._interface_init_(I)
753792

754793
def _libgap_(self):
794+
"""
795+
Return a libgap object.
796+
797+
Unlike :meth:`_gap_`, this method returns an instance of
798+
:class:`sage.libs.gap.libgap.GapElement`, which wraps an object
799+
in libgap embedded in Sage.
800+
801+
Typically you should not need to call this method directly,
802+
instead use :mod:`~sage.libs.gap.libgap`. See example below.
803+
804+
By default, this method makes use of :meth:`_gap_init_`.
805+
Subclasses could override this method to provide a more efficient
806+
implementation.
807+
808+
EXAMPLES::
809+
810+
sage: a = libgap(2/3); a
811+
2/3
812+
sage: type(a)
813+
<class 'sage.libs.gap.element.GapElement_rational'>
814+
815+
``GapElement_rational`` is a subclass of ``GapElement``::
816+
817+
sage: from sage.libs.gap.element import GapElement
818+
sage: isinstance(a, GapElement)
819+
True
820+
821+
The difference between ``libgap`` and ``libgap.eval`` is demonstrated below::
822+
823+
sage: libgap("1+2")
824+
"1+2"
825+
sage: libgap.eval("1+2")
826+
3
827+
828+
Nonetheless, when the argument to ``libgap.eval`` is not a string,
829+
its behavior is identical to ``libgap``::
830+
831+
sage: libgap.eval(2/3)
832+
2/3
833+
"""
755834
from sage.libs.gap.libgap import libgap
756835
return libgap.eval(self)
757836

0 commit comments

Comments
 (0)