Search in sources :

Example 1 with IFunctionEvaluator

use of org.matheclipse.core.eval.interfaces.IFunctionEvaluator in project symja_android_library by axkr.

the class EvalEngine method evalSetAttributesRecursive.

private IExpr evalSetAttributesRecursive(IAST ast, boolean noEvaluation, boolean evalNumericFunction, int level) {
    // final ISymbol symbol = ast.topHead();
    IExpr head = ast.head();
    if (!(head instanceof IPatternObject) && !noEvaluation) {
        IExpr headResult = head.evaluate(this);
        if (headResult.isPresent()) {
            ast = ast.apply(headResult);
            head = headResult;
        }
    }
    ISymbol symbol = head.topHead();
    if (head.isSymbol()) {
        symbol = (ISymbol) head;
    }
    if (symbol.isBuiltInSymbol()) {
        // call so that attributes may be set in
        // AbstractFunctionEvaluator#setUp() method
        ((IBuiltInSymbol) symbol).getEvaluator();
    }
    int headID = ast.headID();
    if (headID >= 0) {
        if (headID == ID.Blank || headID == ID.BlankSequence || headID == ID.BlankNullSequence || headID == ID.Pattern || headID == ID.Optional || headID == ID.OptionsPattern || headID == ID.Repeated || headID == ID.RepeatedNull) {
            return ((IFunctionEvaluator) ((IBuiltInSymbol) ast.head()).getEvaluator()).evaluate(ast, this);
        }
    }
    final int attributes = symbol.getAttributes();
    IASTMutable resultList = F.NIL;
    if ((ISymbol.HOLDALL & attributes) != ISymbol.HOLDALL) {
        final int astSize = ast.size();
        if ((ISymbol.HOLDFIRST & attributes) == ISymbol.NOATTRIBUTE) {
            // the HoldFirst attribute isn't set here
            if (astSize > 1) {
                IExpr expr = ast.arg1();
                if (expr.isAST()) {
                    resultList = evalSetAttributeArg(ast, 1, (IAST) expr, resultList, noEvaluation, level);
                } else if (!(expr instanceof IPatternObject) && !noEvaluation) {
                    IExpr temp = expr.evaluate(this);
                    if (temp.isPresent()) {
                        resultList = ast.setAtCopy(1, temp);
                    }
                }
            }
        }
        if (astSize > 2) {
            if ((ISymbol.HOLDREST & attributes) == ISymbol.NOATTRIBUTE) {
                // the HoldRest attribute isn't set here
                for (int i = 2; i < astSize; i++) {
                    IExpr expr = ast.get(i);
                    if (expr.isAST()) {
                        resultList = evalSetAttributeArg(ast, i, (IAST) expr, resultList, noEvaluation, level);
                    } else if (!(expr instanceof IPatternObject) && !noEvaluation) {
                        IExpr temp = expr.evaluate(this);
                        if (temp.isPresent()) {
                            if (resultList.isPresent()) {
                                resultList.set(i, temp);
                            } else {
                                resultList = ast.setAtCopy(i, temp);
                            }
                        }
                    }
                }
            }
        }
        if (evalNumericFunction && ((ISymbol.HOLDALL & attributes) == ISymbol.NOATTRIBUTE)) {
            IAST f = resultList.orElse(ast);
            if (f.isNumericFunction(true)) {
                IExpr temp = evalLoop(f);
                if (temp.isPresent()) {
                    return temp;
                }
            }
        }
    }
    if (resultList.isPresent()) {
        if (resultList.size() > 2) {
            if (ISymbol.hasFlatAttribute(attributes)) {
                // associative
                IASTAppendable result;
                if ((result = EvalAttributes.flattenDeep(resultList)).isPresent()) {
                    return evalSetOrderless(result, attributes, noEvaluation, level);
                }
            }
            IExpr expr = evalSetOrderless(resultList, attributes, noEvaluation, level);
            if (expr.isPresent()) {
                return expr;
            }
        }
        return resultList;
    }
    if ((ast.getEvalFlags() & IAST.IS_FLATTENED_OR_SORTED_MASK) != 0x0000) {
        // already flattened or sorted
        return ast;
    }
    if (ISymbol.hasFlatAttribute(attributes)) {
        // associative
        IASTAppendable result;
        if ((result = EvalAttributes.flattenDeep(ast)).isPresent()) {
            return evalSetOrderless(result, attributes, noEvaluation, level);
        }
    }
    return evalSetOrderless(ast, attributes, noEvaluation, level);
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IExpr(org.matheclipse.core.interfaces.IExpr) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) IAST(org.matheclipse.core.interfaces.IAST)

