Hi there,

I'm working on #11576 "make it possible to generate sequences of variables
easily". I actually need to achieve a larger goal: I need to have symbolic
variables indexed by any Sage objects (eg: integers, group element,
matrices...). As as said previously here, I started to work on Burcin patch.
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
from #11576 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)
[...]
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

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to