diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java index ce616b7e8..cf0b24db1 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java @@ -76,6 +76,7 @@ import org.matheclipse.core.eval.interfaces.AbstractTrigArg1; import org.matheclipse.core.eval.interfaces.IFunctionEvaluator; import org.matheclipse.core.eval.interfaces.IFunctionExpand; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.eval.interfaces.INumeric; import org.matheclipse.core.eval.interfaces.IRewrite; import org.matheclipse.core.eval.interfaces.ISetEvaluator; @@ -1555,7 +1556,18 @@ public void setUp(final ISymbol newSymbol) { * 1.1018024908797128 * */ - private static final class Gamma extends AbstractFunctionEvaluator { + private static final class Gamma extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return GammaRules.match3(ast, engine); + } + + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return GammaRules.match4(ast, engine); + } // @Override // public IExpr e1ApcomplexArg(Apcomplex arg1) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BesselFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BesselFunctions.java index 7f39f6766..6b7521e16 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BesselFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BesselFunctions.java @@ -19,6 +19,7 @@ import org.matheclipse.core.eval.exception.ValidateException; import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.IFunctionExpand; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.expression.F; import org.matheclipse.core.expression.ImplementationStatus; import org.matheclipse.core.expression.S; @@ -410,7 +411,12 @@ public void setUp(final ISymbol newSymbol) { * * */ - private static final class BesselJ extends AbstractFunctionEvaluator { + private static final class BesselJ extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return BesselJRules.match3(ast, engine); + } /** * Precondition n - 1/2 is an integer number. @@ -650,7 +656,12 @@ public void setUp(final ISymbol newSymbol) { * * */ - private static final class BesselI extends AbstractFunctionEvaluator { + private static final class BesselI extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return BesselIRules.match3(ast, engine); + } @Override @@ -760,7 +771,12 @@ public void setUp(final ISymbol newSymbol) { * * */ - private static final class BesselK extends AbstractFunctionEvaluator { + private static final class BesselK extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return BesselKRules.match3(ast, engine); + } @Override @@ -864,7 +880,12 @@ public void setUp(final ISymbol newSymbol) { * * */ - private static final class BesselY extends AbstractFunctionEvaluator { + private static final class BesselY extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return BesselYRules.match3(ast, engine); + } @Override @@ -1127,7 +1148,12 @@ public void setUp(final ISymbol newSymbol) { * */ private static final class SphericalBesselJ extends AbstractFunctionEvaluator - implements IFunctionExpand { + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return SphericalBesselJRules.match3(ast, engine); + } @Override public IExpr functionExpand(final IAST ast, EvalEngine engine) { @@ -1390,7 +1416,12 @@ public void setUp(final ISymbol newSymbol) { *

Examples

