Skip to content

Commit 4856526

Browse files
committed
WIP #937 N( Equal-expression ) does not return numeric result
1 parent 21f6897 commit 4856526

File tree

5 files changed

+31
-35
lines changed

5 files changed

+31
-35
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/BooleanFunctions.java

-14
Original file line numberDiff line numberDiff line change
@@ -1734,11 +1734,6 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
17341734
return S.Undefined;
17351735
}
17361736

1737-
IAST evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
1738-
if (evalArgs.isPresent()) {
1739-
return evalArgs;
1740-
}
1741-
17421737
if (ast.size() > 2) {
17431738
IExpr.COMPARE_TERNARY b = IExpr.COMPARE_TERNARY.UNDECIDABLE;
17441739
if (ast.isAST2()) {
@@ -2216,11 +2211,6 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
22162211
return S.True;
22172212
}
22182213

2219-
IASTMutable evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
2220-
if (evalArgs.isPresent()) {
2221-
return evalArgs;
2222-
}
2223-
22242214
IASTAppendable flattened;
22252215
if ((flattened = EvalAttributes.flattenDeep(ast)).isPresent()) {
22262216
ast = flattened;
@@ -4671,10 +4661,6 @@ private static final class Unequal extends Equal {
46714661

46724662
@Override
46734663
public IExpr evaluate(final IAST ast, EvalEngine engine) {
4674-
IASTMutable evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
4675-
if (evalArgs.isPresent()) {
4676-
return evalArgs;
4677-
}
46784664
if (ast.exists(x -> x.equals(S.Undefined))) {
46794665
return S.Undefined;
46804666
}

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/GraphicsFunctions.java

-4
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,6 @@ private static final class Labeled extends AbstractCoreFunctionEvaluator {
683683

684684
@Override
685685
public IExpr evaluate(final IAST ast, EvalEngine engine) {
686-
IASTMutable evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
687-
if (evalArgs.isPresent()) {
688-
return evalArgs;
689-
}
690686
return F.NIL;
691687
}
692688

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/EvalEngine.java

+20-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.PrintStream;
44
import java.io.Serializable;
55
import java.util.ArrayDeque;
6+
import java.util.Arrays;
67
import java.util.Deque;
78
import java.util.HashMap;
89
import java.util.IdentityHashMap;
@@ -826,22 +827,6 @@ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg
826827

827828
}
828829

829-
/**
830-
* Evaluate the arguments of the given <code>ast</code> numerically, if {@link #isNumericMode()}
831-
* is <code>true</code> taking the attributes
832-
* <code>HoldFirst, NHoldFirst, HoldRest, NHoldRest, NumericFunction</code> into account.
833-
*
834-
* @param ast
835-
* @param attributes
836-
* @return <code>F.NIL</code> is no evaluation was possible
837-
*/
838-
public IASTMutable evalArgsN(final IAST ast, final int attributes) {
839-
if (isNumericMode()) {
840-
return evalArgs(ast, attributes, true);
841-
}
842-
return F.NIL;
843-
}
844-
845830
/**
846831
* Evaluate the arguments of the given ast, taking the attributes <code>
847832
* HoldFirst, NHoldFirst, HoldRest, NHoldRest, NumericFunction</code> into account.
@@ -856,6 +841,9 @@ public IASTMutable evalArgs(final IAST ast, final int attributes, boolean numeri
856841
final int astSize = ast.size();
857842

858843
if (astSize > 1) {
844+
if (!numericFunction) {
845+
numericFunction = isNumericArg(ast);
846+
}
859847
boolean numericMode = fNumericMode;
860848
boolean localNumericMode = fNumericMode;
861849
final boolean isNumericFunction;
@@ -956,6 +944,20 @@ public IASTMutable evalArgs(final IAST ast, final int attributes, boolean numeri
956944
return F.NIL;
957945
}
958946

947+
/**
948+
* Test if the arguments of this <code>ast</code> should be evaluated numerically in numeric mode.
949+
*
950+
* @param ast
951+
* @return
952+
*/
953+
private boolean isNumericArg(final IAST ast) {
954+
int id = ast.headID();
955+
if (id >= 0) {
956+
return Arrays.binarySearch(F.SORTED_NUMERIC_ARGS_IDS, id) >= 0;
957+
}
958+
return false;
959+
}
960+
959961
/**
960962
* Evaluate an AST with only one argument (i.e. <code>head[arg1]</code>). The evaluation steps are
961963
* controlled by the header attributes.
@@ -1437,11 +1439,12 @@ private IExpr evalNoAttributes(IASTMutable mutableAST) {
14371439
}
14381440
final int astSize = mutableAST.size();
14391441
final boolean localNumericMode = fNumericMode;
1442+
final boolean argNumericMode = isNumericArg(mutableAST);
14401443
IASTMutable[] rlist = new IASTMutable[] {F.NIL};
14411444
mutableAST.forEach(1, astSize, (arg, i) -> {
14421445
if (!arg.isUnevaluated()) {
14431446
fNumericMode = localNumericMode;
1444-
evalArg(rlist, mutableAST, arg, i, false);
1447+
evalArg(rlist, mutableAST, arg, i, argNumericMode);
14451448
}
14461449
});
14471450
if (rlist[0].isPresent()) {

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java

+7
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ public void createUserSymbol(ISymbol symbol) {}
234234
public static final AbstractAST.NILPointer INVALID = AbstractAST.INVALID;
235235
// public final static ISymbol usage = initFinalHiddenSymbol("usage");
236236

237+
/**
238+
* Built-in function IDs those arguments should be evaluated numerically in numeric mode:
239+
*/
240+
public static final int[] SORTED_NUMERIC_ARGS_IDS = new int[] {//
241+
ID.Equal, ID.Greater, ID.GreaterEqual, ID.Labeled, ID.Less, ID.LessEqual, ID.Unequal //
242+
};
243+
237244
/**
238245
* Used to represent a formal pattern <code>a_</code> that will be used only for predefined
239246
* pattern-matching rules and can match one expression.

symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java

+4
Original file line numberDiff line numberDiff line change
@@ -15984,6 +15984,10 @@ public void testN() {
1598415984
"x==-1.5708");
1598515985
check("ConditionalExpression(x==-157079632679/100000000000*C(1),C(1)∈Integers) // N", //
1598615986
"ConditionalExpression(x==-1.5708*C(1),C(1)∈Integers)");
15987+
check("f(1/3)//N", //
15988+
"f(0.333333)");
15989+
check("f(1/2*x)//N", //
15990+
"f(0.5*x)");
1598715991
check("N({Labeled(4/3,\"test\")})", //
1598815992
"{Labeled(1.33333,test)}");
1598915993
check("N(Labeled(4/3,\"test\"))", //

0 commit comments

Comments
 (0)