@Override public IExpr visit(IPattern element) { IExpr temp = fFunction.apply(element); if (temp.isPresent()) { return temp; } ISymbol symbol = element.getSymbol(); if (symbol != null) { IExpr expr = fFunction.apply(symbol); if (expr.isPresent() && expr.isSymbol()) { if (element.isPatternDefault()) { return F.$p((ISymbol) expr, element.getHeadTest(), true); } return F.$p((ISymbol) expr, element.getHeadTest()); } } return F.NIL; }
return F.$p((ISymbol) convert(pn.getSymbol()), convert(pn.getConstraint()), pn.isDefault());
IPattern patt = (IPattern) arg1; if (patt.getHeadTest() == null) { return F.$p(patt.getSymbol(), patt.getHeadTest(), true);
pat = F.$p(pat.getSymbol()); writeAST1(F.Optional, pat); } else if (condition != null) {
temp = F.$p(symbol, null); getNextToken(); } else { if (fToken == TT_IDENTIFIER) { final IExpr check = getSymbol(); temp = F.$p(symbol, check); } else { temp = F.$p(symbol, null); temp = F.$p(symbol, null, true); getNextToken(); } else { if (fToken == TT_IDENTIFIER) { final IExpr check = getSymbol(); temp = F.$p(symbol, check, true); } else { temp = F.$p(symbol, null, true); temp = F.Optional(F.$p(symbol), defaultValue);
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { if (ast.head().equals(F.Pattern)) { if (ast.size() == 3) { if (ast.arg1().isSymbol()) { if (ast.arg2().isBlank()) { IPatternObject blank = (IPatternObject) ast.arg2(); return F.$p((ISymbol) ast.arg1(), blank.getHeadTest()); } if (ast.arg2().isAST(F.Blank, 1)) { return F.$p((ISymbol) ast.arg1()); } if (ast.arg2().isAST(F.BlankSequence, 1)) { return F.$ps((ISymbol) ast.arg1(), null, false, false); } if (ast.arg2().isAST(F.BlankNullSequence, 1)) { return F.$ps((ISymbol) ast.arg1(), null, false, true); } if (ast.arg2().isAST(F.BlankSequence, 2)) { return F.$ps((ISymbol) ast.arg1(), ast.arg2().first(), false, false); } if (ast.arg2().isAST(F.BlankNullSequence, 2)) { return F.$ps((ISymbol) ast.arg1(), ast.arg2().first(), false, true); } } } } return F.NIL; }
/** * Try using the <code>TrigReduce</code> function to get a <code>Plus(...)</code> expression which could be * integrated. * * @param timesAST * an IAST which is a <code>Times(...)</code> expression * @param arg2 * the symbol to get the indefinite integral for. * @return <code>F.NIL</code> if no trigonometric funtion could be found. */ private static IExpr integrateTimesTrigFunctions(final IAST timesAST, IExpr arg2) { Predicate<IExpr> isTrigFunction = Predicates.isAST(new ISymbol[] { F.Cos, F.Sin }); if (timesAST.has(isTrigFunction, false)) { // use a symbol which is not in the symbols map ISymbol pSymbol = new Symbol("$x$", Context.SYSTEM); IExpr fx = F.eval(F.TrigReduce(timesAST)); if (fx.isPlus()) { // Collect arguments for x // Sin(f_) -> Sin(Collect(f, arg2)) fx = F.eval(F.ReplaceAll(fx, F.List(F.Rule(F.Sin(F.$p(pSymbol)), F.Sin(F.Collect(pSymbol, arg2))), F.Rule(F.Cos(F.$p(pSymbol)), F.Cos(F.Collect(pSymbol, arg2)))))); // Integrate[a_+b_+...,x_] -> Integrate[a,x]+Integrate[b,x]+... return ((IAST) fx).mapThread(F.Integrate(null, arg2), 1); } } return F.NIL; }
public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); if (ast.get(1).isSymbol()) { if (ast.get(2).isAST("Blank")) { IAST blank = (IAST) ast.get(2); if (blank.size() == 1) { return F.$p((ISymbol)ast.get(1)); } if (blank.size() == 2) { return F.$p((ISymbol)ast.get(1), blank.get(1)); } } if (ast.get(2).isPattern()) { IPattern blank = (IPattern) ast.get(2); if (blank.isBlank()) { return F.$p((ISymbol)ast.get(1), blank.getCondition()); } } } return null; }
@Override public IExpr visit(IPattern element) { ISymbol symbol = element.getSymbol(); if (symbol != null) { IExpr expr = apply(symbol); if (expr.isPresent() && expr.isSymbol()) { if (element.isPatternDefault()) { return F.$p((ISymbol) expr, element.getHeadTest(), true); } return F.$p((ISymbol) expr, element.getHeadTest()); } } return F.NIL; }
/** * Create a pattern for pattern-matching and term rewriting * * @param symbolName * @param check * additional condition which should be checked in pattern-matching * @param def * use a default value for this pattern if necessary * @return IPattern */ public static IPattern $p(final String symbolName, boolean def) { return $p((Symbol) $s(symbolName), null, def); }
/** * Create a pattern for pattern-matching and term rewriting * * @param symbol * @param def * use a default value for this pattern if necessary * @return IPattern */ public static IPattern $p(final ISymbol symbol, boolean def) { return $p(symbol, null, def); }
public static void init() { // Dist[u_,v_]+Dist[w_,v_] := If[ZeroQ[u+w], 0, Dist[u+w,v]], org.matheclipse.core.reflection.system.Plus.CONST.setUpHashRule(Dist($p("u"), $p("v")), Dist($p("w"), $p("v")), If(ZeroQ(Plus( $s("u"), $s("w"))), C0, Dist(Plus($s("u"), $s("w")), $s("v"))), null); // Dist[u_,v_]-Dist[w_,v_] := If[ZeroQ[u-w], 0, Dist[u-w,v]], org.matheclipse.core.reflection.system.Plus.CONST.setUpHashRule(Dist($p("u"), $p("v")), Times(CN1, Dist($p("w"), $p("v"))), If( ZeroQ(Plus($s("u"), Times(CN1, $s("w")))), C0, Dist(Plus($s("u"), Times(CN1, $s("w"))), $s("v"))), null); // Dist[u_,v_]*w_ := Dist[w*u,v] /; w=!=-1 org.matheclipse.core.reflection.system.Times.CONST.setUpHashRule(Dist($p("u"), $p("v")), $p("w"), Dist(Times($s("w"), $s("u")), $s("v")), UnsameQ($s("w"), CN1)); } }
/** * Create a pattern for pattern-matching and term rewriting * * @param symbolName * @param def * use a default value for this pattern if necessary * @return IPattern */ public static IPattern $p(final String symbolName, boolean def) { return $p($s(symbolName), null, def); }