#9989: easier access to operands of a symbolic expression
----------------------------------------------------+-----------------------
   Reporter:  burcin                                |          Owner:  burcin   
    
       Type:  enhancement                           |         Status:  
needs_review 
   Priority:  major                                 |      Milestone:  
sage-4.7.1   
  Component:  symbolics                             |       Keywords:           
    
Work_issues:                                        |       Upstream:  N/A      
    
   Reviewer:  Robert Bradshaw, Karl-Dieter Crisman  |         Author:  Burcin 
Erocal
     Merged:                                        |   Dependencies:           
    
----------------------------------------------------+-----------------------
Changes (by burcin):

  * status:  needs_work => needs_review
  * reviewer:  Robert Bradshaw, Karl-DIeter Crisman => Robert Bradshaw,
               Karl-Dieter Crisman


Comment:

 Thank you for the thorough reviews. I appreciate the feedback and it's
 certainly good for someone to look over my changes, since there are often
 rough edges I fail to see after staring at the code for a while.

 Replying to [comment:11 kcrisman]:

 > Questions, though.
 >  * Regarding the error message:
 > {{{
 > sage: f = 3*x^2+2*sin(x)-32*sin(ln(x))
 > sage: f.op[3]
 >
 ---------------------------------------------------------------------------
 > IndexError                                Traceback (most recent call
 last)
 > IndexError: operand index out of range, got 3, expect between -3 and 3
 > }}}
 >    Is this really the error message we want?  Here it's the 'exclusive'
 between, but that could be confusing.  Maybe it should say between -3 and
 2 (length ops -1)?

 Fixed.

 >  * Next, I wonder whether the following can be supported:
 > {{{
 > sage: f.op[2:3,3]
 > TypeError: an integer is required
 > }}}
 >    since matrices can do this
 > {{{
 > sage: M = matrix(4,range(16))
 > sage: M[2:3]
 > [ 8  9 10 11]
 > sage: M[2:3,3]
 > [11]
 > }}}
 >    The current code ends everything if it's a slice; you just get the
 operands at that level.  But it would be interesting to get the 2nd
 element of each operand, though perhaps not very useful since you might
 not know what it is ahead of time.  But perhaps for very regular
 expressions (Christoffel symbol-type surfeit of indices?) it could be
 useful.  We might also want something like `sage: M[2:3,3:4]` to be
 supported, such as `sage: f.op[2,0:1]` instead of having to do
 > {{{
 > sage: f.op[2].op[0:1]
 > [sin(log(x))]
 > }}}
 >    But maybe going back and forth between Ginac and Sage in the way
 you'd have to for that is tricky.

 The output is a list if the index is a slice. We could pass further
 indices to the list's `__getitem__()` of course, though I'm not convinced
 this convenience is really a good feature.

 >  * Here is something needed for sure:
 > {{{
 > sage: f = 3*x^2+2*sin(x)-32*sin(ln(x))
 > sage: f[1]
 >
 ---------------------------------------------------------------------------
 > TypeError                                 Traceback (most recent call
 last)
 > TypeError: 'sage.symbolic.expression.Expression' object does not support
 indexing
 > sage: search_src('does not support indexing')
 > <no response>
 > }}}
 >    We should have at least one doctest ''somewhere'' that tests this.

 I added a test in the docstring for `__get__` in `expression.pyx`.


 For patchbot:

 Apply trac_9989-operands.take3.patch

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9989#comment:12>
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