On Fri, Oct 3, 2008 at 2:36 AM, Robert Bradshaw
<[EMAIL PROTECTED]> wrote:
>
> On Oct 2, 2008, at 10:43 PM, Ondrej Certik wrote:
>
>> On Thu, Oct 2, 2008 at 6:43 PM, William Stein <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> On Thu, Oct 2, 2008 at 9:31 AM, jdmuys <[EMAIL PROTECTED]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am a total newcomer, and here is very simple high-school level
>>>> question for which I could not find an answer in several hours of
>>>> searching:
>>>>
>>>> How can I use Sage to simplify ratios involving complex numbers?
>>>>
>>>> By simplify, I mean, to put into the canonical form a+b*i.
>>>>
>>>> For a very simple example: simplifying x=1/(1+i) would yield (1/2
>>>> - i/
>>>> 2)
>>>>
>>>> Note: this is simple to do by hand: multiply both numerator and
>>>> denominator by the conjugate of the denominator. For my example,
>>>> this
>>>> leads to:
>>>>
>>>> x= (1-i)/[(1+i)(1-i)]
>>>> x = (1-i)/[1^2-i^2]
>>>> x = (1-i)/[1+1]
>>>> x = (1-i)/2
>>>> x = 1/2 -i/2
>>>>
>>>> I tried quite a number of things, none of which worked.
>>>>
>>>> Thanks, and sorry if my question is easy (well actually, I hope it's
>>>> easy ;-)
>>>>
>>>
>>> You could get the real and imaginary parts, as follows:
>>>
>>> sage: a = (1-I)/(1 + I)
>>> sage: a.real() + I*a.imag()
>>> -1*I
>>>
>>> If you're coefficients are all rational numbers, you could
>>> alternatively define I to be the generator for the "ring" QQ[sqrt
>>> (-1)],
>>> as follows, and all such expressions will automatically
>>> be simplified the moment you type them in:
>>>
>>> sage: I = QQ[sqrt(-1)].gen()
>>> sage: 1/1 + I
>>> I + 1
>>> sage: 1/(1 + I)
>>> -1/2*I + 1/2
>>> sage: (1-I)/(1 + I)
>>> -I
>>>
>>> Note that expressions like sqrt(2)*I will no longer work
>>> with this new version of I.  To get back the old I, you
>>> can do
>>> sage: reset('I')
>>
>> Or through some package, e.g. sometimes sympy's simplification
>> works well:
>>
>> sage: a = (1-I)/(1 + I)
>> sage: import sympy
>> sysage: sympy.simplify(a)
>> -I
>> sage: SR(sympy.simplify(a))
>> -1*I
>>
>> The SR() converts the expression back from a sympy expression to a
>> Sage expression.
>
> It's really sad that we don't have a more intuitive way to do this.
> There's a maxima command (rectcoords or something like that) but it's
> not obvious how to invoke it directly on the SR object.
>
> I've actually been working on a patch for coercion that will allow
> number fields to come with specified embeddings, in which case we
> will let I be in QQ[sqrt(-1)] (or even perhaps ZZ[sqrt(-1)]), but
> with a specified embedding into CC (and by extension SR) so that

I'm worried that won't work, since CC is 53-bit precision floats, so
"by extension SR" means you'll end up with 1.0*I rather than I.

For the record, Mathematica just automatically simplify things like 1/(1+I),
as does Maple, and Sage should too since since ginsh (ginac's shell) does
simplify 1/(1+I) too (see below):


[EMAIL PROTECTED]:~$ math
Mathematica 6.0 for Linux x86 (64-bit)
Copyright 1988-2007 Wolfram Research, Inc.

In[1]:= I^2
Out[1]= -1

In[2]:= 1/(1+I)
        1   I
Out[2]= - - -
        2   2

---

In Maple:

> 1/(1+I);
                                  1/2 - 1/2 I

In Ginac:
> [EMAIL PROTECTED]:~$ /usr/bin/ginsh
ginsh - GiNaC Interactive Shell (ginac V1.3.5)
  __,  _______  Copyright (C) 1999-2006 Johannes Gutenberg University Mainz,
 (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.
  ._) i N a C | You are welcome to redistribute it under certain conditions.
<-------------' For details type `warranty;'.

Type ?? for a list of help topics.
> I^2;
-1
> 1/(1+I);
1/2-1/2*I


----

The upshot of all this is that Maxima (which Sage currently uses)
is causing this confusion, since it has a different convention than
all the other systems:

> [EMAIL PROTECTED]:~$ maxima
Maxima 5.16.2 http://maxima.sourceforge.net
Using Lisp CLISP 2.46 (2008-07-02)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
...
(%i2) %i^2;
(%o2)                                 - 1
(%i3) 1/(1+%i);
                                      1
(%o3)                               ------
                                    %i + 1


 ---William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to