Double factorial - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Double factorial (/thread-3240.html) |
Double factorial - salvomic - 03-02-2015 01:49 PM hi all, how is a simple (and precise) way to define a command to calculate the "double factorial" (see here) with Prime? I mean to use it as a simple command. We cannot write n!!, as that is not the same... thank you, Salvo RE: Double factorial - Han - 03-02-2015 04:18 PM (03-02-2015 01:49 PM)salvomic Wrote: hi all, The wiki explains how you can calculate it using the regular factorial: If \( n \) is even, then there exists some integer \( k \) such that \( n = 2k \). \[ n!! = n(n-2)(n-4) \dotsm 4 \cdot 2 = (2k)(2k-2)(2k-4)\dotsm (2\cdot 2) \cdot (2\cdot 1) = 2^k k! \] If \( n \) is odd, then there exists some integer \( k \) such that \( n = 2k+1 \). Moreover, \( n-1 \) is even. \[ n!! = \frac{\text{product of all integers from 1 to } n}{\text{product of all even integers from 2 to } n-1} = \frac{n(n-1)(n-2)\dotsm 3 \cdot 2 \cdot 1}{ (n-1)(n-3)(n-5)\dotsm 4 \cdot 2} = \frac{n!}{(n-1)!!} = \frac{(2k+1)!}{2^k k!} \] It should be pretty easy to write your own program using these formulas. (Note: the wiki has a slight error with respect to the formula for odd values of \(n \) ) RE: Double factorial - Helge Gabert - 03-02-2015 04:36 PM No error checking, but something along these lines #cas DFA(n):= BEGIN IF odd(n) THEN product(n,n,1,n,2); ELSE product(n,n,2,n,2); END; END; #end Is this what you are asking (simple program)? RE: Double factorial - salvomic - 03-02-2015 05:15 PM (03-02-2015 04:18 PM)Han Wrote: The wiki explains how you can calculate it using the regular factorial: (03-02-2015 04:36 PM)Helge Gabert Wrote: No error checking, but something along these lines yes, thanks both! so this should be enough "precise" and it is ok both in Home and CAS: Code:
My memory failed, and I didn't remember "product()" thanks again, Salvo RE: Double factorial - Gerald H - 03-02-2015 05:30 PM An assist from the 50G side: :: CK1&Dispatch BINT1 :: COERCEDUP BINT2 #/ DUP FPTR2 ^#FACT Z2_ ROT FPTR2 ^PPow# FPTR2 ^RMULText SWAP #0=case SWAPDROP SWAP FPTR2 ^#FACT FPTR2 ^SWAPRDIV ; ; RE: Double factorial - salvomic - 03-02-2015 05:32 PM (03-02-2015 05:30 PM)Gerald H Wrote: An assist from the 50G side: thanks! 50g is always a great Calc! RE: Double factorial - DrD - 03-03-2015 12:02 PM Here is a slight variation on your theme: Code:
-Dale- RE: Double factorial - salvomic - 03-03-2015 01:24 PM (03-03-2015 12:02 PM)DrD Wrote: Here is a slight variation on your theme: nice, Dale, thanks! RE: Double factorial - salvomic - 03-03-2015 06:15 PM (03-02-2015 05:03 PM)compsystems Wrote: Please HP´ TEAM can include product operator in the next version of ROM, or at least that on the historial, the product command is displayed as an operator... I agree. ∏, Productoria (or, Italian, Produttoria) as operator, a part of the command product: it would be very useful also. Tim, do you think that it's possible to do it? Thank you. Salvo |