Wednesday, January 2, 2019

HP Prime and Casio fx-5800p: Rational Binomial Coefficients

HP Prime and Casio fx-5800p:  Rational Binomial Coefficients

Introduction

Let p be a rational fraction, p = num/dem.  The rational binomial coefficients of order n are defined by:

B_0(p) = 1

B_n(p) = COMB(p, n) = ( p * (p - 1) * (p - 2) * (p - 3) * ... * (p - n + 1) ) / n!

There are algorithms, but the program RATBIN uses the definition. 

HP Prime Program RATBIN

Arguments:  rational fraction, order

EXPORT RATBIN(p,n)
BEGIN
// 2018-12-26 EWS
// p-q, n
// Rational Binomial Coefficient
LOCAL X;
IF n==0 THEN
RETURN 1;
ELSE
IF n==1 THEN
RETURN p;
ELSE
RETURN QPI(ΠLIST(p-MAKELIST(X,X,0,n-1))/n!);
END;
END;
END;

* Note: the result is not always a fraction, but you can convert the answer to fraction by pressing [ a b/c ]

Casio fx-5800p Program RATBIN

For fractional results, use the fraction button [  []/[] ].

"2018-12-26 EWS"
"FRACTION"? → P
"ORDER?" → N
If N=0
Then
0
IfEnd
If N=1
Then
1
IfEnd
If N>1
Then
Prod (P-Seq(X,X,0,N-1,1)) ÷ N! → Q
Q
IfEnd

Examples

b_2(1/2) = -1/8

b_3(1/2) = 1/16

b_4(1/2) = -5/128

b_5(1/2) = 7/256

Source:

Henrici, Peter.  Computational Analysis With the HP-25 Calculator  A Wiley-Interscience Publication. John Wiley & Sons: New York 1977 .  ISBN 0-471-02938-6

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

RPN with HP 15C & DM32: Swapping Items in the Stack

RPN with HP 15C & DM32: Swapping Items in the Stack A New Series Welcome to a new series: RPN with the HP 15C & DM32. ...