/** * Returns an <code>IExpr</code> whose value is <code>(this + that)</code>. Calculates <code>F.eval(F.Plus(this, that))</code> in * the common case and uses a specialized implementation for derived number classes. * * @param that * @return */ default IExpr plus(final IExpr that) { if (that.isZero()) { return this; } EvalEngine engine = EvalEngine.get(); if (engine.isTogetherMode() && (this.isPlusTimesPower() || that.isPlusTimesPower())) { return engine.evaluate(F.Together(F.Plus(this, that))); } return engine.evaluate(F.Plus(this, that)); }
@Override default IExpr subtract(IExpr that) { if (that.isZero()) { return this; } EvalEngine engine = EvalEngine.get(); if (engine.isTogetherMode() && (this.isPlusTimesPower() || that.isPlusTimesPower())) { return engine.evaluate(F.Together(F.Plus(this, F.Times(F.CN1, that)))); } return engine.evaluate(F.Plus(this, F.Times(F.CN1, that))); }
temp = F.eval(F.Together(expr)); count = fComplexityFunction.apply(temp); if (count < minCounter) {
/** * Returns an <code>IExpr</code> whose value is <code>(this * that)</code>. Calculates <code>F.eval(F.Times(this, that))</code> in * the common case and uses a specialized implementation for derived number classes. * * @param that the multiplier expression * @return <code>(this * that)</code> */ default IExpr times(final IExpr that) { if (that.isZero()) { return F.C0; } if (that.isOne()) { return this; } EvalEngine engine = EvalEngine.get(); if (engine.isTogetherMode() && (this.isPlusTimesPower() || that.isPlusTimesPower())) { return engine.evaluate(F.Together(F.Times(this, that))); } return engine.evaluate(F.Times(this, that)); }
/** * Returns an <code>IExpr</code> whose value is <code>(this ^ that)</code>. Calculates <code>F.eval(F.Power(this, that))</code> in * the common case and uses a specialized implementation for derived number classes. * * @param that * @return <code>(this ^ that)</code> */ default IExpr power(final IExpr that) { if (that.isZero()) { if (!this.isZero()) { return F.C1; } } else if (that.isOne()) { return this; } // if (this.isNumber() && that.isNumber()) { // return F.eval(F.Power(this, that)); // } EvalEngine engine = EvalEngine.get(); if (engine.isTogetherMode() && (this.isPlusTimesPower() || that.isPlusTimesPower())) { return engine.evaluate(F.Together(F.Power(this, that))); } return engine.evaluate(F.Power(this, that)); }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 4); // TODO allow multinomials IExpr arg3 = Validate.checkSymbolType(ast, 3); ISymbol x = (ISymbol) arg3; IExpr a = F.evalExpandAll(ast.arg1(), engine); IExpr b = F.evalExpandAll(ast.arg2(), engine); ExprPolynomialRing ring = new ExprPolynomialRing(F.List(x)); try { // check if a is a polynomial otherwise check ArithmeticException, ClassCastException ring.create(a); // check if b is a polynomial otherwise check ArithmeticException, ClassCastException ring.create(b); return F.Together(resultant(a, b, x, engine)); } catch (RuntimeException ex) { throw new WrongArgumentType(ast, b, 2, "Polynomial expected!"); } }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); if (ast.arg1().isList()) { IAST list = (IAST) ast.arg1(); if (list.size() > 1) { int size = list.argSize(); IASTAppendable resultList = F.ListAlloc(list.size()); IASTMutable plus = F.binary(F.Plus, F.C0, list.arg1()); IASTMutable result = plus; for (int i = 2; i <= size; i++) { IExpr temp; if (result.isAST()) { temp = engine.evaluate(F.Together(((IAST) result).copy())); } else { temp = engine.evaluate(result); } resultList.append(temp); IASTMutable plusAST = F.binary(F.Plus, F.C0, list.get(i)); plus.set(1, F.Power(plusAST, F.CN1)); plus = plusAST; } resultList.append(engine.evaluate(F.Together(result))); return resultList; } } return F.NIL; }
/** * Converts a FieldMatrix to the list expression representation. * * @param matrix * @return */ public static IAST matrix2List(final FieldMatrix<ExprFieldElement> matrix) { if (matrix == null) { return null; } final int rowSize = matrix.getRowDimension(); final int colSize = matrix.getColumnDimension(); final IAST out = F.List(); IAST currOutRow; for (int i = 0; i < rowSize; i++) { currOutRow = F.List(); out.add(currOutRow); for (int j = 0; j < colSize; j++) { IExpr expr = matrix.getEntry(i, j).getExpr(); if (expr instanceof INumber) { currOutRow.add(expr); } else { currOutRow.add(F.eval(F.Together(expr))); } } } out.addEvalFlags(IAST.IS_MATRIX); return out; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); FieldMatrix<ExprFieldElement> aMatrix; FieldVector<ExprFieldElement> bVector; try { aMatrix = Convert.list2Matrix((IAST) ast.get(1)); bVector = Convert.list2Vector((IAST) ast.get(2)); final FieldLUDecomposition<ExprFieldElement> lu = new FieldLUDecomposition<ExprFieldElement>(aMatrix); FieldDecompositionSolver<ExprFieldElement> fds = lu.getSolver(); FieldVector<ExprFieldElement> xVector = fds.solve(bVector); return F.eval(F.Together(Convert.vector2List(xVector))); } catch (final ClassCastException e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } catch (final IndexOutOfBoundsException e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } return null; }
/** * Returns an <code>IExpr</code> whose value is <code>(this / that)</code>. Calculates * <code>F.eval(F.Times(this, F.Power(that, F.CN1)))</code> in the common case and uses a specialized implementation for derived * number classes. * * @param that * @return */ @Override default IExpr divide(IExpr that) { if (that.isOne()) { return this; } if (that.isMinusOne()) { return negate(); } EvalEngine engine = EvalEngine.get(); if (engine.isTogetherMode() && (this.isPlusTimesPower() || that.isPlusTimesPower())) { return engine.evaluate(F.Together(F.Times(this, that.inverse()))); } return engine.evaluate(F.Times(this, that.inverse())); }
temp = F.eval(F.Together(expr)); count = LeafCount.leafCount(temp); if (count < minCounter) {
IAST divisorList = ni.divisors(); return F.Together(F.intIterator(F.Times, d -> F.Power(F.Plus(F.C1, F.Negate(F.Power(x, d))), F.MoebiusMu(F.Times(F.Power(d, -1), ni))), divisorList));
u = F.C1; } else { IExpr f = engine.evaluate(F.Together(F.Divide(d, n))); if (f.isFree(y)) { u = engine.evaluate(F.Exp(F.Integrate(f, x)));
rule = F.Rule(listOfVariables.get(j), F.eval(F.Together(plus.getOneIdentity(F.C0)))); list.append(rule);