Re: factorial(100)

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

Re: factorial(100)

Vincent Grunert
Just found this:

use:

#code
gamma(n+1)

instead of:

#code
factorial(n)

it's not pretty but nicer then the bigint solutions I believe.



On Wednesday, February 27, 2013 at 10:58:34 PM UTC+1, nbecker wrote:
Total newb here, just playing around.  A bit surprised by this:

julia> factorial(100)
0



Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Vincent Grunert
https://en.wikipedia.org/wiki/Gamma_function

Just to be on the save side.

On Tuesday, September 1, 2015 at 3:32:17 PM UTC+2, Vincent Grunert wrote:
Just found this:

use:

#code
gamma(n+1)

instead of:

#code
factorial(n)

it's not pretty but nicer then the bigint solutions I believe.



On Wednesday, February 27, 2013 at 10:58:34 PM UTC+1, nbecker wrote:
Total newb here, just playing around.  A bit surprised by this:

julia> factorial(100)
0



Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Vincent Grunert
In reply to this post by Vincent Grunert
It's not a pretty solution but it works:

use:

#code
gamma(n+1)

instead of:

#code
factorial(n)

https://en.wikipedia.org/wiki/Gamma_function

On Wednesday, February 27, 2013 at 10:58:34 PM UTC+1, nbecker wrote:
Total newb here, just playing around.  A bit surprised by this:

julia> factorial(100)
0



Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Yichao Yu
In reply to this post by Vincent Grunert
On Tue, Sep 1, 2015 at 9:34 AM, Vincent Grunert <[hidden email]> wrote:

> https://en.wikipedia.org/wiki/Gamma_function
>
> Just to be on the save side.
>
>
> On Tuesday, September 1, 2015 at 3:32:17 PM UTC+2, Vincent Grunert wrote:
>>
>> Just found this:
>>
>> use:
>>
>> #code
>> gamma(n+1)
>>
>> instead of:
>>
>> #code
>> factorial(n)
>>
>> it's not pretty but nicer then the bigint solutions I believe.
>>

This really depend on what you need. If you need all the digits,
there's no way around using BigInt. If you are doing some floating
point calculation, you can use gamma, although in practice I often
find lgamma is what I really need. (Since factorial often appears in
some expansion coefficient with pretty big numerator and denominator.
Using the log version can avoid floating point overflow)

>>
>>
>> On Wednesday, February 27, 2013 at 10:58:34 PM UTC+1, nbecker wrote:
>>>
>>> Total newb here, just playing around.  A bit surprised by this:
>>>
>>> julia> factorial(100)
>>> 0
>>>
>>>
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Steven G. Johnson


On Tuesday, September 1, 2015 at 9:39:27 AM UTC-4, Yichao Yu wrote:
find lgamma is what I really need. (Since factorial often appears in
some expansion coefficient with pretty big numerator and denominator.
Using the log version can avoid floating point overflow)

If you are doing expansions, e.g. some series formula, it is usually best to compute the series coefficients by a recurrence (e.g. compute the next coefficient as the previous coefficient multiplied by some factor), which is vastly more efficient than calling things like gamma or lgamma for each term, and typically this avoids overflow as well.
Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Cedric St-Jean-2


On Thursday, September 3, 2015 at 10:01:00 PM UTC-4, Steven G. Johnson wrote:

If you are doing expansions, e.g. some series formula, it is usually best to compute the series coefficients by a recurrence

Why? I can see how it can be more efficient, but wouldn't the inaccuracies compound?
Reply | Threaded
Open this post in threaded view
|

Re: factorial(100)

Steven G. Johnson


On Saturday, September 5, 2015 at 2:40:46 PM UTC-4, Cedric St-Jean wrote:


On Thursday, September 3, 2015 at 10:01:00 PM UTC-4, Steven G. Johnson wrote:

If you are doing expansions, e.g. some series formula, it is usually best to compute the series coefficients by a recurrence

Why? I can see how it can be more efficient, but wouldn't the inaccuracies compound?

Not nearly quickly enough to matter in typical calculations.  (For e.g. computation of special functions, it's rare to evaluate series expansions to more than tens of terms.  If you are evaluating series with thousands of terms or more, it is probably something like a Chebyshev expansion where you should be using specialized methods anyway.)

The classic example of computing series terms by a recurrence is the well-known Horner's method.