Skip to content

Commit 3f76bf8

Browse files
committed
WIP #937 N( Equal-expression ) does not return numeric result
1 parent 85954f2 commit 3f76bf8

File tree

6 files changed

+77
-14
lines changed

6 files changed

+77
-14
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,12 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
17331733
if (ast.exists(x -> x.equals(S.Undefined))) {
17341734
return S.Undefined;
17351735
}
1736+
1737+
IAST evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
1738+
if (evalArgs.isPresent()) {
1739+
return evalArgs;
1740+
}
1741+
17361742
if (ast.size() > 2) {
17371743
IExpr.COMPARE_TERNARY b = IExpr.COMPARE_TERNARY.UNDECIDABLE;
17381744
if (ast.isAST2()) {
@@ -2210,6 +2216,11 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
22102216
return S.True;
22112217
}
22122218

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

46614672
@Override
46624673
public IExpr evaluate(final IAST ast, EvalEngine engine) {
4674+
IASTMutable evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
4675+
if (evalArgs.isPresent()) {
4676+
return evalArgs;
4677+
}
46634678
if (ast.exists(x -> x.equals(S.Undefined))) {
46644679
return S.Undefined;
46654680
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.matheclipse.core.convert.RGBColor;
88
import org.matheclipse.core.eval.Errors;
99
import org.matheclipse.core.eval.EvalEngine;
10+
import org.matheclipse.core.eval.interfaces.AbstractCoreFunctionEvaluator;
1011
import org.matheclipse.core.eval.interfaces.AbstractEvaluator;
1112
import org.matheclipse.core.eval.interfaces.AbstractSymbolEvaluator;
1213
import org.matheclipse.core.eval.util.OptionArgs;
@@ -660,6 +661,7 @@ private static void init() {
660661
S.Cylinder.setEvaluator(new Cylinder());
661662
S.Dodecahedron.setEvaluator(new Dodecahedron());
662663
S.Icosahedron.setEvaluator(new Icosahedron());
664+
S.Labeled.setEvaluator(new Labeled());
663665
S.Line.setEvaluator(new Line());
664666
S.Octahedron.setEvaluator(new Octahedron());
665667
S.Point.setEvaluator(new Point());
@@ -677,6 +679,24 @@ private static void init() {
677679
}
678680
}
679681

682+
private static final class Labeled extends AbstractCoreFunctionEvaluator {
683+
684+
@Override
685+
public IExpr evaluate(final IAST ast, EvalEngine engine) {
686+
IASTMutable evalArgs = engine.evalArgsN(ast, ISymbol.NOATTRIBUTE);
687+
if (evalArgs.isPresent()) {
688+
return evalArgs;
689+
}
690+
return F.NIL;
691+
}
692+
693+
@Override
694+
public int[] expectedArgSize(IAST ast) {
695+
return ARGS_2_3;
696+
}
697+
698+
}
699+
680700
private static class Line extends AbstractEvaluator implements IGraphics2D, IGraphics3D {
681701

682702
@Override

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

+16
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,22 @@ public void evalArg(final IASTMutable[] result0, final IAST ast, final IExpr arg
826826

827827
}
828828

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+
829845
/**
830846
* Evaluate the arguments of the given ast, taking the attributes <code>
831847
* HoldFirst, NHoldFirst, HoldRest, NHoldRest, NumericFunction</code> into account.

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

+17-14
Original file line numberDiff line numberDiff line change
@@ -4044,20 +4044,23 @@ public boolean isNumericFunction(boolean allowList) {
40444044
}
40454045
}
40464046
}
4047-
if (allowList) {
4048-
if (head().isSymbol() && ((ISymbol) head()).isNumericFunctionAttribute() || isList()) {
4049-
// check if all arguments are &quot;numeric&quot;
4050-
boolean forAll = forAll(x -> x.isNumericFunction(allowList), 1);
4051-
addEvalFlags(
4052-
forAll ? IAST.IS_NUMERIC_FUNCTION_OR_LIST : IAST.IS_NOT_NUMERIC_FUNCTION_OR_LIST);
4053-
return forAll;
4054-
}
4055-
} else {
4056-
if (head().isSymbol() && ((ISymbol) head()).isNumericFunctionAttribute()) {
4057-
// check if all arguments are &quot;numeric&quot;
4058-
boolean forAll = forAll(x -> x.isNumericFunction(allowList), 1);
4059-
addEvalFlags(forAll ? IAST.IS_NUMERIC_FUNCTION : IAST.IS_NOT_NUMERIC_FUNCTION);
4060-
return forAll;
4047+
if (head().isSymbol()) {
4048+
ISymbol header = (ISymbol) head();
4049+
if (allowList) {
4050+
if (header.isNumericFunctionAttribute() || isList()) {
4051+
// check if all arguments are &quot;numeric&quot;
4052+
boolean forAll = forAll(x -> x.isNumericFunction(allowList), 1);
4053+
addEvalFlags(
4054+
forAll ? IAST.IS_NUMERIC_FUNCTION_OR_LIST : IAST.IS_NOT_NUMERIC_FUNCTION_OR_LIST);
4055+
return forAll;
4056+
}
4057+
} else {
4058+
if (header.isNumericFunctionAttribute()) {
4059+
// check if all arguments are &quot;numeric&quot;
4060+
boolean forAll = forAll(x -> x.isNumericFunction(allowList), 1);
4061+
addEvalFlags(forAll ? IAST.IS_NUMERIC_FUNCTION : IAST.IS_NOT_NUMERIC_FUNCTION);
4062+
return forAll;
4063+
}
40614064
}
40624065
}
40634066
return false;

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

+4
Original file line numberDiff line numberDiff line change
@@ -11685,4 +11685,8 @@ public static boolean isDomain(ISymbol domain) {
1168511685
return domain == Algebraics || domain == Booleans || domain == Complexes || domain == Integers
1168611686
|| domain == Primes || domain == Rationals || domain == Reals;
1168711687
}
11688+
11689+
static {
11690+
C.setAttributes(ISymbol.NHOLDALL);
11691+
}
1168811692
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -15979,6 +15979,11 @@ public void testDeterminePrecision() {
1597915979

1598015980
@Test
1598115981
public void testN() {
15982+
// issue #937
15983+
check("(x==-157079632679/100000000000) // N", //
15984+
"x==-1.5708");
15985+
check("ConditionalExpression(x==-157079632679/100000000000*C(1),C(1)∈Integers) // N", //
15986+
"ConditionalExpression(x==-1.5708*C(1),C(1)∈Integers)");
1598215987
check("N({Labeled(4/3,\"test\")})", //
1598315988
"{Labeled(1.33333,test)}");
1598415989
check("N(Labeled(4/3,\"test\"))", //

0 commit comments

Comments
 (0)