Large factorials?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Large factorials?

M. Schmidt

Hi,

I have tried to find a hint in the octave documentation, but couldn't
find one regarding the subject and the following:

Is there an easy way in octave
   either provided by built-in capabilities,
   or via programming,
   or via setup,
   or via selection of parameters
to get large factorials not as floating point numbers
but as representation of very long integers.

E.g. 50! (or in octave: prod(1:50)) does need more than 60 digits.
How can this be handled to output not in floating point numbers
but as 60+ digit integer??

I would be happy to get helpful answers as soon as possible
and I appreciate your feedback.

Thanks in advance
Michael

--
Michael Schmidt                    [hidden email]
                    SAMBA Admin
Server fuer / Server for  MS + Win95 + WinNT + LANManager
              Fachhochschule Koblenz


Reply | Threaded
Open this post in threaded view
|

Re: Large factorials?

Ted.Harding
( Re Message From: M. Schmidt )

>
> I have tried to find a hint in the octave documentation, but couldn't
> find one regarding the subject and the following:
>
> Is there an easy way in octave
>    either provided by built-in capabilities,
>    or via programming,
>    or via setup,
>    or via selection of parameters
> to get large factorials not as floating point numbers
> but as representation of very long integers.
>
> E.g. 50! (or in octave: prod(1:50)) does need more than 60 digits.
> How can this be handled to output not in floating point numbers
> but as 60+ digit integer??
>
> I would be happy to get helpful answers as soon as possible
> and I appreciate your feedback.
>
> Thanks in advance
> Michael
>
> --
> Michael Schmidt                    [hidden email]
>                     SAMBA Admin
> Server fuer / Server for  MS + Win95 + WinNT + LANManager
>               Fachhochschule Koblenz

Since 50! > 10^60, the number cannot be represented exactly in 32-bit
floating point. Therefore you are basically stuck.

In /theory/ it is possible to program "symbolic" arithmetic in octave,
i.e. (for istance) 123 * 57 could be worked out by breaking it down
into ["1","2","3","*","5","7"] and feeding this to an octave program which
would manipulate it and return ["7","0","1","1"], but I wouldn't like to
do this unless I really had to. However, this would allow you to do
arbitrary-precision arithmetic within octave.

On my UNIX (actually Linux) system I have the "arbitrary precision
calculator" called "bc" which is something of a UNIX classic. This is
ideal for that type of calculation; here is a short "bc" session for 50!
----------------------------------------------------------------------------
root@Tedistan:~# bc -l
bc 1.02 (Mar 3, 92) Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
j=1
for(i=1;i<51;i++) j=j*i
j
30414093201713378043612608166064768844377641568960512000000000000
quit
root@Tedistan:~#
----------------------------------------------------------------------------
Since you can run "bc" as a system task from within octave (provided of
course you're on a UNIX-like system which allows that to be done), if I
needed to get this long string of digits into octave then that's how I
would do it. But you still wouldn't be able to use the string for /exact/
arithmetic calculation within octave by normal methods.

Best wishes,
Ted.                                    ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: Large factorials?

M. Schmidt
> From [hidden email] Thu Aug 28 12:30:05 1997
> From: [hidden email] (Ted Harding)
> Subject: Re: Large factorials?
>
[...]

> >
> > Is there an easy way in octave
> >    either provided by built-in capabilities,
> >    or via programming,
> >    or via setup,
> >    or via selection of parameters
> > to get large factorials not as floating point numbers
> > but as representation of very long integers.
> >
> > E.g. 50! (or in octave: prod(1:50)) does need more than 60 digits.
> > How can this be handled to output not in floating point numbers
> > but as 60+ digit integer??
> >
[...]

>
> Since 50! > 10^60, the number cannot be represented exactly in 32-bit
> floating point. Therefore you are basically stuck.
>
> In /theory/ it is possible to program "symbolic" arithmetic in octave,
> i.e. (for istance) 123 * 57 could be worked out by breaking it down
> into ["1","2","3","*","5","7"] and feeding this to an octave program which
> would manipulate it and return ["7","0","1","1"], but I wouldn't like to
> do this unless I really had to. However, this would allow you to do
> arbitrary-precision arithmetic within octave.
>
> On my UNIX (actually Linux) system I have the "arbitrary precision
> calculator" called "bc" which is something of a UNIX classic. This is
> ideal for that type of calculation; here is a short "bc" session for 50!
[...snipped...]


Thanks for your fast feedback. Good support on this mailing list :-)

Originally I tried to use output_max_field_width in octave,
but even setting this to e.g. output_max_field_widht=1000
and then doing a prod(1:50) in octave gives a different result than
calculating 50! in bc.  How that??

The purpose of the whole thing has been that just for fun I have tried
to check the machine power and to calculate many digits of PI using
Chudnovsky's formula (fine formula, converges linearly, but very fast).

Now I have written it in bc and it's working just fine.
Well, I did know of bc, but originally I have thought octave would be faster,
isn't it?


BTW besides the subject:
Your mail header states that you are using elm pl23. Please be informed that
a long time ago there has been a CERT alert that all elm patchlevels<=24
are vulnerable having a security hole. Take care of this...


Have a nice day
Michael

--
Michael Schmidt                    [hidden email]
                    SAMBA Admin
Server fuer / Server for  MS + Win95 + WinNT + LANManager
              Fachhochschule Koblenz


Reply | Threaded
Open this post in threaded view
|

Re: Large factorials?

M. Schmidt
> From: [hidden email] (M. Schmidt)
> Subject: Re: Large factorials?
>
> > From [hidden email] Thu Aug 28 12:30:05 1997
> > From: [hidden email] (Ted Harding)
> > Subject: Re: Large factorials?
> >
[...]
>
> BTW besides the subject:
> Your mail header states that you are using elm pl23. Please be informed that
> a long time ago there has been a CERT alert that all elm patchlevels<=24
> are vulnerable having a security hole. Take care of this...

Hi again,

as English isn't my mother tongue please excuse my above mistaken phrasing.

Of course it's not meant as an order (phrased as above I have been told it
could be understood so, sorry) but as a friendly advice like "Please take
care with this..." or like "Please take this into consideration...".
If you or anyone did misunderstand this part of my previous email then I
apologize.  Okay?

All the best
and have a nice time

Michael

--
Michael Schmidt                    [hidden email]
                    SAMBA Admin
Server fuer / Server for  MS + Win95 + WinNT + LANManager
              Fachhochschule Koblenz