Package jmathexpr.util.pattern

Examples of jmathexpr.util.pattern.ExpressionPattern


         */
        private class Addition extends SubRule {

            @Override
            public boolean matches(Expression expr) {
                ExpressionPattern sum = new Sum(s, a);
               
                return new Equality(sum, b).matches(expr);
            }
View Full Code Here


         */
        private class Difference extends SubRule {

            @Override
            public boolean matches(Expression expr) {
                ExpressionPattern diff = new Subtraction(s, a);
               
                return new Equality(diff, b).matches(expr);
            }
View Full Code Here

        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 class SqrtAdd extends SubRule {

            @Override
            public boolean matches(Expression expr) {
                ExpressionPattern sum = new Sum(s, a);
               
                return new Equality(sum, b).matches(expr);
            }
View Full Code Here

         */
        private class SqrtSubtract extends SubRule {

            @Override
            public boolean matches(Expression expr) {
                ExpressionPattern diff = new Subtraction(s, a);
               
                return new Equality(diff, b).matches(expr);
            }
View Full Code Here

   
    private static Polynomial toPolynomial(Multiplication term, Variable x) {
        NavigableMap<NaturalNumber, Expression> coeffs = new TreeMap();
        TerminationPattern c = Numbers.constant("c");
        TerminationPattern n = Numbers.constant("n");
        ExpressionPattern cxn = new Multiplication(c, new Exponentiation(x, n));

        if (cxn.matches(term)) {
            coeffs.put((NaturalNumber) n.hit(), c.hit());
        } else {
            throw new IllegalArgumentException("Illegal polynomial term: " + term);
        }
       
View Full Code Here

   
    private Map<Expression, List<ANumber>> selectConstants(List<Expression> evaluated) {
        Map<Expression, List<ANumber>> selected = new HashMap(); // ai*c -> a1, a2, ... an
        NumberPattern a = new NumberPattern();
        TerminationPattern c = new Constant();
        ExpressionPattern p = new Multiplication(a, c);
       
        for (Expression e : evaluated) {
            if (e.isConstant()) {
                if (e instanceof ANumber) { // 1 -> numbers
                    addToSelectionMap(selected, Naturals.one(), (ANumber) e);
                } else if (p.matches(e)) {
                    addToSelectionMap(selected, c.hit(), a.hit());
                } else {
                    addToSelectionMap(selected, e, Naturals.one());
                }
            }
View Full Code Here

   
    private Map<Expression, List<Expression>> selectLikeTerms(List<Expression> evaluated) {
        Map<Expression, List<Expression>> selected = new HashMap(); // ai*f(x) -> a1, a2, ... an
        TerminationPattern c = new Constant();
        TerminationPattern f = new FunctionPattern(new Variable());
        ExpressionPattern p = new Multiplication(c, f);
       
        for (Expression e : evaluated) {
            if (e.isConstant()) {
                continue;
            } else if (p.matches(e)) {
                addToSelectionMap(selected, f.hit(), c.hit());
            } else {
                addToSelectionMap(selected, e, Naturals.one());
            }
        }
View Full Code Here

            return false;
        }
   
        private boolean hasMatchingTerm() {
            ExpressionPattern p;
            Expression e;
           
            for (int i = 0; i < terms.size(); i++) { // looping over the patterns...
                if (matchingPatterns.containsKey(i)) {
                    continue;
                }
               
                p = (ExpressionPattern) terms.get(i);
               
                if (p instanceof AnyPattern && i == terms.size() - 1) {
                    Sum rest = new Sum(expressions);
                   
                    return p.matches(rest);
                }
               
                for (int j = 0; j < expressions.size(); j++) { // ... to find a matching term
                    e = expressions.get(j);

                    if (p.matches(e)) {
                        matchingPatterns.put(i, e);
                        expressions.remove(j);

                        return true;
                    }
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.util.pattern.ExpressionPattern

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.