Search in sources :

Example 21 with IBuiltInSymbol

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

the class FunctionIDGenerator method printGithubSymjaFunctionLineNumber.

public static void printGithubSymjaFunctionLineNumber() {
    try {
        ParserConfig.EXPLICIT_TIMES_OPERATOR = true;
        F.initSymbols();
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < AST2Expr.UPPERCASE_SYMBOL_STRINGS.length; i++) {
            list.add(AST2Expr.UPPERCASE_SYMBOL_STRINGS[i]);
        }
        for (int i = 0; i < AST2Expr.SYMBOL_STRINGS.length; i++) {
            list.add(AST2Expr.SYMBOL_STRINGS[i]);
        }
        for (int i = 0; i < AST2Expr.FUNCTION_STRINGS.length; i++) {
            list.add(AST2Expr.FUNCTION_STRINGS[i]);
        }
        for (int i = 0; i < AST2Expr.DOLLAR_STRINGS.length; i++) {
            list.add(AST2Expr.DOLLAR_STRINGS[i]);
        }
        Collections.sort(list);
        int counter = 0;
        System.out.println("/**\n" + "   * Generated by class: <code>org.matheclipse.core.preprocessor.FunctionIDGenerator\n" + "   * </code>\n" + "   */\n" + "public final static int[] LINE_NUMBER_OF_JAVA_CLASS = new int[] { //");
        for (int i = 0; i < list.size(); i++) {
            counter++;
            if (counter > 10) {
                System.out.println(" //");
                counter = 0;
            }
            ISymbol sym = F.symbol(list.get(i));
            if (sym instanceof IBuiltInSymbol) {
                IBuiltInSymbol builtin = (IBuiltInSymbol) sym;
                IEvaluator eval = builtin.getEvaluator();
                if (eval != null && eval != BuiltInSymbol.DUMMY_EVALUATOR) {
                    Class<? extends IEvaluator> clazz = eval.getClass();
                    if (// 
                    !clazz.isAnonymousClass() && !clazz.isSynthetic() && !clazz.isInterface() && !clazz.isPrimitive()) {
                        // 
                        String fileName = buildFileNameL(clazz);
                        File sourceLocation = new File(fileName);
                        int lineCounter = lineNumberOfClass(sourceLocation, list.get(i));
                        System.out.print(lineCounter);
                    } else {
                        System.out.print("0");
                    }
                } else {
                    System.out.print("0");
                }
            } else {
                System.out.print("0");
            }
            if (i < list.size() - 1) {
                System.out.print(",");
            }
        }
        System.out.print("};");
    } catch (RuntimeException ex) {
        System.out.println();
        ex.printStackTrace();
    }
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) ISymbol(org.matheclipse.core.interfaces.ISymbol) ArrayList(java.util.ArrayList) File(java.io.File)

Example 22 with IBuiltInSymbol

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

the class ExpressionJSONConvert method exportGraphics3DJSON.

