/** * @param that * @return */ @Override public IExpr times(final IExpr that) { if (that instanceof IntegerSym) { return this.multiply((IntegerSym) that); } if (isZero()) { return F.C0; } if (that instanceof FractionSym) { return FractionSym.valueOf(fInteger).multiply((FractionSym) that); } return super.times(that); }
IntegerSym b = this; if (sign() < 0) { b = b.multiply(IntegerSym.valueOf(-1)); result.add(IntegerSym.valueOf(-1));
public IntegerSym jacobiSymbol(IntegerSym b) { if (this.compareTo(IntegerSym.valueOf(1)) == 0) { return IntegerSym.valueOf(1); } if (this.compareTo(IntegerSym.valueOf(2)) == 0) { return b.jacobiSymbolF(); } if (!isOdd()) { return this.quotient(IntegerSym.valueOf(2)).jacobiSymbol(b).multiply(IntegerSym.valueOf(2).jacobiSymbol(b)); } return b.quotient(this).jacobiSymbol(this).multiply(jacobiSymbolG(b)); }
/** * Returns the nth-root of this integer. * * @return <code>k<code> such as <code>k^n <= this < (k + 1)^n</code> * @throws ArithmeticException * if this integer is negative and n is even. */ public IInteger nthRoot(int n) throws ArithmeticException { if (sign() == 0) { return IntegerSym.valueOf(0); } else if (sign() < 0) { if (n % 2 == 0) { // even exponent n throw new ArithmeticException(); } else { // odd exponent n return (IntegerSym) ((IntegerSym) negate()).nthRoot(n).negate(); } } else { IntegerSym result; IntegerSym temp = this; do { result = temp; temp = divideAndRemainder(temp.pow(n - 1))[0].add(temp.multiply(IntegerSym.valueOf(n - 1))).divideAndRemainder( IntegerSym.valueOf(n))[0]; } while (temp.compareTo(result) < 0); return result; } }