help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use GNU MP in octave?


From: Ben Barrowes
Subject: Re: How to use GNU MP in octave?
Date: Tue, 24 May 2005 07:48:04 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20050414

I have written a mex-based toolbox for ML which calls GMP and MPFR routines to achieve arbitrary precision in ML:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6446&objectType=FILE
This toolbox defines a new mp data type and overloads common functions and operators using an @mp directory. I have heard that there is mex functionality written into octave, but I have not experimented with it. If the mex wrapper in octave is substantially similar to ML's, perhaps this toolbox could be ported without too much trouble. Having the Mathematica toolbox available to octave users could also add symbolic capability to octave for those with a MMA installed on their system:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6044&objectType=FILE
Any comments on how easy/difficult a port looks by taking a quick once over of these toolboxes?

Ben Barrowes


Shai Ayal wrote:



Javier Arantegui wrote:

Hello,

El Martes, 24 de Mayo de 2005 05:28, Keith Goodman escribió:

Here's a quote from google


[...]

Let x = lg(8600!). Since lg(xy)=lg(x)+lg(y) you have

x = sum(lg(k),k=1..86000)

Define floor(x) as the integer part of x. Then

86000! = 10^(x-floor(x))*10^floor(x).

You can evaluate x to the degree of accuracy you want, for example,
using Maple I got:

86000! = 7.91222558*10^372239



Unfortunately, Octave doesn't buy the trick :-(:-(

octave:4> k=1:1:86000;
octave:5> x=sum(log10(k))
x =  3.8702e+05
octave:6> 10^(x-floor(x))*10^floor(x)
ans = Inf


Octave doesn't buy this trick since the maximum double value is ~ 10^300. I think Keith meant to say:

use octave to calc 10^(x-floor(x)) which is hard to do by hand, and multiply by 10^floor(x) in your head which is easy, (at least to me ...)


octave:8>  k=1:1:86000;
octave:9>  x=sum(log10(k));
octave:10> format long
octave:11> x
x = 387020.407702849
octave:12> floor(x)
ans = 387020
octave:13> 10^(x-floor(x))
ans = 2.55683586378090

so your answer is approximately 2.55683586378090*10^387020, (or 2.55683586378090e+387020 in octaves output format). 16 decimal digits is the limit of double precision floting point used in octave. If you need more precision, than other programing tools, as suggested in previous emails in this thread are appropriate.

Note that this result is different from the maple result given above, probably due to roundoff errors in the sum. I suppose this could be improved with some more perusing, although the double precision output of maple leads me to suspect that tin his case a a similar algorithm, or some approximation was used, not real arbitrary precision arithmetic.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


--
---- Benjamin E. Barrowes ------- http://alum.mit.edu/www/barrowes
Los Alamos National Laboratory               address@hidden
Biophysics Group P-21, MS-D454                 Phone:(505)606-0105
Los Alamos, NM 87544                             FAX:(270)294-1268
------------------------------------------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]