lnPermutation
Computes the natural logarithm of the number of k-permutations of n items.
The number of k-permutations P(n, k) is the number of ways to choose and arrange k items from a set of n items, where order matters. The logarithmic form avoids overflow for large n and k. Computed as lnFactorial(n) - lnFactorial(n - k). Returns 0.0 when k is 0 (since P(n, 0) = 1).
Example:
lnPermutation(5, 2) // 2.9957... (ln(20), since P(5,2) = 20)
lnPermutation(5, 0) // 0.0 (ln(1))
lnPermutation(5, 5) // 4.7874... (ln(120), since P(5,5) = 5! = 120)Content copied to clipboard
Return
Parameters
n
the total number of items. Must be non-negative.
k
the number of items to arrange. Must satisfy 0 <= k <= n.