use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Definition method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 2);
ISymbol symbol = Validate.checkSymbolType(ast, 1);
PrintStream stream;
stream = engine.getOutPrintStream();
if (stream == null) {
stream = System.out;
}
try {
stream.println(symbol.definitionToString());
} catch (IOException e) {
stream.println(e.getMessage());
if (Config.DEBUG) {
e.printStackTrace();
}
}
return F.Null;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Exponent method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 3, 4);
final IExpr form = engine.evalPattern(ast.arg2());
if (form.isList()) {
return ((IAST) form).mapThread(ast, 2);
}
ISymbol sym = F.Max;
if (ast.isAST3()) {
final IExpr arg3 = engine.evaluate(ast.arg3());
if (arg3.isSymbol()) {
sym = (ISymbol) arg3;
}
}
Set<IExpr> collector = new TreeSet<IExpr>();
IExpr expr = F.evalExpandAll(ast.arg1());
if (expr.isZero()) {
collector.add(F.CNInfinity);
} else if (expr.isAST()) {
IAST arg1 = (IAST) expr;
final IPatternMatcher matcher = new PatternMatcher(form);
if (arg1.isPower()) {
if (matcher.test(arg1.arg1())) {
collector.add(arg1.arg2());
} else {
collector.add(F.C0);
}
} else if (arg1.isPlus()) {
for (int i = 1; i < arg1.size(); i++) {
if (arg1.get(i).isAtom()) {
if (arg1.get(i).isSymbol()) {
if (matcher.test(arg1.get(i))) {
collector.add(F.C1);
} else {
collector.add(F.C0);
}
} else {
collector.add(F.C0);
}
} else if (arg1.get(i).isPower()) {
IAST pow = (IAST) arg1.get(i);
if (matcher.test(pow.arg1())) {
collector.add(pow.arg2());
} else {
collector.add(F.C0);
}
} else if (arg1.get(i).isTimes()) {
timesExponent((IAST) arg1.get(i), matcher, collector);
} else {
collector.add(F.C0);
}
}
} else if (arg1.isTimes()) {
timesExponent(arg1, matcher, collector);
}
} else if (expr.isSymbol()) {
final PatternMatcher matcher = new PatternMatcher(form);
if (matcher.test(expr)) {
collector.add(F.C1);
} else {
collector.add(F.C0);
}
} else {
collector.add(F.C0);
}
IAST result = F.ast(sym);
if (collector.size() == 0) {
collector.add(F.C0);
}
for (IExpr exponent : collector) {
result.append(exponent);
}
return result;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Structure method threadPlusLogicEquationOperators.
/**
* Maps the elements of the <code>expr</code> with the cloned <code>replacement</code>. <code>replacement</code> is
* an IAST where the argument at the given position will be replaced by the currently mapped element.
*
*
* @param expr
* @param replacement
* an IAST there the argument at the given position is replaced by the currently mapped argument of this
* IAST.
* @param position
* @return
*/
public static IAST threadPlusLogicEquationOperators(IExpr expr, IAST replacement, int position) {
if (expr.isAST()) {
IAST ast = (IAST) expr;
if (ast.size() > 1) {
IAST cloned = replacement.clone();
cloned.set(position, null);
ISymbol[] plusLogicEquationHeads = { F.Plus, F.And, F.Or, F.Xor, F.Nand, F.Nor, F.Not, F.Implies, F.Equivalent, F.Equal, F.Unequal, F.Less, F.Greater, F.LessEqual, F.GreaterEqual };
for (int i = 0; i < plusLogicEquationHeads.length; i++) {
if (ast.isAST(plusLogicEquationHeads[i])) {
return ((IAST) ast).mapThread(cloned, position);
}
}
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Structure method threadLogicEquationOperators.
/**
* Maps the elements of the <code>expr</code> with the cloned <code>replacement</code>. <code>replacement</code> is
* an IAST where the argument at the given position will be replaced by the currently mapped element.
*
*
* @param expr
* @param replacement
* an IAST there the argument at the given position is replaced by the currently mapped argument of this
* IAST.
* @param position
* @return
*/
public static IAST threadLogicEquationOperators(IExpr expr, IAST replacement, int position) {
if (expr.isAST()) {
IAST ast = (IAST) expr;
if (ast.size() > 1) {
IAST cloned = replacement.clone();
cloned.set(position, null);
ISymbol[] logicEquationHeads = { F.And, F.Or, F.Xor, F.Nand, F.Nor, F.Not, F.Implies, F.Equivalent, F.Equal, F.Unequal, F.Less, F.Greater, F.LessEqual, F.GreaterEqual };
for (int i = 0; i < logicEquationHeads.length; i++) {
if (ast.isAST(logicEquationHeads[i])) {
return ((IAST) ast).mapThread(cloned, position);
}
}
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class PatternMatching method setDownRule.
public static Object[] setDownRule(IExpr leftHandSide, IExpr rightHandSide, boolean packageMode) {
final Object[] result = new Object[] { null, rightHandSide };
if (leftHandSide.isAST()) {
final ISymbol lhsSymbol = ((IAST) leftHandSide).topHead();
result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, false, leftHandSide, rightHandSide, packageMode);
return result;
}
if (leftHandSide.isSymbol()) {
final ISymbol lhsSymbol = (ISymbol) leftHandSide;
if (lhsSymbol.hasLocalVariableStack()) {
lhsSymbol.set(rightHandSide);
return result;
}
result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, true, leftHandSide, rightHandSide, packageMode);
return result;
}
throw new RuleCreationError(leftHandSide);
}
Aggregations