Post Reply 
(49g/50g) Falling and Rising Factorials
02-05-2021, 08:32 PM
Post: #1
(49g/50g) Falling and Rising Factorials
Here are several programs for computing values of falling and rising factorials. I am posting them as a directory object for convenience but there are no inter-dependencies between the programs, so unused programs can be removed without affecting the others. Most of the programs require the ListExt library.

The first three programs are general-purpose programs.

FALFAC computes the falling factorial x_n. n must be an integer (positive or negative), x may be integer, real, complex or symbolic.

POCH computes the rising factorial (x)n also known as the Pochhammer symbol. Same rules as above.

QPOCH computes the q-Pochhammer symbol (a;q)n, a generalization of the rising factorial that accepts 3 arguments. Details here. n must be an integer, a and q may be integer, real, complex or symbolic.

The next two programs, ZFALFAC and ZPOCH compute the falling and rising factorials respectively. The difference is that n may be real or complex, but cannot be a negative integer. Also, since the programs return floating-point numbers, accuracy is limited to 12 digits.

The last three programs, ZFF, ZPOCH and ZQP are simplified versions of the first three. n must be an integer > 0, and x, a, and q must be integers (positive or negative). They are meant to be used where speed is important, e. g. inside loops.

Except for ZFALFAC and ZPOCH the only limitation on the size of integers is calculator memory.

Examples:

'x' 4 POCH EVAL will return 'x^4+6*x^3+11*x^2+6*x', where the coefficients are the unsigned Stirling numbers of the first kind.

'x' 4 FALFAC EVAL will return 'x^4-6*x^3+11*x^2-6*x', where the coefficients are the signed Stirling numbers of the first kind.

'x' 2 4 QPOCH EVAL will return '64*x^4-120*x^3+70*x^2-15*x+1'. The coefficients are more complicated but are related to the Gaussian binomial coefficients.

Code:

DIR
  FALFAC
  \<< DUP I\->R 0. >
     { 1 - DUP 0 LSEQR UNROT - ADD LPROD }
     { DUP I\->R 0. SAME
        { DROP2 1 }
        { DUP UNROT - SWAP NEG FALFAC INV
        } IFTE
     } IFTE
  \>>
  POCH
  \<< DUP I\->R 0. >
     { 1 - 0 SWAP LSEQR ADD LPROD }
     { DUP I\->R 0. SAME
        { DROP2 1 }
        { DUP UNROT + SWAP NEG POCH INV
        } IFTE
     } IFTE
  \>>
  QPOCH
  \<< 0. PICK3 ABS I\->R SAME NOT
     { DUP I\->R 0. >
        { 0 SWAP 1 - LSEQR ^ * 1 SWAP - LPROD }
        { DUP I\->R 0. <
           { DUP2 DUP 1 - * 2 / ^ 4. ROLLD NEG LSEQ ^ SWAP - LPROD / }
           { DROP2 DROP 1
           } IFTE
        } IFTE
        }
     { DROP2 1 SWAP -
     } IFTE
  \>>
  ZFALFAC
  \<< SWAP 1 - DUP ROT - GAMMA SWAP GAMMA SWAP /
  \>>
  ZPOCH
  \<< OVER + GAMMA SWAP GAMMA /
  \>>
  SFF
  \<< 1 - OVER SWAP - LSEQR LPROD
  \>>
  SPOCH
  \<< 1 - OVER + LSEQR LPROD
  \>>
  SQP
  \<< 0 SWAP 1 - LSEQR ^ * 1 SWAP - LPROD
  \>>
END
Find all posts by this user
Quote this message in a reply
04-19-2021, 07:47 PM (This post was last modified: 04-19-2021 07:51 PM by John Keith.)
Post: #2
RE: (49g/50g) Falling and Rising Factorials
Updating to add a program to compute the q-factorials, [n]q!. With an integer n on level 2 and q on level 1, the program will return a list of the q- factorials from 0 to n. If all commands after the first LSCAN are removed, the program will return the q-numbers, [n]q.

The level 2 argument n must be an integer; q can be integer, real, complex, rational or symbolic. The program requires ListExt 1.3.

Technical information can be found here. Also see the thread on Gaussian binomial coefficients for related programs.

Code:

\<< SWAP 1 - LMRPT 1 { * 1 + EVAL } LSCAN 1 { * EVAL } LSCAN
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)