How does one define a "real" variable

1,540 views
Skip to first unread message

Mani chandra

unread,
Aug 21, 2009, 11:32:38 AM8/21/09
to sage-s...@googlegroups.com
Hi,

How does one define a variable in sage and make sure the it's
conjugate is the same as the variable itself?

Thanks,
Mani chandra

Mani chandra

unread,
Aug 22, 2009, 6:13:55 AM8/22/09
to sage-s...@googlegroups.com
Hi,

Perhaps I wasn't specific.

sage: var('a')
sage: a.conjugate()
conjugate(a)

What I want is for SAGE to return a, instead of conjugate(a). Does "var"
take any arguments that forces a variable to be real?

This is implemented in the sympy package, which I tried to use inside
sage, but..

sage: from sympy import symbols
sage: a, b = symbols('a, b', real=True)
sage: a.conjugate()
a
sage: b.conjugate()
b
sage: x = symbols('x')
sage: x = a + I*b
sage: x.conjugate()
conjugate(a) - I*conjugate(b)

Shouldn't it return a - I*b, instead of conjugate(a) - I*conjugate(b) ?
It does however give the correct answer when I overwrite SAGE's
namespace with sympy's namespace:

sage: from sympy import *
sage: a, b = symbols('a, b', real=True)
sage: x = symbols('x')
sage: x = a + I*b
sage: a.conjugate()
a
sage: b.conjugate()
b
sage: x.conjugate()
a - I*b


William Stein

unread,
Aug 22, 2009, 6:29:19 AM8/22/09
to sage-s...@googlegroups.com
On Sat, Aug 22, 2009 at 3:13 AM, Mani chandra <mcha...@iitk.ac.in> wrote:

Mani chandra wrote:
> Hi,
>
>     How does one define a variable in sage and make sure the it's
> conjugate is the same as the variable itself?
>
> Thanks,
> Mani chandra
>
> >
>
>
Hi,

   Perhaps I wasn't specific.

sage: var('a')
sage: a.conjugate()
conjugate(a)

What I want is for SAGE to return a, instead of conjugate(a). Does "var"
take any arguments that forces a variable to be real?

Unfortunately, I don't think this is implemented yet.

 -- William 



--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Mani chandra

unread,
Aug 22, 2009, 6:40:10 AM8/22/09
to sage-s...@googlegroups.com
William Stein wrote:
>
>
>
> sage: var('a')
> sage: a.conjugate()
> conjugate(a)
>
> What I want is for SAGE to return a, instead of conjugate(a). Does
> "var"
> take any arguments that forces a variable to be real?
>
>
> Unfortunately, I don't think this is implemented yet.
>
> -- William
>
>
Hi,
Can this be some sort of a feature request for the next release?

Thanking you,
Mani chandra

Message has been deleted

Mani chandra

unread,
Aug 22, 2009, 10:16:05 AM8/22/09
to sage-s...@googlegroups.com
Minh Nguyen wrote:
> Hi Mani,
> See ticket #6802:
>
> http://trac.sagemath.org/sage_trac/ticket/6802
>
>
Oops, I should have checked before asking for a feature request. There
seems to be a ticket on this topic since about 5 weeks.

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

Mani chandra

Message has been deleted

Golam Mortuza Hossain

unread,
Aug 22, 2009, 11:11:53 AM8/22/09
to sage-support
Hi,

On Aug 22, 11:20 am, Minh Nguyen <nguyenmi...@gmail.com> wrote:
> On Sun, Aug 23, 2009 at 12:16 AM, Mani chandra<mchan...@iitk.ac.in> wrote:
> >>>       Can this be some sort of a feature request for the next release?
>
> >> See ticket #6802:
>
> >>http://trac.sagemath.org/sage_trac/ticket/6802
>
> > Oops, I should have checked before asking for a feature request. There
> > seems to be a ticket on this topic since about 5 weeks.
>
> >http://trac.sagemath.org/sage_trac/ticket/6559


Here are some related discussions and a pynac patch

http://groups.google.com/group/pynac-devel/browse_thread/thread/76868c8ad5ae5b70

Burcin suggested that to avoid potential issue of having
two different symbols of different domain, we need to move symbol
directory into sage.


Cheers,
Golam

Robert Bradshaw

unread,
Aug 22, 2009, 1:28:56 PM8/22/09
to sage-s...@googlegroups.com
On Aug 22, 2009, at 3:13 AM, Mani chandra wrote:

