3
3
import java .io .PrintStream ;
4
4
import java .io .Serializable ;
5
5
import java .util .ArrayDeque ;
6
+ import java .util .Arrays ;
6
7
import java .util .Deque ;
7
8
import java .util .HashMap ;
8
9
import java .util .IdentityHashMap ;
@@ -826,22 +827,6 @@ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg
826
827
827
828
}
828
829
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
-
845
830
/**
846
831
* Evaluate the arguments of the given ast, taking the attributes <code>
847
832
* HoldFirst, NHoldFirst, HoldRest, NHoldRest, NumericFunction</code> into account.
@@ -856,6 +841,9 @@ public IASTMutable evalArgs(final IAST ast, final int attributes, boolean numeri
856
841
final int astSize = ast .size ();
857
842
858
843
if (astSize > 1 ) {
844
+ if (!numericFunction ) {
845
+ numericFunction = isNumericArg (ast );
846
+ }
859
847
boolean numericMode = fNumericMode ;
860
848
boolean localNumericMode = fNumericMode ;
861
849
final boolean isNumericFunction ;
@@ -956,6 +944,20 @@ public IASTMutable evalArgs(final IAST ast, final int attributes, boolean numeri
956
944
return F .NIL ;
957
945
}
958
946
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
+
959
961
/**
960
962
* Evaluate an AST with only one argument (i.e. <code>head[arg1]</code>). The evaluation steps are
961
963
* controlled by the header attributes.
@@ -1437,11 +1439,12 @@ private IExpr evalNoAttributes(IASTMutable mutableAST) {
1437
1439
}
1438
1440
final int astSize = mutableAST .size ();
1439
1441
final boolean localNumericMode = fNumericMode ;
1442
+ final boolean argNumericMode = isNumericArg (mutableAST );
1440
1443
IASTMutable [] rlist = new IASTMutable [] {F .NIL };
1441
1444
mutableAST .forEach (1 , astSize , (arg , i ) -> {
1442
1445
if (!arg .isUnevaluated ()) {
1443
1446
fNumericMode = localNumericMode ;
1444
- evalArg (rlist , mutableAST , arg , i , false );
1447
+ evalArg (rlist , mutableAST , arg , i , argNumericMode );
1445
1448
}
1446
1449
});
1447
1450
if (rlist [0 ].isPresent ()) {
0 commit comments