#11576: make it possible to generate sequences of variables easily
---------------------------+------------------------------------------------
   Reporter:  kcrisman     |          Owner:  burcin  
       Type:  enhancement  |         Status:  new     
   Priority:  major        |      Milestone:  sage-4.8
  Component:  symbolics    |       Keywords:          
Work_issues:               |       Upstream:  N/A     
   Reviewer:               |         Author:          
     Merged:               |   Dependencies:          
---------------------------+------------------------------------------------

Comment(by hivert):

 Hi there,

 As as said on sage-devel, I started to work on Burcin patch. My goal was
 to be
 able to index a variable by '''any''' Sage object (eg: integers, group
 element, matrices...). So I extended a little Burcin patch. Now I'm faced
 with
 the problem that GiNaC indexed variable seems to have a not trivial
 semantic
 that I don't understand at all. Moreover I don't know how to debug Cython
 /
 C++ code so I'm quite stuck. Here is the problem I have.

 To get it you should apply attachment:indexed_expression-experimental-
 fh.patch
 on a fresh Sage-4.7.2 install. Then I can
 {{{
 sage: m1 = matrix([1,2]); m1.set_immutable()
 sage: m2 = matrix([2,1]); m2.set_immutable()
 sage: a = x.ind[m1]; b = 2*x.ind[m2]
 sage: a + a
 2*x.[1 2]
 sage: a + b
 x.[1 2] + 2*x.[2 1]
 }}}
 which is, in my view very cool !

 However strange thing has occurred under the hood, in particular for a
 strange
 reason I don't understand Sage added the two matrices ! This is apparent
 in
 {{{
 sage: a = x.ind[Permutation([3,2,1])]; b = 2*x.ind[1]
 sage: a+b
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)

 /home/data/Sage-Install/sage-4.7.2/devel/sage-
 review/sage/symbolic/<ipython console> in <module>()

 /home/florent/src/Sage/sage/local/lib/python2.6/site-
 packages/sage/structure/element.so in
 sage.structure.element.RingElement.__add__
 (sage/structure/element.c:11488)()

 /home/florent/src/Sage/sage/local/lib/python2.6/site-
 packages/sage/symbolic/expression.so in
 sage.symbolic.expression.Expression._add_
 (sage/symbolic/expression.cpp:11082)()
    2186                            relational_operator(_right._gobj))
    2187         else:
 -> 2188             x = gadd(left._gobj, _right._gobj)
    2189         return new_Expression_from_GEx(left._parent, x)
    2190

 /home/florent/src/Sage/sage/local/lib/python2.6/site-
 packages/sage/structure/element.so in
 sage.structure.element.RingElement.__sub__
 (sage/structure/element.c:11816)()

 /home/florent/src/Sage/sage/local/lib/python2.6/site-
 packages/sage/structure/coerce.so in
 sage.structure.coerce.CoercionModel_cache_maps.bin_op
 (sage/structure/coerce.c:7489)()

 TypeError: unsupported operand parent(s) for '-': '<class
 'sage.combinat.permutation.Permutation_class'>' and 'Integer Ring'
 }}}
 To make thing crystal clear (I hope):
 {{{
 sage: class bla(SageObject):
 ...       def __add__(self, other):
 ...           print "Addition called"
 sage: a, b = x.ind[m1],2*x.ind[m2]
 sage: m1 = bla()
 sage: m2 = bla()
 sage: m1 + m2
 Addition called
 sage: m1*m2
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)

 /home/data/Sage-Install/sage-4.7.2/devel/sage-
 review/sage/symbolic/<ipython console> in <module>()

 TypeError: unsupported operand type(s) for *: 'bla' and 'bla'
 }}}

 WTF ! Why is it adding or multiplying my indices for nothing ! It is a
 problem
 of Ginac ? of the wrapper ? or behind the chair and the screen ?

 Any help greatly appreciated !

 Cheers,

 Florent

 PS: crosspost on sage-devel.

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