use of org.matheclipse.core.interfaces.IBuiltInSymbol in project symja_android_library by axkr.
the class Derivative method evaluateDIfPossible.
private static IExpr evaluateDIfPossible(IAST head, IAST headDerivative, IAST fullDerivative, EvalEngine engine) {
IASTAppendable newFunction = F.ast(headDerivative.arg1());
IASTAppendable list = F.ListAlloc(headDerivative.size());
IASTAppendable dExpr;
for (int i = 1; i < head.size(); i++) {
IExpr n = head.get(i);
IExpr symbol = F.Slot(i);
if (fullDerivative != null) {
if (fullDerivative.size() != headDerivative.size()) {
return F.NIL;
}
symbol = fullDerivative.get(i);
if (!symbol.isVariable()) {
return F.NIL;
}
}
newFunction.append(symbol);
if (n.isOne()) {
list.append(symbol);
} else {
int ni = n.toIntDefault();
if (ni < 0) {
if (ni == Integer.MIN_VALUE) {
list.append(F.list(symbol, n));
} else {
return F.NIL;
}
} else if (ni > 0) {
int iterationLimit = engine.getIterationLimit();
if (iterationLimit > 0 && iterationLimit < ni) {
// Iteration limit of `1` exceeded.
return IOFunctions.printMessage(S.Derivative, "itlim", F.list(F.ZZ(iterationLimit)), engine);
}
list.append(F.list(symbol, n));
}
}
}
boolean doEval = false;
IExpr temp = newFunction;
if (headDerivative.arg1().isBuiltInSymbol()) {
IBuiltInSymbol builtin = (IBuiltInSymbol) headDerivative.arg1();
if (builtin.isNumericFunctionAttribute()) {
if (head.isAST1()) {
int n = head.first().toIntDefault();
if (n > 0) {
IExpr dResult = S.Derivative.evalDownRule(engine, (n == 1) ? headDerivative : headDerivative.setAtCopy(0, head.setAtCopy(1, F.C1)));
if (dResult.isPresent()) {
doEval = true;
}
}
} else {
IExpr dResult = S.Derivative.evalDownRule(engine, headDerivative);
if (dResult.isPresent()) {
doEval = true;
}
}
}
} else {
temp = engine.evaluateNIL(newFunction);
if (temp.isPresent()) {
doEval = true;
}
}
if (doEval) {
dExpr = F.ast(S.D, list.size() + 1);
dExpr.append(temp);
// w.r.t these symbols
dExpr.appendArgs(list);
return F.Function(engine.evaluate(dExpr));
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IBuiltInSymbol in project symja_android_library by axkr.
the class F method $s.
/**
* <p>
* Get or create a global predefined symbol which is retrieved from the SYSTEM context map or created or retrieved
* from the SYSTEM context variables map.
* </p>
* <p>
* <b>Note:</b> user defined variables on the context path are defined with method <code>userSymbol()</code>
* </p>
*
* @param symbolName
* the name of the symbol
* @param setEval
* if <code>true</code> determine and assign the built-in evaluator object to the symbol.
* @return
*/
private static ISymbol $s(final String symbolName, boolean setEval) {
String name = symbolName;
if (Config.PARSER_USE_LOWERCASE_SYMBOLS) {
if (symbolName.length() == 1) {
name = symbolName;
} else {
name = symbolName.toLowerCase(Locale.ENGLISH);
}
}
ISymbol symbol = Context.PREDEFINED_SYMBOLS_MAP.get(name);
if (symbol != null) {
return symbol;
}
if (Config.SERVER_MODE) {
symbol = HIDDEN_SYMBOLS_MAP.get(name);
// symbol = engine.getUserVariable(name);
if (symbol != null) {
return symbol;
}
if (Config.PARSER_USE_LOWERCASE_SYMBOLS) {
if (SYMBOL_OBSERVER.createPredefinedSymbol(name)) {
// second try, because the symbol may now be added to
// fSymbolMap
ISymbol secondTry = Context.PREDEFINED_SYMBOLS_MAP.get(name);
if (secondTry != null) {
return secondTry;
}
}
} else {
if (Character.isUpperCase(name.charAt(0))) {
if (SYMBOL_OBSERVER.createPredefinedSymbol(name)) {
// second try, because the symbol may now be added to
// fSymbolMap
ISymbol secondTry = Context.PREDEFINED_SYMBOLS_MAP.get(name);
if (secondTry != null) {
return secondTry;
}
}
}
}
symbol = new BuiltInSymbol(name);
// engine.putUserVariable(name, symbol);
HIDDEN_SYMBOLS_MAP.put(name, symbol);
if (name.charAt(0) == '$') {
SYMBOL_OBSERVER.createUserSymbol(symbol);
}
} else {
symbol = HIDDEN_SYMBOLS_MAP.get(name);
if (symbol != null) {
return symbol;
}
symbol = new BuiltInSymbol(name);
HIDDEN_SYMBOLS_MAP.put(name, symbol);
if (symbol.isBuiltInSymbol()) {
if (!setEval) {
((IBuiltInSymbol) symbol).setEvaluator(BuiltInSymbol.DUMMY_EVALUATOR);
} else {
((IBuiltInSymbol) symbol).getEvaluator();
}
}
}
return symbol;
}
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;
}
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;
}
use of org.matheclipse.core.interfaces.IBuiltInSymbol in project symja_android_library by axkr.
the class F method localBiFunction.
public static IBuiltInSymbol localBiFunction(final String symbolName, BiFunction<IExpr, IExpr, IExpr> function) {
IBuiltInSymbol localBuittIn = new BuiltInSymbol(symbolName, java.lang.Integer.MAX_VALUE);
localBuittIn.setEvaluator(new AbstractCoreFunctionEvaluator() {
@Override
public IExpr evaluate(IAST ast, EvalEngine engine) {
return function.apply(ast.arg1(), ast.arg2());
}
});
return localBuittIn;
}
Aggregations