#9964: Document _pari_ and _pari_init_
-----------------------------+----------------------------------------------
   Reporter:  jdemeyer       |       Owner:  mvngu   
       Type:  defect         |      Status:  new     
   Priority:  blocker        |   Milestone:  sage-4.6
  Component:  documentation  |    Keywords:          
     Author:                 |    Upstream:  N/A     
   Reviewer:                 |      Merged:          
Work_issues:                 |  
-----------------------------+----------------------------------------------

Comment(by mhansen):

 I'll add my post from sage-devel here.

 {{{

 Here's what is going on.  We have the pexpect interface to GP (which
 we will refer to as gp) as well as C interface to PARI (which we will
 refer to as pari).

 gp:
   - Defined in sage/intefaces/gp.py
   - Specifies name="pari" in the constructor
 (sage/interfaces/gp.py:156), which would normally make gp(foo) try to
 call foo._pari_(), but there is special case code in Expect.__call__
 to change this to use foo._gp_() instead.
 (sage/interfaces/expect.py:1056)
   -  foo._gp_(gp) which is supposed to return a GpElement
   - SageObject provides a default implementation of _gp_() which
 calls SageObject._interface_(gp), which in turn tries to call
 _pari_init_ (since gp has name="pari")
   - Generally, the thing returned from the _XXX_init_ methods is a
 string, but what really matters is that it is some object such that
 when it's passed to the __call__ method of the interface object, it
 "returns the right thing".  See sage/structure/sage_object.pyx:387.
   - SageObject also defines a default implementation of _gp_init_
 which just calls _pari_init_.  I don't think this function is run
 anywhere.


 pari:
  - Defined in sage/libs/pari/gen.pyx
  - Uses foo._pari_() which is supposed to return a PARI GEN object.
 sage/libs/pari/gen.pyx:8414
  - SageObject defines a default implementation of _pari_() which will
 try calling pari(foo._pari_init_()).
  - pari("string") will eventually call gp_read_str("string") which
 should return a GEN object.

 The idea behind all of the _XXX_ and _XXX_init_ methods is that _XXX_
 returns the actual object whereas _XXX_init_ returns something which
 is fed into the parent's __call__ method.

 The reason why the PARI situation is a bit more complicated is that
 anything string you return from _gp_init_ should be valid as a
 _pari_init_ function.  We should really name the name="pari" in the gp
 Expect object so that we can remove the special case code.  We should
 then also just have the default implementation of _gp_init_ call
 _pari_init_ so that if you just define that, it will work for both gp
 and pari.
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9964#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to