Search in sources :

Example 1 with VisitorReplaceAllDFS

use of org.matheclipse.core.visit.VisitorReplaceAllDFS in project symja_android_library by axkr.

the class TrigToExp method evaluate.

/**
 * Exponential definitions for trigonometric functions
 *
 * <p>
 * See <a href=
 * "http://en.wikipedia.org/wiki/List_of_trigonometric_identities#Exponential_definitions"> List
 * of trigonometric identities - Exponential definitions</a>,<br>
 * <a href="http://en.wikipedia.org/wiki/Hyperbolic_function">Hyperbolic function</a>
 */
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    IExpr temp = StructureFunctions.threadLogicEquationOperators(ast.arg1(), ast, 1);
    if (temp.isPresent()) {
        return temp;
    }
    IExpr arg1 = ast.arg1();
    Function<IExpr, IExpr> fun = x -> {
        IExpr t = x.rewrite(ID.Exp);
        if (!t.isPresent()) {
            return x.rewrite(ID.Log);
        }
        return t.rewrite(ID.Log).orElse(t);
    };
    VisitorReplaceAllDFS dfs = new VisitorReplaceAllDFS(fun, 1);
    return arg1.accept(dfs).orElse(arg1);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) ID(org.matheclipse.core.expression.ID) VisitorReplaceAllDFS(org.matheclipse.core.visit.VisitorReplaceAllDFS) AbstractEvaluator(org.matheclipse.core.eval.interfaces.AbstractEvaluator) StructureFunctions(org.matheclipse.core.builtin.StructureFunctions) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) ISymbol(org.matheclipse.core.interfaces.ISymbol) Function(java.util.function.Function) IFunctionEvaluator(org.matheclipse.core.eval.interfaces.IFunctionEvaluator) VisitorReplaceAllDFS(org.matheclipse.core.visit.VisitorReplaceAllDFS) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

Function (java.util.function.Function)1 StructureFunctions (org.matheclipse.core.builtin.StructureFunctions)1 EvalEngine (org.matheclipse.core.eval.EvalEngine)1 AbstractEvaluator (org.matheclipse.core.eval.interfaces.AbstractEvaluator)1 IFunctionEvaluator (org.matheclipse.core.eval.interfaces.IFunctionEvaluator)1 ID (org.matheclipse.core.expression.ID)1 IAST (org.matheclipse.core.interfaces.IAST)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1 VisitorReplaceAllDFS (org.matheclipse.core.visit.VisitorReplaceAllDFS)1