*/ private static final class SphericalBesselY extends AbstractFunctionEvaluator - implements IFunctionExpand { + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return SphericalBesselYRules.match3(ast, engine); + } @Override public IExpr functionExpand(final IAST ast, EvalEngine engine) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ExpTrigsFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ExpTrigsFunctions.java index 6c29d99de..d199fed2e 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ExpTrigsFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ExpTrigsFunctions.java @@ -48,6 +48,7 @@ import org.matheclipse.core.eval.interfaces.AbstractEvaluator; import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.AbstractTrigArg1; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.eval.interfaces.INumeric; import org.matheclipse.core.eval.interfaces.IReciprocalTrigonometricFunction; import org.matheclipse.core.eval.interfaces.IRewrite; @@ -903,7 +904,14 @@ public IExpr evalAsLeadingTerm(IAST ast, ISymbol x, IExpr logx, int cdir) { * See * Inverse_trigonometric functions */ - private static final class ArcTan extends AbstractArg12 implements INumeric, IRewrite { + private static final class ArcTan extends AbstractArg12 implements INumeric, IRewrite, IMatch + { + + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return ArcTanRules.match3(ast, engine); + } @Override public IExpr e1ObjArg(final IExpr arg1) { @@ -2244,7 +2252,17 @@ public void setUp(ISymbol newSymbol) { } /** See Wikipedia - Logarithm */ - private static final class Log extends AbstractArg12 implements INumeric, IRewrite { + private static final class Log extends AbstractArg12 implements INumeric, IRewrite, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return LogRules.match3(ast, engine); + } + + @Override + public IExpr evaluate(IAST ast, EvalEngine engine) { + return super.evaluate(ast, engine); + } @Override public IExpr e1ApfloatArg(Apfloat arg1) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/HypergeometricFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/HypergeometricFunctions.java index 90dd9e691..25c228476 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/HypergeometricFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/HypergeometricFunctions.java @@ -21,6 +21,7 @@ import org.matheclipse.core.eval.exception.ValidateException; import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.IFunctionExpand; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.expression.F; import org.matheclipse.core.expression.ImplementationStatus; import org.matheclipse.core.expression.S; @@ -887,7 +888,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class Hypergeometric1F1 extends AbstractFunctionEvaluator { + private static class Hypergeometric1F1 extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return Hypergeometric1F1Rules.match4(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1077,7 +1083,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class Hypergeometric2F1 extends AbstractFunctionEvaluator { + private static class Hypergeometric2F1 extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match5(IAST ast, EvalEngine engine) { + return F.NIL; + // return Hypergeometric2F1Rules.match5(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1243,7 +1254,13 @@ public void setUp(final ISymbol newSymbol) { } } - private static class Hypergeometric2F1Regularized extends AbstractFunctionEvaluator { + private static class Hypergeometric2F1Regularized extends AbstractFunctionEvaluator + implements IMatch { + @Override + public IExpr match5(IAST ast, EvalEngine engine) { + return F.NIL; + // return Hypergeometric2F1RegularizedRules.match5(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1319,7 +1336,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class HypergeometricPFQ extends AbstractFunctionEvaluator { + private static class HypergeometricPFQ extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return HypergeometricPFQRules.match4(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1422,7 +1444,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class HypergeometricU extends AbstractFunctionEvaluator { + private static class HypergeometricU extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return HypergeometricURules.match4(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1769,8 +1796,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class WhittakerM extends AbstractFunctionEvaluator { - + private static class WhittakerM extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return WhittakerMRules.match4(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { @@ -1834,7 +1865,12 @@ public void setUp(final ISymbol newSymbol) { } } - private static class WhittakerW extends AbstractFunctionEvaluator { + private static class WhittakerW extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return WhittakerWRules.match4(ast, engine); + } @Override public IExpr evaluate(IAST ast, EvalEngine engine) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PolynomialFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PolynomialFunctions.java index 46b4924ad..9dccb313e 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PolynomialFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PolynomialFunctions.java @@ -24,6 +24,7 @@ import org.matheclipse.core.eval.exception.Validate; import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.IFunctionExpand; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.eval.util.OptionArgs; import org.matheclipse.core.expression.F; import org.matheclipse.core.expression.ImplementationStatus; @@ -1145,10 +1146,17 @@ public void setUp(final ISymbol newSymbol) { - private static final class SphericalHarmonicY extends AbstractFunctionEvaluator { + private static final class SphericalHarmonicY extends AbstractFunctionEvaluator + implements IMatch { + @Override + public IExpr match5(IAST ast, EvalEngine engine) { + return F.NIL; + // return SphericalHarmonicYRules.match5(ast, engine); + } @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { + IExpr l = ast.arg1(); IExpr m = ast.arg2(); IExpr t = ast.arg3(); @@ -1798,11 +1806,16 @@ public void setUp(final ISymbol newSymbol) { } } - private static final class JacobiP extends AbstractFunctionEvaluator { + private static final class JacobiP extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match5(IAST ast, EvalEngine engine) { + return F.NIL; + // return JacobiPRules.match5(ast, engine); + } @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { - + // } IExpr n = ast.arg1(); IExpr a = ast.arg2(); IExpr b = ast.arg3(); @@ -2105,7 +2118,12 @@ public void setUp(final ISymbol newSymbol) { * 3/8-15/4*x^2+35/8*x^4 * */ - private static final class LegendreP extends AbstractFunctionEvaluator { + private static final class LegendreP extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return LegendrePRules.match3(ast, engine); + } @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { @@ -2188,7 +2206,12 @@ public void setUp(final ISymbol newSymbol) { * 55/24*z-35/8*z^3-3/16*Log(1-z)+15/8*z^2*Log(1-z)-35/16*z^4*Log(1-z)+3/16*Log(1+z)-15/8*z^2*Log(1+z)+35/16*z^4*Log(1+z) * */ - static final class LegendreQ extends AbstractFunctionEvaluator { + static final class LegendreQ extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return LegendreQRules.match3(ast, engine); + } @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java index dfe278a4b..c688dfa4c 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java @@ -42,6 +42,7 @@ import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.AbstractTrigArg1; import org.matheclipse.core.eval.interfaces.IFunctionExpand; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.eval.interfaces.INumeric; import org.matheclipse.core.expression.ApcomplexNum; import org.matheclipse.core.expression.ApfloatNum; @@ -987,7 +988,12 @@ public void setUp(final ISymbol newSymbol) { } - private static class HurwitzLerchPhi extends AbstractFunctionEvaluator { + private static class HurwitzLerchPhi extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return HurwitzLerchPhiRules.match4(ast, engine); + } @Override @@ -1416,8 +1422,12 @@ public void setUp(final ISymbol newSymbol) { } - private static class LerchPhi extends AbstractFunctionEvaluator { - + private static class LerchPhi extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return LerchPhiRules.match4(ast, engine); + } @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { @@ -1552,7 +1562,13 @@ public void setUp(final ISymbol newSymbol) { - private static class PolyGamma extends AbstractFunctionEvaluator implements IFunctionExpand { + private static class PolyGamma extends AbstractFunctionEvaluator + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return PolyGammaRules.match3(ast, engine); + } public IExpr e1ApfloatArg(Apfloat arg1) { FixedPrecisionApfloatHelper h = EvalEngine.getApfloat(); @@ -1730,7 +1746,14 @@ public void setUp(final ISymbol newSymbol) { } - private static class PolyLog extends AbstractFunctionEvaluator implements IFunctionExpand { + private static class PolyLog extends AbstractFunctionEvaluator + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return PolyLogRules.match3(ast, engine); + } + @Override public IExpr functionExpand(final IAST ast, EvalEngine engine) { @@ -2094,7 +2117,13 @@ public IExpr e2ObjArg(IExpr k, IExpr z) { } - private static class StieltjesGamma extends AbstractFunctionEvaluator { + private static class StieltjesGamma extends AbstractFunctionEvaluator implements IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return StieltjesGammaRules.match3(ast, engine); + } + @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { @@ -2103,10 +2132,6 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { // Non-negative machine-sized integer expected at position `2` in `1`. return Errors.printMessage(S.StieltjesGamma, "intnm", F.List(ast, F.C1), engine); } - if (ast.isAST2()) { - IExpr a = ast.arg2(); - - } return F.NIL; } @@ -2128,7 +2153,13 @@ public void setUp(final ISymbol newSymbol) { } - private static final class StruveH extends AbstractFunctionEvaluator implements IFunctionExpand { + private static final class StruveH extends AbstractFunctionEvaluator + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return StruveHRules.match3(ast, engine); + } @Override public IExpr functionExpand(final IAST ast, EvalEngine engine) { @@ -2220,7 +2251,13 @@ public void setUp(final ISymbol newSymbol) { } - private static final class StruveL extends AbstractFunctionEvaluator implements IFunctionExpand { + private static final class StruveL extends AbstractFunctionEvaluator + implements IFunctionExpand, IMatch { + @Override + public IExpr match3(IAST ast, EvalEngine engine) { + return F.NIL; + // return StruveLRules.match3(ast, engine); + } @Override public IExpr functionExpand(final IAST ast, EvalEngine engine) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java index f4dc93471..1289b77ac 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StatisticsFunctions.java @@ -2605,7 +2605,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { } return F.num(StatUtils.geometricMean(arg1DoubleArray)); } - return F.Power(list.apply(S.Times), F.fraction(1, arg1.argSize())); + return F.Power(list.apply(S.Times), F.QQ(1, arg1.argSize())); } return F.NIL; } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/BuiltInSymbol.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/BuiltInSymbol.java index 4a9a14b18..5b02eada5 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/BuiltInSymbol.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/BuiltInSymbol.java @@ -20,6 +20,7 @@ import org.matheclipse.core.interfaces.IExpr; import org.matheclipse.core.interfaces.IPredicate; import org.matheclipse.core.interfaces.ISymbol; +import org.matheclipse.core.patternmatching.RulesData; import org.matheclipse.parser.client.ParserConfig; /** Implements Symbols for function, constant and variable names */ @@ -155,6 +156,15 @@ public int compareTo(IExpr expr) { return super.compareTo(expr); } + /** {@inheritDoc} */ + @Override + public final RulesData createRulesData(int[] sizes) { + if (fRulesData == null) { + fRulesData = new RulesData(sizes, this); + } + return fRulesData; + } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/Symbol.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/Symbol.java index 0fe70f278..ee141a3f1 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/Symbol.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/Symbol.java @@ -240,7 +240,7 @@ public IExpr copy() { /** {@inheritDoc} */ @Override - public final RulesData createRulesData(int[] sizes) { + public RulesData createRulesData(int[] sizes) { if (fRulesData == null) { fRulesData = new RulesData(sizes); } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/patternmatching/RulesData.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/patternmatching/RulesData.java index d61b3b6e6..66ea618a3 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/patternmatching/RulesData.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/patternmatching/RulesData.java @@ -9,13 +9,16 @@ import java.util.Map; import org.matheclipse.core.basic.Config; import org.matheclipse.core.eval.EvalEngine; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.eval.util.OpenIntToIExprHashMap; import org.matheclipse.core.expression.Context; import org.matheclipse.core.expression.F; import org.matheclipse.core.expression.S; import org.matheclipse.core.interfaces.IAST; import org.matheclipse.core.interfaces.IASTAppendable; +import org.matheclipse.core.interfaces.IBuiltInSymbol; import org.matheclipse.core.interfaces.IEvalStepListener; +import org.matheclipse.core.interfaces.IEvaluator; import org.matheclipse.core.interfaces.IExpr; import org.matheclipse.core.interfaces.IPatternObject; import org.matheclipse.core.interfaces.IStringX; @@ -92,6 +95,8 @@ private static boolean isComplicatedPatternExpr(IExpr a1) { private Map fEqualDownRules; + private IMatch fMatcher; + /** * List of pattern matchers. The corresponding priority is stored in fPriorityDownRules * . @@ -125,6 +130,26 @@ public RulesData(int[] sizes) { } } + public RulesData(int[] sizes, IBuiltInSymbol head) { + // this.context = context; + clear(); + IEvaluator evaluator = head.getEvaluator(); + if (evaluator instanceof IMatch) { + fMatcher = (IMatch) evaluator; + } + + if (sizes.length > 0) { + int capacity; + if (sizes[0] > 0) { + capacity = sizes[0]; + if (capacity < 8) { + capacity = 8; + } + fEqualDownRules = new HashMap(capacity); + } + } + } + /** * Run the given visitor on every IAST stored in the rule database. Example: optimize internal * memory usage by sharing common objects. @@ -412,14 +437,20 @@ public IExpr evalDownRule(final IExpr expr, EvalEngine engine) { return res.getRHS(); } } - if (!expr.isASTOrAssociation()) { return F.NIL; } - boolean evalRHSMode = engine.isEvalRHSMode(); try { engine.setEvalRHSMode(true); + + if (fMatcher != null && expr.isAST() && expr.size() < 6) { + IExpr temp = evalDecisionTree(expr, engine); + if (temp.isPresent()) { + return temp; + } + } + IPatternMatcher pmEvaluator; if (fPatternDownRules != null) { int patternHash = 0; @@ -481,6 +512,34 @@ public IExpr evalDownRule(final IExpr expr, EvalEngine engine) { return F.NIL; } + /** + * Try matching the expr expression with the pattern-matching rules create with the + * org.matheclipse.core.decisiontree.RulesToDecionTree if a matching rule was found, + * return the evaluated right-hand-side of that matching rule, otherwise return {@link F#NIL}. + * + * @param expr the expression which will be tested for matching an existing pattern-matching rule + * @param engine the evaluation engine + * @return {@link F#NIL} if no matching/evaluation was possible + */ + private IExpr evalDecisionTree(final IExpr expr, EvalEngine engine) { + IExpr match = F.NIL; + switch (expr.size()) { + case 2: + match = fMatcher.match2((IAST) expr, engine); + break; + case 3: + match = fMatcher.match3((IAST) expr, engine); + break; + case 4: + match = fMatcher.match4((IAST) expr, engine); + break; + case 5: + match = fMatcher.match5((IAST) expr, engine); + break; + } + return match; + } + private static boolean isShowSteps(IPatternMatcher pmEvaluator) { IExpr head = pmEvaluator.getLHS().head(); if (head.isSymbol() && ((ISymbol) head).isContext(Context.RUBI)) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/InverseLaplaceTransform.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/InverseLaplaceTransform.java index 29129f9dc..440183920 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/InverseLaplaceTransform.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/InverseLaplaceTransform.java @@ -6,6 +6,7 @@ import org.matheclipse.core.eval.EvalEngine; import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator; import org.matheclipse.core.eval.interfaces.IFunctionEvaluator; +import org.matheclipse.core.eval.interfaces.IMatch; import org.matheclipse.core.expression.F; import org.matheclipse.core.expression.ImplementationStatus; import org.matheclipse.core.expression.S; @@ -25,7 +26,7 @@ * * *
- * + * *

* returns the inverse laplace transform. * @@ -45,7 +46,7 @@ * 3*E^t+2*Cos(2*t) * */ -public class InverseLaplaceTransform extends AbstractFunctionEvaluator { +public class InverseLaplaceTransform extends AbstractFunctionEvaluator implements IMatch { /** * The {@code InverseLaplaceTransformStehfest} implements the numerical calculation of the inverse @@ -131,10 +132,14 @@ public double inverseTransform(double time) { } - - public InverseLaplaceTransform() {} + @Override + public IExpr match4(IAST ast, EvalEngine engine) { + return F.NIL; + // return InverseLaplaceTransformRules.match4(ast, engine); + } + /** See: Inverse Laplace transforms */ @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/ArcTanRules.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/ArcTanRules.java index c5f9cd684..de48130a7 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/ArcTanRules.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/ArcTanRules.java @@ -13,7 +13,7 @@ public class ArcTanRules { *

  • index 0 - number of equal rules in RULES
  • * */ - final public static int[] SIZES = { 24, 1 }; + final public static int[] SIZES = { 23, 2 }; final public static IAST RULES = List( IInit(ArcTan, SIZES), @@ -77,8 +77,8 @@ public class ArcTanRules { // ArcTan(x_,Undefined):=Undefined ISetDelayed(ArcTan(x_,Undefined), Undefined), - // ArcTan(Infinity,y_)=0 - ISet(ArcTan(oo,y_), + // ArcTan(Infinity,y_):=0 + ISetDelayed(ArcTan(oo,y_), C0), // ArcTan(Infinity)=Pi/2 ISet(ArcTan(oo), diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/FunctionExpandRules.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/FunctionExpandRules.java index 78c9f2521..4f8875c11 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/FunctionExpandRules.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/FunctionExpandRules.java @@ -144,6 +144,9 @@ public class FunctionExpandRules { // Hypergeometric1F1(a_,1,z_):=LaguerreL(-a,z) SetDelayed(Hypergeometric1F1(a_,C1,z_), LaguerreL(Negate(a),z)), + // Hypergeometric1F1(a_,b_,z_):=(E^(z/2)*z^(1/2-a)*BesselI(1/2*(-1+b),z/2)*Gamma(1/2+a))/4^(1/2-a)/;a==b/2 + SetDelayed(Hypergeometric1F1(a_,b_,z_), + Condition(Times(Power(Power(C4,Subtract(C1D2,a)),CN1),Exp(Times(C1D2,z)),Power(z,Subtract(C1D2,a)),BesselI(Times(C1D2,Plus(CN1,b)),Times(C1D2,z)),Gamma(Plus(C1D2,a))),Equal(a,Times(C1D2,b)))), // Hypergeometric2F1(2,b_,c_,-1/2):=1/3*(3-b)/;5/2-b/2==Expand(c) SetDelayed(Hypergeometric2F1(C2,b_,c_,CN1D2), Condition(Times(C1D3,Subtract(C3,b)),Equal(Plus(QQ(5L,2L),Times(CN1D2,b)),Expand(c)))), diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/HurwitzLerchPhiRules.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/HurwitzLerchPhiRules.java index 8b9afc893..33e704d2d 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/HurwitzLerchPhiRules.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/HurwitzLerchPhiRules.java @@ -32,9 +32,9 @@ public class HurwitzLerchPhiRules { // HurwitzLerchPhi(z_,1,1):=-Log(1-z)/z ISetDelayed(HurwitzLerchPhi(z_,C1,C1), Times(CN1,Power(z,CN1),Log(Subtract(C1,z)))), - // HurwitzLerchPhi(-1,s_,1):=(1-2^(1-s))*Zeta(s) + // HurwitzLerchPhi(-1,s_,1):=(1-2^(1-s))*Zeta(s)/;s!=1 ISetDelayed(HurwitzLerchPhi(CN1,s_,C1), - Times(Subtract(C1,Power(C2,Subtract(C1,s))),Zeta(s))), + Condition(Times(Subtract(C1,Power(C2,Subtract(C1,s))),Zeta(s)),Unequal(s,C1))), // HurwitzLerchPhi(0,1,a_):=1/a ISetDelayed(HurwitzLerchPhi(C0,C1,a_), Power(a,CN1)) diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/SphericalHarmonicYRules.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/SphericalHarmonicYRules.java index 46ec93dee..27d8ef5f1 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/SphericalHarmonicYRules.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/rules/SphericalHarmonicYRules.java @@ -13,13 +13,13 @@ public class SphericalHarmonicYRules { *
  • index 0 - number of equal rules in RULES
  • * */ - final public static int[] SIZES = { 1, 10 }; + final public static int[] SIZES = { 0, 11 }; final public static IAST RULES = List( IInit(SphericalHarmonicY, SIZES), - // SphericalHarmonicY(0,0,t_,p_)=1/(2*Sqrt(Pi)) - ISet(SphericalHarmonicY(C0,C0,t_,p_), - Times(C1D2,Power(Pi,CN1D2))), + // SphericalHarmonicY(0,0,t_,p_):=1/(2*Sqrt(Pi)) + ISetDelayed(SphericalHarmonicY(C0,C0,t_,p_), + Power(Times(C2,CSqrtPi),CN1)), // SphericalHarmonicY(1,-1,t_,p_):=(Sqrt(3/(2*Pi))*Sin(t))/(2*E^(I*p)) ISetDelayed(SphericalHarmonicY(C1,CN1,t_,p_), Times(C1D2,Power(Exp(Times(CI,p)),CN1),Sqrt(Times(C3,Power(C2Pi,CN1))),Sin(t))), diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/BesselFunctionTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/BesselFunctionTest.java index 9ef885791..7fbb5f72b 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/BesselFunctionTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/BesselFunctionTest.java @@ -300,6 +300,9 @@ public void testBesselK() { @Test public void testBesselY() { + check("BesselY(-5/2, z)", // + "(Sqrt(2/Pi)*((-3*Cos(z))/z-Sin(z)+(3*Sin(z))/z^2))/Sqrt(z)"); + checkNumeric("BesselY(2.5,-5)", // "I*(-0.2943723749617925)"); check("BesselY(3.5,-5)", // diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/FunctionExpandTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/FunctionExpandTest.java index 58460718d..7e70d9779 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/FunctionExpandTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/FunctionExpandTest.java @@ -273,6 +273,12 @@ public void testFunctionExpandHarmonicNumber() { "-Pi/(2*Sqrt(3))-Log(6)-Log(Sqrt(3)/2)"); } + @Test + public void testFunctionExpandJacobiP() { + check("FunctionExpand(JacobiP(n,a,b,1))", // + "Gamma(1+a+n)/(Gamma(1+a)*Gamma(1+n))"); + } + @Test public void testFunctionExpandBeta() { diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/JacobiTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/JacobiTestCase.java index 03ac078c8..f0f06c937 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/JacobiTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/JacobiTestCase.java @@ -210,6 +210,8 @@ public void testJacobiDN() { @Test public void testJacobiSC() { + check("JacobiSC((I*EllipticK(1 - m))/2, m)", // + "I/Sqrt(1+Sqrt(m))"); check("JacobiSC(Pi/3,0.333333)", // "1.54453"); check("JacobiSC(0.2,0.5)", // @@ -222,8 +224,7 @@ public void testJacobiSC() { ""); check("f(1/2*I*x)", // "{x}"); - check("JacobiSC((I*EllipticK(1 - m))/2, m)", // - "I/Sqrt(1+Sqrt(m))"); + check("JacobiSC(z,0)", // "Tan(z)"); check("JacobiSC(z,1)", // diff --git a/symja_android_library/rules/ArcTanRules.m b/symja_android_library/rules/ArcTanRules.m index 143096ec8..5d4f9c73f 100644 --- a/symja_android_library/rules/ArcTanRules.m +++ b/symja_android_library/rules/ArcTanRules.m @@ -22,7 +22,7 @@ ArcTan(Undefined, y_):=Undefined, ArcTan(x_, Undefined):=Undefined, - ArcTan(Infinity, y_)=0, + ArcTan(Infinity, y_):=0, ArcTan(Infinity)=Pi/2, ArcTan(-Infinity)=-Pi/2, ArcTan(I*Infinity)=Pi/2, diff --git a/symja_android_library/rules/FunctionExpandRules.m b/symja_android_library/rules/FunctionExpandRules.m index 15325dbb2..cfe2ae9ab 100644 --- a/symja_android_library/rules/FunctionExpandRules.m +++ b/symja_android_library/rules/FunctionExpandRules.m @@ -64,6 +64,8 @@ Hypergeometric0F1(a_,z_) := z^(1/2-a/2)*BesselI(-1+a,2*Sqrt(z))*Gamma(a), Hypergeometric1F1(a_,1,z_) := LaguerreL(-a,z), + Hypergeometric1F1(a_,b_,z_) := (E^(z/2)*z^(1/2-a)*BesselI(1/2*(-1+b),z/2)*Gamma(1/2+a))/4^(1/2-a) + /; a==b/2, Hypergeometric2F1(2, b_, c_, -1/2) := (3-b)/3 /; (5/2 - 1/2*b)==Expand(c), diff --git a/symja_android_library/rules/HurwitzLerchPhiRules.m b/symja_android_library/rules/HurwitzLerchPhiRules.m index 59929c746..8011d3c4b 100644 --- a/symja_android_library/rules/HurwitzLerchPhiRules.m +++ b/symja_android_library/rules/HurwitzLerchPhiRules.m @@ -5,6 +5,6 @@ HurwitzLerchPhi(z_, 0, a_) := 1/(1-z), HurwitzLerchPhi(0, s_, a_) := a^(-s), HurwitzLerchPhi(z_, 1, 1) := -Log(1-z)/z, - HurwitzLerchPhi(-1, s_, 1) := (1-2^(1-s))*Zeta(s), + HurwitzLerchPhi(-1, s_, 1) := (1-2^(1-s))*Zeta(s) /; s!=1, HurwitzLerchPhi(0, 1, a_) := 1/a } \ No newline at end of file diff --git a/symja_android_library/rules/SphericalHarmonicYRules.m b/symja_android_library/rules/SphericalHarmonicYRules.m index a6764f986..ac47d8422 100644 --- a/symja_android_library/rules/SphericalHarmonicYRules.m +++ b/symja_android_library/rules/SphericalHarmonicYRules.m @@ -1,5 +1,5 @@ { - SphericalHarmonicY(0, 0, t_, p_) = 1/(2*Sqrt(Pi)), + SphericalHarmonicY(0, 0, t_, p_) := 1/(2*Sqrt(Pi)), SphericalHarmonicY(1, -1, t_, p_) := ((1/2)*Sqrt(3/(2*Pi))*Sin(t))/E^(I*p), SphericalHarmonicY(1, 1, t_, p_) := (-1/2)*E^(I*p)*Sqrt(3/(2*Pi))*Sin(t), SphericalHarmonicY(n_, 0, 0, p_) := Sqrt(1 + 2*n)/(2*Sqrt(Pi)),