|
99 | 99 | import org.matheclipse.core.interfaces.IAST;
|
100 | 100 | import org.matheclipse.core.interfaces.IASTAppendable;
|
101 | 101 | import org.matheclipse.core.interfaces.IASTMutable;
|
| 102 | +import org.matheclipse.core.interfaces.IBigNumber; |
102 | 103 | import org.matheclipse.core.interfaces.IBuiltInSymbol;
|
103 | 104 | import org.matheclipse.core.interfaces.IComplex;
|
104 | 105 | import org.matheclipse.core.interfaces.IComplexNum;
|
@@ -2656,14 +2657,14 @@ private static IExpr numericEvalAST1(IExpr expr, EvalEngine engine) {
|
2656 | 2657 | final int oldSignificantFigures = engine.getSignificantFigures();
|
2657 | 2658 | try {
|
2658 | 2659 | long numericPrecision = oldDigitPrecision; // Config.MACHINE_PRECISION;
|
2659 |
| - if (expr.isNumericFunction(true)) { |
2660 |
| - engine.setNumericMode(true, numericPrecision, oldSignificantFigures); |
2661 |
| - IExpr temp = engine.evalWithoutNumericReset(expr); |
2662 |
| - if (temp.isListOrAssociation() || temp.isRuleAST()) { |
2663 |
| - return ((IAST) temp).mapThread(F.N(F.Slot1), 1); |
2664 |
| - } |
2665 |
| - return temp; |
2666 |
| - } |
| 2660 | + // if (expr.isNumericFunction(true)) { |
| 2661 | + // engine.setNumericMode(true, numericPrecision, oldSignificantFigures); |
| 2662 | + // IExpr temp = engine.evalWithoutNumericReset(expr); |
| 2663 | + // if (temp.isListOrAssociation() || temp.isRuleAST()) { |
| 2664 | + // return ((IAST) temp).mapThread(F.N(F.Slot1), 1); |
| 2665 | + // } |
| 2666 | + // return temp; |
| 2667 | + // } |
2667 | 2668 | expr = engine.evaluate(expr);
|
2668 | 2669 | if (expr.isInexactNumber()) {
|
2669 | 2670 | return expr;
|
@@ -3561,7 +3562,7 @@ public static IExpr sqrtDenest(IRational arg1, IExpr arg2) {
|
3561 | 3562 | return F.NIL;
|
3562 | 3563 | }
|
3563 | 3564 |
|
3564 |
| - public IExpr binaryOperator(IAST ast, final IExpr base, final IExpr exponent, |
| 3565 | + public static IExpr binaryOperator(IAST ast, final IExpr base, final IExpr exponent, |
3565 | 3566 | EvalEngine engine) {
|
3566 | 3567 | try {
|
3567 | 3568 | if (base.isInexactNumber() && exponent.isInexactNumber()) {
|
@@ -7034,6 +7035,57 @@ protected ISymbol getArithmeticSymbol() {
|
7034 | 7035 |
|
7035 | 7036 | }
|
7036 | 7037 |
|
| 7038 | + /** |
| 7039 | + * Eval in double numeric mode by "widen the input domain" to Apfloat values. |
| 7040 | + * |
| 7041 | + * @param powerAST2 "binary {@link S#Power} function" |
| 7042 | + * @return |
| 7043 | + */ |
| 7044 | + public static IExpr intPowerFractionNumeric(IAST powerAST2) { |
| 7045 | + IExpr base = powerAST2.base(); |
| 7046 | + IExpr exponent = powerAST2.exponent(); |
| 7047 | + if ((base instanceof IBigNumber) && exponent.isFraction()) { |
| 7048 | + IFraction exp = (IFraction) exponent; |
| 7049 | + int denom = exp.denominator().toIntDefault(); |
| 7050 | + if (denom > 0L) { |
| 7051 | + if (base.isRational()) { |
| 7052 | + IRational iBase = (IRational) base; |
| 7053 | + double fNum = base.evalf(); |
| 7054 | + if (!Double.isFinite(fNum) || fNum <= Double.MIN_VALUE || fNum >= Double.MAX_VALUE) { |
| 7055 | + if (iBase.isPositive()) { |
| 7056 | + // special case root of "rational base" |
| 7057 | + ApfloatNum apfloat = iBase.apfloatNumValue(); |
| 7058 | + if (exp.numerator().isOne()) { |
| 7059 | + return F.num(apfloat.rootN(denom).doubleValue()); |
| 7060 | + } else if (exp.numerator().isMinusOne()) { |
| 7061 | + return F.num(apfloat.rootN(denom).inverse().doubleValue()); |
| 7062 | + } |
| 7063 | + } else if (iBase.isNegative()) { |
| 7064 | + ApcomplexNum apcomplex = iBase.apcomplexNumValue(); |
| 7065 | + if (exp.numerator().isOne()) { |
| 7066 | + return F.complexNum(apcomplex.rootN(denom).evalfc()); |
| 7067 | + } else if (exp.numerator().isMinusOne()) { |
| 7068 | + return F.complexNum(apcomplex.rootN(denom).inverse().evalfc()); |
| 7069 | + } |
| 7070 | + } |
| 7071 | + } |
| 7072 | + } else if (base.isComplex()) { |
| 7073 | + IComplex iBase = (IComplex) base; |
| 7074 | + org.hipparchus.complex.Complex fComplex = base.evalfc(); |
| 7075 | + if (!fComplex.isFinite()) { |
| 7076 | + ApcomplexNum apcomplex = iBase.apcomplexNumValue(); |
| 7077 | + if (exp.numerator().isOne()) { |
| 7078 | + return F.complexNum(apcomplex.rootN(denom).evalfc()); |
| 7079 | + } else if (exp.numerator().isMinusOne()) { |
| 7080 | + return F.complexNum(apcomplex.rootN(denom).inverse().evalfc()); |
| 7081 | + } |
| 7082 | + } |
| 7083 | + } |
| 7084 | + } |
| 7085 | + } |
| 7086 | + return F.NIL; |
| 7087 | + } |
| 7088 | + |
7037 | 7089 | /**
|
7038 | 7090 | * Try simpplifying <code>(power0Arg1 ^ power0Arg2) * (power1Arg1 ^ power1Arg2)</code>
|
7039 | 7091 | *
|
|
0 commit comments