Dangerous mixing of different domains for symbolic variables

18 views
Skip to first unread message

Golam Mortuza Hossain

unread,
Sep 2, 2009, 7:49:33 AM9/2/09
to sage-...@googlegroups.com
Hi,

This is from sage-support

On Sep 1, 11:35 pm, Mani chandra <mchan...@iitk.ac.in> wrote:
>
--------
sage: x = a + I*b
sage: real(x.conjugate().simplify())
real_part(a) + imag_part(b)

sage: real(x.conjugate())
real_part(a) - imag_part(b)
---------

This seems to be happening because maxima(via simplify)
treats variables as real whereas pynac treats as complex.
----------
sage: x.conjugate()
conjugate(a) - I*conjugate(b)

sage: x.conjugate().simplify()
a - I*b
----------

William mentioned in this thread

http://groups.google.com/group/sage-support/browse_thread/thread/7bf451cf8202e085/10e81a803518f17c

that Sage does attempt to make default domain for maxima
to be complex. So something must be going horribly wrong.

Here is the trac ticket

http://trac.sagemath.org/sage_trac/ticket/6862


Cheers,
Golam

kcrisman

unread,
Sep 2, 2009, 9:31:44 AM9/2/09
to sage-devel

I wonder what the OP in the previous thread has for an OS, as well as
for you. That's because the code mentioned there in calculus/
calculus.py

maxima = Maxima(init_code = ['display2d:false; domain: complex;
keepfloat:
true; load(topoly_solver)'],
script_subdirectory=None)

seems to be not loading, perhaps. Note that

sage: y = x.conjugate()
sage: y.simplify??

sends one to symbolic/expression, and there it is simply y._maxima_()
which is invoked, which is imported from sage/calculus/calculus.

Is there any way to check what the domain is in a maxima session done
by Sage (as opposed to one initiated by the user)? This could be
related to the problem in reviewing #3587.

- kcrisman

Robert Dodier

unread,
Sep 2, 2009, 11:02:50 AM9/2/09
to sage-devel
FYI the Maxima functions conjugate, realpart/imagpart, & cabs/carg
have been revised recently. Maybe you can try it with the most recent
version (5.19.2). For the purposes of debugging I think it's best if
you
use Maxima directly instead of going through Sage.

On Sep 2, 5:49 am, Golam Mortuza Hossain <gmhoss...@gmail.com> wrote:

> This seems to be happening because maxima(via simplify)
> treats variables as real whereas pynac treats as complex.

FWIW in order for conjugate & friends to recognize variables as
complex, probably it is necessary to declare them as such
(i.e. declare(foo, complex)). I think domain:complex won't have
the same effect. Maybe Sage is already calling declare.

HTH

Robert Dodier

kcrisman

unread,
Sep 2, 2009, 11:13:22 AM9/2/09
to sage-devel
Very interesting. Continuing from the above code:

sage: assume(a,'complex')
sage: x.conjugate().simplify()
-I*b + conjugate(a)

Clearly we were not calling declare. Is there any way to do this for
ANY globally defined variable, though? It seems overkill to put it in
var(), and one wouldn't want it to conflict with (say) assume
(n,'integer') or something.

What does domain: complex do, then? Is it for solve, perhaps?

But as Robert says, Maxima performs as advertised. I think that it is
once again clear that Maxima (like matplotlib) has a lot of
functionality which remains unexposed.

- kcrisman

Golam Mortuza Hossain

unread,
Sep 2, 2009, 6:43:41 PM9/2/09
to sage-...@googlegroups.com
Hi,

On Wed, Sep 2, 2009 at 12:13 PM, kcrisman<kcri...@gmail.com> wrote:

>> FWIW in order for conjugate & friends to recognize variables as
>> complex, probably it is necessary to declare them as such
>> (i.e. declare(foo, complex)). I think domain:complex won't have
>> the same effect. Maybe Sage is already calling declare.
>
> Very interesting.  Continuing from the above code:
>
> sage: assume(a,'complex')
> sage: x.conjugate().simplify()
> -I*b + conjugate(a)
>
> Clearly we were not calling declare.  Is there any way to do this for
> ANY globally defined variable, though?  It seems overkill to put it in
> var(), and one wouldn't want it to conflict with (say) assume
> (n,'integer') or something.


In any case, current var() needs an upgrade. We now have three
tickets against it

(1) Custom typesetting:

http://trac.sagemath.org/sage_trac/ticket/6403

(2) Custom domain:

http://trac.sagemath.org/sage_trac/ticket/6559

(3) Syncing domain of variables with maxima:

http://trac.sagemath.org/sage_trac/ticket/6862


I did bit of work on the first two and unless someone else
fixes the third one, may be I will have a look at it.


Cheers,
Golam

Golam Mortuza Hossain

unread,
Sep 4, 2009, 9:32:40 AM9/4/09
to sage-...@googlegroups.com
Hi,

> On Wed, Sep 2, 2009 at 12:13 PM, kcrisman<kcri...@gmail.com> wrote:

>> Very interesting.  Continuing from the above code:
>>
>> sage: assume(a,'complex')
>> sage: x.conjugate().simplify()
>> -I*b + conjugate(a)
>>
>> Clearly we were not calling declare.  Is there any way to do this for
>> ANY globally defined variable, though?  It seems overkill to put it in
>> var(), and one wouldn't want it to conflict with (say) assume
>> (n,'integer') or something.


I played around little bit to fix this bug. Unfortunately, it doesn't seem
that we can avoid calling "declare()" in maxima for each (complex)
variable defined in sage.

The best thing we can do is to delay the declaration into maxima until
we actually need to call maxima to do some computation. This way
can avoid slowing down stuffs.

Maxima-interface experts: Is it possible to append such declaration
statements into maxima init string or similar?


Thanks,
Golam

William Stein

unread,
Sep 4, 2009, 10:15:22 AM9/4/09
to sage-devel
2009/9/4 Golam Mortuza Hossain <gmho...@gmail.com>:

>
> Hi,
>
>> On Wed, Sep 2, 2009 at 12:13 PM, kcrisman<kcri...@gmail.com> wrote:
>
>>> Very interesting.  Continuing from the above code:
>>>
>>> sage: assume(a,'complex')
>>> sage: x.conjugate().simplify()
>>> -I*b + conjugate(a)
>>>
>>> Clearly we were not calling declare.  Is there any way to do this for
>>> ANY globally defined variable, though?  It seems overkill to put it in
>>> var(), and one wouldn't want it to conflict with (say) assume
>>> (n,'integer') or something.
>
>
> I played around little bit to fix this bug. Unfortunately, it doesn't seem
> that we can avoid calling "declare()" in maxima for each (complex)
> variable defined in sage.
>
> The best thing we can do is to delay the declaration into maxima until
> we actually need to call maxima to do some computation.  This way
> can avoid slowing down stuffs.

This is definitely possible.

> Maxima-interface experts: Is it possible to append such declaration
> statements into maxima init string or similar?

That's definitely not the way to do it.

What we need is to queue up (put in some list somewhere) all
declaration that could ever be needed, then whenever we do a Sage -->
calculus Maxima conversion, we would empty the queue if it is
nonempty. Also, if Maxima were to crash/get restarted (does that ever
happen anymore), we would need to make sure all var's get set again.
This seems very do-able.

William

Reply all
Reply to author
Forward
0 new messages