Discussion:
Double Factorial
Jason Merrill
2008-08-27 00:34:11 UTC
Permalink
I couldn't find a double factorial function in sage. That is,

n!! == n*(n - 2)*(n - 4)...

Does Sage have a double factorial somewhere that I'm missing. If not,
could it?

Regards,

JM
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-***@googlegroups.com
To unsubscribe from this group, send email to sage-support-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---
William Stein
2008-08-27 01:20:56 UTC
Permalink
Post by Jason Merrill
I couldn't find a double factorial function in sage. That is,
n!! == n*(n - 2)*(n - 4)...
Does Sage have a double factorial somewhere that I'm missing. If not,
could it?
I had to write this for Pynac. Here's the 1-liner that does it...

def doublefactorial(x):
n = Integer(x)
if n < -1:
raise ValueError, "argument must be >= -1"
return prod([n - 2*i for i in range(n//2)])

sage: doublefactorial(20)
3715891200

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-***@googlegroups.com
To unsubscribe from this group, send email to sage-support-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---
Robert Bradshaw
2008-08-27 01:37:36 UTC
Permalink
Post by William Stein
Post by Jason Merrill
I couldn't find a double factorial function in sage. That is,
n!! == n*(n - 2)*(n - 4)...
Does Sage have a double factorial somewhere that I'm missing. If not,
could it?
I had to write this for Pynac. Here's the 1-liner that does it...
n = Integer(x)
raise ValueError, "argument must be >= -1"
return prod([n - 2*i for i in range(n//2)])
sage: doublefactorial(20)
3715891200
Yes, Integers have a (highly optimized) multifactorial method.

sage: a = 20

sage: a.multifactorial(2)
3715891200

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-***@googlegroups.com
To unsubscribe from this group, send email to sage-support-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---
Jason Merrill
2008-08-27 02:25:34 UTC
Permalink
Post by Robert Bradshaw
Does Sage have a double factorial somewhere that I'm missing.  If not,
could it?
Yes, Integers have a (highly optimized) multifactorial method.
sage: a = 20
sage: a.multifactorial(2)
  3715891200
- Robert
Perfect. Thanks.

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

Continue reading on narkive:
Loading...