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)); } }
/** * Search for one of the <code>Derivative[..]</code> rules from the * <code>System.mep</code> file read at startup time. * * Examples for rules from the <code>System.mep</code> file:<br/> * <code>Derivative[Cos]=(-1)*Sin[#]&</code><br/> * <code>Derivative[Sin]=Cos[#]&</code><br/> * <code>Derivative[Tan]=Cos[#]^(-2)&</code><br/> * * @param x * @param arg1 * @param header * @return */ private IExpr getDerivativeArg1(IExpr x, final IExpr arg1, final IExpr header) { IExpr der = F.evalNull(F.Derivative, header); if (der != null) { // we've found a derivative for a function of the form f[x_] IExpr derivative = F.eval(F.$(der, arg1)); return F.Times(derivative, F.D(arg1, x)); } return null; }
ORDERLESS_MATCHER.definePatternHashRule(Power(Sin(x_), C2), Power(Cos(x_), C2), C1); ORDERLESS_MATCHER.definePatternHashRule(Power(F.Sech(x_), C2), Power(F.Tanh(x_), C2), C1); ORDERLESS_MATCHER.defineHashRule(ArcSin(x_), ArcCos(x_), F.CPiHalf); ORDERLESS_MATCHER.defineHashRule(ArcTan(x_), ArcCot(x_), F.CPiHalf); ORDERLESS_MATCHER.defineHashRule(ArcTan(x_), ArcTan(y_), // Times(C1D2, Pi), // And(Positive(x), Equal(y, Power(x, CN1)))); ORDERLESS_MATCHER.defineHashRule(F.ArcTan(F.C1D3), F.ArcTan(F.C1D2), // Times(F.C1D4, Pi)); ORDERLESS_MATCHER.defineHashRule(F.ArcTan(F.C1D3), F.ArcTan(F.QQ(1L, 7L)), // F.ArcTan(F.C1D2));
@Override public IExpr cdf(IAST dist, IExpr k) { IExpr[] minMax = minmax(dist); if (minMax != null) { IExpr a = minMax[0]; IExpr b = minMax[1]; IExpr function = // [$ (Piecewise({{(1 - a + Floor(#))/(1 - a + b), a<=#<b}, {1, # >= b}}, 0)) & $] F.Function(F.Piecewise(F.List( F.List(F.Times(F.Power(F.Plus(F.C1, F.Negate(a), b), -1), F.Plus(F.C1, F.Negate(a), F.Floor(F.Slot1))), F.And(F.LessEqual(a, F.Slot1), F.Less(F.Slot1, b))), F.List(F.C1, F.GreaterEqual(F.Slot1, b))), F.C0)); // $$; return callFunction(function, k); } return F.NIL; }
switch (size) { case 1: ast = (IASTMutable) F.headAST0(convertNode(functionNode.get(0))); break; case 2: ast = (IASTMutable) F.unaryAST1(convertNode(functionNode.get(0)), convertNode(functionNode.get(1))); break; case 3: ast = (IASTMutable) F.binaryAST2(convertNode(functionNode.get(0)), convertNode(functionNode.get(1)), convertNode(functionNode.get(2))); break; case 4: ast = (IASTMutable) F.ternaryAST3(convertNode(functionNode.get(0)), convertNode(functionNode.get(1)), convertNode(functionNode.get(2)), convertNode(functionNode.get(3))); break; default: IASTAppendable appendableAST = F.ast(convertNode(functionNode.get(0)), functionNode.size(), false); for (int i = 1; i < functionNode.size(); i++) { appendableAST.append(convertNode(functionNode.get(i))); return F.Power(ast.arg1(), F.C1D2); return F.Power(F.E, ast.arg1()); return F.Power(arg1Power.base(), ((INumber) arg1Power.exponent()).negate()); final Pattern3Node p3n = (Pattern3Node) node; SymbolNode sn = p3n.getSymbol(); return F.$ps((ISymbol) convertNode(sn), convertNode(p3n.getConstraint()), p3n.isDefault(), true);
public static IExpr parzenWindow(IExpr x) { return // [$ Piecewise({{-2*(-1 + 2*x)^3, Inequality(1/4, Less, x, LessEqual, 1/2)},{2*(1 + 2*x)^3, Inequality(-(1/2), // LessEqual, x, Less, -(1/4))},{1 - 24*x^2 - 48*x^3, Inequality(-(1/4), LessEqual, x, Less, 0)}, {1 - 24*x^2 + // 48*x^3, 0 <= x <= 1/4}}, 0) $] F.Piecewise(F.List( F.List(F.Times(F.CN2, F.Power(F.Plus(F.CN1, F.Times(F.C2, x)), 3)), F.And(F.Less(F.C1D4, x), F.LessEqual(x, F.C1D2))), F.List(F.Times(F.C2, F.Power(F.Plus(F.C1, F.Times(F.C2, x)), 3)), F.And(F.LessEqual(F.CN1D2, x), F.Less(x, F.CN1D4))), F.List(F.Plus(F.C1, F.Times(F.ZZ(-24L), F.Sqr(x)), F.Times(F.ZZ(-48L), F.Power(x, 3))), F.And(F.LessEqual(F.CN1D4, x), F.Less(x, F.C0))), F.List(F.Plus(F.C1, F.Times(F.ZZ(-24L), F.Sqr(x)), F.Times(F.ZZ(48L), F.Power(x, 3))), F.LessEqual(F.C0, x, F.C1D4))), F.C0); // $$; }
@Override public IExpr cdf(IAST dist, IExpr k) { if (dist.isAST2()) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); IExpr function = // [$ (Piecewise({{BetaRegularized(1 - m, n - Floor(#), 1 + Floor(#)), 0<=#<n}, {1, # >= n}}, // 0)) & $] F.Function(F.Piecewise(F.List( F.List(F.BetaRegularized(F.Plus(F.C1, F.Negate(m)), F.Plus(n, F.Negate(F.Floor(F.Slot1))), F.Plus(F.C1, F.Floor(F.Slot1))), F.And(F.LessEqual(F.C0, F.Slot1), F.Less(F.Slot1, n))), F.List(F.C1, F.GreaterEqual(F.Slot1, n))), F.C0)); // $$; return callFunction(function, k); } 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 static IExpr tukeyWindow(IExpr x) { return // [$ Piecewise({{1, -(1/3) - 2*x <= 0 && -(1/3) + 2*x <= 0}, {(1/2)*(1 + Cos(3*Pi*(1/6 + x))), x >= -(1/2) && // -(1/3) - 2*x > 0}, {(1/2)*(1 + Cos(3*Pi*(-(1/6) + x))), -(1/3) + 2*x > 0 && x <= 1/2}}, 0) $] F.Piecewise(F.List( F.List(F.C1, F.And(F.LessEqual(F.Plus(F.CN1D3, F.Times(F.CN2, x)), F.C0), F.LessEqual(F.Plus(F.CN1D3, F.Times(F.C2, x)), F.C0))), F.List(F.Times(F.C1D2, F.Plus(F.C1, F.Cos(F.Times(F.C3, F.Pi, F.Plus(F.QQ(1L, 6L), x))))), F.And(F.GreaterEqual(x, F.CN1D2), F.Greater(F.Plus(F.CN1D3, F.Times(F.CN2, x)), F.C0))), F.List(F.Times(F.C1D2, F.Plus(F.C1, F.Cos(F.Times(F.C3, F.Pi, F.Plus(F.QQ(-1L, 6L), x))))), F.And(F.Greater(F.Plus(F.CN1D3, F.Times(F.C2, x)), F.C0), F.LessEqual(x, F.C1D2)))), F.C0); // $$; }
/** * <p> * Match <code>a_.*variable^n_+b_.*variable^m_</code> to * <code>E^(((-I)*Pi + Log(a) - Log(b))/(m - n)) /; FreeQ(a,x)&&FreeQ(b,x)&&FreeQ(n,x)&&FreeQ(m,x)</code> * </p> * * @param ast * @param x * @return */ private static IExpr matchSpecialExpressions(IAST ast, IExpr exprWithoutVariable, IExpr x) { if (exprWithoutVariable.isZero()) { final Matcher matcher = new Matcher(); // match a_.*variable^n_.+b_.*variable^m_ to E^(((-I)*Pi + Log(a) - Log(b))/(m - n)) matcher.caseOf( F.Plus(F.Times(F.b_DEFAULT, F.Power(x, F.m_)), F.Times(F.a_DEFAULT, F.Power(x, F.n_DEFAULT))), // F.Condition( F.Exp(F.Times(F.Power(F.Plus(F.m, F.Negate(F.n)), -1), F.Plus(F.Times(F.CNI, F.Pi), F.Log(F.a), F.Negate(F.Log(F.b))))), F.And(F.FreeQ(F.a, x), F.FreeQ(F.b, x), F.FreeQ(F.n, x), F.FreeQ(F.m, x)))); return matcher.replaceAll(ast); } return F.NIL; }
final IAST ast = F.ast(convert(functionNode.get(0)), functionNode.size(), false); for (int i = 1; i < functionNode.size(); i++) { ast.add(convert(functionNode.get(i))); return F.$s(nodeStr); return F.$ps((ISymbol) convert(p2n.getSymbol()), convert(p2n.getConstraint()), p2n.isDefault()); return F.$p((ISymbol) convert(pn.getSymbol()), convert(pn.getConstraint()), pn.isDefault()); final String iStr = integerNode.getString(); if (iStr != null) { return F.integer(iStr, integerNode.getNumberFormat()); return F.integer(integerNode.getIntValue()); return F.fraction((IInteger) convert(fr.getNumerator()), (IInteger) convert(fr.getDenominator())).negate(); return F.fraction((IInteger) convert(((FractionNode) node).getNumerator()), (IInteger) convert(((FractionNode) node) .getDenominator())); return F.stringx(node.getString()); return F.num(node.getString()); return F.$s(node.toString());
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { Validate.checkSize(ast, 2); int[] dim = ast.arg1().isMatrix(); if (dim == null && ast.arg1().isListOfLists()) { return F.NIL; } if (dim != null) { IAST matrix = (IAST) ast.arg1(); return matrix.mapMatrixColumns(dim, x -> F.MeanDeviation(x)); } int length = ast.arg1().isVector(); if (length > 0) { IAST vector = (IAST) ast.arg1(); int size = vector.size(); IASTAppendable sum = F.PlusAlloc(size); final IExpr mean = F.eval(F.Mean(F.Negate(vector))); vector.forEach(x -> sum.append(F.Abs(F.Plus(x, mean)))); return F.Times(F.Power(F.ZZ(size - 1), -1), sum); } return F.NIL; }
public static IExpr bartlettWindow(IExpr x) { return // [$ Piecewise({{1 - 2*x, 0 <= x <= 1/2}, {1 + 2*x, Inequality(-(1/2), LessEqual, x, Less, 0)}}, 0) // $] F.Piecewise(F.List(F.List(F.Plus(F.C1, F.Times(F.CN2, x)), F.LessEqual(F.C0, x, F.C1D2)), F.List(F.Plus(F.C1, F.Times(F.C2, x)), F.And(F.LessEqual(F.CN1D2, x), F.Less(x, F.C0)))), F.C0); // $$; }
@Override public IExpr cdf(IAST dist, IExpr k) { if (dist.isAST1()) { IExpr p = dist.arg1(); IExpr function = // [$ (Piecewise({{0, # < 0}, {1 - p, 0<=#<1 }}, 1)) & $] F.Function( F.Piecewise( F.List(F.List(F.C0, F.Less(F.Slot1, F.C0)), F.List(F.Plus(F.C1, F.Negate(p)), F.And(F.LessEqual(F.C0, F.Slot1), F.Less(F.Slot1, F.C1)))), F.C1)); // $$; return callFunction(function, k); } return F.NIL; }
temp = F.evalExpandAll(expr); count = fComplexityFunction.apply(temp); if (count < minCounter) { temp = F.eval(F.TrigExpand(expr)); count = fComplexityFunction.apply(temp); if (count < minCounter) { temp = F.eval(F.TrigToExp(expr)); count = fComplexityFunction.apply(temp); if (count < minCounter) { temp = F.eval(F.ExpToTrig(expr)); count = fComplexityFunction.apply(temp); if (count < minCounter) { temp = F.eval(F.Together(expr)); count = fComplexityFunction.apply(temp); if (count < minCounter) { IExpr denominator = parts[1]; if (denominator.isPlus() && !numerator.isPlusTimesPower()) { IExpr test = ((IAST) denominator).map(x -> F.Divide(x, numerator), 1); temp = F.eval(F.Divide(F.C1, test)); count = fComplexityFunction.apply(temp); if (count < minCounter) { temp = F.eval(F.Factor(expr)); count = fComplexityFunction.apply(temp);
public IExpr evaluate(final IAST functionList) { if (functionList.size() != 3) { throw new WrongNumberOfArguments(functionList, 2, functionList.size() - 1); } IExpr arg1 = functionList.get(1); IExpr arg2 = functionList.get(2); int dim1 = arg1.isVector(); if (dim1 > (-1)) { int dim2 = arg2.isVector(); if (dim1 == dim2) { if (dim1 == 0) { return F.C0; } IAST a1 = ((IAST) arg1); IAST a2 = ((IAST) arg2); IAST plusAST = F.Plus(); for (int i = 1; i < a1.size(); i++) { plusAST.add(F.Sqr(F.Abs(F.Subtract(a1.get(i), a2.get(i))))); } return F.Sqrt(plusAST); } } return null; }