Search in sources :

Example 36 with ISymbol

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

the class JASModInteger method expr2IExprPoly.

private GenPolynomial<ModLong> expr2IExprPoly(final IExpr exprPoly) throws ArithmeticException, ClassCastException {
    if (exprPoly instanceof IAST) {
        final IAST ast = (IAST) exprPoly;
        GenPolynomial<ModLong> result = fPolyFactory.getZERO();
        GenPolynomial<ModLong> p = fPolyFactory.getZERO();
        if (ast.isPlus()) {
            IExpr expr = ast.arg1();
            result = expr2IExprPoly(expr);
            for (int i = 2; i < ast.size(); i++) {
                expr = ast.get(i);
                p = expr2IExprPoly(expr);
                result = result.sum(p);
            }
            return result;
        } else if (ast.isTimes()) {
            IExpr expr = ast.arg1();
            result = expr2IExprPoly(expr);
            for (int i = 2; i < ast.size(); i++) {
                expr = ast.get(i);
                p = expr2IExprPoly(expr);
                result = result.multiply(p);
            }
            return result;
        } else if (ast.isPower()) {
            final IExpr expr = ast.arg1();
            for (int i = 0; i < fVariables.size(); i++) {
                if (fVariables.get(i).equals(expr)) {
                    int exponent = -1;
                    try {
                        exponent = Validate.checkPowerExponent(ast);
                    } catch (WrongArgumentType e) {
                    //
                    }
                    if (exponent < 0) {
                        throw new ArithmeticException("JASConvert:expr2Poly - invalid exponent: " + ast.arg2().toString());
                    }
                    ExpVector e = ExpVector.create(fVariables.size(), i, exponent);
                    return fPolyFactory.getONE().multiply(e);
                }
            }
        }
    } else if (exprPoly instanceof ISymbol) {
        for (int i = 0; i < fVariables.size(); i++) {
            if (fVariables.get(i).equals(exprPoly)) {
                ExpVector e = ExpVector.create(fVariables.size(), i, 1L);
                return fPolyFactory.getONE().multiply(e);
            }
        }
        return new GenPolynomial(fPolyFactory, exprPoly);
    } else if (exprPoly instanceof IInteger) {
        return fPolyFactory.fromInteger((java.math.BigInteger) ((IInteger) exprPoly).asType(java.math.BigInteger.class));
    } else if (exprPoly instanceof IFraction) {
        return fraction2Poly((IFraction) exprPoly);
    }
    if (exprPoly.isFree(t -> fVariables.contains(t), true)) {
        return new GenPolynomial(fPolyFactory, exprPoly);
    } else {
        for (int i = 0; i < fVariables.size(); i++) {
            if (fVariables.get(i).equals(exprPoly)) {
                ExpVector e = ExpVector.create(fVariables.size(), i, 1L);
                return fPolyFactory.getONE().multiply(e);
            }
        }
    }
    throw new ClassCastException(exprPoly.toString());
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) GenPolynomial(edu.jas.poly.GenPolynomial) ISymbol(org.matheclipse.core.interfaces.ISymbol) ModLong(edu.jas.arith.ModLong) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IInteger(org.matheclipse.core.interfaces.IInteger) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 37 with ISymbol

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

the class D method getDerivativeArg1.

/**
	 * Search for one of the <code>Derivative[a1][head]</code> rules.
	 * 
	 * 
	 * @param x
	 * @param a1
	 * @param header
	 * @return
	 */
