+- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP-65/67/97 Software Library (/forum-12.html) +--- Thread: (HP-67/97) Combinatorics - Extended factorial, gamma, permutations, combinations (/thread-15194.html) (HP-67/97) Combinatorics - Extended factorial, gamma, permutations, combinations - Dave Britten - 06-15-2020 01:42 PM This program provides implementations of factorial (with support for numbers greater than 69), gamma, combinations (nCr), and permutations (nPr). They run in constant time without any looping (slightly faster for integers no greater than 69 when the built-in factorial can be used). It is 92 steps, and fits comfortably on one side of a card. The program relies on using Nemes' formula to calculate an approximation of the natural logarithm of gamma without overflowing on large inputs. Large combinations/permutations are generally accurate to around 5 decimal places, but accuracy worsens as the difference between x and y increases (precision is lost when subtracting ln(x!) and ln(y!) when they differ greatly in magnitude). Keys A - ln(x!) B - ln(Γ) b - Γ(x) C - ln(yCx) c - yCx D - ln(yPx) d - yPx E - e^x→x*10^y e - Round Int Usage To use any of these functions, enter arguments in the x and y registers, and press the key for the desired function. The functions that return a natural logarithm will not overflow for large inputs/outputs. The shifted versions of Γ, nCr, and nPr return a decimal result to x, with the natural logarithm in y. Thus if the calculation overflows (9.999999999 99), it's not necessary to repeat the calculation, simply press x>Y 3  STO 1   ; n 4  LN 5  *       ; r * ln(n) 6  RCL 0 7  2  8  - 9  RCL 1  10 6  11 *  12 STO* 1 13 - 14 RCL 1 15 / 16 RCL 0 17 1 18 - 19 * 20 1 21 + 22 LN 23 RCL 0 24 2 25 / 26 *       ; ln_nr(n,r)``` Note: register X = ln_nr(n,r), Y = r*log(n). To get ln_nPr(n,r), press "+" Example, for ln_nPr(1e6, 100) 1e6 ENTER 100 [R/S] ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿→ X = -.004950165034, Y = 1381.551056 + ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿ ﻿→ ln_nPr = 1381.546106