Re: [sage-support] strange n()

2010-04-11 Thread bb

Mike Hansen schrieb:

On Sat, Apr 10, 2010 at 3:37 AM, bb bblo...@arcor.de wrote:
  

sage: n(sqrt(2.), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2), digits=40)
1.414213562373095048801688724209698078570
sage:



If you wanted this to be more like Maxima, the appropriate thing to do
would some something like:

sage: RealNumber = RealField(137)
sage: sqrt(2.0)
1.414213562373095048801688724209698078570
sage: sqrt(2).n(digits=40)
1.414213562373095048801688724209698078570

  

Sage is missing the errror forwarding of Mathematica.



Yes, Sage does not have a numerical type that does Mathematica's
significance arithmetic.  An interesting thread about the merits and
demerits of significance arithmetic is
http://sci.tech-archive.net/Archive/sci.math.symbolic/2008-03/msg00014.html
.

One could do a little work to get Sage's interval arithmetic to do
something similar.

--Mike

  
Tnx for helping. I did some more experimentation. I dont want to bother 
you, but if you have some time and some pation I would be thankfull for 
one more explanation. Your tip works as expected, but if I use the 
method n() I still get 53 bit of significant bits??? (see last 
expression of the snippet.)


I argue, that the parameter of n() is set elsewhere in another Variable 
than RealNumber?


sage: RealNumber = RealField(137)
sage: sqrt(2.)
1.414213562373095048801688724209698078570
sage: _.prec()
137
sage: 
sqrt(2.000)

1.414213562373095048801688724209698078570
sage: _.prec()
137
sage: 
n(sqrt(2.000), 
digits=60)

1.41421356237309504880168872420969807856967336610324780267484
sage: _.prec()
203
sage: 
n(sqrt(2.000))

1.41421356237310
sage: _.prec()
53
sage:

Regards BB

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread Mike Hansen
On Sun, Apr 11, 2010 at 10:01 AM, bb bblo...@arcor.de wrote:
 Tnx for helping. I did some more experimentation. I dont want to bother you,
 but if you have some time and some pation I would be thankfull for one more
 explanation. Your tip works as expected, but if I use the method n() I still
 get 53 bit of significant bits??? (see last expression of the snippet.)

 I argue, that the parameter of n() is set elsewhere in another Variable than
 RealNumber?

Yes, in the code for n, we have the following:

if prec is None:
if digits is None:
prec = 53
else:
prec = int((digits+1) * 3.32192) + 1

so it just defaults to 53 if nothing is passed in.  The RealNumber =
RealField(137) just changes the precision for floating point literals
entered on the command line.

--Mike

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread bb

Mike Hansen schrieb:

On Sun, Apr 11, 2010 at 10:01 AM, bb bblo...@arcor.de wrote:
  

Tnx for helping. I did some more experimentation. I dont want to bother you,
but if you have some time and some pation I would be thankfull for one more
explanation. Your tip works as expected, but if I use the method n() I still
get 53 bit of significant bits??? (see last expression of the snippet.)

I argue, that the parameter of n() is set elsewhere in another Variable than
RealNumber?



Yes, in the code for n, we have the following:

if prec is None:
if digits is None:
prec = 53
else:
prec = int((digits+1) * 3.32192) + 1

so it just defaults to 53 if nothing is passed in.  The RealNumber =
RealField(137) just changes the precision for floating point literals
entered on the command line.

--Mike

  

Tnx for clearing that n()-question!

In an earlier posting (I am always thankful for any help!) you wrote:
One could do a little work to get Sage's interval arithmetic to do
something similar. Would be an interesting experiment.

I found an internet page about that topic concerning MPFR from 2/5/2006:
http://www.ma.utexas.edu/users/kschalm/mpfr-in-sage.html
(MPFR seems to be very broadly used by different Progs under GNU Lesser 
GPL. Added is a list of related software.)


There are used some Sage-examples with a strange line-numbering with 
underscores? May be that is an outdated Sage-Version? Actual versions do 
not do any line numbering.


I did not find any evidence that MPFR or MAPM is included in Sage? I do 
not understand if MPFR is compiled with Sage in this examples on that 
page? I cannot find any evidence that MPFR is loaded?


In an extension of the floating point issue I am actually interested in: 
I found a list of libs to support floating point arithmetics that are 
not in the list of included libs to Sage. I found some examples to 
include tools with a CLI via http in the documentatin. I did not find 
hints how to include C/C++ or other language libs to Sage? (To clear 
that statement: The fact I could not find it does not mean it is not 
documented in some place!)


Again - please ignore my boring question if you feel bothered - I can 
understand that! With yor response you opened a door for floting point 
questions.


Tnx anyway - regards BB




--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-11 Thread Mike Hansen
On Sun, Apr 11, 2010 at 12:47 PM, bb bblo...@arcor.de wrote:
 In an earlier posting (I am always thankful for any help!) you wrote:
 One could do a little work to get Sage's interval arithmetic to do
 something similar. Would be an interesting experiment.

Here's a brief example

sage: RIF
Real Interval Field with 53 bits of precision
sage: R = RealIntervalField(200); R
Real Interval Field with 200 bits of precision
sage: f = RIF(pi) + 0.5; f
3.641592653589794?
sage: g = R(f); g
3.641592653589794?
sage: g.parent()
Real Interval Field with 200 bits of precision

