Package jmathexpr.arithmetic.pattern

Examples of jmathexpr.arithmetic.pattern.PolynomialTermPattern


        return (lhsIsLinear && (rhs.isConstant() || rhsIsLinear))
                || (rhsIsLinear && (lhs.isConstant() || lhsIsLinear));
    }
   
    public static boolean isLinear(Expression expr, Variable x) {
        ExpressionPattern pattern = new PolynomialTermPattern(x, 1);
       
        if (pattern.matches(expr)) {
            return true;
        } else if (expr instanceof Negation) {
            return isLinear(((Negation) expr).getChild(), x);
        } else if (expr instanceof Division) {
            Expression lhs = ((Division) expr).lhs();
View Full Code Here


    }
   
    private NavigableMap<NaturalNumber, Expression> extractCoefficients(
            List<Expression> terms, Variable x) {
        NavigableMap<NaturalNumber, Expression> map = new TreeMap(); // order -> coefficient
        PolynomialTermPattern pt = new PolynomialTermPattern(x);
        NaturalNumber n;
        Expression c, c0;
       
        for (Expression t : terms) {
            if (pt.matches(t)) {
                n = pt.exponent();
                c = pt.coefficient();
            } else {
                throw new IllegalArgumentException(
                        String.format("Illegal polynomial term: %s (%s)", t, t.getClass()));
            }
           
View Full Code Here

                && (lhs.isConstant() || LinearEquation.isLinear(lhs, x) || lhsIsQuadratic));
    }
   
    private static boolean isQuadratic(Expression expr, Variable x) {
        NaturalNumber two = Naturals.getInstance().create(2);
        ExpressionPattern pattern = new PolynomialTermPattern(x, 2);
       
        if (pattern.matches(expr)) {
            return true;
        } else if (expr instanceof Negation) {
            return isQuadratic(((Negation) expr).getChild(), x);
        } else if (expr instanceof Division) {
            Expression lhs = ((Division) expr).lhs();
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.pattern.PolynomialTermPattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.