private IExpr getDerivativeArg1(IExpr x, final IExpr a1, final IExpr head, EvalEngine engine) {
    if (head.isSymbol()) {
        ISymbol header = (ISymbol) head;
        // IExpr der = Derivative.derivative(1, header, engine);
        // if (der.isPresent()) {
        // // we've found a derivative for a function of the form f[x_]
        // IExpr derivative = F.eval(F.unaryAST1(der, a1));
        // return F.Times(F.D(a1, x), derivative);
        // }
        IAST fDerivParam = Derivative.createDerivative(1, header, a1);
        if (x.equals(a1)) {
            // return F.NIL;
            return fDerivParam;
        }
        return F.Times(F.D(a1, x), fDerivParam);
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 38 with ISymbol

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

the class Eliminate method evaluate.

/** {@inheritDoc} */
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    try {
        IAST vars = Validate.checkSymbolOrSymbolList(ast, 2);
        IAST termsEqualZeroList = checkEquations(ast, 1);
        IAST result = termsEqualZeroList;
        IAST temp;
        IAST equalAST;
        ISymbol variable;
        VariableCounterVisitor exprAnalyzer;
        for (int i = 1; i < vars.size(); i++) {
            variable = (ISymbol) vars.get(i);
            ArrayList<VariableCounterVisitor> analyzerList = new ArrayList<VariableCounterVisitor>();
            for (int j = 1; j < result.size(); j++) {
                equalAST = result.getAST(j);
                exprAnalyzer = new VariableCounterVisitor(equalAST, variable);
                equalAST.accept(exprAnalyzer);
                analyzerList.add(exprAnalyzer);
            }
            Collections.sort(analyzerList);
            temp = eliminateOneVariable(analyzerList, variable);
            if (temp.isPresent()) {
                result = temp;
            } else {
                return result;
            }
        }
        return result;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) ArrayList(java.util.ArrayList) IAST(org.matheclipse.core.interfaces.IAST)

Example 39 with ISymbol

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

the class FindRoot method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3);
    ISymbol method = Newton;
    int maxIterations = 100;
    if (ast.size() >= 4) {
        final Options options = new Options(ast.topHead(), ast, 3, engine);
        IExpr optionMaxIterations = options.getOption("MaxIterations");
        if (optionMaxIterations.isSignedNumber()) {
            maxIterations = ((ISignedNumber) optionMaxIterations).toInt();
        }
        IExpr optionMethod = options.getOption("Method");
        if (optionMethod.isSymbol()) {
            method = ((ISymbol) optionMethod);
        } else {
            if (ast.arg3().isSymbol()) {
                method = (ISymbol) ast.arg3();
            }
        }
    }
    if ((ast.arg2().isList())) {
        IAST list = (IAST) ast.arg2();
        IExpr function = ast.arg1();
        if (list.size() >= 3 && list.arg1().isSymbol()) {
            if (function.isAST(F.Equal, 3)) {
                function = F.Plus(((IAST) function).arg1(), F.Negate(((IAST) function).arg2()));
            }
            ISignedNumber min = list.arg2().evalSignedNumber();
            ISignedNumber max = null;
            if (list.size() > 3) {
                max = list.arg3().evalSignedNumber();
            }
            if (min != null) {
                return F.List(F.Rule(list.arg1(), Num.valueOf(findRoot(method, maxIterations, list, min, max, function, engine))));
            }
        }
    }
    return F.NIL;
}
Also used : Options(org.matheclipse.core.eval.util.Options) ISymbol(org.matheclipse.core.interfaces.ISymbol) ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 40 with ISymbol

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

the class CDF method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    if (ast.arg1().isAST()) {
        IAST arg1 = (IAST) ast.arg1();
        IExpr xArg = ast.arg2();
        if (arg1.isAST()) {
            IAST dist = (IAST) arg1;
            if (dist.head().isSymbol()) {
                ISymbol head = (ISymbol) dist.head();
                if (engine.isNumericMode()) {
                    // numeric calculations
                    return evaluateNumericMode(dist, xArg, head);
                } else {
                // symbolic calculations
                }
            }
        }
    }
    return F.NIL;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

ISymbol (org.matheclipse.core.interfaces.ISymbol)117 IExpr (org.matheclipse.core.interfaces.IExpr)79 IAST (org.matheclipse.core.interfaces.IAST)76 IInteger (org.matheclipse.core.interfaces.IInteger)18 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)12 INum (org.matheclipse.core.interfaces.INum)10 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)10 IFraction (org.matheclipse.core.interfaces.IFraction)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 ArrayList (java.util.ArrayList)6 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)6 HashSet (java.util.HashSet)5 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 Num (org.matheclipse.core.expression.Num)5 GenPolynomial (edu.jas.poly.GenPolynomial)4 Options (org.matheclipse.core.eval.util.Options)4 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)4 ExpVector (edu.jas.poly.ExpVector)3