Even when you increase the precision, it doesn't print out more digits
since it knows the upper and lower bounds.  However, this does not
currently play nice with the .n() stuff.


 I found an internet page about that topic concerning MPFR from 2/5/2006:
 http://www.ma.utexas.edu/users/kschalm/mpfr-in-sage.html
 (MPFR seems to be very broadly used by different Progs under GNU Lesser GPL.
 Added is a list of related software.)

 There are used some Sage-examples with a strange line-numbering with
 underscores? May be that is an outdated Sage-Version? Actual versions do not
 do any line numbering.

This page is indeed quite outdated.


 I did not find any evidence that MPFR or MAPM is included in Sage? I do not
 understand if MPFR is compiled with Sage in this examples on that page? I
 cannot find any evidence that MPFR is loaded?

MPFR is included in Sage by default.  Sage's RealNumber class is a
wrapper around an MPFR object.  Any high-precision floating point
arithmetic in Sage uses MPFR.

 In an extension of the floating point issue I am actually interested in: I
 found a list of libs to support floating point arithmetics that are not in
 the list of included libs to Sage. I found some examples to include tools
 with a CLI via http in the documentatin. I did not find hints how to include
 C/C++ or other language libs to Sage? (To clear that statement: The fact I
 could not find it does not mean it is not documented in some place!)

If you want to interface with other C/C++ libraries, the easiest way
to do so is using Cython [1].  There are also lots of examples in the
Sage library; for example,
$SAGE_ROOT/devel/sage/sage/rings/real_mpfr.pyx

--Mike

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


[sage-support] strange n()

2010-04-10 Thread bb

Just experimenting with Sage syntax I found something strange:

sage: n(pi)
3.14159265358979
sage: n(pi,20)
3.1416
sage: n(pi,29)
3.1415927
sage: n(pi,59)
3.1415926535897932
sage: n(pi,0x59)
3.1415926535897932384626434
sage: pi.n(digits=17)
3.1415926535897932
sage:

Is there any explanation?

Regards BB

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Mike Hansen
On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
 Is there any explanation?

Could you be more specific in your question?  Everything there looks
normal to me.  n(pi, 20) means to compute using 20 bits of precision.

--Mike

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Alex Ghitza
On Sat, 10 Apr 2010 01:08:12 -0700, Mike Hansen mhan...@gmail.com wrote:
 On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
  Is there any explanation?
 
 Could you be more specific in your question?  Everything there looks
 normal to me.  n(pi, 20) means to compute using 20 bits of precision.

... which you can figure out from the first two lines of the docstring
for n, by typing n? at the Sage prompt :).


Best,
Alex


-- 
Alex Ghitza -- http://aghitza.org/
Lecturer in Mathematics -- The University of Melbourne -- Australia

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread bb

Mike Hansen schrieb:

On Sat, Apr 10, 2010 at 1:02 AM, bb bblo...@arcor.de wrote:
  

Is there any explanation?



Could you be more specific in your question?  Everything there looks
normal to me.  n(pi, 20) means to compute using 20 bits of precision.

--Mike

  

Ok, I see - the argument defines the number of bits and not of digits!

In any other CAS (I know) that parameter describes the number of digits 
displayed. I. e .


Maxima:
(%i2) fpprec: 40;
(%o2) 40
(%i3) bfloat(sqrt(2.));
(%o3) 1.41421356237309504880168872420969807857b0
(%i4) bfloat(sqrt(2));
(%o4) 1.41421356237309504880168872420969807857b0
(%i4)

That are 40 digits (with decimal point)

Mathematica:

N[sqrt[2], 40]
1.41421356237309504880168872420969807857
delivers 40 decimal places including the decimal point.
N[sqrt[2.], 40]
1.414213562373095
(that is because Mathematica assumes a 18 bit machine precision in the 
number 2.0 and cuts off questionable digits of precision)


Sage works a bit different from the main stream with the definition of 
the number of digits. So one should not wonder about my misinterpretation!

But thanks for helping! Now I understand the difference:

sage: n(sqrt(2.), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2), digits=40)
1.414213562373095048801688724209698078570
sage:

Sage is missing the errror forwarding of Mathematica.

sage: n(sqrt(2.000), digits=40)
1.414213562373095145474621858738828450441
sage: n(sqrt(2.000), digits=40)
1.414213562373095048804445654500039353252
sage: n(sqrt(2.000), digits=40)
1.414213562373095048801688724209698078570
sage: n(sqrt(2.000), digits=41)
1.4142135623730950488016887242096980785697
sage:

So one has an assortet collection and a rich choice of different 
numbers. Where I find the calculation philosophie of maxima not too bad!


Regards BB




--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.


Re: [sage-support] strange n()

2010-04-10 Thread Mike Hansen
On Sat, Apr 10, 2010 at 3:37 AM, bb bblo...@arcor.de wrote:
 sage: n(sqrt(2.), digits=40)
 1.414213562373095145474621858738828450441
 sage: n(sqrt(2), digits=40)
 1.414213562373095048801688724209698078570
 sage:

If you wanted this to be more like Maxima, the appropriate thing to do
would some something like:

sage: RealNumber = RealField(137)
sage: sqrt(2.0)
1.414213562373095048801688724209698078570
sage: sqrt(2).n(digits=40)
1.414213562373095048801688724209698078570


 Sage is missing the errror forwarding of Mathematica.

Yes, Sage does not have a numerical type that does Mathematica's
significance arithmetic.  An interesting thread about the merits and
demerits of significance arithmetic is
http://sci.tech-archive.net/Archive/sci.math.symbolic/2008-03/msg00014.html
.

One could do a little work to get Sage's interval arithmetic to do
something similar.

--Mike

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using remove me as the subject.