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:
- October 16, 2015
- Author:
- Joseph A. Huwaldt, Date: May 11, 2011
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BinomialCoef
copy()
Returns a copy of this binomial coefficient matrixallocated
by the calling thread (possibly on the stack).double
get(int n, int k)
Return the specified binomial coefficient (n / k)static BinomialCoef
newInstance(int size)
Returns aBinomialCoef
instance holding the coefficients (at least) up to the specified size.static void
recycle(BinomialCoef instance)
Recycles aBinomialCoef
instance immediately (on the stack when executing in a StackContext).int
size()
Return the size of the binomial coefficient matrix (the maximum binomial index value: (N/N)).javolution.text.Text
toText()
Returns the text representation of this binomial coefficient matrix.
-
-
-
Method Detail
-
newInstance
public static BinomialCoef newInstance(int size)
Returns aBinomialCoef
instance 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:
size
in interfaceSizedObject
-
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 matrixallocated
by the calling thread (possibly on the stack).- Specified by:
copy
in interfacejavolution.lang.ValueType
- Returns:
- an identical and independent copy of this binomial coefficient matrix.
-
recycle
public static void recycle(BinomialCoef instance)
Recycles aBinomialCoef
instance immediately (on the stack when executing in a StackContext).
-
toText
public javolution.text.Text toText()
Returns the text representation of this binomial coefficient matrix.- Returns:
- the text representation of this binomial coefficient matrix.
-
-