Example 2 with IFunctionEvaluator

use of org.matheclipse.core.eval.interfaces.IFunctionEvaluator in project symja_android_library by axkr.

the class EvalEngine method evalASTBuiltinFunction.

/**
 * @param symbol
 * @param ast
 * @return <code>F.NIL</code> if no evaluation happened
 */
private IExpr evalASTBuiltinFunction(final ISymbol symbol, IAST ast) {
    final int attributes = symbol.getAttributes();
    if (fEvalLHSMode) {
        if ((ISymbol.HOLDALL & attributes) == ISymbol.HOLDALL) {
            // (i.e. Sin, Cos,...)
            if (!(symbol.equals(S.Set) || symbol.equals(S.SetDelayed) || symbol.equals(S.UpSet) || symbol.equals(S.UpSetDelayed))) {
                return F.NIL;
            }
        } else {
            if ((ISymbol.NUMERICFUNCTION & attributes) != ISymbol.NUMERICFUNCTION) {
                return F.NIL;
            }
        }
    }
    if (!symbol.equals(S.Integrate)) {
        IExpr result;
        if ((result = symbol.evalDownRule(this, ast)).isPresent()) {
            return result;
        }
    }
    if (symbol.isBuiltInSymbol()) {
        final IEvaluator evaluator = ((IBuiltInSymbol) symbol).getEvaluator();
        if (evaluator instanceof IFunctionEvaluator) {
            if (ast.isEvalFlagOn(IAST.BUILT_IN_EVALED) && isSymbolicMode(attributes)) {
                return F.NIL;
            }
            // evaluate a built-in function.
            final IFunctionEvaluator functionEvaluator = (IFunctionEvaluator) evaluator;
            OptionsResult opres = checkBuiltinArguments(ast, functionEvaluator);
            if (opres == null) {
                return F.NIL;
            }
            ast = opres.result;
            try {
                if (evaluator instanceof AbstractFunctionOptionEvaluator) {
                    AbstractFunctionOptionEvaluator optionsEvaluator = (AbstractFunctionOptionEvaluator) evaluator;
                    IExpr result = optionsEvaluator.evaluate(ast, opres.argSize, opres.options, this);
                    if (result.isPresent()) {
                        return result;
                    }
                } else {
                    IExpr result = fNumericMode ? functionEvaluator.numericEval(ast, this) : functionEvaluator.evaluate(ast, this);
                    if (result.isPresent()) {
                        return result;
                    }
                }
            } catch (ValidateException ve) {
                return IOFunctions.printMessage(ast.topHead(), ve, this);
            } catch (FlowControlException e) {
                throw e;
            } catch (SymjaMathException ve) {
                LOGGER.log(getLogLevel(), ast.topHead(), ve);
                return F.NIL;
            }
        // cannot generally set the result as evaluated in built-in function. Especially problems in
        // `togetherMode`
        // if (isSymbolicMode(attributes) && !isTogetherMode()) {
        // ast.addEvalFlags(IAST.BUILT_IN_EVALED);
        // }
        }
    }
    return F.NIL;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ValidateException(org.matheclipse.core.eval.exception.ValidateException) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) AbstractFunctionOptionEvaluator(org.matheclipse.core.eval.interfaces.AbstractFunctionOptionEvaluator) FlowControlException(org.matheclipse.core.eval.exception.FlowControlException) IExpr(org.matheclipse.core.interfaces.IExpr) SymjaMathException(org.matheclipse.core.eval.exception.SymjaMathException)

Example 3 with IFunctionEvaluator

