Post Reply 
Double factorial
03-02-2015, 01:49 PM (This post was last modified: 03-02-2015 05:28 PM by salvomic.)
Post: #1
Double factorial
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

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-02-2015, 04:18 PM
Post: #2
RE: Double factorial
(03-02-2015 01:49 PM)salvomic Wrote:  hi all,
how it 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

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 \) )

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-02-2015, 04:36 PM
Post: #3
RE: Double factorial
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)?
Find all posts by this user
Quote this message in a reply
03-02-2015, 05:15 PM
Post: #4
RE: Double factorial
(03-02-2015 04:18 PM)Han Wrote:  The wiki explains how you can calculate it using the regular factorial:
...
It should be pretty easy to write your own program using these formulas. (Note: the wiki has a slight error ...

(03-02-2015 04:36 PM)Helge Gabert Wrote:  No error checking, but something along these lines

#cas
...
Is this what you are asking (simple program)?

yes, thanks both!
so this should be enough "precise" and it is ok both in Home and CAS:
Code:

EXPORT factorial(n)
//Double factorial n!!
BEGIN
local f;
IF odd(n) THEN f:=product(X,X,,1,n,2);
ELSE f:=product(X,X,2,n,2); END;
RETURN(f);
END;

My memory failed, and I didn't remember "product()" Smile

thanks again,
Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-02-2015, 05:30 PM
Post: #5
RE: Double factorial
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
;
;
Find all posts by this user
Quote this message in a reply
03-02-2015, 05:32 PM
Post: #6
RE: Double factorial
(03-02-2015 05:30 PM)Gerald H Wrote:  An assist from the 50G side:
...

thanks!
50g is always a great Calc!

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-03-2015, 12:02 PM
Post: #7
RE: Double factorial
Here is a slight variation on your theme:

Code:

EXPORT factorial(n)
//Double factorial n!!
BEGIN
RETURN IFTE(odd(n), product(X,X,1,n,2), product(X,X,2,n,2));
END;

-Dale-
Find all posts by this user
Quote this message in a reply
03-03-2015, 01:24 PM
Post: #8
RE: Double factorial
(03-03-2015 12:02 PM)DrD Wrote:  Here is a slight variation on your theme:

...
-Dale-

nice, Dale, thanks!

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
03-03-2015, 06:15 PM
Post: #9
RE: Double factorial
(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

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: