/** * The Bernoulli number at the index provided. * * @param n the index, non-negative. * @return the B_0=1 for n=0, B_1=-1/2 for n=1, B_2=1/6 for n=2 etc */ public Rational at(int n) { if (n == 1) { return (new Rational(-1, 2)); } else if (n % 2 != 0) { return Rational.ZERO; } else { final int nindx = n / 2; if (a.size() <= nindx) { for (int i = 2 * a.size(); i <= n; i += 2) { set(i, doubleSum(i)); } } return a.get(nindx); } } /* Generate a new B_n by a standard double sum.
/** * The Bernoulli number at the index provided. * * @param n the index, non-negative. * @return the B_0=1 for n=0, B_1=-1/2 for n=1, B_2=1/6 for n=2 etc */ public Rational at(int n) { if (n == 1) { return (new Rational(-1, 2)); } else if (n % 2 != 0) { return Rational.ZERO; } else { final int nindx = n / 2; if (a.size() <= nindx) { for (int i = 2 * a.size(); i <= n; i += 2) { set(i, doubleSum(i)); } } return a.get(nindx); } } /* Generate a new B_n by a standard double sum.
Rational b = (new Bernoulli()).at(n).abs(); b = b.divide((new Factorial()).at(n)); b = b.multiply(BigInteger.ONE.shiftLeft(n - 1)); Bernoulli bern = new Bernoulli(); Factorial fact = new Factorial(); Rational b = bern.at(2 * npr).multiply(bern.at(n + 1 - 2 * npr)); b = b.divide(fact.at(2 * npr)).divide(fact.at(n + 1 - 2 * npr)); b = b.multiply(1 - 2 * npr);
Rational b = (new Bernoulli()).at(n).abs(); b = b.divide((new Factorial()).at(n)); b = b.multiply(BigInteger.ONE.shiftLeft(n - 1)); Bernoulli bern = new Bernoulli(); Factorial fact = new Factorial(); Rational b = bern.at(2 * npr).multiply(bern.at(n + 1 - 2 * npr)); b = b.divide(fact.at(2 * npr)).divide(fact.at(n + 1 - 2 * npr)); b = b.multiply(1 - 2 * npr);