Search in sources :

Example 26 with WrongArgumentType

use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.

the class Roots method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    IExpr arg1 = ast.arg1();
    if (arg1.isAST(F.Equal, 3)) {
        IAST eq = (IAST) arg1;
        if (eq.arg2().isZero()) {
            arg1 = eq.arg1();
        } else {
            arg1 = engine.evaluate(F.Subtract(eq.arg1(), eq.arg2()));
        }
    } else {
        throw new WrongArgumentType(ast, ast.arg1(), 1, "Equal() expression expected!");
    }
    VariablesSet eVar = null;
    if (ast.arg2().isList()) {
        eVar = new VariablesSet(ast.arg2());
    } else {
        eVar = new VariablesSet();
        eVar.add(ast.arg2());
    }
    if (!eVar.isSize(1)) {
        // factorization only possible for univariate polynomials
        throw new WrongArgumentType(ast, ast.arg2(), 2, "Only one variable expected");
    }
    IAST variables = eVar.getVarList();
    IExpr variable = variables.arg1();
    IAST list = roots(arg1, false, variables, engine);
    if (list.isPresent()) {
        IAST or = F.Or();
        for (int i = 1; i < list.size(); i++) {
            or.append(F.Equal(variable, list.get(i)));
        }
        return or;
    }
    return F.NIL;
}
Also used : WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) VariablesSet(org.matheclipse.core.convert.VariablesSet)

Example 27 with WrongArgumentType

use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.

the class ReplaceAll method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    if (ast.isAST1()) {
        return F.operatorFormAST1(ast);
    }
    Validate.checkSize(ast, 3);
    try {
        if (ast.arg2().isListOfLists()) {
            IAST result = F.List();
            for (IExpr subList : (IAST) ast.arg2()) {
                result.append(F.subst(ast.arg1(), (IAST) subList));
            }
            return result;
        }
        if (ast.arg2().isAST()) {
            return F.subst(ast.arg1(), (IAST) ast.arg2());
        } else {
            WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
            engine.printMessage(wat.getMessage());
        }
    } catch (WrongArgumentType wat) {
        engine.printMessage(wat.getMessage());
    }
    return F.NIL;
}
Also used : WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 28 with WrongArgumentType

use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.

the class ReplaceList method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    if (!ToggleFeature.REPLACE_LIST) {
        return F.NIL;
    }
    Validate.checkRange(ast, 3, 4);
    IAST result = F.List();
    try {
        int maxNumberOfResults = Integer.MAX_VALUE;
        IExpr arg1 = ast.arg1();
        IExpr rules = F.eval(ast.arg2());
        if (ast.isAST3()) {
            IExpr arg3 = F.eval(ast.arg3());
            if (arg3.isSignedNumber()) {
                maxNumberOfResults = ((ISignedNumber) arg3).toInt();
            }
        }
        return replaceExpr(ast, arg1, rules, result, maxNumberOfResults, engine);
    } catch (ArithmeticException ae) {
        engine.printMessage(ae.getMessage());
    } catch (WrongArgumentType wat) {
        engine.printMessage(wat.getMessage());
    }
    return result;
}
Also used : WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 29 with WrongArgumentType

use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.

the class ReplaceRepeated method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    try {
        Validate.checkSize(ast, 3);
        if (ast.arg2().isListOfLists()) {
            IAST result = F.List();
            for (IExpr subList : (IAST) ast.arg2()) {
                result.append(ast.arg1().replaceRepeated((IAST) subList));
            }
            return result;
        }
        if (ast.arg2().isAST()) {
            return ast.arg1().replaceRepeated((IAST) ast.arg2());
        } else {
            WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
            engine.printMessage(wat.getMessage());
        }
    } catch (WrongArgumentType wat) {
        engine.printMessage(wat.getMessage());
    }
    return F.NIL;
}
Also used : WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 30 with WrongArgumentType

use of org.matheclipse.core.eval.exception.WrongArgumentType in project symja_android_library by axkr.

the class Replace method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    if (ast.isAST1()) {
        return F.operatorFormAST1(ast);
    }
    Validate.checkRange(ast, 3, 4);
    try {
        IExpr arg1 = ast.arg1();
        IExpr rules = F.eval(ast.arg2());
        if (ast.isAST3()) {
            // arg3 should contain a "level specification":
            return replaceExprWithLevelSpecification(ast, arg1, rules, ast.arg3(), engine);
        }
        return replaceExpr(ast, arg1, rules, engine);
    } catch (WrongArgumentType wat) {
        engine.printMessage(wat.getMessage());
    }
    return F.NIL;
}
Also used : WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)37 IAST (org.matheclipse.core.interfaces.IAST)30 IExpr (org.matheclipse.core.interfaces.IExpr)29 ISymbol (org.matheclipse.core.interfaces.ISymbol)12 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)7 IInteger (org.matheclipse.core.interfaces.IInteger)6 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)5 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)4 ExpVector (edu.jas.poly.ExpVector)3 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)3 IFraction (org.matheclipse.core.interfaces.IFraction)3 ModLong (edu.jas.arith.ModLong)2 GenPolynomial (edu.jas.poly.GenPolynomial)2 ArrayList (java.util.ArrayList)2 Apint (org.apfloat.Apint)2 PrettyPrint (edu.jas.kern.PrettyPrint)1 Function (java.util.function.Function)1 IntVariable (jp.ac.kobe_u.cs.cream.IntVariable)1 Apfloat (org.apfloat.Apfloat)1 MathIllegalStateException (org.hipparchus.exception.MathIllegalStateException)1