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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations