[sage-devel] Re: base_ring()

2009-09-03 Thread Jan Groenewald

Hi William

On Wed, Sep 02, 2009 at 10:31:01PM -0700, William Stein wrote:
  Is this the intended behaviour?
 
  sage: z=1.+sqrt(-1); print z; z.base_ring()
  1.00 + 1.00*I
  Symbolic Ring
  sage: z=1.+sqrt(-1.); print z; z.base_ring()
  1.00 + 1.00*I
  Real Field with 53 bits of precision
  note the sqrt(-1) versus sqrt(-1.)
 
Yes, this is definitely the intended behavior.  Why do you think either
one is wrong?  

Uhm, I have asked the originator to join the thread.

The first one, I is not a symbolic variable, it is sqrt(-1).
I am not sure what something like integers with I adjoined is?

The second is not a real field, it is the complex field?

regards,
Jan

-- 
   .~. 
   /V\ Jan Groenewald
  /( )\www.aims.ac.za
  ^^-^^ 

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread William Stein
2009/9/2 Jan Groenewald j...@aims.ac.za


 Hi William

 On Wed, Sep 02, 2009 at 10:31:01PM -0700, William Stein wrote:
   Is this the intended behaviour?
 
   sage: z=1.+sqrt(-1); print z; z.base_ring()
   1.00 + 1.00*I
   Symbolic Ring
   sage: z=1.+sqrt(-1.); print z; z.base_ring()
   1.00 + 1.00*I
   Real Field with 53 bits of precision
   note the sqrt(-1) versus sqrt(-1.)
 
 Yes, this is definitely the intended behavior.  Why do you think
 either
 one is wrong?

 Uhm, I have asked the originator to join the thread.

 The first one, I is not a symbolic variable, it is sqrt(-1).

I am not sure what something like integers with I adjoined is?


If you take any integer (or rational) alpha such that alpha is not a perfect
square, and try to compute sqrt(alpha), Sage promotes alpha to the symbolic
ring (SR) and takes the square root there.  Thus the first is correct, since
sqrt(-1) is not in ZZ, so the square root is instead taken in the symbolic
ring, which yields I.

In the second case, the expression z=1.+sqrt(-1.) is in the complex real
field with 53 bits precision.  The *base ring* of that field is the real
field with 53 bits precision.  Maybe you were instead thinking about the
parent of z?

William



 The second is not a real field, it is the complex field?

 regards,
 Jan

 --
   .~.
   /V\ Jan Groenewald
  /( )\www.aims.ac.za
  ^^-^^

 



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

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread Jan Groenewald

Hi William

On Wed, Sep 02, 2009 at 11:18:40PM -0700, William Stein wrote:
If you take any integer (or rational) alpha such that alpha is not a
perfect square, and try to compute sqrt(alpha), Sage promotes alpha to the
symbolic ring (SR) and takes the square root there.  Thus the first is
correct, since sqrt(-1) is not in ZZ, so the square root is instead taken
in the symbolic ring, which yields I. 

OK

In the second case, the expression z=1.+sqrt(-1.) is in the complex real
field with 53 bits precision.  The *base ring* of that field is the real
field with 53 bits precision.  Maybe you were instead thinking about the
parent of z?

Thanks

sage: z=1.+sqrt(-1); print z; z.parent()
1.00 + 1.00*I
Symbolic Ring
sage: z=1.+sqrt(-1.); print z; z.parent()
1.00 + 1.00*I
Complex Field with 53 bits of precision
sage: 

regards,
Jan
-- 
   .~. 
   /V\ Jan Groenewald
  /( )\www.aims.ac.za
  ^^-^^ 

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread Dirk

I'm the originator.  In fairness to Jan, I must say that I only showed
him the code and output with no other comment than that I hoped that
the students would not ask me to explain it.

I've in the meantime found a way of illustrating the point I meant to
make more clearly.

sage: z=1.+sqrt(-1)
sage: base_ring(z)
Symbolic Ring
sage: base_ring(real(z))
Symbolic Ring
sage: base_ring(imag(z))
Real Field with 53 bits of precision

Dirk

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread William Stein
2009/9/2 Dirk dirk.lau...@gmail.com


 I'm the originator.  In fairness to Jan, I must say that I only showed
 him the code and output with no other comment than that I hoped that
 the students would not ask me to explain it.

 I've in the meantime found a way of illustrating the point I meant to
 make more clearly.

 sage: z=1.+sqrt(-1)
 sage: base_ring(z)
 Symbolic Ring
 sage: base_ring(real(z))
 Symbolic Ring
 sage: base_ring(imag(z))
 Real Field with 53 bits of precision

 Dirk


I see, your point is that the following is inconsistent:

sage: z = 1.0+1.0*I
sage: type(real(z))
type 'sage.symbolic.expression.Expression'
sage: type(imag(z))
type 'sage.rings.real_mpfr.RealNumber'

I agree that this definitely looks like a bug.

William

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread javier

Hi William,

On Sep 3, 8:18 am, William Stein wst...@gmail.com wrote:
 I am not sure what something like integers with I adjoined is?


