prevent complex numbers ?

3 views
Skip to first unread message

anos...@googlemail.com

unread,
Nov 27, 2008, 9:58:33 AM11/27/08
to sage-support
Hello,

the example below shows that a complex number ( i think the "I" stands
for it ? ) appears by doing a simplify_full. Is there a way to prevent
this and to get output in real number format?

sage: var('omgo zr ys cz')
sage: eqomgo = omgo == (sqrt(2*ys - 2*cz)*sqrt(2*zr - 2*cz))/(2*zr -
2*cz)
sage: eqomgo.rhs().simplify_full()
I*sqrt(cz - ys)/sqrt(zr - cz)

Thanks,
Andreas

Robert Bradshaw

unread,
Nov 28, 2008, 3:14:40 AM11/28/08
to sage-s...@googlegroups.com


Is ys assumed to be larger than cz? What about zr and cz? You can use
the assume command

sage: assume(ys > cz)
sage: assume(zr > cz)

Then do

sage: sage: eqomgo.rhs().simplify_full().real()
-sqrt(ys - cz)/sqrt(zr - cz)

- Robert

anos...@googlemail.com

unread,
Nov 28, 2008, 7:28:30 AM11/28/08
to sage-support


On Nov 28, 9:14 am, Robert Bradshaw <rober...@math.washington.edu>
wrote:
Thanks for your answer!
Sorry, i didn't wrote that we tried the assume command. We just forgot
to use the real() function...

anos...@googlemail.com

unread,
Dec 1, 2008, 6:47:54 AM12/1/08
to sage-support


On Nov 28, 1:28 pm, "anost...@googlemail.com"
Hello again,

my problem was / is the prevention of falling into complex numbers. Is
there also a way to define variables to be and stay in a real format
for a whole worksheet? So i could avoid the use of the real() function
after each equation.

Thanks,
Andreas

Is there also a way to define the variables at the start of a
worksheet to

Stan Schymanski

unread,
Dec 1, 2008, 8:11:44 AM12/1/08
to sage-support
Hi Robert,

I wasn't aware of the real() function; pretty cool. I tried it out
myself in the above example and found an error. Not sure whether this
is an error in the real() function or in simplify_full. I suspect the
latter. Could you comment on this? I would also be very interested in
a way of defining symbolic variables such that they can only be real.
Is this only possible by doing assume(omgo,'real')?

Here is the error I found. The result given by omgo.simplify_full
().real() is different to the one obtained by omgo.factor().

Thanks for your help!

Stan

----------------------------------------------------------------------
| Sage Version 3.2, Release Date: 2008-11-20 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: var('omgo zr ys cz')
(omgo, zr, ys, cz)
sage: omgo = (sqrt(-zr^2 + 2*ys*zr + (2*cz - zr)^2 - 2*ys*(2*cz - zr))
+ 2*zr- 2*cz)/(2*zr - 2*cz)
sage: assume(cz>ys,cz>zr)
sage: omgo.factor()
(zr + sqrt(cz - ys)*sqrt(cz - zr) - cz)/(zr - cz)
sage: omgo.simplify_full().real()
(zr - sqrt(cz - ys)*sqrt(cz - zr) - cz)/(zr - cz)

On Nov 28, 9:14 am, Robert Bradshaw <rober...@math.washington.edu>
wrote:

Robert Bradshaw

unread,
Dec 1, 2008, 11:50:46 PM12/1/08
to sage-s...@googlegroups.com
On Dec 1, 2008, at 5:11 AM, Stan Schymanski wrote:

> Hi Robert,
>
> I wasn't aware of the real() function; pretty cool. I tried it out
> myself in the above example and found an error. Not sure whether this
> is an error in the real() function or in simplify_full. I suspect the
> latter. Could you comment on this? I would also be very interested in
> a way of defining symbolic variables such that they can only be real.
> Is this only possible by doing assume(omgo,'real')?

Yes.

sage: assume(x, 'real')
sage: x.imag()
0

Are you saying you would like to pass in a domain when creating the
variables? Something like

sage: var('omega', domain=RR)

> Here is the error I found. The result given by omgo.simplify_full
> ().real() is different to the one obtained by omgo.factor().

Currently we're using maxima as a back end for all the calculus
operations. This is probably due to maxima's simplifications being
lax with branch cuts, similar to

-1 = sqrt(-1)^2 = sqrt(-1) * sqrt(-1) "=" sqrt(-1 * -1) = sqrt(1) = 1

> Thanks for your help!

You're welcome.

- Robert

Stan Schymanski

unread,
Dec 2, 2008, 6:11:19 PM12/2/08
to sage-support
Hi Robert,

On Dec 2, 5:50 am, Robert Bradshaw <rober...@math.washington.edu>
wrote:

> Are you saying you would like to pass in a domain when creating the  
> variables? Something like
>
> sage: var('omega', domain=RR)

YES, that would be great.

>
> > Here is the error I found. The result given by omgo.simplify_full
> > ().real() is different to the one obtained by omgo.factor().
>
> Currently we're using maxima as a back end for all the calculus  
> operations. This is probably due to maxima's simplifications being  
> lax with branch cuts, similar to
>
> -1 = sqrt(-1)^2 = sqrt(-1) * sqrt(-1) "=" sqrt(-1 * -1) = sqrt(1) = 1
>

I see now how this comes about. Do you reckon it would help to submit
this as a bug to maxima? Errors like these make the simplify_full
function rather useless.

By the way, the assume(omega,'real') line does not have the desired
effect on simplify_full:

var('omgo zr ys cz')
assume(omgo, 'real')
omgo = (sqrt(-zr^2 + 2*ys*zr + (2*cz - zr)^2 - 2*ys*(2*cz - zr)) +
2*zr- 2*cz)/(2*zr - 2*cz)
omgo.simplify_full()
(I*sqrt(cz - ys)*sqrt(zr - cz) + zr - cz)/(zr - cz)
omgo.simplify_full()(cz=10,ys=5,zr=4).n()
1.91287092917528
omgo(cz=10,ys=5,zr=4).n()
0.0871290708247230

Useless, indeed!

Thanks again,
Stan

Burcin Erocal

unread,
Dec 3, 2008, 4:28:50 AM12/3/08
to sage-s...@googlegroups.com
On Tue, 2 Dec 2008 15:11:19 -0800 (PST)
Stan Schymanski <schy...@gmail.com> wrote:

>
> Hi Robert,
>
> On Dec 2, 5:50 am, Robert Bradshaw <rober...@math.washington.edu>
> wrote:
>
> > Are you saying you would like to pass in a domain when creating the
> > variables? Something like
> >
> > sage: var('omega', domain=RR)
>
> YES, that would be great.

This is on the todo list for the pynac symbolics:

http://wiki.sagemath.org/symbolics/pynac_todo

as

* symbol domains (ginac supports real, complex, integer)

I hope to start working on pynac again in a couple of weeks.


Cheers,

Burcin

Reply all
Reply to author
Forward
0 new messages