use of org.matheclipse.core.eval.util.IAssumptions in project symja_android_library by axkr.
the class FunctionExpand method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr result = F.REMEMBER_AST_CACHE.getIfPresent(ast);
if (result != null) {
return result;
}
IExpr arg1 = ast.arg1();
IExpr assumptionExpr = F.NIL;
if (ast.size() > 2) {
IExpr arg2 = ast.arg2();
if (!arg2.isRule()) {
assumptionExpr = arg2;
}
final OptionArgs options = new OptionArgs(ast.topHead(), ast, 2, engine);
assumptionExpr = options.getOption(S.Assumptions).orElse(assumptionExpr);
}
if (assumptionExpr.isPresent()) {
if (assumptionExpr.isAST()) {
IAssumptions oldAssumptions = engine.getAssumptions();
IAssumptions assumptions;
if (oldAssumptions == null) {
assumptions = org.matheclipse.core.eval.util.Assumptions.getInstance(assumptionExpr);
} else {
assumptions = oldAssumptions.copy();
assumptions = assumptions.addAssumption(assumptionExpr);
}
if (assumptions != null) {
try {
engine.setAssumptions(assumptions);
return callMatcher(ast, arg1);
} finally {
engine.setAssumptions(oldAssumptions);
}
}
}
}
// don't call PowerExpand
return callMatcher(ast, arg1);
}
use of org.matheclipse.core.eval.util.IAssumptions in project symja_android_library by axkr.
the class ComplexExpand method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr temp = StructureFunctions.threadLogicEquationOperators(ast.arg1(), ast, 1);
if (temp.isPresent()) {
return temp;
}
IAssumptions oldAssumptions = engine.getAssumptions();
try {
IExpr arg1 = ast.arg1();
IAST arg2 = F.NIL;
if (ast.isAST2()) {
arg2 = ast.arg2().isList() ? (IAST) ast.arg2() : F.list(ast.arg2());
}
VariablesSet eVar = new VariablesSet(arg1);
List<IExpr> varList = eVar.getVarList().copyTo();
IASTAppendable assumptionExpr = F.ListAlloc(varList.size() + 1);
for (int i = 0; i < varList.size(); i++) {
final IExpr variable = varList.get(i);
if (arg2.isPresent()) {
boolean hasMatched = false;
for (int j = 1; j < arg2.size(); j++) {
if (S.MatchQ.ofQ(variable, arg2.get(j))) {
hasMatched = true;
break;
}
}
if (hasMatched) {
continue;
}
}
assumptionExpr.append(F.Element(variable, S.Reals));
}
IAssumptions assumptions;
if (oldAssumptions == null) {
assumptions = org.matheclipse.core.eval.util.Assumptions.getInstance(assumptionExpr);
} else {
assumptions = oldAssumptions.copy();
assumptions = assumptions.addAssumption(assumptionExpr);
}
engine.setAssumptions(assumptions);
ComplexExpandVisitor tteVisitor = new ComplexExpandVisitor(engine);
IExpr result = arg1.accept(tteVisitor);
if (result.isPresent()) {
return result;
}
return arg1;
} finally {
engine.setAssumptions(oldAssumptions);
}
}
Aggregations