Skip to content

Improve documentation of various gap-related methods #39905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/sage/libs/gap/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ cdef initialize()
### Evaluate string in GAP #################################################
############################################################################

# Evaluate a string
cdef Obj gap_eval(str gap_string) except? NULL
4 changes: 4 additions & 0 deletions src/sage/libs/gap/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ cdef Obj gap_eval(str gap_string) except? NULL:
r"""
Evaluate a string in GAP.

This function cannot be used directly from Python, use
:meth:`~sage.libs.gap.libgap.Gap.eval` method on global ``libgap``
variable instead.

INPUT:

- ``gap_string`` -- string; a valid statement in GAP
Expand Down
67 changes: 67 additions & 0 deletions src/sage/structure/sage_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,84 @@ cdef class SageObject:
return True

def _gap_(self, G=None):
"""
Return a Gap object.

Unlike :meth:`_libgap_`, this method returns an instance of
:class:`sage.interfaces.gap.GapElement`, which wraps an object
in the GAP interpreter spawned as a subprocess of Sage.

Typically you should not need to call this method directly,
instead just call :mod:`~sage.interfaces.gap`
on the object. See example below.

EXAMPLES::

sage: a = gap(2/3); a
2/3
sage: type(a)
<class 'sage.interfaces.gap.GapElement'>

sage: a = (2/3)._gap_(); a
2/3
sage: type(a)
<class 'sage.interfaces.gap.GapElement'>
"""
if G is None:
import sage.interfaces.gap
G = sage.interfaces.gap.gap
return self._interface_(G)

def _gap_init_(self):
"""
Return a string that provides a representation of ``self`` in GAP.

This method is indirectly used by :meth:`_libgap_` and :meth:`_gap_`
by essentially passing their output to
:meth:`libgap.eval <sage.libs.gap.libgap.Gap.eval>`
and :mod:`~sage.interfaces.gap` respectively,
unless the subclass overrides them with more efficient variants.

EXAMPLES::

sage: (2/3)._gap_init_()
'2/3'
sage: Zmod(4)._gap_init_()
'ZmodnZ(4)'
"""
import sage.interfaces.gap
I = sage.interfaces.gap.gap
return self._interface_init_(I)

def _libgap_(self):
"""
Return a libgap object.

Unlike :meth:`_gap_`, this method returns an instance of
:class:`sage.libs.gap.libgap.GapElement`, which wraps an object
in libgap embedded in Sage. As explained in
:mod:`sage.libs.gap.libgap`, this is much faster.

Typically you should not need to call this method directly,
instead use :mod:`~sage.libs.gap.libgap`. See example below.

By default, this method makes use of :meth:`_gap_init_`.
Subclasses could override this method to provide a more efficient
implementation.

EXAMPLES::

sage: a = libgap(2/3); a
2/3
sage: type(a)
<class 'sage.libs.gap.element.GapElement_Rational'>

TESTS::

sage: from sage.libs.gap.element import GapElement
sage: isinstance(a, GapElement)
True
"""
from sage.libs.gap.libgap import libgap
return libgap.eval(self)

Expand Down
Loading