Package jmathexpr

Examples of jmathexpr.Expression


        }
       
        NavigableMap<NaturalNumber, Expression> q = new TreeMap(); // quotient
        NavigableMap<NaturalNumber, Expression> r = new TreeMap(); // reminder
        NaturalNumber bdeg = b.degree();
        Expression bc = b.leadCoefficient();
        Expression c; // next coefficient
        NaturalNumber n; // degree of the next term in q
        Expression rp, bi; // temporary variables
        NaturalNumber p; //temporary position
       
        q.put(ZERO, ZERO);
        r.putAll(this.coeffs);
       
View Full Code Here


     * @param subtrahend the subtrahend polynomial
     * @return P(X) - Q(X)
     */
    public Polynomial subtract(Polynomial subtrahend) {
        NavigableMap<NaturalNumber, Expression> map = new TreeMap();
        Expression minuend, c;
       
        map.putAll(coeffs);
       
        for (NaturalNumber n : subtrahend.coeffs.keySet()) {
            minuend = coeffs.get(n);
View Full Code Here

        }
    }
   
    private Polynomial divideByConstant(Expression expr) {
        NavigableMap<NaturalNumber, Expression> map = new TreeMap();
        Expression c;
       
        for (NaturalNumber n : coeffs.keySet()) {
            c = coeffs.get(n);
           
            map.put(n, new Division(c, expr).evaluate());
View Full Code Here

     *
     * @return the negated polynomial
     */
    public Polynomial negate() {
        NavigableMap<NaturalNumber, Expression> map = new TreeMap();
        Expression c;
       
        for (NaturalNumber n : coeffs.keySet()) {
            c = coeffs.get(n);
           
            if (c instanceof ANumber) {
View Full Code Here

     * @param addition an addition pattern
     * @return true if this polynomial matches the addition
     */
    public boolean matches(Addition addition) {
        if (coeffs.size() == 2) {
            Expression lhs = getTerm(coeffs.lastKey());
            Expression rhs = getTerm(coeffs.firstKey());
           
            return ((ExpressionPattern) addition.lhs()).matches(lhs)
                    && ((ExpressionPattern) addition.rhs()).matches(rhs);
        } else {
            return false;
View Full Code Here

     * @param multiplication the product pattern
     * @return true if this polynomial matches the pattern
     */
    public boolean matches(Multiplication multiplication) {
        if (coeffs.size() == 1) {
            Expression term = getTerm(coeffs.lastKey());
           
            return multiplication.matches(term);
        } else {
            return false;
        }
View Full Code Here

     * @return true if this polynomial has exactly one term x (= 1*x^1) and it
     * equals to the given variable
     */
    public boolean matches(Variable var) {
        if (coeffs.size() == 1) {
            Expression c = leadCoefficient();
           
            return c instanceof ANumber && ((ANumber) c).isOne() && var.matches(x);
        } else {
            return false;
        }
View Full Code Here

    }
   
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        Expression c;
       
        for (NaturalNumber n : coeffs.descendingKeySet()) {
            c = coeffs.get(n);
           
            if (result.length() == 0) {
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();
View Full Code Here

        return operands();
    }
   
    @Override
    public Expression evaluate() {
        Expression simplified = simplify();
       
        if (!(simplified instanceof Sum)) return simplified;
       
        List<Expression> evaluated = ((Sum) simplified).terms;
        Map<Expression, List<ANumber>> constants = selectConstants(evaluated);
        Expression constant = combineConstants(constants);
       
        if (constants.size() == terms.size()) {
            return constant;
        }
View Full Code Here

TOP

Related Classes of jmathexpr.Expression

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.