>
> Mani chandra wrote:
>> Hi,
>>
>> How does one define a variable in sage and make sure the it's
>> conjugate is the same as the variable itself?
>>
>> Thanks,
>> Mani chandra
>>
>>>
>>
>>
> Hi,
>
> Perhaps I wasn't specific.
>
> sage: var('a')
> sage: a.conjugate()
> conjugate(a)
>
> What I want is for SAGE to return a, instead of conjugate(a). Does
> "var"
> take any arguments that forces a variable to be real?

You have to invoke simplify for it to look at assumptions.

sage: var('a')
sage: assume(a, 'real')
sage: a.conjugate().simplify()
a

- Robert

Mani chandra

unread,
Aug 22, 2009, 2:03:58 PM8/22/09
to sage-s...@googlegroups.com
There seems to be something wrong with this implementation:
sage: var('a, b')
(a, b)
sage: assume(a, 'real')
sage: assume(b, 'real')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)

/home/mc/<ipython console> in <module>()

/opt/sage/sage/local/lib/python2.6/site-packages/sage/symbolic/assumptions.pyc
in assume(*args)
194 else:
195 try:
--> 196 x.assume()
197 except KeyError:
198 raise TypeError, "assume not defined for objects
of type '%s'"%type(x)

/opt/sage/sage/local/lib/python2.6/site-packages/sage/symbolic/assumptions.pyc
in assume(self)
96 maxima.set("context", cur)
97
---> 98 if not self in _assumptions:
99 maxima.activate(self._context)
100 _assumptions.append(self)

/opt/sage/sage/local/lib/python2.6/site-packages/sage/symbolic/assumptions.pyc
in __cmp__(self, other)
70 if isinstance(self, GenericDeclaration) and
isinstance(other, GenericDeclaration):
71 return cmp( (self._var, self._assumption),
---> 72 (other._var, other._assumption) )
73 else:
74 return cmp(type(self), type(other))

/opt/sage/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.__nonzero__
(sage/symbolic/expression.cpp:7506)()

AttributeError: 'GenericDeclaration' object has no attribute 'variables'


Looks like it can define only one variable in the namespace as real.
This is pretty strange.

--Mani chandra

Golam Mortuza Hossain

unread,
Aug 22, 2009, 4:23:56 PM8/22/09
to sage-s...@googlegroups.com
Hi,


On Sat, Aug 22, 2009 at 2:28 PM, Robert
Bradshaw<robe...@math.washington.edu> wrote:
> You have to invoke simplify for it to look at assumptions.
>
> sage: var('a')
> sage: assume(a, 'real')
> sage: a.conjugate().simplify()
> a

I guess, we should be careful here. When you invoke ".simplify()"
the expression is passed to maxima. For maxima, default domain
for variables is *real* where as for pynac it is *complex*.

So you will get above answer without "assume(a, 'real')".

I think, we should forward this issue to sage-devel as it seems
to be a dangerous mixing.

Cheers,
Golam

Robert Bradshaw

unread,
Aug 22, 2009, 5:39:14 PM8/22/09
to sage-s...@googlegroups.com

I thought we used to put maxima in complex mode, do we not do that
anymore? I guess more things got shook up in the symbolic switchover
than I thought.

- Robert


William Stein

unread,
Aug 22, 2009, 5:41:21 PM8/22/09
to sage-s...@googlegroups.com

Robert, we still do that.  The initialization code in calculus.py is:

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

 

Robert Bradshaw

unread,
Aug 22, 2009, 5:47:28 PM8/22/09
to sage-s...@googlegroups.com

Hmm... guess its a bug (or missunderstanding) in domain: complex.

- Robert

Mani chandra

unread,
Aug 27, 2009, 10:15:58 PM8/27/09
to sage-s...@googlegroups.com
Minh Nguyen wrote:
> On Sun, Aug 23, 2009 at 12:16 AM, Mani chandra<mcha...@iitk.ac.in> wrote:
>
>> Minh Nguyen wrote:
>>
>
> Ticket #6802 has been closed as a duplicate of #6559.
>
>
Hi,

Just wanted to ask, since you're the release manager for the next
release, do you think ticket no. 6559 will make it?

Thanking you,
Mani chandra

Reply all
Reply to author
Forward
Message has been deleted
0 new messages