Search in sources :

Example 6 with IBuiltInSymbol

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

the class F method initFinalSymbol.

/**
	 * Insert a new Symbol in the <code>SYSTEM</code> context.
	 * 
	 * @param symbolName
	 *            the predefined symbol name in upper-case form
	 * @param evaluator
	 *            defines the evaluation behaviour of the symbol
	 * @return
	 */
public static IBuiltInSymbol initFinalSymbol(final String symbolName, IEvaluator evaluator) {
    IBuiltInSymbol temp = new BuiltInSymbol(symbolName, evaluator);
    evaluator.setUp(temp);
    Context.SYSTEM.put(symbolName, temp);
    return temp;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol)

Example 7 with IBuiltInSymbol

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

the class F method initFinalSymbol.

/**
	 * Convert the symbolName to lowercase (if <code>Config.PARSER_USE_LOWERCASE_SYMBOLS</code> is set) and insert a new
	 * Symbol in the <code>PREDEFINED_SYMBOLS_MAP</code>. The symbol is created using the given upper case string to use
	 * it as associated class name in package org.matheclipse.core.reflection.system.
	 * 
	 * @param symbolName
	 *            the predefined symbol name in upper-case form
	 * @return
	 */
public static IBuiltInSymbol initFinalSymbol(final String symbolName) {
    IBuiltInSymbol temp = new BuiltInSymbol(symbolName);
    Context.SYSTEM.put(symbolName, temp);
    return temp;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol)

Example 8 with IBuiltInSymbol

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

the class DoubleStackEvaluator method evalAST.

public static double evalAST(double[] stack, final int top, final IAST ast) {
    final ISymbol symbol = (ISymbol) ast.get(0);
    if (symbol.isBuiltInSymbol()) {
        final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
        if (module instanceof INumeric) {
            int newTop = top;
            // fast evaluation path
            if (top + ast.size() >= stack.length) {
                stack = new double[ast.size() + 50];
            }
            for (int i = 1; i < ast.size(); i++) {
                ++newTop;
                stack[newTop] = DoubleStackEvaluator.eval(stack, newTop, ast.get(i));
            }
            return ((INumeric) module).evalReal(stack, newTop, ast.size() - 1);
        }
    }
    // slow evaluation path
    final IExpr result = F.evaln(ast);
    if (result instanceof Num) {
        return ((Num) result).doubleValue();
    }
    throw new UnsupportedOperationException("EvalDouble#evalAST(): " + ast);
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) ISymbol(org.matheclipse.core.interfaces.ISymbol) INumeric(org.matheclipse.core.eval.interfaces.INumeric) Num(org.matheclipse.core.expression.Num) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IExpr (org.matheclipse.core.interfaces.IExpr)5 ISymbol (org.matheclipse.core.interfaces.ISymbol)5 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)4 Num (org.matheclipse.core.expression.Num)3 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 IAST (org.matheclipse.core.interfaces.IAST)2 DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)1 INumeric (org.matheclipse.core.eval.interfaces.INumeric)1 INumericComplex (org.matheclipse.core.eval.interfaces.INumericComplex)1 INumericComplexConstant (org.matheclipse.core.eval.interfaces.INumericComplexConstant)1 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)1 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)1