use of org.matheclipse.core.eval.interfaces.IFunctionEvaluator in project symja_android_library by axkr.

the class ExprEvaluatorTests method builtinFunctionFuzz.

/**
 * Fuzz testing - automated software testing that involves providing random arguments as inputs
 * for the Symja built-in functions.
 */
public static void builtinFunctionFuzz() {
    Config.FILESYSTEM_ENABLED = false;
    EvalEngine engine = new EvalEngine(true);
    engine.setRecursionLimit(256);
    engine.setIterationLimit(1000);
    ExprEvaluator eval = new ExprEvaluator(engine, true, (short) 20);
    byte[] bArray = new byte[0];
    ByteArrayExpr ba = ByteArrayExpr.newInstance(bArray);
    byte[] b0Array = new byte[] { 0 };
    ByteArrayExpr b0a = ByteArrayExpr.newInstance(b0Array);
    F.x.setAttributes(ISymbol.PROTECTED);
    F.y.setAttributes(ISymbol.PROTECTED);
    double[] doubleArr = new double[] { 1.0, -1.0, 0.0, 2.0, 100.0, 200.0 };
    int[] dims = new int[] { 2, 3 };
    NumericArrayExpr nae = new NumericArrayExpr(doubleArr, dims, NumericArrayExpr.Real64);
    Config.MAX_AST_SIZE = 10000;
    Config.MAX_OUTPUT_SIZE = 10000;
    Config.MAX_INPUT_LEAVES = 100L;
    Config.MAX_MATRIX_DIMENSION_SIZE = 100;
    Config.MAX_PRECISION_APFLOAT = 100;
    Config.MAX_BIT_LENGTH = 20000;
    Config.MAX_POLYNOMIAL_DEGREE = 100;
    IAST seedList = // 
    F.List(// 
    ba, // 
    b0a, // 
    nae, // 
    S.$Aborted, // 
    S.False, // 
    S.True, // 
    S.E, // 
    S.Pi, // 
    S.Indeterminate, // 
    F.Missing("test"), // 
    F.complex(-0.5, 0.5), // 
    F.complex(0.0, 0.5), // 
    F.complex(0.0, -1.0), // 
    F.complex(0.0, 1.0), // 
    F.complex(2.0, -1.0), // 
    F.complex(2.0, 1.0), // 
    F.complex(-2.0, -2.0), // 
    F.complex(-2.0, 2.0), // 
    F.complexNum("-0.8", "1.2", 30), // 
    F.num(0.5), // 
    F.num(-0.5), // 
    F.num(Math.PI * (-0.5)), // 
    F.num(Math.PI * 0.5), // 
    F.num(-Math.PI), // 
    F.num(Math.PI), // 
    F.num(-Math.E), // 
    F.num(Math.E), // 
    F.num("-0.8", 30), // 
    F.C0, // 
    F.C1, // 
    F.CN1, // 
    F.CN1D2, // 
    F.C1D2, // 
    F.CNI, // 
    F.CI, // 
    F.ZZ(42), // 
    F.CC(Long.MAX_VALUE, Long.MIN_VALUE, Long.MIN_VALUE, Long.MAX_VALUE), // 
    F.QQ(Long.MAX_VALUE, Long.MIN_VALUE), // 
    F.QQ(Long.MIN_VALUE, Long.MAX_VALUE), // 
    F.Slot2, // some primes
    F.C2, F.C3, F.C5, F.C7, F.ZZ(11), F.ZZ(13), F.ZZ(17), F.ZZ(19), F.ZZ(101), F.ZZ(1009), // 
    F.ZZ(10007), // 
    F.CN2, // 
    F.CN3, // 
    F.CN5, // 
    F.CN7, // 
    F.ZZ(-11), // 
    F.ZZ(-13), // 
    F.ZZ(-17), // 
    F.ZZ(-19), // 
    F.ZZ(-101), // 
    F.ZZ(-1009), // 
    F.ZZ(-10007), // 
    F.ZZ(Integer.MIN_VALUE), // 
    F.ZZ(Integer.MAX_VALUE), // 
    F.ZZ(Byte.MIN_VALUE), // 
    F.ZZ(Byte.MAX_VALUE), // 
    F.CInfinity, // 
    F.CNInfinity, // 
    F.Null, // 
    F.Power(F.x, F.C2), // 
    F.Indeterminate, // 
    F.ComplexInfinity, // 
    F.x_, // 
    F.y_, // any sequence of one or more expressions
    F.x__, // any sequence of one or more expressions
    F.y__, // any sequence of zero or more expressions
    F.x___, // any sequence of zero or more expressions
    F.y___, // 
    F.CEmptyList, // 
    F.assoc(F.List(F.Rule(F.a, F.C0), F.RuleDelayed(F.b, F.C1))), // 
    F.assoc(F.List()), // 
    F.assoc(F.List(F.Rule(F.stringx("s1"), F.C0), F.RuleDelayed(F.stringx("s2"), F.C1))), F.assoc(F.List(F.Rule(F.stringx("s1"), F.assoc(F.List(F.Rule(F.a, F.C0), F.RuleDelayed(F.b, F.C1)))), F.RuleDelayed(F.stringx("s2"), // 
    F.assoc(F.List(F.Rule(F.a, F.C0), F.RuleDelayed(F.b, F.C1)))))), // 
    SparseArrayExpr.newDenseList(F.List(F.C0, F.C0), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.C0, F.C1, F.C0, F.C2), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0)), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1)), F.C0), // 
    F.Function(F.EvenQ(F.Slot1)), // 
    F.Function(F.Expand(F.Power(F.Plus(F.C2, F.Slot1), F.C3))), // 
    S.Graph.of(F.List(F.Rule(F.C1, F.C2), F.Rule(F.C2, F.C3), F.Rule(F.C3, F.C1))), // 
    S.Graph.of(F.List()), S.Graph.of(F.List(F.Rule(F.C1, F.C2), F.Rule(F.C2, F.C3), F.Rule(F.C3, F.C1)), // 
    F.List(F.Rule(S.EdgeWeight, F.List(F.CD0, F.CD1, F.CD1)))), // 
    F.CEmptySequence, // 
    F.CEmptyList, // 
    F.List(F.List(F.C0)), // 
    F.List(F.List(F.C1)), // 
    F.List(F.List(F.CN1)), // 
    F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1)), // 
    F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0)), // 
    F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1), F.C0), // 
    F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0), F.C0), F.List(F.num("-3.1415", 30), F.num("2.987", 30), F.num("-1", 30), F.num("0.0", 30), // 
    F.num("1", 30)), // 
    F.List(F.CN1, F.CN2, F.C3), // 
    F.List(F.CN1D2, F.CN2, F.C3), // 
    F.List(F.x, F.CN2, F.C3), // 
    F.List(F.x, F.C5, F.CN3), // 
    F.List(F.x, F.CN3, F.CN1D2), // 
    F.List(F.x, F.CN1D2, F.C1D2, F.C1D4), // 
    F.List(F.C0, F.C0), // 
    F.List(F.C0, F.C0, F.C0), // 
    F.List(F.C1, F.C2, F.C3), // 
    F.List(F.C1, F.C1, F.C1), // 
    F.List(F.C1, F.C2, F.C3, F.a), // 
    F.List(F.C0, F.C0, F.C0, F.C0), // 
    F.List(F.C1, F.C1, F.C1, F.C1), // 
    F.List(F.x, F.CN1, F.C1, F.C1), // 
    F.List(F.x, F.C0, F.C0, F.C0), // 
    F.List(F.x, F.C1, F.CN1, F.CN1), // 
    F.List(F.CN1), // 
    F.List(F.C0), // 
    F.List(F.C1), // simulate level spec
    F.List(F.CN5), // simulate level spec
    F.List(F.C7), // 
    F.List(F.complex(0.0, -1.0)), // 
    F.List(F.complex(0.0, 1.0)), // 
    F.List(F.x), // 
    F.List(F.CN3D2), // 
    F.List(F.C3D2), // 
    F.List(F.C3D4), // 
    F.Part(F.x, F.C1), // 
    F.Part(F.x, F.C2), // 
    F.Part(F.x, F.ZZ(Integer.MAX_VALUE)), // 
    F.Part(F.x, F.CN1, F.C1, F.C1), // 
    F.Part(F.x, F.C1, F.C1, F.C1, F.C1), // 
    F.C1DSqrt5, // GoldenRatio
    F.Divide(F.Plus(F.C1, F.Sqrt(5)), F.C2), // 1/GoldenRatio
    F.Divide(F.C2, F.Plus(F.C1, F.Sqrt(5))), // 
    F.Negate(F.Sqrt(2)), // 
    F.Divide(F.Sqrt(2), F.C2), // 
    F.Negate(F.Divide(F.Sqrt(2), F.C2)), // 
    F.Plus(F.Sqrt(2), F.C1), // 
    F.Plus(F.Sqrt(2), F.CN1), // 
    F.Exp(F.Times(F.Pi, F.CI, F.C1D3)), // 
    F.Plus(F.C1, F.CI), // 
    F.Plus(F.CN1, F.CI), // 
    F.Times(F.Sqrt(2), F.C7), // 
    F.Times(F.Sqrt(2), F.Sqrt(5)), // 
    F.CSqrt2, // 
    F.C2Pi, // 
    F.CN3D2, // 
    F.C3D2, // 
    F.C3D4, // 
    F.QQ(Long.MAX_VALUE, 7L), // 
    F.QQ(Long.MIN_VALUE, 11L), // 
    F.QQ(7, Long.MAX_VALUE), // 
    F.QQ(11, Long.MAX_VALUE), // 
    F.QQ(Long.MAX_VALUE, Long.MAX_VALUE), // 
    F.QQ(Long.MIN_VALUE, Long.MAX_VALUE), // 
    F.Slot2, // 
    F.Slot(Integer.MAX_VALUE), // 
    IQuantity.of(1.2, "m"), // 
    F.RegularExpression("?i)"), // 
    F.CEmptyString, // 
    F.stringx("\\"), // 
    F.stringx("\r"), // 
    F.stringx("\t"), // 
    F.stringx("\n"), // 
    F.stringx("\r\n"), // 
    F.stringx("\n   "), // 
    F.stringx("\uffff"), // division by zero problem
    F.Power(F.C0, F.CN1), // 
    F.Subtract(F.C1, F.C1), // 
    F.Rule(S.Modulus, F.C2), // 
    F.Rule(S.Modulus, F.C10), // 
    F.Rule(S.Heads, S.True), // 
    F.Rule(S.Heads, S.False), // 
    F.$OptionsPattern(), // 
    F.OptionValue(F.a), // 
    F.OptionValue(F.b), // 
    F.OptionValue(F.x), F.OptionValue(F.y));
    ThreadLocalRandom random = ThreadLocalRandom.current();
    String[] functionStrs = AST2Expr.FUNCTION_STRINGS;
    int[] counter = new int[] { 0 };
    for (int loop = 0; loop < 20000; loop++) {
        for (int i = 0; i < functionStrs.length; i++) {
            IBuiltInSymbol sym = (IBuiltInSymbol) F.symbol(functionStrs[i]);
            if (sym == S.PolynomialGCD || sym == S.TestReport || sym == S.VerificationTest || sym == S.On || sym == S.Off || sym == S.Compile || sym == S.CompiledFunction || sym == S.FactorialPower || sym == S.Pause || sym == S.Power || sym == S.OptimizeExpression || sym == S.Share || sym == S.Set || sym == S.SetDelayed || sym == S.UpSet || sym == S.UpSetDelayed) {
                continue;
            }
            IEvaluator evaluator = sym.getEvaluator();
            if (evaluator instanceof IFunctionEvaluator) {
                int[] argSize = ((IFunctionEvaluator) evaluator).expectedArgSize(null);
                if (argSize != null) {
                    int end = argSize[1];
                    if (end <= 10) {
                        int start = argSize[0];
                        if (start == 0) {
                            start = 1;
                        }
                        generateASTs(sym, start, end, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, false);
                        generateASTs(sym, start, end, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, false);
                        if (argSize.length > 2) {
                            generateASTs(sym, start, end, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, true);
                            generateASTs(sym, start, end, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, true);
                        }
                        continue;
                    } else {
                        int start = random.nextInt(argSize[0], 10);
                        generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, false);
                        generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, false);
                        if (argSize.length > 2) {
                            generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, true);
                            generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, true);
                        }
                    }
                } else {
                    int start = random.nextInt(1, 7);
                    generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, false);
                    generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, false, true);
                    generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, false);
                    generateASTs(sym, start, start + 4, seedList, random, counter, (IFunctionEvaluator) evaluator, engine, true, true);
                }
            }
        }
    }
}
Also used : ExprEvaluator(org.matheclipse.core.eval.ExprEvaluator) NumericArrayExpr(org.matheclipse.core.expression.data.NumericArrayExpr) ByteArrayExpr(org.matheclipse.core.expression.data.ByteArrayExpr) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) EvalEngine(org.matheclipse.core.eval.EvalEngine) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IAST(org.matheclipse.core.interfaces.IAST)

