Search in sources :

Example 6 with IAssumptions

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);
}
Also used : IAssumptions(org.matheclipse.core.eval.util.IAssumptions) OptionArgs(org.matheclipse.core.eval.util.OptionArgs) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 7 with IAssumptions

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);
    }
}
Also used : IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAssumptions(org.matheclipse.core.eval.util.IAssumptions) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) VariablesSet(org.matheclipse.core.convert.VariablesSet)

Aggregations

IAssumptions (org.matheclipse.core.eval.util.IAssumptions)7 IExpr (org.matheclipse.core.interfaces.IExpr)6 IAST (org.matheclipse.core.interfaces.IAST)3 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)3 OptionArgs (org.matheclipse.core.eval.util.OptionArgs)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 Level (org.apache.logging.log4j.Level)1 ApfloatContext (org.apfloat.ApfloatContext)1 VariablesSet (org.matheclipse.core.convert.VariablesSet)1 LimitException (org.matheclipse.core.eval.exception.LimitException)1 ValidateException (org.matheclipse.core.eval.exception.ValidateException)1 ASTSeriesData (org.matheclipse.core.expression.ASTSeriesData)1 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)1