I guess that means the complex numbers of the fomr a + bI with  a, b
integers, or Z[I] (the Gaussian Integers). Mathematica prides itself
to be able to apply primality tests, factorization algorithms and the
kind in this ring:
http://reference.wolfram.com/mathematica/ref/GaussianIntegers.html

Maybe we should add an easy way of working with it, taking advantage
of Sage fast arithmetic for integers?

Cheers
Javier
--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread William Stein
2009/9/3 javier vengor...@gmail.com


 Hi William,

 On Sep 3, 8:18 am, William Stein wst...@gmail.com wrote:
  I am not sure what something like integers with I adjoined is?


 I guess that means the complex numbers of the fomr a + bI with  a, b
 integers, or Z[I] (the Gaussian Integers). Mathematica prides itself
 to be able to apply primality tests, factorization algorithms and the
 kind in this ring:
 http://reference.wolfram.com/mathematica/ref/GaussianIntegers.html

 Maybe we should add an easy way of working with it, taking advantage
 of Sage fast arithmetic for integers?


Sage has the Gaussian integers, and I'm sure the basic arithmetic and
functionality is as good or better than Mathematica already.

sage: R.I = ZZ[sqrt(-1)]; R
Order in Number Field in I with defining polynomial x^2 + 1
sage: a = 2 + 3*I
sage: timeit('a*a')
625 loops, best of 3: 1.4 µs per loop
sage: R.ideal(3)
Fractional ideal (3)
sage: R.ideal(3).factor()
Fractional ideal (3)
sage: R.ideal(5).factor()
(Fractional ideal (-I - 2)) * (Fractional ideal (2*I + 1))
sage: R.class_group()
Class group of order 1 with structure  of Number Field in I with defining
polynomial x^2 + 1
sage: P = R.ideal(11); P
Fractional ideal (11)
sage: P.is_prime()
True
sage: k = R.quotient(P,'a'); k
Quotient of Maximal Order in Number Field in I with defining polynomial x^2
+ 1 by the ideal (11)

Of course Sage can do all the above sort of stuff with any number field.

William

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread javier


On Sep 3, 9:36 am, William Stein wst...@gmail.com wrote:
 Sage has the Gaussian integers, and I'm sure the basic arithmetic and
 functionality is as good or better than Mathematica already.

