@@ -741,17 +741,84 @@ 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. As explained in
800+ :mod:`sage.libs.gap.libgap`, this is much faster.
801+
802+ Typically you should not need to call this method directly,
803+ instead use :mod:`~sage.libs.gap.libgap`. See example below.
804+
805+ By default, this method makes use of :meth:`_gap_init_`.
806+ Subclasses could override this method to provide a more efficient
807+ implementation.
808+
809+ EXAMPLES::
810+
811+ sage: a = libgap(2/3); a
812+ 2/3
813+ sage: type(a)
814+ <class 'sage.libs.gap.element.GapElement_Rational'>
815+
816+ TESTS::
817+
818+ sage: from sage.libs.gap.element import GapElement
819+ sage: isinstance(a, GapElement)
820+ True
821+ """
755822 from sage.libs.gap.libgap import libgap
756823 return libgap.eval(self )
757824
0 commit comments