50
50
import org .matheclipse .core .eval .exception .Validate ;
51
51
import org .matheclipse .core .eval .exception .ValidateException ;
52
52
import org .matheclipse .core .eval .interfaces .ICoreFunctionEvaluator ;
53
+ import org .matheclipse .core .eval .interfaces .IFunctionEvaluator ;
53
54
import org .matheclipse .core .eval .interfaces .IRewrite ;
54
55
import org .matheclipse .core .eval .util .AbstractAssumptions ;
55
56
import org .matheclipse .core .eval .util .SourceCodeProperties ;
@@ -1961,7 +1962,7 @@ public IExpr.COMPARE_TERNARY equalTernary(IExpr that, EvalEngine engine) {
1961
1962
@ Override
1962
1963
public final INumber evalNumber () {
1963
1964
if (isNumericFunction (true )) {
1964
- IExpr result = EvalEngine .get ().evalN (this );
1965
+ IExpr result = EvalEngine .get ().evalNumericFunction (this );
1965
1966
if (result .isNumber ()) {
1966
1967
return (INumber ) result ;
1967
1968
}
@@ -1973,7 +1974,7 @@ public final INumber evalNumber() {
1973
1974
@ Override
1974
1975
public final IReal evalReal () {
1975
1976
if (isNumericFunction (true )) {
1976
- IExpr result = EvalEngine .get ().evalN (this );
1977
+ IExpr result = EvalEngine .get ().evalNumericFunction (this );
1977
1978
if (result .isReal ()) {
1978
1979
return (IReal ) result ;
1979
1980
}
@@ -1986,7 +1987,7 @@ public final IReal evalReal() {
1986
1987
} else if (isAST (S .Labeled , 3 , 4 )) {
1987
1988
IExpr arg1 = arg1 ();
1988
1989
if (arg1 .isNumericFunction (true )) {
1989
- IExpr result = EvalEngine .get ().evalN (arg1 );
1990
+ IExpr result = EvalEngine .get ().evalNumericFunction (arg1 );
1990
1991
if (result .isReal ()) {
1991
1992
return (IReal ) result ;
1992
1993
}
@@ -3963,8 +3964,7 @@ public final boolean isModuleOrWithCondition() {
3963
3964
@ Override
3964
3965
public boolean isNegative () {
3965
3966
if (isNumericFunction (true )) {
3966
-
3967
- IExpr result = EvalEngine .get ().evalN (this );
3967
+ IExpr result = EvalEngine .get ().evalNumericFunction (this );
3968
3968
if (result .isReal ()) {
3969
3969
return result .isNegative ();
3970
3970
}
@@ -4050,6 +4050,9 @@ public boolean isNumericFunction(boolean allowList) {
4050
4050
if (header .isNumericFunctionAttribute () || isList ()) {
4051
4051
// check if all arguments are "numeric"
4052
4052
boolean forAll = forAll (x -> x .isNumericFunction (allowList ), 1 );
4053
+ if (forAll && !isList ()) {
4054
+ forAll = hasExpectedArgSize (header );
4055
+ }
4053
4056
addEvalFlags (
4054
4057
forAll ? IAST .IS_NUMERIC_FUNCTION_OR_LIST : IAST .IS_NOT_NUMERIC_FUNCTION_OR_LIST );
4055
4058
return forAll ;
@@ -4058,6 +4061,9 @@ public boolean isNumericFunction(boolean allowList) {
4058
4061
if (header .isNumericFunctionAttribute ()) {
4059
4062
// check if all arguments are "numeric"
4060
4063
boolean forAll = forAll (x -> x .isNumericFunction (allowList ), 1 );
4064
+ if (forAll ) {
4065
+ forAll = hasExpectedArgSize (header );
4066
+ }
4061
4067
addEvalFlags (forAll ? IAST .IS_NUMERIC_FUNCTION : IAST .IS_NOT_NUMERIC_FUNCTION );
4062
4068
return forAll ;
4063
4069
}
@@ -4066,6 +4072,28 @@ public boolean isNumericFunction(boolean allowList) {
4066
4072
return false ;
4067
4073
}
4068
4074
4075
+ private boolean hasExpectedArgSize (ISymbol header ) {
4076
+ if (header .isBuiltInSymbol ()) {
4077
+ IEvaluator evaluator = ((IBuiltInSymbol ) header ).getEvaluator ();
4078
+ if (evaluator instanceof IFunctionEvaluator ) {
4079
+ int [] expected = ((IFunctionEvaluator ) evaluator ).expectedArgSize (this );
4080
+ if (expected != null ) {
4081
+ int argSize = argSize ();
4082
+ if (argSize < expected [0 ] || argSize > expected [1 ]
4083
+ || (expected [1 ] == Integer .MAX_VALUE && expected .length == 2 )) {
4084
+ if (argSize < expected [0 ]) {
4085
+ return false ;
4086
+ }
4087
+ if (argSize > expected [1 ]) {
4088
+ return false ;
4089
+ }
4090
+ }
4091
+ }
4092
+ }
4093
+ }
4094
+ return true ;
4095
+ }
4096
+
4069
4097
/** {@inheritDoc} */
4070
4098
@ Override
4071
4099
public boolean isNumericFunction (VariablesSet varSet ) {
@@ -4254,7 +4282,7 @@ public final boolean isPolynomialOfMaxDegree(ISymbol variable, long maxDegree) {
4254
4282
@ Override
4255
4283
public boolean isPositive () {
4256
4284
if (isNumericFunction (true )) {
4257
- IExpr result = EvalEngine .get ().evalN (this );
4285
+ IExpr result = EvalEngine .get ().evalNumericFunction (this );
4258
4286
if (result .isReal ()) {
4259
4287
return ((IReal ) result ).isPositive ();
4260
4288
}
@@ -4399,9 +4427,12 @@ public boolean isRealResult() {
4399
4427
}
4400
4428
}
4401
4429
}
4402
- IReal e = evalReal ();
4430
+ INumber e = evalNumber ();
4403
4431
if (e != null ) {
4404
- return true ;
4432
+ if (e .isReal ()) {
4433
+ return true ;
4434
+ }
4435
+ return false ;
4405
4436
}
4406
4437
if (isPlus () || isTimes ()) {
4407
4438
// check if all arguments are "real values"
0 commit comments