Search in sources :

Example 26 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class RubiIntegrationTest method testRubi002.

public void testRubi002() {
    IAST ast;
    ast = ExpandToSum(Times(x, Plus(a, b)), x);
    check(ast, "(a+b)*x");
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 27 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class EvalEngine method evalTrace.

/**
	 * Evaluate the expression and return the <code>Trace[expr]</code> (i.e. all (sub-)expressions needed to calculate
	 * the result).
	 * 
	 * @param expr
	 *            the expression which should be evaluated.
	 * @param matcher
	 *            a filter which determines the expressions which should be traced, If the matcher is set to
	 *            <code>null</code>, all expressions are traced.
	 * @param list
	 *            an IAST object which will be cloned for containing the traced expressions. Typically a
	 *            <code>F.List()</code> will be used.
	 * @return
	 */
public final IAST evalTrace(final IExpr expr, Predicate<IExpr> matcher, IAST list) {
    IAST traceList = F.List();
    try {
        beginTrace(matcher, list);
        evaluate(expr);
    } finally {
        traceList = endTrace();
    }
    return traceList;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 28 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class EvalEngine method evalASTArg1.

/**
	 * Evaluate an AST with only one argument (i.e. <code>head[arg1]</code>). The evaluation steps are controlled by the
	 * header attributes.
	 * 
	 * @param ast
	 * @return
	 */
private IExpr evalASTArg1(final IAST ast) {
    // special case ast.isAST1()
    // head == ast[0] --- arg1 == ast[1]
    IExpr result = ast.head().evaluateHead(ast, this);
    if (result.isPresent()) {
        return result;
    }
    final ISymbol symbol = ast.topHead();
    final int attr = symbol.getAttributes();
    if ((result = flattenSequences(ast)).isPresent()) {
        return result;
    }
    if ((ISymbol.FLAT & attr) == ISymbol.FLAT) {
        final IExpr arg1 = ast.arg1();
        if (arg1.topHead().equals(symbol)) {
            // associative
            return arg1;
        }
    }
    if ((result = evalArgs(ast, attr)).isPresent()) {
        return result;
    }
    if ((ISymbol.LISTABLE & attr) == ISymbol.LISTABLE) {
        final IExpr arg1 = ast.arg1();
        if (arg1.isRealVector() && ((IAST) arg1).size() > 1) {
            if (symbol.isBuiltInSymbol()) {
                final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
                if (module instanceof DoubleUnaryOperator) {
                    DoubleUnaryOperator oper = (DoubleUnaryOperator) module;
                    return ASTRealVector.map((IAST) arg1, oper);
                }
            }
        } else if (arg1.isRealMatrix()) {
            if (symbol.isBuiltInSymbol()) {
                final IEvaluator module = ((IBuiltInSymbol) symbol).getEvaluator();
                if (module instanceof DoubleUnaryOperator) {
                    DoubleUnaryOperator oper = (DoubleUnaryOperator) module;
                    return ASTRealMatrix.map((IAST) arg1, oper);
                }
            }
        }
        if (arg1.isList()) {
            // thread over the list
            return EvalAttributes.threadList(ast, F.List, ast.head(), ((IAST) arg1).size() - 1);
        }
    }
    if ((ISymbol.NUMERICFUNCTION & attr) == ISymbol.NUMERICFUNCTION) {
        if (ast.arg1().isIndeterminate()) {
            return F.Indeterminate;
        }
    }
    if (!(ast.arg1() instanceof IPatternObject)) {
        final IExpr arg1 = ast.arg1();
        ISymbol lhsSymbol = null;
        if (arg1.isSymbol()) {
            lhsSymbol = (ISymbol) arg1;
        } else {
            lhsSymbol = arg1.topHead();
        }
        if ((result = lhsSymbol.evalUpRule(this, ast)).isPresent()) {
            return result;
        }
    }
    return F.NIL;
}
Also used : IBuiltInSymbol(org.matheclipse.core.interfaces.IBuiltInSymbol) IEvaluator(org.matheclipse.core.interfaces.IEvaluator) ISymbol(org.matheclipse.core.interfaces.ISymbol) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 29 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class Validate method checkEquationsAndInequations.

/**
	 * Check if the argument at the given <code>ast</code> position is an equation or inequation (i.e.
	 * <code>Equal(a,b)</code>) or a list of equations or inequations or a boolean <code>And()</code> expression of
	 * equations and return a list of expanded expressions, which should be equal to <code>0</code>.
	 * 
	 * @param ast
	 * @param position
	 *            the position of the equations argument in the <code>ast</code> expression.
	 * @return
	 */
public static IAST checkEquationsAndInequations(final IAST ast, int position) {
    IExpr expr = ast.get(position);
    IAST eqns = null;
    IAST termsEqualZeroList = F.List();
    if (expr.isList() || expr.isAnd()) {
        // a list of equations or inequations or a boolean AND expression of
        // equations
        eqns = (IAST) expr;
        for (int i = 1; i < eqns.size(); i++) {
            if (eqns.get(i).isAST2()) {
                IAST eq = (IAST) eqns.get(i);
                termsEqualZeroList.append(checkEquationAndInequation(eq));
            } else {
                // not an equation or inequation
                throw new WrongArgumentType(eqns, eqns.get(i), i, "Equation or inequation expression expected");
            }
        }
    } else {
        if (expr.isAST()) {
            termsEqualZeroList.append(checkEquationAndInequation((IAST) expr));
        }
    }
    return termsEqualZeroList;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 30 with IAST

use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.

the class AbstractArg1 method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    final IExpr arg1 = ast.arg1();
    final IExpr result = e1ObjArg(arg1);
    if (result.isPresent()) {
        return result;
    }
    // argument dispatching
    if (arg1 instanceof IAST) {
        return e1FunArg((IAST) arg1);
    }
    final int hier = ast.arg1().hierarchy();
    if (hier <= IExpr.INTEGERID) {
        if (hier <= IExpr.DOUBLECOMPLEXID) {
            if (hier == IExpr.DOUBLEID) {
                if (arg1 instanceof ApfloatNum) {
                    return e1ApfloatArg(((ApfloatNum) arg1).apfloatValue());
                }
                return e1DblArg(((Num) arg1).doubleValue());
            }
            if (arg1 instanceof ApcomplexNum) {
                return e1ApcomplexArg(((ApcomplexNum) arg1).apcomplexValue());
            }
            return e1ComplexArg(((ComplexNum) arg1).complexValue());
        } else {
            return e1IntArg((IInteger) arg1);
        }
    } else {
        if (hier <= IExpr.COMPLEXID) {
            if (hier == IExpr.FRACTIONID) {
                return e1FraArg((IFraction) ast.arg1());
            }
            return e1ComArg((IComplex) ast.arg1());
        } else {
            if (hier == IExpr.SYMBOLID) {
                return e1SymArg((ISymbol) ast.arg1());
            }
        }
    }
    return F.NIL;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) ApcomplexNum(org.matheclipse.core.expression.ApcomplexNum)

Aggregations

IAST (org.matheclipse.core.interfaces.IAST)413 IExpr (org.matheclipse.core.interfaces.IExpr)248 ISymbol (org.matheclipse.core.interfaces.ISymbol)76 IInteger (org.matheclipse.core.interfaces.IInteger)34 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)30 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)22 ExpVector (edu.jas.poly.ExpVector)15 ArrayList (java.util.ArrayList)14 BigRational (edu.jas.arith.BigRational)13 JASIExpr (org.matheclipse.core.convert.JASIExpr)13 VariablesSet (org.matheclipse.core.convert.VariablesSet)13 INum (org.matheclipse.core.interfaces.INum)13 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)12 GenPolynomial (edu.jas.poly.GenPolynomial)11 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)11 IFraction (org.matheclipse.core.interfaces.IFraction)11 INumber (org.matheclipse.core.interfaces.INumber)11 IComplex (org.matheclipse.core.interfaces.IComplex)10 ModLong (edu.jas.arith.ModLong)9 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)9