private static JsonNode exportGraphics3DJSON(IExpr data3D) {
    if (data3D.isList()) {
        IAST list = (IAST) data3D;
        ArrayNode temp = JSON_OBJECT_MAPPER.createArrayNode();
        for (int i = 1; i < list.size(); i++) {
            IExpr arg = list.getAST(i);
            if (arg.isAST()) {
                IAST ast = (IAST) arg;
                if (ast.head().isBuiltInSymbol()) {
                    StringBuilder buf = new StringBuilder();
                    IBuiltInSymbol symbol = (IBuiltInSymbol) ast.head();
                    IEvaluator evaluator = symbol.getEvaluator();
                    if (evaluator instanceof IGraphics3D) {
                    // JsonNode n = ((IGraphics3D) evaluator).graphics3D(buf, (IAST) ast);
                    // temp.add(n);
                    }
                }
            }
        }
        return temp;
    }
    ArrayNode temp = JSON_OBJECT_MAPPER.createArrayNode();
    temp.add(temp.toString());
    return temp;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IAST(org.matheclipse.core.interfaces.IAST) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IExpr(org.matheclipse.core.interfaces.IExpr) IGraphics3D(org.matheclipse.core.graphics.IGraphics3D)

Example 23 with IBuiltInSymbol

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

the class Programming method rememberBlockVariables.

/**
 * Remember which local variable names we use in the given <code>assignedValues</code> and <code>
 * assignedRules</code>.
 *
 * @param variablesList initializer variables list from the <code>Block</code> function
 * @param assignedValues the variables mapped to their values (IExpr) before evaluating the block
 * @param assignedRules the variables mapped to their rules (RulesData) before evaluating the
 *        block
 * @param engine the evaluation engine
 */
public static void rememberBlockVariables(IAST variablesList, final ISymbol[] symbolList, final IExpr[] assignedValues, final RulesData[] assignedRules, final EvalEngine engine) {
    ISymbol variableSymbol;
    for (int i = 1; i < variablesList.size(); i++) {
        if (variablesList.get(i).isSymbol()) {
            variableSymbol = (ISymbol) variablesList.get(i);
            if (variableSymbol.isBuiltInSymbol()) {
                ISymbol substitute = ((IBuiltInSymbol) variableSymbol).mapToGlobal(engine);
                if (substitute != null) {
                    variableSymbol = substitute;
                }
            }
            symbolList[i] = variableSymbol;
            assignedValues[i] = variableSymbol.assignedValue();
            assignedRules[i] = variableSymbol.getRulesData();
        } else if (variablesList.get(i).isAST(S.Set, 3)) {
            final IAST setFun = (IAST) variablesList.get(i);
            if (setFun.arg1().isSymbol()) {
                variableSymbol = (ISymbol) setFun.arg1();
                if (variableSymbol.isBuiltInSymbol()) {
                    ISymbol substitute = ((IBuiltInSymbol) variableSymbol).mapToGlobal(engine);
                    if (substitute != null) {
                        variableSymbol = substitute;
                    }
                }
                symbolList[i] = variableSymbol;
                assignedValues[i] = variableSymbol.assignedValue();
                assignedRules[i] = variableSymbol.getRulesData();
            }
        }
    }
    for (int i = 1; i < variablesList.size(); i++) {
        if (variablesList.get(i).isSymbol()) {
            variableSymbol = symbolList[i];
            variableSymbol.assignValue(null, false);
            variableSymbol.setRulesData(null);
        } else {
            if (variablesList.get(i).isAST(S.Set, 3)) {
                final IAST setFun = (IAST) variablesList.get(i);
                if (setFun.arg1().isSymbol()) {
                    variableSymbol = symbolList[i];
                    IExpr temp = engine.evaluate(setFun.arg2());
                    variableSymbol.assignValue(temp, false);
                    variableSymbol.setRulesData(null);
                }
            }
        }
    }
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 24 with IBuiltInSymbol

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

the class GraphicsFunctions method primitivesDimension.

public static boolean primitivesDimension(IAST list, Dimensions2D dim) {
    for (int i = 1; i < list.size(); i++) {
        if (list.get(i).isAST()) {
            IAST primitive = (IAST) list.get(i);
            if (primitive.head().isBuiltInSymbol()) {
                IBuiltInSymbol symbol = (IBuiltInSymbol) primitive.head();
                IEvaluator evaluator = symbol.getEvaluator();
                if (evaluator instanceof IGraphics3D) {
                    if (!((IGraphics3D) evaluator).graphics2DDimension(primitive, dim)) {
                    // return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IAST(org.matheclipse.core.interfaces.IAST) IGraphics3D(org.matheclipse.core.graphics.IGraphics3D)

Example 25 with IBuiltInSymbol

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

the class GraphicsFunctions method exportGraphics3DRecursive.

public static boolean exportGraphics3DRecursive(StringBuilder buf, IAST data3D) {
    if (data3D.isList()) {
        boolean first = true;
        IAST rgbColor = F.NIL;
        IExpr opacity = F.NIL;
        IAST list = data3D;
        for (int i = 1; i < list.size(); i++) {
            IExpr arg = list.get(i);
            if (arg.isAST()) {
                IAST ast = (IAST) arg;
                if (ast.isList()) {
                    StringBuilder primitivesBuffer = new StringBuilder();
                    if (exportGraphics3DRecursive(primitivesBuffer, ast)) {
                        if (!first) {
                            buf.append(",");
                        }
                        first = false;
                        buf.append(primitivesBuffer);
                    }
                } else if (ast.isRGBColor()) {
                    rgbColor = ast;
                } else if (ast.isAST(S.Opacity, 2)) {
                    opacity = ast.arg1();
                } else if (ast.head().isBuiltInSymbol()) {
                    IBuiltInSymbol symbol = (IBuiltInSymbol) ast.head();
                    IEvaluator evaluator = symbol.getEvaluator();
                    if (evaluator instanceof IGraphics3D) {
                        StringBuilder primitivesBuffer = new StringBuilder();
                        if (((IGraphics3D) evaluator).graphics3D(primitivesBuffer, ast, rgbColor, opacity)) {
                            if (!first) {
                                buf.append(",");
                            }
                            first = false;
                            buf.append(primitivesBuffer);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) IGraphics3D(org.matheclipse.core.graphics.IGraphics3D)

Aggregations

IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)34 IExpr (org.matheclipse.core.interfaces.IExpr)20 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)15 IAST (org.matheclipse.core.interfaces.IAST)13 ISymbol (org.matheclipse.core.interfaces.ISymbol)11 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)6 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 IFunctionEvaluator (org.matheclipse.core.eval.interfaces.IFunctionEvaluator)4 IOException (java.io.IOException)3 IGraphics3D (org.matheclipse.core.graphics.IGraphics3D)3 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ExprEvaluator (org.matheclipse.core.eval.ExprEvaluator)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 Num (org.matheclipse.core.expression.Num)2 ByteArrayExpr (org.matheclipse.core.expression.data.ByteArrayExpr)2 IDistribution (org.matheclipse.core.interfaces.IDistribution)2