Search in sources :

Example 1 with Symbol

use of org.matheclipse.core.expression.Symbol in project symja_android_library by axkr.

the class Integrate method integrateTimesTrigFunctions.

/**
	 * Try using the <code>TrigReduce</code> function to get a
	 * <code>Plus(...)</code> expression which could be integrated.
	 * 
	 * @param timesAST
	 *            an IAST which is a <code>Times(...)</code> expression
	 * @param arg2
	 *            the symbol to get the indefinite integral for.
	 * @return <code>F.NIL</code> if no trigonometric funtion could be found.
	 */
private IExpr integrateTimesTrigFunctions(final IAST timesAST, ISymbol arg2) {
    Predicate<IExpr> isTrigFunction = Predicates.isAST(new ISymbol[] { F.Cos, F.Sin });
    if (timesAST.isMember(isTrigFunction, false)) {
        // use a symbol which is not in the symbols map
        ISymbol pSymbol = new Symbol("$x$");
        IExpr fx = F.eval(F.TrigReduce(timesAST));
        if (fx.isPlus()) {
            // Collect arguments for x
            // Sin(f_) -> Sin(Collect(f, arg2))
            fx = F.eval(F.ReplaceAll(fx, F.List(F.Rule(F.Sin(F.$p(pSymbol)), F.Sin(F.Collect(pSymbol, arg2))), F.Rule(F.Cos(F.$p(pSymbol)), F.Cos(F.Collect(pSymbol, arg2))))));
            // Integrate[a_+b_+...,x_] -> Integrate[a,x]+Integrate[b,x]+...
            return ((IAST) fx).mapThread(F.Integrate(null, arg2), 1);
        }
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) Symbol(org.matheclipse.core.expression.Symbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 2 with Symbol

use of org.matheclipse.core.expression.Symbol in project symja_android_library by axkr.

the class MagicProcessor method preProcessQues.

String preProcessQues() {
    // Convert expression like "2*x+7=10" to Solve(2*x+7 - 10 == 0, x)
    if (outPut.contains("=")) {
        String processEq = inputQuestionIsPossiblyASystemOfEquation(outPut);
        if (processEq != null) {
            // Args will be handled in wrtArgumentMising
            outPut = ((ISymbol) F.Solve).toString() + "(" + processEq + ")";
        }
    /*
			 * String [] list = outPut.split("="); if(list.length == 2) { String
			 * eq = list[1] + "- (" + list[0] + ")"; IExpr eqn =
			 * MathUtils.parse(eq, null); if(eqn.isAST() && isPolynomial((IAST)
			 * eqn)) { String vars = solve_get_arg_if_missing(eqn); isSysOfEq =
			 * true; outPut = ((Symbol) F.Solve).toString() + "(" + eq + " == 0"
			 * + "," + vars + ")"; } }
			 */
    }
    IExpr ques = MathUtils.parse(outPut, null);
    if (ques == null)
        return outPut;
    Log.debug("ques = " + ques.toString());
    if (wrtArgumentMising(ques, F.Solve)) {
        IExpr equations = getArg1(ques);
        String vars = solve_get_arg_if_missing(equations);
        if (vars != null && err == null) {
            outPut = ((Symbol) F.Solve).toString() + "(" + equations.toString() + "," + vars + ")";
            Log.debug(" Result after eq processing " + outPut);
        }
    }
    if (wrtArgumentMising(ques, F.D)) {
        IExpr fn = getArg1(ques);
        // Extract variables from equations
        org.matheclipse.core.convert.VariablesSet eVar = new org.matheclipse.core.convert.VariablesSet(fn);
        String var = null;
        if (eVar.isSize(1))
            var = getVarString(eVar, false);
        else
            var = getVarString(eVar, true);
        outPut = ((Symbol) F.D).toString() + "(" + fn.toString() + "," + var + ")";
    }
    if (wrtArgumentMising(ques, F.Integrate)) {
        IExpr fn = getArg1(ques);
        // Extract variables from equations
        org.matheclipse.core.convert.VariablesSet eVar = new org.matheclipse.core.convert.VariablesSet(fn);
        String var = null;
        if (eVar.isSize(1))
            var = getVarString(eVar, false);
        else
            var = getVarString(eVar, true);
        outPut = ((Symbol) F.Integrate).toString() + "(" + fn.toString() + "," + var + ")";
    }
    Log.debug("Processed q = " + outPut);
    return (err == null) ? outPut : err;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) Symbol(org.matheclipse.core.expression.Symbol) ISymbol(org.matheclipse.core.interfaces.ISymbol) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

Symbol (org.matheclipse.core.expression.Symbol)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 IAST (org.matheclipse.core.interfaces.IAST)1