@@ -741,17 +741,96 @@ cdef class SageObject:
741
741
return True
742
742
743
743
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
+ """
744
767
if G is None :
745
768
import sage.interfaces.gap
746
769
G = sage.interfaces.gap.gap
747
770
return self ._interface_(G)
748
771
749
772
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
+ """
750
789
import sage.interfaces.gap
751
790
I = sage.interfaces.gap.gap
752
791
return self ._interface_init_(I)
753
792
754
793
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
+ """
755
834
from sage.libs.gap.libgap import libgap
756
835
return libgap.eval(self )
757
836
0 commit comments