Package jahuwaldt.js.math
Class BinomialCoef
- java.lang.Object
-
- jahuwaldt.js.math.BinomialCoef
-
- All Implemented Interfaces:
SizedObject,javolution.lang.Immutable,javolution.lang.ValueType
public final class BinomialCoef extends java.lang.Object implements javolution.lang.ValueType, SizedObject
This class represents an immutable matrix of binomial coefficients (n/k) defined up to a specified maximum index.
( n ) n! ( ) = -------- 0 ≤ k ≤ n ( k ) k!(n-k)!Reference: http://en.wikipedia.org/wiki/Binomial_coefficient
Modified by: Joseph A. Huwaldt
- Version:
- February 22, 2025
- Author:
- Joseph A. Huwaldt, Date: May 11, 2011
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BinomialCoefcopy()Returns a copy of this binomial coefficient matrixallocatedby the calling thread (possibly on the stack).doubleget(int n, int k)Return the specified binomial coefficient (n / k)static BinomialCoefnewInstance(int size)Returns aBinomialCoefinstance holding the coefficients (at least) up to the specified size.static voidrecycle(BinomialCoef instance)Recycles aBinomialCoefinstance immediately (on the stack when executing in a StackContext).intsize()Return the size of the binomial coefficient matrix (the maximum binomial index value: (N/N)).javolution.text.TexttoText()Returns the text representation of this binomial coefficient matrix.
-
-
-
Method Detail
-
newInstance
public static BinomialCoef newInstance(int size)
Returns aBinomialCoefinstance holding the coefficients (at least) up to the specified size. The returned instance may be recycled and may contain more coefficients than the requested size.- Parameters:
size- the desired size to compute coefficients for:N = size - 1 ==> (N/N)orsize = N + 1.- Returns:
- The binomial coefficient matrix having at least specified size.
-
size
public int size()
Return the size of the binomial coefficient matrix (the maximum binomial index value: (N/N)).- Specified by:
sizein interfaceSizedObject- Returns:
- the size of the object.
-
get
public double get(int n, int k)
Return the specified binomial coefficient (n / k)- Parameters:
n- The 1st index into the binomial coefficient matrix (n / k). Must be < size().k- The 2nd index into the binomial coefficient matrix (n / k). Must be < size().- Returns:
- The specified binomial coefficient as a double.
-
copy
public BinomialCoef copy()
Returns a copy of this binomial coefficient matrixallocatedby the calling thread (possibly on the stack).- Specified by:
copyin interfacejavolution.lang.ValueType- Returns:
- an identical and independent copy of this binomial coefficient matrix.
-
recycle
public static void recycle(BinomialCoef instance)
Recycles aBinomialCoefinstance immediately (on the stack when executing in a StackContext).- Parameters:
instance- The instance of this class to be recycled.
-
toText
public javolution.text.Text toText()
Returns the text representation of this binomial coefficient matrix.- Returns:
- the text representation of this binomial coefficient matrix.
-
-