@Override public IExpr apply(final IExpr arg) { return fConstant.replaceAll(F.Rule(fLHS, arg)); }
public IExpr createFunction(final IParserFactory factory, final IExpr argument) { if (fOperatorString.equals("?")) { return F.Information(argument, F.Rule(F.LongForm, F.False)); } // ?? operator: return F.Information(argument); }
@Override public IExpr apply(final IExpr firstArg) { return fEngine.evalN(F.subst(fFunction, F.Rule(fVariable, firstArg))); }
public IExpr apply(final IExpr firstArg) { return F.evaln(F.subst(fFunction, F.Rule(fVariable, firstArg))); }
@Override public void solved(Solver solver, Solution solution) { if (solution != null) { Set<Entry<ISymbol, IntVariable>> set = map.entrySet(); IASTAppendable temp = F.ListAlloc(set.size()); for (Entry<ISymbol, IntVariable> entry : set) { temp.append(F.Rule(entry.getKey(), F.integer(solution.getIntValue(entry.getValue())))); } result.append(temp); } } }, 10000);
/** * Create a new <code>F.Limit( arg1, ... )</code> expression from his <code>LimitData</code> object * * @param arg1 * the first argument of the Limit expression * @return a new <code>F.Limit( arg1, ... )</code> expression */ public IAST limit(IExpr arg1) { // if (direction == DIRECTION_FROM_LARGER_VALUES) { // return F.Limit(arg1, rule, F.Rule(F.Direction, F.CN1)); // } if (direction == DIRECTION_FROM_BELOW) { return F.Limit(arg1, rule, F.Rule(F.Direction, F.C1)); } return F.Limit(arg1, rule); }
/** * Substitute all (sub-) expressions <code>x</code> with <code>y</code>. If no substitution matches, the method * returns the given <code>expr</code>. * * @param expr * the complete expresssion * @param x * the subexpression which should be replaced * @param y * the expression which replaces <code>x</code> * @return the input <code>expr</code> if no substitution of a (sub-)expression was possible or the substituted * expression. */ public static IExpr subs(final IExpr expr, final IExpr x, final IExpr y) { return expr.replaceAll(F.Rule(x, y)).orElse(expr); }
public FindFitParametricFunction(final IExpr function, final IAST gradientList, final IAST listOfSymbols, final ISymbol x, final EvalEngine engine) { this.function = function; this.engine = engine; this.gradientList = gradientList; this.listOfRules = F.ListAlloc(gradientList.size()); this.listOfRules.append(F.Rule(x, F.Null)); for (int i = 1; i < listOfSymbols.size(); i++) { this.listOfRules.append(F.Rule(listOfSymbols.get(i), F.Null)); } }
public IAST literals2VariableList(final SortedSet<Literal> literals, Map<String, Integer> map) { IASTAppendable list = F.ast(F.List, map.size(), true); // initialize all list elements with Null for (int i = 0; i < map.size(); i++) { list.set(i + 1, F.Null); } for (Literal a : literals) { Integer val = map.get(a.name()); if (val != null) { if (a.phase()) { list.set(val + 1, F.Rule(variable2symbolMap.get(a.variable()), F.True)); } else { list.set(val + 1, F.Rule(variable2symbolMap.get(a.variable()), F.False)); } } } return list; } }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); final EvalEngine engine = EvalEngine.get(); IExpr leftHandSide = ast.get(1); leftHandSide = PatternMatcher.evalLeftHandSide(leftHandSide, engine); IExpr arg2 = engine.evalNull(ast.get(2)); if (arg2 == null) { if (leftHandSide.equals(ast.get(1))) { return null; } return Rule(leftHandSide, ast.get(2)); } return Rule(leftHandSide, arg2); }
/** * Get the coefficient rules of a polynomial <code>List()</code> form * * @return the monomials of a polynomial */ public IAST coefficientRules() { IASTAppendable result = F.ListAlloc(val.size()); for (Map.Entry<ExpVectorLong, IExpr> monomial : val.entrySet()) { IExpr coeff = monomial.getValue(); ExpVectorLong exp = monomial.getKey(); int len = exp.length(); IASTAppendable ruleList = F.ListAlloc(len); for (int i = 0; i < len; i++) { ruleList.append(F.integer(exp.getVal(len - i - 1))); } result.append(F.Rule(ruleList, coeff)); } return result; }
/** * Substitute all (sub-) expressions with the given replacement expression. If no (sub-) expression matches, the * method returns the given <code>expr</code>. * * @param expr * @param subExpr * @param replacementExpr * @return the input <code>expr</code> if no substitution of a (sub-)expression was possible or the substituted * expression. */ public static IExpr subst(IExpr expr, IExpr subExpr, IExpr replacementExpr) { return expr.replaceAll(Functors.rules(Rule(subExpr, replacementExpr), EvalEngine.get())).orElse(expr); }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 3); IExpr leftHandSide = ast.arg1(); if (leftHandSide.isAST()) { leftHandSide = engine.evalHoldPattern((IAST) leftHandSide); } else { leftHandSide = engine.evaluate(leftHandSide); } IExpr arg2 = engine.evaluateNull(ast.arg2()); if (!arg2.isPresent()) { if (leftHandSide.equals(ast.arg1())) { return F.NIL; } return Rule(leftHandSide, ast.arg2()); } return Rule(leftHandSide, arg2); }
@Override public double[] computeDerivatives(double t, double[] xyz) { double[] xyzDot = new double[fDimension]; IExpr[] replacements = new IExpr[fDimension]; IASTAppendable rules = F.ListAlloc(fDimension + 1); for (int i = 0; i < fDimension; i++) { replacements[i] = F.$(fVariables.get(i + 1), fT); rules.append(F.Rule(replacements[i], F.num(xyz[i]))); } rules.append(F.Rule(fT, F.num(t))); IExpr[] dotEquations = new IExpr[fDimension]; for (int i = 0; i < fDimension; i++) { dotEquations[i] = fDotEquations[i].replaceAll(rules); } for (int i = 0; i < fDimension; i++) { xyzDot[i] = ((INum) fEngine.evalN(dotEquations[i])).doubleValue(); } return xyzDot; } }
/** * Get a list of rules <code>{listOfSymbols[1] -> values[0], .... }</code>. * * @param listOfSymbols * @param values * * @return */ private static IExpr convertToRulesList(IAST listOfSymbols, double[] values) { IASTAppendable result = F.ListAlloc(listOfSymbols.size()); for (int i = 1; i < listOfSymbols.size(); i++) { result.append(F.Rule(listOfSymbols.get(i), F.num(values[i - 1]))); } return result; }
protected static IExpr simplexSolver(VariablesSet vars, LinearObjectiveFunction f, OptimizationData... optData) { try { SimplexSolver solver = new SimplexSolver(); PointValuePair solution = solver.optimize(optData); double[] values = solution.getPointRef(); IASTAppendable list = F.ListAlloc(values.length); List<IExpr> varList = vars.getArrayList(); for (int i = 0; i < values.length; i++) { list.append(F.Rule(varList.get(i), F.num(values[i]))); } IAST result = F.List(F.num(f.value(values)), list); return result; } catch (MathIllegalStateException oe) { throw new WrappedException(oe); // if (Config.SHOW_STACKTRACE) { // oe.printStackTrace(); // } } } }
/** * Get exponent vectors and coefficients of monomials of a polynomial expression. * * @param polynomial * @param variablesList * @param termOrder * the JAS term ordering * @return the list of monomials of the univariate polynomial. */ public static IAST coefficientRules(IExpr polynomial, final List<IExpr> variablesList, final TermOrder termOrder) throws JASConversionException { JASIExpr jas = new JASIExpr(variablesList, ExprRingFactory.CONST, termOrder, false); GenPolynomial<IExpr> polyExpr = jas.expr2IExprJAS(polynomial); IASTAppendable resultList = F.ListAlloc(polyExpr.length()); for (Monomial<IExpr> monomial : polyExpr) { IExpr coeff = monomial.coefficient(); ExpVector exp = monomial.exponent(); int len = exp.length(); IASTAppendable ruleList = F.ListAlloc(len); for (int i = 0; i < len; i++) { ruleList.append(F.integer(exp.getVal(len - i - 1))); } resultList.append(F.Rule(ruleList, coeff)); } return resultList; }
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { if (ast.isAST2() && (ast.arg2().isVector() == 3)) { IAST list = (IAST) ast.arg2(); final int upperLimit = Validate.checkIntType(list, 3, 0); if (upperLimit < 0) { return F.NIL; } IASTAppendable fadd = F.PlusAlloc(upperLimit+2); fadd.append(F.ReplaceAll(ast.arg1(), F.Rule(list.arg1(), list.arg2()))); IExpr temp = ast.arg1(); IExpr factor = null; for (int i = 1; i <= upperLimit; i++) { temp = F.D(temp, list.arg1()); factor = F.Times(F.Power(F.Factorial(F.integer(i)), F.CN1), F.Power(F.Plus(list.arg1(), F.Times(F.CN1, list.arg2())), F .integer(i))); fadd.append(F.Times(F.ReplaceAll(temp, F.Rule(list.arg1(), list.arg2())), factor)); } return fadd; } return F.NIL; } }