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 4bef976e10..7c8aea1564 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 @@ -2569,6 +2569,9 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { @Override public IExpr numericEval(final IAST ast, EvalEngine engine) { IExpr arg1 = ast.arg1(); + if (arg1.isList()) { + return ((IAST) arg1).mapThread(ast, 1); + } if (ast.isAST1()) { return numericEvalAST1(arg1, engine); } @@ -2588,7 +2591,7 @@ public IExpr numericEval(final IAST ast, EvalEngine engine) { return Errors.printMessage(S.N, "precgt", F.list(arg2, F.ZZ(Config.MAX_PRECISION_APFLOAT)), engine); } - return numericEvalAST2(arg1, nDigitPrecision, engine); + return numericEvalAST2(arg1, arg2, nDigitPrecision, engine); } finally { engine.setNumericMode(oldNumericMode); engine.setNumericPrecision(oldDigitPrecision); @@ -2605,13 +2608,24 @@ private static IExpr numericEvalAST1(IExpr expr, EvalEngine engine) { // avoid infinite recursions in symbolic mode if (expr.isNumericFunction(true)) { engine.setNumericMode(true, numericPrecision, oldSignificantFigures); - return engine.evalWithoutNumericReset(expr); + IExpr temp = engine.evalWithoutNumericReset(expr); + if (temp.isList()) { + return ((IAST) temp).mapThread(F.N(F.Slot1), 1); + } + return temp; } expr = engine.evaluate(expr); if (expr.isInexactNumber()) { return expr; } + if (expr.isList()) { + return ((IAST) expr).mapThread(F.N(F.Slot1), 1); + } engine.setNumericMode(true, numericPrecision, oldSignificantFigures); + if (expr.isAST()) { + ISymbol topSymbol = expr.topHead(); + expr = engine.evalArgs((IAST) expr, topSymbol.getAttributes(), true).orElse(expr); + } return engine.evalWithoutNumericReset(expr); } finally { engine.setNumericMode(oldNumericMode); @@ -2619,12 +2633,16 @@ private static IExpr numericEvalAST1(IExpr expr, EvalEngine engine) { } } - private static IExpr numericEvalAST2(IExpr expr, long nDigitPrecision, EvalEngine engine) { + private static IExpr numericEvalAST2(IExpr expr, IExpr arg2, long nDigitPrecision, + EvalEngine engine) { // first try symbolic evaluation expr = engine.evaluate(expr); if (expr.isInexactNumber()) { return expr; } + if (expr.isList()) { + return ((IAST) expr).mapThread(F.N(F.Slot1, arg2), 1); + } final int maxSize = (Config.MAX_OUTPUT_SIZE > Short.MAX_VALUE) ? Short.MAX_VALUE : Config.MAX_OUTPUT_SIZE; int significantFigures = (nDigitPrecision > maxSize) ? maxSize : (int) nDigitPrecision; diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BooleanFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BooleanFunctions.java index 92252c11e2..0e7318878f 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BooleanFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BooleanFunctions.java @@ -4092,7 +4092,7 @@ private static final class SameQ extends AbstractCoreFunctionEvaluator @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { if (ast.size() > 2) { - IAST temp = engine.evalArgs(ast, ISymbol.NOATTRIBUTE).orElse(ast); + IAST temp = engine.evalArgs(ast, ISymbol.NOATTRIBUTE, false).orElse(ast); if (temp.isAST2()) { return temp.arg1().isSame(temp.arg2()) ? S.True : S.False; } @@ -4720,7 +4720,7 @@ private static final class UnsameQ extends AbstractCoreFunctionEvaluator @Override public IExpr evaluate(final IAST ast, EvalEngine engine) { if (ast.size() > 2) { - IAST temp = engine.evalArgs(ast, ISymbol.NOATTRIBUTE).orElse(ast); + IAST temp = engine.evalArgs(ast, ISymbol.NOATTRIBUTE, false).orElse(ast); if (temp.isAST2()) { return temp.arg1().isSame(temp.arg2()) ? S.False : S.True; } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ClusteringFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ClusteringFunctions.java index 6d03733d3d..ab6c4851c6 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ClusteringFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/ClusteringFunctions.java @@ -141,7 +141,9 @@ public double compute(double[] a, double[] b) throws MathIllegalArgumentExceptio @Override public IExpr distance(IExpr a, IExpr b, EvalEngine engine) { - return F.Divide(F.Total(F.Abs(F.Subtract(a, b))), F.Total(F.Abs(F.Plus(a, b)))); + IExpr divide = F.Divide(F.Total(F.Abs(F.Subtract(a, b))), F.Total(F.Abs(F.Plus(a, b)))); + divide = engine.evaluate(divide); + return divide; } } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/EllipticIntegrals.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/EllipticIntegrals.java index 43c7f66078..0256e21831 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/EllipticIntegrals.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/EllipticIntegrals.java @@ -978,15 +978,13 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { if (engine.isDoubleMode() && x.isNumber() && m.isNumber()) { if (x.isReal() && m.isReal()) { try { - return F - .complexNum(EllipticFunctionsJS.jacobiTheta(a, x.evalf(), m.evalf())); + return F.complexNum(EllipticFunctionsJS.jacobiTheta(a, x.evalf(), m.evalf())); } catch (RuntimeException rex) { LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); } } else if (x.isInexactNumber() && m.isInexactNumber()) { try { - return F.complexNum( - EllipticFunctionsJS.jacobiTheta(a, x.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.jacobiTheta(a, x.evalfc(), m.evalfc())); } catch (ValidateException ve) { return Errors.printMessage(ast.topHead(), ve, engine); } catch (RuntimeException rex) { @@ -1105,8 +1103,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiCD(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiCD(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiCD(zDouble, mDouble)); // } @@ -1165,8 +1162,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiCN(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiCN(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiCN(zDouble, mDouble)); // } @@ -1216,8 +1212,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiDN(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiDN(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiDN(zDouble, mDouble)); // } @@ -1281,8 +1276,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiSC(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiSC(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiSC(zDouble, mDouble)); // } @@ -1336,8 +1330,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiSD(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiSD(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiSD(zDouble, mDouble)); // } @@ -1397,8 +1390,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // } catch (ValidateException ve) { // } // if (Double.isNaN(zDouble) || Double.isNaN(mDouble)) { - return F - .complexNum(EllipticFunctionsJS.inverseJacobiSN(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.inverseJacobiSN(z.evalfc(), m.evalfc())); // } else { // return F.num(EllipticFunctionsJS.inverseJacobiSN(zDouble, mDouble)); // } @@ -1466,11 +1458,9 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { if (engine.isDoubleMode() && z.isNumber() && m.isNumber()) { try { if (z.isReal() && m.isReal()) { - return F - .complexNum(EllipticFunctionsJS.jacobiAmplitude(z.evalf(), m.evalf())); + return F.complexNum(EllipticFunctionsJS.jacobiAmplitude(z.evalf(), m.evalf())); } - return F - .complexNum(EllipticFunctionsJS.jacobiAmplitude(z.evalfc(), m.evalfc())); + return F.complexNum(EllipticFunctionsJS.jacobiAmplitude(z.evalfc(), m.evalfc())); } catch (RuntimeException rex) { LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); return F.NIL; @@ -2075,14 +2065,16 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { IAST list = (IAST) ast.arg1(); IExpr g2 = list.arg1(); IExpr g3 = list.arg2(); - // numric mode isn't set here - if (g2.isInexactNumber() && g3.isInexactNumber()) { - try { - org.hipparchus.complex.Complex[] invariants = - EllipticFunctionsJS.weierstrassHalfPeriods(g2.evalfc(), g3.evalfc()); - return Object2Expr.convertComplex(false, invariants); - } catch (RuntimeException rex) { - LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); + // numeric mode isn't set here + if (g2.isInexactNumber() || g3.isInexactNumber()) { + if (g2.isNumber() && g3.isNumber()) { + try { + org.hipparchus.complex.Complex[] invariants = + EllipticFunctionsJS.weierstrassHalfPeriods(g2.evalfc(), g3.evalfc()); + return Object2Expr.convertComplex(false, invariants); + } catch (RuntimeException rex) { + LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); + } } } } @@ -2109,16 +2101,18 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { IAST list = (IAST) ast.arg1(); IExpr g2 = list.arg1(); IExpr g3 = list.arg2(); - // numric mode isn't set here - if (g2.isInexactNumber() && g3.isInexactNumber()) { - try { - org.hipparchus.complex.Complex[] invariants = - EllipticFunctionsJS.weierstrassInvariants(g2.evalfc(), g3.evalfc()); - return Object2Expr.convertComplex(false, invariants); - } catch (ValidateException ve) { - return Errors.printMessage(ast.topHead(), ve, engine); - } catch (RuntimeException rex) { - LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); + // numeric mode isn't set here + if (g2.isInexactNumber() || g3.isInexactNumber()) { + if (g2.isNumber() && g3.isNumber()) { + try { + org.hipparchus.complex.Complex[] invariants = + EllipticFunctionsJS.weierstrassInvariants(g2.evalfc(), g3.evalfc()); + return Object2Expr.convertComplex(false, invariants); + } catch (ValidateException ve) { + return Errors.printMessage(ast.topHead(), ve, engine); + } catch (RuntimeException rex) { + LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); + } } } } @@ -2156,11 +2150,11 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { // 1 + (3/2) Cot(Sqrt(3/2)*u)^2 return F.Plus(F.C1, F.Times(F.C3D2, F.Sqr(F.Cot(F.Times(F.Sqrt(F.C3D2), u))))); } - // numric mode isn't set here - if (u.isInexactNumber() && g2.isInexactNumber() && g3.isInexactNumber()) { + // numeric mode isn't set here + if (u.isInexactNumber() && g2.isNumber() && g3.isNumber()) { try { - return F.complexNum(EllipticFunctionsJS.weierstrassP(u.evalfc(), g2.evalfc(), - g3.evalfc())); + return F + .complexNum(EllipticFunctionsJS.weierstrassP(u.evalfc(), g2.evalfc(), g3.evalfc())); } catch (RuntimeException rex) { LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); } @@ -2201,11 +2195,11 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { return F.Times(F.CN3, F.Sqrt(F.C3D2), F.Cot(F.Times(F.Sqrt(F.C3D2), u)), F.Sqr(F.Csc(F.Times(F.Sqrt(F.C3D2), u)))); } - // numric mode isn't set here - if (u.isInexactNumber() && g2.isInexactNumber() && g3.isInexactNumber()) { + // numeric mode isn't set here + if (u.isInexactNumber() && g2.isNumber() && g3.isNumber()) { try { - return F.complexNum(EllipticFunctionsJS.weierstrassPPrime(u.evalfc(), - g2.evalfc(), g3.evalfc())); + return F.complexNum( + EllipticFunctionsJS.weierstrassPPrime(u.evalfc(), g2.evalfc(), g3.evalfc())); } catch (RuntimeException rex) { LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); } 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 b35bf0d84d..cef89b0828 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 @@ -1181,44 +1181,43 @@ public IExpr evaluate(IAST ast, EvalEngine engine) { b = bVector; } - // if (engine.isArbitraryMode() && a.isVector() > 0 && b.isVector() > 0) { - // try { - // HypergeometricHelper.hypergeometricPFQ(); - // } catch (ValidateException ve) { - // return IOFunctions.printMessage(ast.topHead(), ve, engine); - // } catch (RuntimeException rex) { - // LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); - // } - // } + // numeric mode isn't set here - if (engine.isDoubleMode() && a.isVector() > 0 && b.isVector() > 0) { - try { - double A[] = a.toDoubleVector(); - double B[] = b.toDoubleVector(); - double cDouble = Double.NaN; - try { - cDouble = c.evalf(); - } catch (ValidateException ve) { - } - if (A == null || B == null || Double.isNaN(cDouble)) { - Complex AC[] = a.toComplexVector(); - Complex BC[] = b.toComplexVector(); - if (AC != null && BC != null) { - return F.complexNum( - HypergeometricJS.hypergeometricPFQ(AC, BC, c.evalfc(), Config.DOUBLE_TOLERANCE)); - } - } else { - INum result = F.num(HypergeometricJS.hypergeometricPFQ(A, B, cDouble)); + if (c.isInexactNumber() || a.isInexactVector() > 0 || b.isInexactVector() > 0) { + return numericHypergeometricPFQ(a, b, c, ast, engine); + } - return result; - } + return F.NIL; + } + private IExpr numericHypergeometricPFQ(IExpr a, IExpr b, IExpr c, IAST ast, EvalEngine engine) { + try { + double A[] = a.toDoubleVector(); + double B[] = b.toDoubleVector(); + double cDouble = Double.NaN; + try { + cDouble = c.evalf(); } catch (ValidateException ve) { - return Errors.printMessage(ast.topHead(), ve, engine); - } catch (RuntimeException rex) { - LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); } + if (A == null || B == null || Double.isNaN(cDouble)) { + Complex AC[] = a.toComplexVector(); + Complex BC[] = b.toComplexVector(); + if (AC != null && BC != null) { + return F.complexNum( + HypergeometricJS.hypergeometricPFQ(AC, BC, c.evalfc(), Config.DOUBLE_TOLERANCE)); + } + } else { + INum result = F.num(HypergeometricJS.hypergeometricPFQ(A, B, cDouble)); + + return result; + } + + } catch (ValidateException ve) { + return Errors.printMessage(ast.topHead(), ve, engine); + } catch (RuntimeException rex) { + LOGGER.log(engine.getLogLevel(), ast.topHead(), rex); } + return F.NIL; } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java index 559edd3b9e..716aff2730 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java @@ -2034,14 +2034,14 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { Times(C4, matrix.getEntry(0, 1), matrix.getEntry(1, 0)), Times(CN2, matrix.getEntry(0, 0), matrix.getEntry(1, 1)), Sqr(matrix.getEntry(1, 1)))); - IExpr eigenValues = List( + IAST eigenValues = List( Times(C1D2, Plus(Negate(sqrtExpr), matrix.getEntry(0, 0), matrix.getEntry(1, 1))), Times(C1D2, Plus(sqrtExpr, matrix.getEntry(0, 0), matrix.getEntry(1, 1)))); - return sortValuesIfNumeric((IAST) eigenValues, arg2); + return sortValuesIfNumeric(eigenValues, arg2); } } else { - boolean hasNumericArgument = arg1.isEvalFlagOn(IAST.CONTAINS_NUMERIC_ARG); + boolean hasNumericArgument = arg1.isNumericArgument(true);// (IAST.CONTAINS_NUMERIC_ARG); if (!hasNumericArgument) { ISymbol x = F.Dummy("x"); IExpr m = engine.evaluate(F.CharacteristicPolynomial(arg1, x)); @@ -2065,7 +2065,8 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { // switch to numeric calculation IExpr eigenValues = numericEval(ast, engine); if (eigenValues.isList()) { - return sortValuesIfNumeric((IAST) eigenValues, arg2); + IAST sortFunction = sortValuesIfNumeric((IASTMutable) eigenValues, arg2); + return engine.evaluate(sortFunction); } return F.NIL; } @@ -2079,8 +2080,10 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { * elements are sorted in order of decreasing absolute value. * @return */ - private IExpr sortValuesIfNumeric(IAST eigenValuesList, final IExpr arg2) { + private IAST sortValuesIfNumeric(IAST eigenValuesList, final IExpr arg2) { if (eigenValuesList.forAll(v -> v.isNumericFunction())) { + eigenValuesList = eigenValuesList.copy(); + ((IASTMutable) eigenValuesList).sortInplace(); if (arg2 != null && arg2.isPresent()) { int n = arg2.toIntDefault(); if (n < 0) { 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 e042471f77..a9ddbc3c60 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 @@ -761,8 +761,10 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { // IExpr a = dist.arg1(); IExpr b = dist.arg2(); - if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + if (!engine.isArbitraryMode() // + && (a.isNumericArgument(true) // + || b.isNumericArgument(true) // + || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.BetaDistribution(a.evalf(), b.evalf()) // @@ -790,7 +792,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr a = dist.arg1(); IExpr b = dist.arg2(); if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.BetaDistribution(a.evalf(), b.evalf()) // @@ -886,7 +888,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr a = dist.arg1(); IExpr b = dist.arg2(); if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.BetaDistribution(a.evalf(), b.evalf()) // @@ -1454,7 +1456,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr v = dist.arg1(); if (!engine.isArbitraryMode() && // - (v.isNumericArgument() || k.isNumericArgument())) { + (v.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.ChiSquaredDistribution(v.evalf()) // @@ -1501,7 +1503,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr v = dist.arg1(); if (!engine.isArbitraryMode() && // - (v.isNumericArgument() || k.isNumericArgument())) { + (v.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.ChiSquaredDistribution(v.evalf()) // @@ -1535,7 +1537,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr v = dist.arg1(); if (!engine.isArbitraryMode() && // - (v.isNumericArgument() || k.isNumericArgument())) { + (v.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.ChiSquaredDistribution(v.evalf()) // @@ -1962,7 +1964,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.FDistribution(n.evalf(), m.evalf()) // @@ -1987,7 +1989,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.FDistribution(n.evalf(), m.evalf()) // @@ -2023,7 +2025,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.FDistribution(n.evalf(), m.evalf()) // @@ -2341,7 +2343,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr a = dist.arg1(); IExpr b = dist.arg2(); if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.GammaDistribution(a.evalf(), b.evalf()) // @@ -2382,7 +2384,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr a = dist.arg1(); IExpr b = dist.arg2(); if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.GammaDistribution(a.evalf(), b.evalf()) // @@ -2511,7 +2513,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr a = dist.arg1(); IExpr b = dist.arg2(); if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.GammaDistribution(a.evalf(), b.evalf()) // @@ -2945,7 +2947,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { final double z = (k.evalf() - n.evalf()) / m.evalf(); return F.num(1.0 - Math.exp(-Math.exp(z))); @@ -2972,7 +2974,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { double p = k.evalf(); MathUtils.checkRangeInclusive(p, 0, 1); @@ -3930,7 +3932,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr n = dist.arg1(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || k.isNumericArgument(true))) { try { double x = k.evalf(); if (x <= 0.0) { @@ -3978,7 +3980,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr n = dist.arg1(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || k.isNumericArgument(true))) { try { double x = k.evalf(); if (F.isEqual(x, 1.0)) { @@ -4367,7 +4369,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr m = dist.arg2(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.LogNormalDistribution(n.evalf(), m.evalf()) // @@ -4416,7 +4418,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.LogNormalDistribution(n.evalf(), m.evalf()) // @@ -4453,7 +4455,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr m = dist.arg2(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.LogNormalDistribution(n.evalf(), m.evalf()) // @@ -4938,7 +4940,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.NakagamiDistribution(n.evalf(), m.evalf()) // @@ -4964,7 +4966,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.NakagamiDistribution(n.evalf(), m.evalf()) // @@ -5000,7 +5002,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr m = dist.arg2(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.NakagamiDistribution(n.evalf(), m.evalf()) // @@ -5247,7 +5249,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.NormalDistribution(n.evalf(), m.evalf()) // @@ -5278,7 +5280,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.NormalDistribution(n.evalf(), m.evalf()) // @@ -5310,7 +5312,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.NormalDistribution(n.evalf(), m.evalf()) // @@ -6824,7 +6826,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr n = dist.arg1(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.TDistribution(n.evalf()) // .cumulativeProbability(k.evalf())); @@ -6856,7 +6858,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { if (dist.isAST1()) { IExpr n = dist.arg1(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.TDistribution(n.evalf()) // .inverseCumulativeProbability(k.evalf())); @@ -6903,7 +6905,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num(new org.hipparchus.distribution.continuous.TDistribution(n.evalf()) // .density(k.evalf())); @@ -7173,7 +7175,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr a = minMax[0]; IExpr b = minMax[1]; if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.UniformRealDistribution(a.evalf(), @@ -7202,7 +7204,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr a = minMax[0]; IExpr b = minMax[1]; if (!engine.isArbitraryMode() && // - (a.isNumericArgument() || b.isNumericArgument() || k.isNumericArgument())) { + (a.isNumericArgument(true) || b.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F .num(new org.hipparchus.distribution.continuous.UniformRealDistribution(a.evalf(), @@ -7475,7 +7477,7 @@ public IExpr cdf(IAST dist, IExpr k, EvalEngine engine) { IExpr m = dist.arg2(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.WeibullDistribution(n.evalf(), m.evalf()) // @@ -7500,7 +7502,7 @@ public IExpr inverseCDF(IAST dist, IExpr k, EvalEngine engine) { IExpr n = dist.arg1(); IExpr m = dist.arg2(); if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.WeibullDistribution(n.evalf(), m.evalf()) // @@ -7536,7 +7538,7 @@ public IExpr pdf(IAST dist, IExpr k, EvalEngine engine) { IExpr m = dist.arg2(); // if (!engine.isArbitraryMode() && // - (n.isNumericArgument() || m.isNumericArgument() || k.isNumericArgument())) { + (n.isNumericArgument(true) || m.isNumericArgument(true) || k.isNumericArgument(true))) { try { return F.num( new org.hipparchus.distribution.continuous.WeibullDistribution(n.evalf(), m.evalf()) // diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StructureFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StructureFunctions.java index 8b1706501c..9126c33318 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StructureFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/StructureFunctions.java @@ -639,7 +639,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { final IExpr arg3 = function.arg3(); attributes = AttributeFunctions.getSymbolsAsAttributes(arg3.makeList(), engine); } - IAST astEvaled = engine.evalArgs(ast, attributes).orElse(ast); + IAST astEvaled = engine.evalArgs(ast, attributes, false).orElse(ast); IExpr arg1 = function.arg1(); if (function.isAST1()) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/EvalEngine.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/EvalEngine.java index 4f273c43c3..6374de5203 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/EvalEngine.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/EvalEngine.java @@ -696,12 +696,22 @@ private IAST endTrace() { */ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg, final int i, final boolean isNumericFunction) { - - final IExpr evaledArg = evalLoop(arg); + final IExpr evaledArg; + if (isNumericFunction) { + evaledArg = evalLoop(arg); + } else { + boolean isNumericMode = fNumericMode; + try { + fNumericMode = false; + evaledArg = evalLoop(arg); + } finally { + fNumericMode = isNumericMode; + } + } if (evaledArg.isPresent()) { if (result0[0].isNIL()) { result0[0] = ast.copy(); - if (isNumericFunction && evaledArg.isNumericArgument()) { + if (isNumericFunction && evaledArg.isNumericArgument(true)) { result0[0].addEvalFlags( (ast.getEvalFlags() & IAST.IS_MATRIX_OR_VECTOR) | IAST.CONTAINS_NUMERIC_ARG); } else { @@ -710,10 +720,11 @@ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg } result0[0].set(i, evaledArg); } else { - if (arg.isNumericArgument()) { + if (isNumericFunction && arg.isNumericArgument(false)) { ast.addEvalFlags(ast.getEvalFlags() | IAST.CONTAINS_NUMERIC_ARG); } } + } /** @@ -722,17 +733,22 @@ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg * * @param ast * @param attributes + * @param numericFunction2 TODO * @return F.NIL is no evaluation was possible */ - public IASTMutable evalArgs(final IAST ast, final int attributes) { + public IASTMutable evalArgs(final IAST ast, final int attributes, boolean numericFunction) { final int astSize = ast.size(); if (astSize > 1) { boolean numericMode = fNumericMode; boolean localNumericMode = fNumericMode; - final boolean isNumericFunction = - (ISymbol.NUMERICFUNCTION & attributes) == ISymbol.NUMERICFUNCTION; - boolean isNumericArgument = ast.isNumericArgument(); + final boolean isNumericFunction; + if ((ISymbol.NUMERICFUNCTION & attributes) == ISymbol.NUMERICFUNCTION) { + isNumericFunction = true; + } else { + isNumericFunction = numericFunction; + } + final boolean isNumericArgument = ast.isNumericArgument(true); if (!fNumericMode) { if (isNumericFunction && isNumericArgument) { localNumericMode = true; @@ -812,11 +828,12 @@ public IASTMutable evalArgs(final IAST ast, final int attributes) { } } } - if (!isNumericArgument && ast.isNumericArgument()) { + if (isNumericFunction // + && !isNumericArgument // + && rlist[0].isNIL() // + && ast.isNumericArgument(true)) { // one of the arguments is a numeric value - if (rlist[0].isNIL()) { - return evalArgs(ast, attributes); - } + return evalArgs(ast, attributes, isNumericFunction); } return rlist[0]; } @@ -851,11 +868,11 @@ private IExpr evalASTArg1(final IAST ast) { // pattern-matching". // Functions like Times and PLus implement OneIdentity as extra transformation! - if ((result = evalArgs(ast, attributes)).isPresent()) { + final IExpr arg1 = ast.arg1(); + if ((result = evalArgs(ast, attributes, false)).isPresent()) { return result; } - final IExpr arg1 = ast.arg1(); if (ISymbol.hasFlatAttribute(attributes)) { if (arg1.head().equals(symbol)) { // associative @@ -1205,7 +1222,7 @@ public IExpr evalAttributes(ISymbol symbol, IASTMutable mutableAST) { } } - IASTMutable resultList = evalArgs(mutableAST, attributes); + IASTMutable resultList = evalArgs(mutableAST, attributes, false); if (resultList.isPresent()) { return resultList; } @@ -1233,7 +1250,7 @@ public IExpr evalAttributes(ISymbol symbol, IASTMutable mutableAST) { if (resultList.isAssociation()) { return resultList; } - return evalArgs(resultList, ISymbol.NOATTRIBUTE).orElse(resultList); + return evalArgs(resultList, ISymbol.NOATTRIBUTE, false).orElse(resultList); } } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/interfaces/AbstractMatrix1Expr.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/interfaces/AbstractMatrix1Expr.java index 397d2ae1e5..5c2b0606a8 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/interfaces/AbstractMatrix1Expr.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/interfaces/AbstractMatrix1Expr.java @@ -46,7 +46,7 @@ public IExpr evaluate(final IAST ast, final EvalEngine engine) { try { int[] dim = checkMatrixDimensions(ast.arg1()); if (dim != null) { - if (ast.arg1().isNumericArgument()) { + if (ast.arg1().isNumericArgument(true)) { RealMatrix m = ast.arg1().toRealMatrix(); if (m != null) { return realMatrixEval(m, engine); diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ASTRealVector.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ASTRealVector.java index dad99631e1..d92abd42a4 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ASTRealVector.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ASTRealVector.java @@ -410,6 +410,12 @@ public final int isVector() { return vector.getDimension(); } + /** {@inheritDoc} */ + @Override + public final int isInexactVector() { + return vector.getDimension(); + } + /** {@inheritDoc} */ @Override public boolean isNumericAST() { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractAST.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractAST.java index 1da9860b85..399a2c134f 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractAST.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractAST.java @@ -848,6 +848,11 @@ public final int isVector() { return -1; } + @Override + public final int isInexactVector() { + return -1; + } + /** {@inheritDoc} */ @Override public final boolean isZERO() { @@ -3947,14 +3952,17 @@ public final boolean isNot() { /** {@inheritDoc} */ @Override - public boolean isNumericArgument() { + public boolean isNumericArgument(boolean allowList) { if (isEvalFlagOn(IAST.CONTAINS_NUMERIC_ARG)) { - return forAll(x -> x.isNumericFunction(true) - || (x.isList() && ((IAST) x).forAll(y -> y.isNumericFunction(true)))); + return forAll(x -> x.isNumericFunction(allowList) + || (x.isList() && ((IAST) x).forAll(y -> y.isNumericFunction(allowList)))); + } + if (allowList && isList()) { + return exists(x -> x.isNumericArgument(allowList)); } // TODO optimize this expression: - return isAST(S.Interval) && forAll(x -> x.isNumericArgument() - || (x.isList() && ((IAST) x).forAll(y -> y.isNumericArgument()))); + return isAST(S.Interval) && forAll(x -> x.isNumericArgument(allowList) + || (x.isList() && ((IAST) x).forAll(y -> y.isNumericArgument(allowList)))); } /** {@inheritDoc} */ @@ -4701,6 +4709,18 @@ public int isVector() { return -1; } + /** {@inheritDoc} */ + @Override + public int isInexactVector() { + int result = isVector(); + if (result >= 0) { + if (exists(x -> x.isInexactNumber())) { + return result; + } + } + return -1; + } + /** {@inheritDoc} */ @Override public boolean isNumericAST() { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java index 7d78ac8c29..0d77063798 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/data/SparseArrayExpr.java @@ -6,6 +6,7 @@ import java.io.ObjectOutput; import java.util.Arrays; import java.util.function.Function; +import java.util.function.Predicate; import org.hipparchus.Field; import org.hipparchus.FieldElement; import org.hipparchus.exception.LocalizedCoreFormats; @@ -1456,6 +1457,20 @@ public boolean equals(final Object obj) { return false; } + @Override + public boolean exists(Predicate predicate) { + if (predicate.test(fDefaultValue)) { + return true; + } + for (TrieNode entry : fData.nodeSet()) { + IExpr value = entry.getValue(); + if (predicate.test(value)) { + return true; + } + } + return false; + } + /** {@inheritDoc} */ @Override public IExpr evaluate(EvalEngine engine) { @@ -1466,11 +1481,11 @@ public IExpr evaluate(EvalEngine engine) { IExpr temp = engine.evaluateNIL(fDefaultValue); if (temp.isPresent()) { evaled = true; - if (temp.isNumericArgument()) { + if (temp.isNumericArgument(true)) { containsNumericArg = true; } newDefaultValue = temp; - } else if (fDefaultValue.isNumericArgument()) { + } else if (fDefaultValue.isNumericArgument(true)) { containsNumericArg = true; } final Trie trie = Config.TRIE_INT2EXPR_BUILDER.build(); @@ -1479,12 +1494,12 @@ public IExpr evaluate(EvalEngine engine) { temp = engine.evaluateNIL(value); if (temp.isPresent()) { evaled = true; - if (temp.isNumericArgument()) { + if (temp.isNumericArgument(true)) { containsNumericArg = true; } trie.put(entry.getKey(), temp); } else { - if (value.isNumericArgument()) { + if (value.isNumericArgument(true)) { containsNumericArg = true; } trie.put(entry.getKey(), value); @@ -1553,6 +1568,21 @@ public String fullFormString() { return result.fullFormString(); } + @Override + public boolean forAll(Predicate predicate) { + if (!predicate.test(fDefaultValue)) { + return false; + } + for (TrieNode entry : fData.nodeSet()) { + IExpr value = entry.getValue(); + if (!predicate.test(value)) { + return false; + } + } + + return true; + } + public IASTAppendable fullForm() { IAST dimensionList = F.ast(S.List, fDimension); IASTAppendable result = F.ast(S.SparseArray, 6); @@ -1687,8 +1717,7 @@ public IExpr getPart(IAST ast, int startPosition) { count++; } else if (partIndex[i - startPosition] > dims[i - startPosition] || partIndex[i - startPosition] <= 0) { - return Errors.printMessage(S.Part, "partw", F.list(ast.get(i), ast), - EvalEngine.get()); + return Errors.printMessage(S.Part, "partw", F.list(ast.get(i), ast), EvalEngine.get()); } } for (int i = partSize; i < dims.length; i++) { @@ -1819,6 +1848,33 @@ public int isVector() { return (fDimension.length == 1) ? fDimension[0] : -1; } + /** {@inheritDoc} */ + @Override + public int isInexactVector() { + int result = isVector(); + if (result >= 0) { + if (isEvalFlagOn(IAST.CONTAINS_NUMERIC_ARG)) { + return result; + } + if (exists(x -> x.isInexactNumber())) { + return result; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean isNumericArgument(boolean allowList) { + if (allowList) { + if (isEvalFlagOn(IAST.CONTAINS_NUMERIC_ARG)) { + return true; + } + return exists(x -> x.isNumericArgument(true)); + } + return false; + } + @Override public ISparseArray join(ISparseArray that) { SparseArrayExpr thatArray = (SparseArrayExpr) that; @@ -1973,6 +2029,7 @@ public int size() { @Override public double[][] toDoubleMatrix() { if (fDimension.length == 2 && fDimension[0] > 0 && fDimension[1] > 0) { + IExpr value = null; try { double[][] result = new double[fDimension[0]][fDimension[1]]; if (!fDefaultValue.isZero()) { @@ -1985,12 +2042,16 @@ public double[][] toDoubleMatrix() { } for (TrieNode entry : fData.nodeSet()) { int[] key = entry.getKey(); - IExpr value = entry.getValue(); + value = entry.getValue(); result[key[0] - 1][key[1] - 1] = value.evalf(); } return result; } catch (ArgumentTypeException rex) { - + if (value != null && value.isIndeterminate()) { + // Input matrix contains an indeterminate entry. + Errors.printMessage(S.SparseArray, "mindet", F.List()); + return null; + } } } return null; @@ -2000,6 +2061,7 @@ public double[][] toDoubleMatrix() { @Override public double[] toDoubleVector() { if (fDimension.length == 1 && fDimension[0] > 0) { + IExpr value = null; try { double[] result = new double[fDimension[0]]; if (!fDefaultValue.isZero()) { @@ -2010,12 +2072,16 @@ public double[] toDoubleVector() { } for (TrieNode entry : fData.nodeSet()) { int[] key = entry.getKey(); - IExpr value = entry.getValue(); + value = entry.getValue(); result[key[0] - 1] = value.evalf(); } return result; } catch (ArgumentTypeException rex) { - + if (value != null && value.isIndeterminate()) { + // Input matrix contains an indeterminate entry. + Errors.printMessage(S.SparseArray, "mindet", F.List()); + return null; + } } } return null; @@ -2073,6 +2139,7 @@ public RealMatrix toRealMatrix() { @Override public RealVector toRealVector() { if (fDimension.length == 1 && fDimension[0] > 0) { + IExpr value = null; try { OpenMapRealVector result = new OpenMapRealVector(fDimension[0]); if (!fDefaultValue.isZero()) { @@ -2083,12 +2150,16 @@ public RealVector toRealVector() { } for (TrieNode entry : fData.nodeSet()) { int[] key = entry.getKey(); - IExpr value = entry.getValue(); + value = entry.getValue(); result.setEntry(key[0] - 1, value.evalf()); } return result; } catch (ArgumentTypeException rex) { - + if (value != null && value.isIndeterminate()) { + // Input matrix contains an indeterminate entry. + Errors.printMessage(S.SparseArray, "mindet", F.List()); + return null; + } } } return null; diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/integrate/rubi/UtilityFunctionCtors.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/integrate/rubi/UtilityFunctionCtors.java index 8dea448d9c..bb451cb28e 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/integrate/rubi/UtilityFunctionCtors.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/integrate/rubi/UtilityFunctionCtors.java @@ -2121,7 +2121,7 @@ public static IExpr evalRubiDistTimes(IAST astTimes, EvalEngine engine) { for (int i = 1; i < astTimes.size(); i++) { IExpr temp = astTimes.get(i); if (temp.isAST(Dist) && temp.size() == 4) { - IAST dist = engine.evalArgs((IAST) temp, ISymbol.NOATTRIBUTE).orElse((IAST) temp); + IAST dist = engine.evalArgs((IAST) temp, ISymbol.NOATTRIBUTE, false).orElse((IAST) temp); temp = astTimes.splice(i).oneIdentity1(); temp = engine.evaluate(temp); if (!temp.isMinusOne()) { @@ -2161,7 +2161,7 @@ public static IExpr evalRubiDistPlus(IAST astPlus, EvalEngine engine) { IExpr arg1 = astPlus.get(i); if (arg1.isAST(Dist) && arg1.size() == 4) { // dist1 = Dist[u_,v_,x_] - IAST dist1 = engine.evalArgs((IAST) arg1, ISymbol.NOATTRIBUTE).orElse((IAST) arg1); // (IAST) + IAST dist1 = engine.evalArgs((IAST) arg1, ISymbol.NOATTRIBUTE, false).orElse((IAST) arg1); // (IAST) // arg1; IExpr v = dist1.arg2(); IExpr x = dist1.arg3(); @@ -2170,7 +2170,7 @@ public static IExpr evalRubiDistPlus(IAST astPlus, EvalEngine engine) { if (arg2.isAST(Dist) && arg2.size() == 4 && arg2.getAt(2).equals(v) && arg2.getAt(3).equals(x)) { // dist2=Dist[w_,v_,x_] - IAST dist2 = engine.evalArgs((IAST) arg2, ISymbol.NOATTRIBUTE).orElse((IAST) arg2); // (IAST) + IAST dist2 = engine.evalArgs((IAST) arg2, ISymbol.NOATTRIBUTE, false).orElse((IAST) arg2); // (IAST) // arg2; IASTAppendable result = astPlus.removeAtClone(j); result.remove(i); @@ -2184,7 +2184,7 @@ public static IExpr evalRubiDistPlus(IAST astPlus, EvalEngine engine) { } if (arg2.isTimes2() && arg2.first().isMinusOne() && arg2.second().isAST(Dist)) { // -1 * Dist[w_,v_,x_] - IAST dist2 = engine.evalArgs((IAST) arg2.second(), ISymbol.NOATTRIBUTE) + IAST dist2 = engine.evalArgs((IAST) arg2.second(), ISymbol.NOATTRIBUTE, false) .orElse((IAST) arg2.second()); // (IAST) arg2.second(); if (dist2.size() == 4 && dist2.getAt(2).equals(v) && dist2.getAt(3).equals(x)) { IASTAppendable result = astPlus.removeAtClone(j); @@ -2202,7 +2202,7 @@ public static IExpr evalRubiDistPlus(IAST astPlus, EvalEngine engine) { } else if (arg1.isTimes2() && arg1.first().isMinusOne() && arg1.second().isAST(Dist)) { // -1 * Dist[w_,v_,x_] IAST dist1 = - engine.evalArgs((IAST) arg1.second(), ISymbol.NOATTRIBUTE).orElse((IAST) arg1.second()); // (IAST) + engine.evalArgs((IAST) arg1.second(), ISymbol.NOATTRIBUTE, false).orElse((IAST) arg1.second()); // (IAST) // arg1.second(); IExpr v = dist1.arg2(); IExpr x = dist1.arg3(); @@ -2211,7 +2211,7 @@ public static IExpr evalRubiDistPlus(IAST astPlus, EvalEngine engine) { if (arg2.isAST(Dist) && arg2.size() == 4 && arg2.getAt(2).equals(v) && arg2.getAt(3).equals(x)) { // dist2 = Dist[u_,v_,x_] - IAST dist2 = engine.evalArgs((IAST) arg2, ISymbol.NOATTRIBUTE).orElse((IAST) arg2); // (IAST) + IAST dist2 = engine.evalArgs((IAST) arg2, ISymbol.NOATTRIBUTE, false).orElse((IAST) arg2); // (IAST) // arg2; IASTAppendable result = astPlus.removeAtClone(j); result.remove(i); diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java index a0b127a9a8..90b9f23c2d 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java @@ -3124,6 +3124,17 @@ default boolean isNumeric() { * @return */ default boolean isNumericArgument() { + return isNumericArgument(true); + } + + /** + * Test if this expression is a numeric number (i.e. an instance of type INum or type + * IComplexNum), an ASTRealVector or an ASTRealMatrix. + * + * @param allowLists additional to numeric functions and numeric numbers allow lists to have + * inexact values + */ + default boolean isNumericArgument(boolean allowList) { return this instanceof INum || this instanceof IComplexNum || this instanceof ASTRealVector || this instanceof ASTRealMatrix; } @@ -4098,6 +4109,11 @@ default int isVector() { return -1; } + default int isInexactVector() { + // default: no vector + return -1; + } + /** * Test if this expression is the With function With[<arg1>, <arg2>] * diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/polynomials/QuarticSolver.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/polynomials/QuarticSolver.java index c5d732a9ad..c7cf5aa14a 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/polynomials/QuarticSolver.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/polynomials/QuarticSolver.java @@ -799,9 +799,9 @@ public static IASTAppendable quasiSymmetricQuarticSolve(IExpr a, IExpr b, IExpr } /** - * Sort the arguments, which are assumed to be of type List() + * Sort the arguments of a list. * - * @param resultList + * @param resultList assumed to be of type List() * @return */ public static IASTMutable sortASTArguments(IASTMutable resultList) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/Solve.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/Solve.java index b67af4f8df..1513c4f97d 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/Solve.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/reflection/system/Solve.java @@ -1898,7 +1898,7 @@ public static IExpr solveIntegers(final IAST ast, IAST equationVariables, @Override public IExpr evaluate(IAST ast, final int argSize, final IExpr[] options, final EvalEngine engine, IAST originalAST) { - boolean isNumericArgument = ast.arg1().isEvalFlagOn(IAST.CONTAINS_NUMERIC_ARG); + boolean isNumericArgument = !ast.arg1().isFree(x -> x.isInexactNumber(), false); if (argSize > 0 && argSize < ast.argSize()) { ast = ast.copyUntil(argSize + 1); } 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 765f42b031..d20f19ed57 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 @@ -58,6 +58,7 @@ public void testSphericalHankelH2() { public void testWeberE() { check("WeberE(1.5, 3.5)", // - "0.212207*HypergeometricPFQ({1.0},{0.25,1.75},-3.0625)+0.891268*HypergeometricPFQ({1.0},{0.75,2.25},-3.0625)"); + "0.212207*HypergeometricPFQ({1},{0.25,1.75},-3.0625)+0.891268*HypergeometricPFQ({\n" + + "1},{0.75,2.25},-3.0625)"); } } diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java index ffd543bd41..cb5b60faea 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java @@ -68,26 +68,27 @@ public void testAntisymmetricMatrixQ() { } public void testCholeskyDecomposition() { - // message: CholeskyDecomposition: The matrix {{2,1}, {3,a}} is not hermitian or real and - // symmetric. - check("CholeskyDecomposition({{2,1},{3,a}})", // - "CholeskyDecomposition({{2,1},{3,a}})"); - check("CholeskyDecomposition({{2,1},{1,3}})", // - "{{Sqrt(2),1/Sqrt(2)},\n" // - + " {0,Sqrt(5/2)}}"); check("matG=CholeskyDecomposition({{11.0,3.0},{3.0, 5.0}})", // "{{3.31662,0.904534},\n" + // - " {0.0,2.04495}}"); + " {0,2.04495}}"); check("Transpose(matG).matG", // "{{11.0,3.0},\n" + // " {3.0,5.0}}"); check("CholeskyDecomposition({{0.5, 0.3, 0.4}, {0.3, 1.1, -0.2}, {0.4, -0.2, 0.7}})", // "{{0.707107,0.424264,0.565685},\n" // - + " {0.0,0.959166,-0.458732},\n" // - + " {0.0,0.0,0.411783}}"); + + " {0,0.959166,-0.458732},\n" // + + " {0,0,0.411783}}"); check("CholeskyDecomposition({{2, I}, {-I, 3}})", // "{{Sqrt(2),I/Sqrt(2)},\n" // + " {0,Sqrt(5/2)}}"); + + // message: CholeskyDecomposition: The matrix {{2,1}, {3,a}} is not hermitian or real and + // symmetric. + check("CholeskyDecomposition({{2,1},{3,a}})", // + "CholeskyDecomposition({{2,1},{3,a}})"); + check("CholeskyDecomposition({{2,1},{1,3}})", // + "{{Sqrt(2),1/Sqrt(2)},\n" // + + " {0,Sqrt(5/2)}}"); } public void testCirclePoints() { @@ -496,12 +497,19 @@ public void testEigensystem() { } public void testEigenvalues() { + check("Eigenvalues(SparseArray({{1.0, 2, 3}, {4, 5, 6}, {7, 8, 9}}))", // + "{16.11684,-1.11684,-9.2965*10^-16}"); + + check("Eigenvalues({{-3.0,-1.5,-3.0},{0,-1,0},{1,0,0}})", // + "{-1.5+I*(-0.866025),-1.5+I*0.866025,-1.0}"); + check("Eigenvalues({{1.0, 2, 3}, {4, 5, 6}, {7, 8, 9}})", // + "{16.11684,-1.11684,-9.2965*10^-16}"); + // example from https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors check("Eigenvalues({{2,0,0,0},{1,2,0,0},{0,1,3,0},{0,0,1,3}})", // "{3,3,2,2}"); - check("Eigenvalues({{-3.0,-1.5,-3.0},{0,-1,0},{1,0,0}})", // - "{-1.5+I*0.866025,-1.5+I*(-0.866025),-1.0}"); + check("Eigenvalues({{1,1,1},{2,2,2},{3,3,3}})", // "{6,0,0}"); check("Eigenvalues({{-2,-2,4}, {-1,-3,7}, {2,4,6}})", // @@ -550,13 +558,10 @@ public void testEigenvalues() { // Eigenvalues check("Eigenvalues({{-8, 12, 4}, {12, -20, 0}, {4, 0, -2}}) // N // Chop", // "{-27.59215,-4.6517,2.24386}"); - check("Eigenvalues(SparseArray({{1.0, 2, 3}, {4, 5, 6}, {7, 8, 9}}))", // - "{16.11684,-1.11684,-9.2965*10^-16}"); check("Eigenvalues(A)", // "Eigenvalues(A)"); - check("Eigenvalues({{1.0, 2, 3}, {4, 5, 6}, {7, 8, 9}})", // - "{16.11684,-1.11684,-9.2965*10^-16}"); + check("Eigenvalues({{a}})", // "{a}"); check("Eigenvalues({{a, b}, {0, a}})", // @@ -907,7 +912,7 @@ public void testInverse() { + "10+s+4*s^2+s^3)},\n"// + " {s/(-10+s+4*s^2+s^3),(-2-s)/(10-s-4*s^2-s^3),(8+5*s+s^2)/(-10+s+4*s^2+s^3)}}"); check("N(Inverse({{1,2.0},{3,4}}),50)", // - "{{-2,1},\n" + " {1.5,-0.5}}"); + "{{-2.0,1.0},{1.5,-0.5}}"); check("Inverse({{1,2},{3,4}})", "{{-2,1},\n" + " {3/2,-1/2}}"); check("Inverse({{1,2.0},{3,4}})", "{{-2.0,1.0},\n" + " {1.5,-0.5}}"); @@ -1595,13 +1600,7 @@ public void testQRDecomposition() { "-3/Sqrt(35)"); // TODO MMA gives 2x3 and 2x2 matrices check("QRDecomposition({{1, 2}, {3, 4}, {5, 6}}) // N", // - "{\n" // - + "{{-0.169031,-0.507093,-0.845154},\n"// - + " {0.897085,0.276026,-0.345033},\n"// - + " {0.408248,-0.816497,0.408248}},\n"// - + "{{-5.91608,-7.43736},\n"// - + " {0.0,0.828079},\n"// - + " {0.0,0.0}}}");// + "{{{-0.169031,-0.507093,-0.845154},{0.897085,0.276026,-0.345033},{0.408248,-0.816497,0.408248}},{{-5.91608,-7.43736},{0.0,0.828079},{0.0,0.0}}}");// check("QRDecomposition({{12, -51, 4}, {6, 167, -68}, {-4, 24, -41}})", // "{\n" + "{{-6/7,-3/7,2/7},\n" // @@ -1834,7 +1833,7 @@ public void testSchurDecomposition() { + " {0.00010145,1.18284,4.04539},\n" // + " {0.0,-8.89583*10^-24,0.6}}}"); check("m - q.t.ConjugateTranspose(q) // Chop", // - "{{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}}"); + "{{0,0,0},{0,0,0},{0,0,0}}"); check( "m = {{1.81066, 0.31066, 1.5}, {-0.53033, 2.03033, 0.43934}, {-0.96967, -0.53033, 2.56066}};", // @@ -1848,7 +1847,7 @@ public void testSchurDecomposition() { + " {1.71543,1.9817,-0.476196},\n" // + " {0.0,-3.59747*10^-17,2.22049}}}"); check("m - q.t.ConjugateTranspose(q) // Chop", // - "{{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}}"); + "{{0,0,0},{0,0,0},{0,0,0}}"); } public void testSingularValueDecomposition() { diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java index e7eaa2e834..81d4037dee 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java @@ -2244,6 +2244,14 @@ public void testBitLength() { } public void testBrayCurtisDistance() { + check("-1*{10.5, 10} ", // + "{-10.5,-10}"); + check("{-1, -1} - 1 * {10.5, 10} ", // + "{-11.5,-11}"); + check("{-1, -1} + {10.5, 10} ", // + "{9.5,9}"); + + check("BrayCurtisDistance({-1, -1}, {10.5, 10})", // "1.21622"); check("BrayCurtisDistance({x,-2,3},{x,5,-3})", // @@ -3852,7 +3860,7 @@ public void testContinuedFraction() { check("ContinuedFraction(9/22)", // "{0,2,2,4}"); check("ContinuedFraction(9.0/22)", // - "{0.0,2.0,2.0,3.0,1.0}"); + "{0,2,2,3,1}"); check("ContinuedFraction(-19/10)", // "{-1,-1,-9}"); check("ContinuedFraction(7283752929681393 / 4096)", // @@ -4420,8 +4428,8 @@ public void testCountDistinct() { public void testCovariance() { - check("Covariance({{0.25,0.33,0.45} })", // - "Covariance(\n"// + check("Covariance({{0.25,0.33,0.45}})", // + "Covariance(\n" // + "{{0.25,0.33,0.45}})"); check("Covariance({{0.25,0.13,0.45,0.02},{0.25,0.36,0.45,0.02}})", // "{{0.0,0.0,0.0,0.0},\n" // @@ -10247,7 +10255,7 @@ public void testGCD() { } public void testGeometricMean() { - check("GeometricMean(13.261197054679151) // N", // + checkNumeric("GeometricMean(13.261197054679151) // N", // "GeometricMean(13.261197054679151)"); checkNumeric("GeometricMean({1, 2.0, 3, 4})", // "2.213363839400643"); @@ -10973,20 +10981,24 @@ public void testHypergeometric2F1Regularized() { } public void testHypergeometricPFQ() { - check("HypergeometricPFQ({1/2, b}, {3/2, b + 1}, z)", // - "(b*(Sqrt(Pi)*Sqrt(1/z)*Erfi(Sqrt(z))+(-Gamma(b)+Gamma(b,-z))/(-z)^b))/(-1+2*b)"); - check("HypergeometricPFQ({a,b}, {c,d}, 0)", // - "1"); - check("HypergeometricPFQ({a, b}, {c, b}, z)", // - "HypergeometricPFQ({a},{c},z)"); + // message HypergeometricPFQ: general hypergeometric argument currently restricted. check("HypergeometricPFQ({1, 1, 1}, {3/2, 3/2, 3/2}, 10.0)", // - "HypergeometricPFQ({1.0,1.0,1.0},{1.5,1.5,1.5},10.0)"); + "HypergeometricPFQ({1,1,1},{3/2,3/2,3/2},10.0)"); check("HypergeometricPFQ({1, 1}, {3, 3, 3}, 2.)", // - "HypergeometricPFQ({1.0,1.0},{3.0,3.0,3.0},2.0)"); + "HypergeometricPFQ({1,1},{3,3,3},2.0)"); + check("HypergeometricPFQ({I, I, I}, {2, 2 , 2}, -1.0*I)", // "0.870032+I*(-0.00484538)"); check("HypergeometricPFQ({1, 2, 3, 4}, {5, 6, 7}, {0.1, 0.3, 0.5})", // "{1.01164,1.03627,1.06296}"); + + check("HypergeometricPFQ({1/2, b}, {3/2, b + 1}, z)", // + "(b*(Sqrt(Pi)*Sqrt(1/z)*Erfi(Sqrt(z))+(-Gamma(b)+Gamma(b,-z))/(-z)^b))/(-1+2*b)"); + check("HypergeometricPFQ({a,b}, {c,d}, 0)", // + "1"); + check("HypergeometricPFQ({a, b}, {c, b}, z)", // + "HypergeometricPFQ({a},{c},z)"); + } public void testHypergeometricU() { @@ -11025,7 +11037,7 @@ public void testI() { public void testIdentity() { check("Composition(Through, {Identity, Sqrt}) /@ {0, 1.0, 2.0, 3.0, 4.0}", // - "{{0.0,0.0},{1.0,1.0},{2.0,1.41421},{3.0,1.73205},{4.0,2.0}}"); + "{{0,0},{1.0,1.0},{2.0,1.41421},{3.0,1.73205},{4.0,2.0}}"); check("Identity'", // "1&"); check("D(Identity(Sin(x)),x)", // @@ -13940,7 +13952,7 @@ public void testMantissaExponent() { check("MantissaExponent(N(Pi, 20))", // "{0.31415926535897932384,1}"); check("MantissaExponent(3.4*10^30)", // - "{0.34,31.0}"); + "{0.34,31}"); } public void testMap() { @@ -14621,7 +14633,8 @@ public void testMedianFilter() { public void testMeijerG() { check("MeijerG({{}, {0.33}}, {{Pi}, {E}}, {-0.5,0.5})", // - "{(0.0864683+I*0.0412186)*Hypergeometric1F1Regularized(3.81159,1.42331,-0.5),-0.0957901*Hypergeometric1F1Regularized(3.81159,1.42331,0.5)}"); + "{(0.0864683+I*0.0412186)*Hypergeometric1F1Regularized(3.81159,1-E+Pi,-0.5),-0.0957901*Hypergeometric1F1Regularized(3.81159,\n" + + "1-E+Pi,0.5)}"); check("MeijerG({{}, {a2}}, {{b1}, {b2}}, z)", // "(z^b1*Hypergeometric1F1Regularized(1-a2+b1,1+b1-b2,z))/Gamma(a2-b1)"); @@ -15930,9 +15943,11 @@ public void testNextPrime() { } public void testNHoldAll() { - check("N(f(2, 3))", "f(2.0,3.0)"); + check("N(f(2, 3))", // + "f(2.0,3.0)"); check("SetAttributes(f, NHoldAll)", ""); - check("N(f(2, 3))", "f(2,3)"); + check("N(f(2, 3))", // + "f(2,3)"); } public void testNIntegrate() { @@ -19130,8 +19145,7 @@ public void testPrimePi() { public void testPrincipleComponents() { // message SparseArray: Input matrix contains an indeterminate entry. - check( - "PrincipalComponents(SparseArray({{0,0},{0,0}},0) ^ (I*1/3*Pi))", // + check("PrincipalComponents(SparseArray({{0,0},{0,0}},0) ^ (I*1/3*Pi))", // "PrincipalComponents(SparseArray(Number of elements: 4 Dimensions: {2,2} Default value: 0))"); check("PrincipalComponents({{0.25,0.33,0.45,0.01}},Method->\"Correlation\")", // "{{0.0,0.0,0.0,0.0}}"); @@ -19218,7 +19232,7 @@ public void testPrincipleComponents() { check("Variance(pc)", // "{4100.023,196.3743,75.84303,12.0943}"); check("Mean(pc) // Chop", // - "{0.0,0.0,0.0,0.0}"); + "{0,0,0,0}"); check("Correlation(pc)", // "{{1.0,0.0,0.0,0.0},\n" // + " {0.0,1.0,0.0,0.0},\n" // @@ -20421,7 +20435,7 @@ public void testRealAbs() { check("RealAbs(-Infinity)", // "Infinity"); check("RealAbs({1.2, 1.5, 0})", // - "{1.2,1.5,0.0}"); + "{1.2,1.5,0}"); check("RealAbs(Interval({-1, 2}))", // "Interval({0,2})"); check("D(RealAbs(x),x)", // @@ -22986,6 +23000,11 @@ public void testSubtractFrom() { } public void testSurd() { + checkNumeric("N(Surd({-3, -2, -1, 0, 1, 2, 3}, 7))", // + "{-1.169930812758687,-1.1040895136738123,-1.0,0.0,1.0,1.1040895136738123,1.169930812758687}"); + checkNumeric("N(Surd( -2, 5),25)", // + "-1.148698354997035006798626"); + check("Surd(EulerGamma,3)", // "EulerGamma^(1/3)"); check("Surd(EulerGamma,-7)", // @@ -23099,10 +23118,6 @@ public void testSurd() { "Surd(I,2)"); check("Surd({-3, -2, -1, 0, 1, 2, 3}, 7)", // "{-3^(1/7),-2^(1/7),-1,0,1,2^(1/7),3^(1/7)}"); - checkNumeric("N(Surd({-3, -2, -1, 0, 1, 2, 3}, 7))", // - "{-1.169930812758687,-1.1040895136738123,-1.0,0.0,1.0,1.1040895136738123,1.169930812758687}"); - checkNumeric("N(Surd( -2, 5),25)", // - "-1.148698354997035006798626"); } public void testSurvivalFunction() { @@ -23413,6 +23428,9 @@ public void testTakeLargest() { } public void testTakeLargestBy() { + check( + "TakeLargestBy({-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0},Abs,3)", // + "{-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0}"); check("TakeLargestBy({254/315+(14954373125000+I*7875000*Sqrt(9477810222))^(1/3)/31500+\n" // + " 1215035/63*2^(1/3)/(29908746250000+I*15750000*Sqrt(9477810222))^(1/3),254/315+\n" // + " 1215035/63*(-1+I*Sqrt(3))/(2^(2/3)*(29908746250000+I*15750000*Sqrt(9477810222))^(\n" // @@ -25198,11 +25216,6 @@ public void testWeierstrassP() { } public void testWeierstrassPPrime() { - check("WeierstrassPPrime(z, {0, 0}) ", // - "-2/z^3"); - check("WeierstrassPPrime(z, {3, 1}) ", // - "-3*Sqrt(3/2)*Cot(Sqrt(3/2)*z)*Csc(Sqrt(3/2)*z)^2"); - check("WeierstrassPPrime(2.0, {1,2} )", // "8.39655+I*1.28374*10^-14"); check("WeierstrassPPrime(5., {1, 2}) ", // @@ -25214,6 +25227,10 @@ public void testWeierstrassPPrime() { check("Table(WeierstrassPPrime(x,{1.0,3.0} ), {x,-2.0, 2.0, 1/4})", // "{-19.23245+I*(-2.02665*10^-14),-5.13514+I*(-3.76819*10^-15),-1.68643+I*(-1.16607*10^-15),-0.0838866+I*(-5.45142*10^-16),1.44536+I*(-3.30329*10^-16),4.48151+I*2.98579*10^-16,15.89616+I*1.58114*10^-15,127.9683+I*1.1967*10^-15,ComplexInfinity,-127.9683+I*(-1.1967*10^-15),-15.89616+I*(-1.58114*10^-15),-4.48151+I*(-2.98579*10^-16),-1.44536+I*3.30329*10^-16,0.0838866+I*5.45142*10^-16,1.68643+I*1.16607*10^-15,5.13514+I*3.76819*10^-15,19.23245+I*2.02665*10^-14}"); // + check("WeierstrassPPrime(z, {0, 0}) ", // + "-2/z^3"); + check("WeierstrassPPrime(z, {3, 1}) ", // + "-3*Sqrt(3/2)*Cot(Sqrt(3/2)*z)*Csc(Sqrt(3/2)*z)^2"); } public void testWhich() { diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/PolynomialFunctionsTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/PolynomialFunctionsTest.java index cd745539b8..c78010c2fd 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/PolynomialFunctionsTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/PolynomialFunctionsTest.java @@ -138,6 +138,10 @@ public void testGegenbauerC() { } public void testHermiteH() { + checkNumeric("HermiteH({-1,2.987,0,1},-1009)", // + "{HermiteH(-1,-1009),Indeterminate,1,-2018}"); + checkNumeric("HermiteH( 1 ,-1009)", // + "-2018"); checkNumeric("HermiteH(3.1, 5)", // "1177.0141932545182"); checkNumeric("HermiteH(.71, .87)", // diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SolveTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SolveTest.java index b3db068f06..8651048a24 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SolveTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/SolveTest.java @@ -533,7 +533,7 @@ public void testSolve() { // github #117 check("Solve({x+y^2==9.1, y==2*x+2}, {x,y})", // - "{{x->-2.71893,y->-3.43787},{x->0.468934,y->2.93787}}"); + "{{y->-3.43787,x->-2.71893},{y->2.93787,x->0.468934}}"); check("Solve(-28 - 4*Sqrt(-1 + x) + 4*x==0,x)", // "{{x->10}}"); @@ -620,7 +620,7 @@ public void testSolve() { "{{x->0.6666666666666665*y*z}}"); // Issue #160 checkNumeric("Solve((2.10937501*y)/(0.6923076944378698*z)==(0.6923076944378698*z)/x,x)", // - "{{x->(0.2272189352323269*z^2.0)/y}}"); + "{{x->(0.22721893523232692*z^2.0)/y}}"); // Issue #159 check("Solve(x==2*Sqrt(y)*Sqrt(z),y)", // "{{y->x^2/(4*z)}}"); @@ -738,7 +738,7 @@ public void testSolve() { checkNumeric("z=22.13904248493947", // 7 "22.13904248493947"); checkNumeric("Solve(x/y==z/x,x)", // - "{{x->-81.08825721072822},{x->81.08825721072822}}"); + "{{x->-81.08825721072805},{x->81.08825721072805}}"); } public void testNSolve() { @@ -892,19 +892,19 @@ public void testNSolve() { check("NSolve((-3+E^(2*x))==0,x)", // "{{x->0.549306}}"); check("NSolve(E^(3*x)-4*E^x+3*E^(-x)==0,x)", // - "{{x->ConditionalExpression((I*6.28319)*C(1.0),C(1)∈Integers)},{x->ConditionalExpression(I*3.14159+(I*6.28319)*C(1.0),C(\n" - + "1)∈Integers)},{x->ConditionalExpression(0.549306+(I*6.28319)*C(1.0),C(1)∈Integers)},{x->ConditionalExpression(0.549306+I*3.14159+(I*6.28319)*C(1.0),C(\n" - + "1)∈Integers)}}"); + "{{x->ConditionalExpression((I*6.28319)*C(1),C(1)∈Integers)},{x->ConditionalExpression(I*3.14159+(I*6.28319)*C(\n" + + "1),C(1)∈Integers)},{x->ConditionalExpression(0.549306+(I*6.28319)*C(1),C(1)∈Integers)},{x->ConditionalExpression(0.549306+I*3.14159+(I*6.28319)*C(\n" + + "1),C(1)∈Integers)}}"); check("NSolve(1+E^x==0,x)", // "{{x->I*3.14159}}"); check("Solve(1+E^x==0,x)", // "{{x->ConditionalExpression(I*Pi+I*2*Pi*C(1),C(1)∈Integers)}}"); check("NSolve(a+E^(b*x)==0,x)", // - "{{x->ConditionalExpression(((I*6.28319)*C(1.0)+Log(-a))/b,C(1)∈Integers)}}"); + "{{x->ConditionalExpression(((I*6.28319)*C(1)+Log(-a))/b,C(1)∈Integers)}}"); check("NSolve(E^x==b,x)", // - "{{x->ConditionalExpression((I*6.28319)*C(1.0)+Log(b),C(1)∈Integers)}}"); + "{{x->ConditionalExpression((I*6.28319)*C(1)+Log(b),C(1)∈Integers)}}"); check("NSolve(a^x==42,x)", // "{{x->3.73767/Log(a)}}"); // @@ -1323,7 +1323,7 @@ public void testSolveIssue130() { public void testSolveIssue413() { // eval quiet without message check("Solve({8.0*E - 9 == x0/x1, x0==x1^4.0},{x0, x1}) ", // - "{{x0->29.77443,x1->2.33594},{x0->-14.88721+I*(-25.78541),x1->-1.16797+I*(-2.02298)},{x0->-14.88721+I*25.78541,x1->-1.16797+I*2.02298}}"); + "{{x1->-1.16797+I*2.02298,x0->-14.88721+I*25.78541},{x1->-1.16797+I*(-2.02298),x0->-14.88721+I*(-25.78541)},{x1->0.0,x0->0.0},{x1->2.33594,x0->29.77443}}"); // eval quiet without message check("Solve({x0^2.0*Sin(x1)==5.0,x1^3.0*Cos(x0)==5.0},{x0,x1}) ", // "Solve({x0^2.0*Sin(x1)==5.0,x1^3.0*Cos(x0)==5.0},{x0,x1})");