/** * Returns n!. Shorthand for {@code n} <a * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * product of the numbers {@code 1,...,n}. * <p> * <Strong>Preconditions</strong>: * <ul> * <li> {@code n >= 0} (otherwise * {@code IllegalArgumentException} is thrown)</li> * <li> The result is small enough to fit into a {@code long}. The * largest value of {@code n} for which {@code n!} < * Long.MAX_VALUE} is 20. If the computed value exceeds {@code Long.MAX_VALUE} * an {@code ArithMeticException } is thrown.</li> * </ul> * </p> * * @param n argument * @return {@code n!} * @throws MathArithmeticException if the result is too large to be represented * by a {@code long}. * @throws NotPositiveException if {@code n < 0}. * @throws MathArithmeticException if {@code n > 20}: The factorial value is too * large to fit in a {@code long}. * @deprecated use {@link CombinatoricsUtils#factorial(int)} */ @Deprecated public static long factorial(final int n) throws NotPositiveException, MathArithmeticException { return CombinatoricsUtils.factorial(n); }
double inv = 1.0 / CombinatoricsUtils.factorial(i); for (int j = 0; j < y.length; ++j) { y[j] *= inv;
/** Evaluate Taylor expansion of a derivative structure. * @param ds array holding the derivative structure * @param dsOffset offset of the derivative structure in its array * @param delta parameters offsets (Δx, Δy, ...) * @return value of the Taylor expansion at x + Δx, y + Δy, ... * @throws MathArithmeticException if factorials becomes too large */ public double taylor(final double[] ds, final int dsOffset, final double ... delta) throws MathArithmeticException { double value = 0; for (int i = getSize() - 1; i >= 0; --i) { final int[] orders = getPartialDerivativeOrders(i); double term = ds[dsOffset + i]; for (int k = 0; k < orders.length; ++k) { if (orders[k] > 0) { try { term *= FastMath.pow(delta[k], orders[k]) / CombinatoricsUtils.factorial(orders[k]); } catch (NotPositiveException e) { // this cannot happen throw new MathInternalError(e); } } } value += term; } return value; }
return sum / factorial(k);
public static int getNumMatches(Entry<? extends Collection<?>, ? extends Collection<?>> quadGroup) { int result; int c = quadGroup.getKey().size(); int q = quadGroup.getValue().size(); if(c > q) { // If there are more candidates quads than query quads, we can't map all of them result = 0; } else { result = (int)(CombinatoricsUtils.factorial(q) / CombinatoricsUtils.factorial(q - c)); } return result; }
/** * Returns n!. Shorthand for {@code n} <a * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * product of the numbers {@code 1,...,n}. * <p> * <Strong>Preconditions</strong>: * <ul> * <li> {@code n >= 0} (otherwise * {@code IllegalArgumentException} is thrown)</li> * <li> The result is small enough to fit into a {@code long}. The * largest value of {@code n} for which {@code n!} < * Long.MAX_VALUE} is 20. If the computed value exceeds {@code Long.MAX_VALUE} * an {@code ArithMeticException } is thrown.</li> * </ul> * </p> * * @param n argument * @return {@code n!} * @throws MathArithmeticException if the result is too large to be represented * by a {@code long}. * @throws NotPositiveException if {@code n < 0}. * @throws MathArithmeticException if {@code n > 20}: The factorial value is too * large to fit in a {@code long}. * @deprecated use {@link CombinatoricsUtils#factorial(int)} */ @Deprecated public static long factorial(final int n) throws NotPositiveException, MathArithmeticException { return CombinatoricsUtils.factorial(n); }
/** * Returns n!. Shorthand for {@code n} <a * href="http://mathworld.wolfram.com/Factorial.html"> Factorial</a>, the * product of the numbers {@code 1,...,n}. * <p> * <Strong>Preconditions</strong>: * <ul> * <li> {@code n >= 0} (otherwise * {@code IllegalArgumentException} is thrown)</li> * <li> The result is small enough to fit into a {@code long}. The * largest value of {@code n} for which {@code n!} < * Long.MAX_VALUE} is 20. If the computed value exceeds {@code Long.MAX_VALUE} * an {@code ArithMeticException } is thrown.</li> * </ul> * </p> * * @param n argument * @return {@code n!} * @throws MathArithmeticException if the result is too large to be represented * by a {@code long}. * @throws NotPositiveException if {@code n < 0}. * @throws MathArithmeticException if {@code n > 20}: The factorial value is too * large to fit in a {@code long}. * @deprecated use {@link CombinatoricsUtils#factorial(int)} */ @Deprecated public static long factorial(final int n) throws NotPositiveException, MathArithmeticException { return CombinatoricsUtils.factorial(n); }
/** * Gets the probability to arrive {@link #getK() K} events in the current time, * considering the expected average arrival time {@link #getLambda() lambda}. * It computes the Probability Mass Function (PMF) of the Poisson distribution. * @return * @see <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a> */ public double eventsArrivalProbability(){ return (Math.pow(getLambda(), k) * Math.exp(-getLambda())) / CombinatoricsUtils.factorial(k); }
double inv = 1.0 / CombinatoricsUtils.factorial(i); for (int j = 0; j < y.length; ++j) { y[j] *= inv;
double inv = 1.0 / CombinatoricsUtils.factorial(i); for (int j = 0; j < y.length; ++j) { y[j] *= inv;
/** Evaluate Taylor expansion of a derivative structure. * @param ds array holding the derivative structure * @param dsOffset offset of the derivative structure in its array * @param delta parameters offsets (Δx, Δy, ...) * @return value of the Taylor expansion at x + Δx, y + Δy, ... * @throws MathArithmeticException if factorials becomes too large */ public double taylor(final double[] ds, final int dsOffset, final double ... delta) throws MathArithmeticException { double value = 0; for (int i = getSize() - 1; i >= 0; --i) { final int[] orders = getPartialDerivativeOrders(i); double term = ds[dsOffset + i]; for (int k = 0; k < orders.length; ++k) { if (orders[k] > 0) { try { term *= Math.pow(delta[k], orders[k]) / CombinatoricsUtils.factorial(orders[k]); } catch (NotPositiveException e) { // this cannot happen throw new MathInternalError(e); } } } value += term; } return value; }
/** Evaluate Taylor expansion of a derivative structure. * @param ds array holding the derivative structure * @param dsOffset offset of the derivative structure in its array * @param delta parameters offsets (Δx, Δy, ...) * @return value of the Taylor expansion at x + Δx, y + Δy, ... * @throws MathArithmeticException if factorials becomes too large */ public double taylor(final double[] ds, final int dsOffset, final double ... delta) throws MathArithmeticException { double value = 0; for (int i = getSize() - 1; i >= 0; --i) { final int[] orders = getPartialDerivativeOrders(i); double term = ds[dsOffset + i]; for (int k = 0; k < orders.length; ++k) { if (orders[k] > 0) { try { term *= FastMath.pow(delta[k], orders[k]) / CombinatoricsUtils.factorial(orders[k]); } catch (NotPositiveException e) { // this cannot happen throw new MathInternalError(e); } } } value += term; } return value; }
scenarios = permuteBenchmarks ? Ints.checkedCast(CombinatoricsUtils.factorial(selectedDatabases.size())) : 1;
return sum / factorial(k);