Hi Burcin,

> Your example was trying to multiply two instances of the class bla.
> Here is what I guess you meant to write:
> 
> sage: m1 = bla()
> sage: m2 = bla()
> sage: a, b = x.ind[m1],2*x.ind[m2]
> Traceback (most recent call last)
> <snip>
> in sage.symbolic.expression.Expression._add_
> (sage/symbolic/expression.cpp:11082)()
> 
> TypeError: unsupported operand type(s) for -: 'bla' and 'bla'
> 
> 
> Note that it is trying to subtract the objects. Probably trying to
> check equality. :)

Of course ! I should had figured out it !

> > 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 ?
> 
> Here is the backtrace:
> 
> Breakpoint 2, GiNaC::numeric::sub (this=0x7fffffffb4a0, other=...)
>     at numeric.cpp:1745
> 1745      {
> (gdb) call this->dbgprint()
> <class '__main__.bla'>
> (gdb) call other.dbgprint()
> <class '__main__.bla'>
> (gdb) bt
> #0  GiNaC::numeric::sub (this=0x7fffffffb4a0, other=...) at numeric.cpp:1745
> #1  0x00007fffd687c599 in GiNaC::operator- (lh=<value optimized out>, 
>     rh=<value optimized out>) at operators.cpp:97
> #2  0x00007fffd6879226 in GiNaC::numeric::compare_same_type (this=0x4796060, 
>     other=...) at numeric.cpp:1700
> #3  0x00007fffd67ca25a in compare (this=0x3d9cd10, other=...) at ex.h:339
> #4  GiNaC::idx::compare_same_type (this=0x3d9cd10, other=...) at idx.cpp:278
> #5  0x00007fffd6ce0aad in compare (this=<value optimized out>, 
>     other=<value optimized out>)
>     at /home/burcin/sage/sage-4.7.2/local/include/pynac/ex.h:339
> #6  GiNaC::container<std::vector>::compare_same_type (
>     this=<value optimized out>, other=<value optimized out>)
>     at /home/burcin/sage/sage-4.7.2/local/include/pynac/container.h:625
> #7  0x00007fffd67b5f5e in compare (this=0x45508e0, lh=<value optimized out>, 
>     rh=...) at ex.h:339
> #8  GiNaC::expairseq::construct_from_2_ex (this=0x45508e0, 
>     lh=<value optimized out>, rh=...) at expairseq.cpp:887
> #9  0x00007fffd6771beb in GiNaC::add::add (this=0x45508e0, lh=..., rh=...)
>     at add.cpp:70
> #10 0x00007fffd687c46c in exadd (lh=..., rh=...) at operators.cpp:42
> #11 GiNaC::operator+ (lh=..., rh=...) at operators.cpp:69
> #12 0x00007fffd644e489 in
> __pyx_f_4sage_8symbolic_10expression_10Expression__add_
> (__pyx_v_left=0x4757050, __pyx_v_right=0x4757d40, 

I should really learn how to debug those. Is
    http://wiki.cython.org/DebuggingTechniques
the best starting point. Any suggestions ?


> In English: it tries to normalize the resulting expression in 
> construct_from_2_ex(). This means checking if the two arguments are equal. 
> Going through idx::compare_same type(), it ends up in 
> numeric::compare_same_type(). Here is the code for that function:
> 
>   int numeric::compare_same_type(const basic &other) const
>   {
>     GINAC_ASSERT(is_exactly_a<numeric>(other));
>     const numeric &o = static_cast<const numeric &>(other);
>     int cmpval = (real() - o.real()).csgn();
>     if (cmpval != 0)
>           return cmpval;
>     return (imag() - o.imag()).csgn();
>   }
> 
> We should change this somehow. Maybe we could try PyObject_Compare and fall 
> back to this if it fails.

Looks to me like a solution. Does it mean patch GiNaC at sage level or at
PyNaC level ?

> Comments?

Is there a way to tell, at the Ginac/C++ level, if an object is a standard
GiNaC one or an abject wrapping a Python object ?

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