Sure, what I meant (sorry if I wasn't very clear) is to make an
straightforward way to access it, kind of

R = GaussianIntegers()

in which you could factor directly the elements without needing to
define the ideals generated by them. Functionality is of course
equivalent to what we already have, just thought it would be nice
(maybe just for marketing reasons) to be able to do something like

(1 + I).is_prime()

Cheers
Javier
--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread John Cremona

2009/9/3 javier vengor...@gmail.com:


 On Sep 3, 9:36 am, William Stein wst...@gmail.com wrote:
 Sage has the Gaussian integers, and I'm sure the basic arithmetic and
 functionality is as good or better than Mathematica already.

 Sure, what I meant (sorry if I wasn't very clear) is to make an
 straightforward way to access it, kind of

 R = GaussianIntegers()

 in which you could factor directly the elements without needing to
 define the ideals generated by them. Functionality is of course
 equivalent to what we already have, just thought it would be nice
 (maybe just for marketing reasons) to be able to do something like

 (1 + I).is_prime()

I always thought that Maple's and Mathematica's ability to work
directly with Gaussian Integers was just that, a marketing ploy,
giving certain customers the impression of very fancy capabilities
with algebraic numbers.  But of course number theorists know that this
is just one interesting ring o algebraic integers, certainly the
easiest to define, but not exactly typical.  A number theorist
requires far more than that -- as Sage does provide -- and for others
is this not just a curiosity?  Maybe a useful one for teaching,
though, and implementing this would certainly be possible.

John


 Cheers
 Javier
 


--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread kcrisman



 is this not just a curiosity?  Maybe a useful one for teaching,
 though, and implementing this would certainly be possible.

Very useful.  I had to resort to some annoying crutches (i.e., using
the theorem in the code instead of discovering the theorem via the
demonstration of the code) to do stuff with Gaussian integers last
spring in my undergraduate course.   In particular,

(1 + I).is_prime()

would have been really useful, but was not available.  I realize that
in the symbolic ring it is not clear what should be prime, but then
again

sage: is_prime(SR(3))
True

yet in theory it might not be a generator of a prime ideal depending
on what else is in the symbolic ring:

sage: 1/3 in SR
True

So anything that gives easy access to this particular number field
*and* its elements being treated as generators of the ideals would be
very nice, for instance for things like Gaussian constellations etc.
If there are any other rings of integers of number fields that show up
a lot they could have shortcuts too, maybe Cyclotomic_Integers(n) or
something, in the way Javier points out.

- kcrisman
--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread John H Palmieri

On Sep 3, 12:36 am, William Stein wst...@gmail.com wrote:

 Sage has the Gaussian integers, and I'm sure the basic arithmetic and
 functionality is as good or better than Mathematica already.

 sage: R.I = ZZ[sqrt(-1)]; R
 Order in Number Field in I with defining polynomial x^2 + 1

Okay, this looks like a bug to me:

--
| Sage Version 4.1.1, Release Date: 2009-08-14   |
| Type notebook() for the GUI, and license() for information.|
--
sage: I
I
sage: R.I = ZZ[sqrt(-1)]
sage: I
1
sage: I^2
1

Why is I equal to 1 all of a sudden?  Same problem here:

sage: reset()
sage: R.a = ZZ[sqrt(-5)]
sage: a
1
sage: R.1
a
sage: R.1 == a
False
sage: (R.1)^2
-5
sage: R.inject_variables()
Defining a
sage: a
1


Ouch.
--
John

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread William Stein
On Thu, Sep 3, 2009 at 9:15 AM, John H Palmieri jhpalmier...@gmail.comwrote:


 On Sep 3, 12:36 am, William Stein wst...@gmail.com wrote:
 
  Sage has the Gaussian integers, and I'm sure the basic arithmetic and
  functionality is as good or better than Mathematica already.
 
  sage: R.I = ZZ[sqrt(-1)]; R
  Order in Number Field in I with defining polynomial x^2 + 1

 Okay, this looks like a bug to me:

 --
 | Sage Version 4.1.1, Release Date: 2009-08-14   |
 | Type notebook() for the GUI, and license() for information.|
 --
 sage: I
 I
 sage: R.I = ZZ[sqrt(-1)]
 sage: I
 1
 sage: I^2
 1

 Why is I equal to 1 all of a sudden?  Same problem here:

 sage: reset()
 sage: R.a = ZZ[sqrt(-5)]
 sage: a
 1
 sage: R.1
 a
 sage: R.1 == a
 False
 sage: (R.1)^2
 -5
 sage: R.inject_variables()
 Defining a
 sage: a
 1


 Ouch.
 --


it's actually not a bug; it's confusing (in this particular situation)
documented behavior.  It's clearly confusing.

What is happening is that R = ZZ[blah, blahs] constructs the smallest
*order* that contains blahs.  These aren't in general monogenic (generated
by one element), so R.gens() is just a ZZ basis for that order.  So:

sage: ZZ[sqrt(-5)]
Order in Number Field in a with defining polynomial x^2 + 5
sage: ZZ[sqrt(-5)].gens()
[1, a]
sage: R.a,b = ZZ[sqrt(-5)]
sage: b^2
-5

Obviously this is confusing in this special cases, as we were both
confused.  Number fields are monogenic so work as expected:

sage: R.I = QQ[sqrt(-1)]
sage: I^2
-1
sage: R.gens()
(I,)

William

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-03 Thread John Cremona

2009/9/3 John H Palmieri jhpalmier...@gmail.com:

 On Sep 3, 12:36 am, William Stein wst...@gmail.com wrote:

 Sage has the Gaussian integers, and I'm sure the basic arithmetic and
 functionality is as good or better than Mathematica already.

 sage: R.I = ZZ[sqrt(-1)]; R
 Order in Number Field in I with defining polynomial x^2 + 1

 Okay, this looks like a bug to me:

 --
 | Sage Version 4.1.1, Release Date: 2009-08-14                       |
 | Type notebook() for the GUI, and license() for information.        |
 --
 sage: I
 I
 sage: R.I = ZZ[sqrt(-1)]
 sage: I
 1
 sage: I^2
 1

 Why is I equal to 1 all of a sudden?  Same problem here:

Here is the reason, which caught me out also.   ZZ[sqrt(-1)] is an
order, and has two gens, namely its ZZ-module generators:

sage: R = ZZ[sqrt(-1)]
sage: R.gens()
[1, I]
sage: R.one,I = ZZ[sqrt(-1)]
sage: one
1
sage: I
I
sage: I^2
-1

So, R needs two names, you only gave it one.

I guess WAS is about to say the same thing but I'll post anyway...

John



 sage: reset()
 sage: R.a = ZZ[sqrt(-5)]
 sage: a
 1
 sage: R.1
 a
 sage: R.1 == a
 False
 sage: (R.1)^2
 -5
 sage: R.inject_variables()
 Defining a
 sage: a
 1


 Ouch.
 --
 John

 


--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-devel] Re: base_ring()

2009-09-02 Thread William Stein
On Wed, Sep 2, 2009 at 9:56 PM, Jan Groenewald j...@aims.ac.za wrote:


 Hi

 Sage-support did not solicit an answer.
 Both of these seem wrong:

 Is this the intended behaviour?

 sage: z=1.+sqrt(-1); print z; z.base_ring()
 1.00 + 1.00*I
 Symbolic Ring
 sage: z=1.+sqrt(-1.); print z; z.base_ring()
 1.00 + 1.00*I
 Real Field with 53 bits of precision
 note the sqrt(-1) versus sqrt(-1.)


Yes, this is definitely the intended behavior.  Why do you think either one
is wrong?

William

--~--~-~--~~~---~--~~
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
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---