Search in sources :

Example 66 with ISymbol

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

the class F method initFinalHiddenSymbol.

/**
	 * 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 ISymbol initFinalHiddenSymbol(final String symbolName) {
    ISymbol temp = new Symbol(symbolName);
    HIDDEN_SYMBOLS_MAP.put(symbolName, temp);
    return temp;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol)

Example 67 with ISymbol

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

the class F method local.

/**
	 * Get a local symbol which is created or retrieved from the eval engines thread local variables map and push a
	 * value on the local stack;
	 * 
	 * @param symbolName
	 *            the name of the symbol
	 * @param value
	 * @return
	 */
public static ISymbol local(@Nonnull final String symbolName, @Nonnull IExpr value) {
    // HashMap<String, ISymbol> variableMap = EvalEngine.getVariableMap();
    // ISymbol temp = variableMap.get(symbolName);
    // if (temp != null) {
    // temp.pushLocalVariable(value);
    // return temp;
    // }
    ISymbol temp = new Symbol(symbolName);
    // variableMap.put(symbolName, temp);
    temp.pushLocalVariable(value);
    return temp;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol)

Example 68 with ISymbol

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

the class ContextPath method removeSymbol.

public ISymbol removeSymbol(String symbolName) {
    String name = symbolName;
    if (Config.PARSER_USE_LOWERCASE_SYMBOLS) {
        if (symbolName.length() == 1) {
            name = symbolName;
        } else {
            name = symbolName.toLowerCase(Locale.ENGLISH);
        }
    }
    Context context;
    ISymbol symbol;
    for (int i = path.size() - 1; i >= 0; i--) {
        context = path.get(i);
        if (context.equals(Context.SYSTEM)) {
            // don't remove predefined symbols
            continue;
        }
        symbol = context.remove(name);
        if (symbol != null) {
            return symbol;
        }
    }
    return null;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol)

Example 69 with ISymbol

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

the class QuarticSolver method convertTerm2Coefficients.

private static boolean convertTerm2Coefficients(final IExpr exprPoly, IExpr x, IExpr[] coefficients) {
    if (exprPoly.isFree(x, true)) {
        coefficients[0] = F.eval(F.Plus(coefficients[0], exprPoly));
        return true;
    }
    if (exprPoly instanceof IAST) {
        IAST ast = (IAST) exprPoly;
        if (ast.isTimes()) {
            int exponent = -1;
            IAST coeff = ast.clone();
            for (int i = 1; i < ast.size(); i++) {
                if (ast.get(i).isPower()) {
                    final IExpr temp = ast.get(i).getAt(1);
                    if (x.equals(temp)) {
                        try {
                            exponent = Validate.checkPowerExponent((IAST) ast.get(i));
                        } catch (WrongArgumentType e) {
                        }
                        if (exponent < 0 || exponent > 4) {
                            return false;
                        }
                        coeff.remove(i);
                        coefficients[exponent] = F.eval(F.Plus(coefficients[exponent], coeff));
                        return true;
                    }
                } else if (x.equals(ast.get(i))) {
                    coeff.remove(i);
                    coefficients[1] = F.eval(F.Plus(coefficients[1], coeff));
                    return true;
                }
            }
            return true;
        } else if (ast.isPower()) {
            final IExpr temp = ast.arg1();
            if (x.equals(temp)) {
                int exponent = -1;
                try {
                    exponent = Validate.checkPowerExponent((IAST) ast);
                } catch (WrongArgumentType e) {
                }
                if (exponent < 0 || exponent > 4) {
                    return false;
                }
                coefficients[exponent] = F.eval(F.Plus(coefficients[exponent], F.C1));
                return true;
            }
        }
    } else if (exprPoly instanceof ISymbol) {
        if (x.equals(exprPoly)) {
            coefficients[1] = F.eval(F.Plus(coefficients[1], F.C1));
            return true;
        }
    }
    return false;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 70 with ISymbol

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

the class HornerScheme method collectTerm.

private void collectTerm(ISymbol sym, IExpr expr) {
    if (expr instanceof IAST) {
        IAST term = (IAST) expr;
        if (term.isASTSizeGE(F.Times, 2)) {
            for (int i = 1; i < term.size(); i++) {
                if (sym.equals(term.get(i))) {
                    IAST temp = F.ast(term, F.Times, false, i, i + 1);
                    addToMap(F.C1, temp);
                    return;
                } else if (term.get(i).isAST(F.Power, 3)) {
                    IAST pow = (IAST) term.get(i);
                    if (pow.arg1().equals(sym) && pow.arg2() instanceof ISignedNumber) {
                        IAST temp = F.ast(term, F.Times, false, i, i + 1);
                        addToMap((ISignedNumber) pow.arg2(), temp);
                        return;
                    }
                }
            }
        } else if (term.isAST(F.Power, 3)) {
            if (term.arg1().equals(sym) && term.arg2() instanceof ISignedNumber) {
                addToMap((ISignedNumber) term.arg2(), F.C1);
                return;
            }
        }
    } else if (expr instanceof ISymbol && expr.equals(sym)) {
        addToMap(F.C1, F.C1);
        return;
    }
    addToMap(F.C0, expr);
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

ISymbol (org.matheclipse.core.interfaces.ISymbol)117 IExpr (org.matheclipse.core.interfaces.IExpr)79 IAST (org.matheclipse.core.interfaces.IAST)76 IInteger (org.matheclipse.core.interfaces.IInteger)18 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)12 INum (org.matheclipse.core.interfaces.INum)10 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)10 IFraction (org.matheclipse.core.interfaces.IFraction)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 ArrayList (java.util.ArrayList)6 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)6 HashSet (java.util.HashSet)5 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 Num (org.matheclipse.core.expression.Num)5 GenPolynomial (edu.jas.poly.GenPolynomial)4 Options (org.matheclipse.core.eval.util.Options)4 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)4 ExpVector (edu.jas.poly.ExpVector)3