Example 4 with IFunctionEvaluator

use of org.matheclipse.core.eval.interfaces.IFunctionEvaluator in project symja_android_library by axkr.

the class ExprEvaluatorTests method checkEvaluator.

void checkEvaluator(IAST ast, String expected) {
    EvalEngine engine = EvalEngine.get();
    try {
        IFunctionEvaluator evaluator = (IFunctionEvaluator) ((IBuiltInSymbol) ast.topHead()).getEvaluator();
        if (evaluator instanceof IFunctionEvaluator) {
            IExpr result = evaluator.evaluate(ast, engine);
            assertEquals(expected, result.toString());
            return;
        }
    } catch (RuntimeException rex) {
        rex.printStackTrace();
    }
    fail();
}
Also used : IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) EvalEngine(org.matheclipse.core.eval.EvalEngine) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 5 with IFunctionEvaluator

use of org.matheclipse.core.eval.interfaces.IFunctionEvaluator in project symja_android_library by axkr.

the class ExprEvaluatorTests method nonBuiltinFunctionFuzz.

public static void nonBuiltinFunctionFuzz() {
    Config.MAX_AST_SIZE = 10000;
    Config.MAX_OUTPUT_SIZE = 10000;
    Config.MAX_INPUT_LEAVES = 100L;
    Config.MAX_MATRIX_DIMENSION_SIZE = 100;
    Config.MAX_PRECISION_APFLOAT = 100;
    Config.MAX_BIT_LENGTH = 200000;
    Config.MAX_POLYNOMIAL_DEGREE = 100;
    Config.FILESYSTEM_ENABLED = false;
    EvalEngine engine = new EvalEngine(true);
    engine.setRecursionLimit(256);
    engine.setIterationLimit(1000);
    ExprEvaluator eval = new ExprEvaluator(engine, true, (short) 20);
    byte[] bArray = new byte[0];
    ByteArrayExpr ba = ByteArrayExpr.newInstance(bArray);
    byte[] b0Array = new byte[] { 0 };
    ByteArrayExpr b0a = ByteArrayExpr.newInstance(b0Array);
    F.x.setAttributes(ISymbol.PROTECTED);
    F.y.setAttributes(ISymbol.PROTECTED);
    IAST seedList = // 
    F.List(// 
    ba, // 
    b0a, // 
    F.complex(-0.5, 0.5), // 
    F.complex(0.0, 0.5), // 
    F.complex(0.0, -1.0), // 
    F.complex(0.0, 1.0), // 
    F.num(0.5), // 
    F.num(-0.5), // 
    F.num(Math.PI * (-0.5)), // 
    F.num(Math.PI * 0.5), // 
    F.num(-Math.PI), // 
    F.num(Math.PI), // 
    F.num(-Math.E), // 
    F.num(Math.E), // 
    F.C0, // 
    F.C1, // 
    F.CN1, // 
    F.CN1D2, // 
    F.C1D2, // 
    F.CNI, // 
    F.CI, // 
    F.CInfinity, // 
    F.CNInfinity, // 
    F.Null, // 
    F.Power(F.x, F.C2), // 
    F.Indeterminate, // 
    F.ComplexInfinity, // 
    F.x_, // 
    F.y_, // 
    F.CEmptyList, // 
    F.assoc(F.List(F.Rule(F.a, F.C0), F.RuleDelayed(F.b, F.C1))), // 
    F.assoc(F.List()), // 
    F.assoc(F.List(F.Rule(F.stringx("s1"), F.C0), F.RuleDelayed(F.stringx("s2"), F.C1))), // 
    SparseArrayExpr.newDenseList(F.List(F.C0, F.C0), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.C0, F.C1, F.C0, F.C2), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0)), F.C0), // 
    SparseArrayExpr.newDenseList(F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1)), F.C0), // 
    F.List(F.List(F.C0)), // 
    F.List(F.List(F.C1)), // 
    F.List(F.List(F.CN1)), // 
    F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1)), // 
    F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0)), // 
    F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1), F.C0), // 
    F.List(F.List(F.C0, F.C0), F.List(F.C0, F.C0), F.C0), // 
    F.List(F.CN1, F.CN2, F.C3), // 
    F.List(F.CN1D2, F.CN2, F.C3), // 
    F.List(F.x, F.CN2, F.C3), // 
    F.List(F.x, F.C5, F.CN3), // 
    F.List(F.x, F.CN3, F.CN1D2), // simulate level spec
    F.List(F.CN5), // simulate level spec
    F.List(F.C7), // 
    F.C1DSqrt5, // 
    F.C2Pi, // 
    F.CN3D2, // 
    F.C3D2, // 
    F.C3D4, // 
    F.Slot2, // 
    F.stringx(""), // 
    F.stringx("\\"), // 
    F.stringx("\r"), // 
    F.stringx("\t"), // 
    F.stringx("\n"), // 
    F.stringx("\r\n"), // 
    F.stringx("\n   "), // 
    F.stringx("\uffff"), F.Subtract(F.C1, F.C1));
    String[] functionStrs = AST2Expr.FUNCTION_STRINGS;
    ThreadLocalRandom random = ThreadLocalRandom.current();
    int[] counter = new int[] { 0 };
    for (int i = 0; i < functionStrs.length; i++) {
        IBuiltInSymbol sym = (IBuiltInSymbol) F.symbol(functionStrs[i]);
        IEvaluator evaluator = sym.getEvaluator();
        if (evaluator instanceof IFunctionEvaluator) {
            continue;
        }
        generateASTs(sym, 1, 5, seedList, random, counter, null, engine, false, false);
        generateASTs(sym, 1, 5, seedList, random, counter, null, engine, false, true);
        generateASTs(sym, 1, 5, seedList, random, counter, null, engine, true, false);
        generateASTs(sym, 1, 5, seedList, random, counter, null, engine, true, true);
    }
}
Also used : ExprEvaluator(org.matheclipse.core.eval.ExprEvaluator) ByteArrayExpr(org.matheclipse.core.expression.data.ByteArrayExpr) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) EvalEngine(org.matheclipse.core.eval.EvalEngine) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

IFunctionEvaluator (org.matheclipse.core.eval.interfaces.IFunctionEvaluator)5 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)4 EvalEngine (org.matheclipse.core.eval.EvalEngine)3 IAST (org.matheclipse.core.interfaces.IAST)3 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)2 ByteArrayExpr (org.matheclipse.core.expression.data.ByteArrayExpr)2 FlowControlException (org.matheclipse.core.eval.exception.FlowControlException)1 SymjaMathException (org.matheclipse.core.eval.exception.SymjaMathException)1 ValidateException (org.matheclipse.core.eval.exception.ValidateException)1 AbstractFunctionOptionEvaluator (org.matheclipse.core.eval.interfaces.AbstractFunctionOptionEvaluator)1 NumericArrayExpr (org.matheclipse.core.expression.data.NumericArrayExpr)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)1 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1