@Nonnull public Variable newInstance() { return new Fraction(null, null); } }
static Generic linear(Generic parameter[]) { Generic a = new Fraction(parameter[0], parameter[1]).selfSimplify(); return a.negate(); }
@Nonnull public Generic divide(@Nonnull Generic that) throws NotDivisibleException { if (that instanceof JsclVector) { throw new ArithmeticException("Unable to divide vector by vector!"); } else if (that instanceof Matrix) { return multiply(that.inverse()); } else { final JsclVector result = (JsclVector) newInstance(); for (int i = 0; i < rows; i++) { try { result.elements[i] = elements[i].divide(that); } catch (NotDivisibleException e) { result.elements[i] = new Fraction(elements[i], that).selfExpand(); } } return result; } }
@Nonnull public Generic divide(@Nonnull Generic that) throws NotDivisibleException { if (that instanceof Matrix) { return multiply(that.inverse()); } else if (that instanceof JsclVector) { throw new ArithmeticException("Unable to divide matrix by vector: matrix could not be divided by vector!"); } else { Matrix m = (Matrix) newInstance(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { try { m.elements[i][j] = elements[i][j].divide(that); } catch (NotDivisibleException e) { m.elements[i][j] = new Fraction(elements[i][j], that).selfExpand(); } } } return m; } }
public Generic selfElementary() { return new Fraction(parameters[0], new Abs(parameters[0]).selfElementary()).selfElementary(); }
public Variable variableValue() throws NotVariableException { try { integerValue(); throw new NotVariableException(); } catch (NotIntegerException e) { if (numerator.compareTo(BigInteger.valueOf(1)) == 0) return new Inverse(new JsclInteger(denominator)); else return new Fraction(new JsclInteger(numerator), new JsclInteger(denominator)); } }
static Generic quadratic(Generic parameter[], int subscript) { Generic a = new Fraction(parameter[1], parameter[2]).selfSimplify(); Generic b = new Fraction(parameter[0], parameter[2]).selfSimplify(); Generic y = new Sqrt( a.pow(2).subtract(JsclInteger.valueOf(4).multiply(b)) ).selfSimplify(); switch (subscript) { case 0: return new Fraction( a.subtract(y), JsclInteger.valueOf(2) ).selfSimplify().negate(); default: return new Fraction( a.add(y), JsclInteger.valueOf(2) ).selfSimplify().negate(); } }
public Generic selfElementary() { return new Fraction( new Cosh(parameters[0]).selfElementary(), new Sinh(parameters[0]).selfElementary() ).selfElementary(); }
public Generic selfElementary() { return new Fraction( new Sinh(parameters[0]).selfElementary(), new Cosh(parameters[0]).selfElementary() ).selfElementary(); }
public Generic selfElementary() { return new Fraction( new Sin(parameters[0]).selfElementary(), new Cos(parameters[0]).selfElementary() ).selfElementary(); }
public Generic selfElementary() { return new Fraction( new Cos(parameters[0]).selfElementary(), new Sin(parameters[0]).selfElementary() ).selfElementary(); }
static Generic nth(Generic parameter[]) { int degree = parameter.length - 1; Generic a = new Fraction(parameter[0], parameter[degree]).selfSimplify(); return new Pow( a.negate(), new Inverse(JsclInteger.valueOf(degree)).selfSimplify() ).selfSimplify(); }
public Generic selfExpand() { if (isZero()) return JsclInteger.valueOf(0); try { int s = subscript.integerValue().intValue(); switch (degree()) { case 1: return new Fraction(parameters[0], parameters[1]).selfExpand().negate(); } } catch (NotIntegerException e) { } return expressionValue(); }
public Generic antiDerivative(int n) throws NotIntegrableException { // tmp = ln(x) - 1 final Generic tmp = new Ln(parameters[0]).expressionValue().subtract(ONE); // ln10 = ln (10) final Generic ln10 = new Ln(JsclInteger.valueOf(10L)).expressionValue(); return new Fraction(parameters[0].multiply(tmp), ln10).expressionValue(); }
public Generic identity(Generic a, Generic b) { Generic ta = new Tan(a).selfSimplify(); Generic tb = new Tan(b).selfSimplify(); return new Fraction( ta.add(tb), JsclInteger.valueOf(1).subtract( ta.multiply(tb) ) ).selfSimplify(); }
public Generic identity(Generic a, Generic b) { Generic ta = new Cot(a).selfSimplify(); Generic tb = new Cot(b).selfSimplify(); return new Fraction( ta.multiply(tb).subtract(JsclInteger.valueOf(1)), ta.add(tb) ).selfSimplify(); }
public Generic identity(Generic a, Generic b) { Generic ta = new Tanh(a).selfSimplify(); Generic tb = new Tanh(b).selfSimplify(); return new Fraction( ta.add(tb), JsclInteger.valueOf(1).add( ta.multiply(tb) ) ).selfSimplify(); }
public Generic identity(Generic a, Generic b) { Generic ta = new Coth(a).selfSimplify(); Generic tb = new Coth(b).selfSimplify(); return new Fraction( ta.multiply(tb).add(JsclInteger.valueOf(1)), ta.add(tb) ).selfSimplify(); }
@Nullable private Generic simplifyFractions() { final Generic n[] = Fraction.separateCoefficient(parameters[0]); if (n[0].compareTo(JsclInteger.valueOf(1)) != 0 || n[1].compareTo(JsclInteger.valueOf(1)) != 0) { // n final Generic numerator = new Sqrt(n[0]).selfSimplify(); // d final Generic denominator = new Sqrt(n[1]).selfSimplify(); // fraction = n / d final Generic fraction = new Fraction(numerator, denominator).selfSimplify(); return new Sqrt(n[2]).selfSimplify().multiply(fraction); } return null; }