Package jmathexpr.arithmetic.op

Examples of jmathexpr.arithmetic.op.Multiplication


    public Polynomial multiply(Expression multiplier) {
        if (multiplier.isConstant()) {
            NavigableMap<NaturalNumber, Expression> multiplied = new TreeMap();
           
            for (NaturalNumber n : coeffs.keySet()) {
                multiplied.put(n, new Multiplication(coeffs.get(n), multiplier).evaluate());
            }

            return new Polynomial(multiplied, x);
        } else
            throw new UnsupportedOperationException("Missing implementation: " + multiplier);
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 Expression sqrt(Multiplication product) {
        Expression l = new Sqrt(product.lhs()).evaluate();
        Expression r = new Sqrt(product.rhs()).evaluate();

        if (!(l instanceof Sqrt && r instanceof Sqrt)) {
            return new Multiplication(l, r).evaluate();
        } else {
            return new Sqrt(product);
        }
    }
View Full Code Here

        @Override
        public Expression apply() {
            Expression sqrt = new Sqrt(arg.hit());
           
            return new Division(new Multiplication(fraction.numerator(), sqrt),
                       new Multiplication(fraction.denominator(), sqrt));
        }
View Full Code Here

            return new Sqrt(arg).matches(a);
        }

        @Override
        public Expression apply() {
            return new Equality(new Multiplication(p, new Sqrt(arg.hit())), Naturals.zero());
        }
View Full Code Here

     */
    private class LeftAddition extends SubRule {

        @Override
        public boolean matches(Expression expr) {
            boolean matches = new Multiplication(a, new Addition(b, c)).matches(expr);
           
            return matches && !(a.hit() instanceof ANumber && ((ANumber) a.hit()).isOne());
        }
View Full Code Here

            return matches && !(a.hit() instanceof ANumber && ((ANumber) a.hit()).isOne());
        }

        @Override
        public Expression apply() {
            return new Addition(new Multiplication(a.hit(), b.hit()),
                    new Multiplication(a.hit(), c.hit()));
        }
View Full Code Here

     */
    private class LeftSubtraction extends SubRule {

        @Override
        public boolean matches(Expression expr) {
            boolean matches = new Multiplication(a, new Subtraction(b, c)).matches(expr);
           
            return matches && !(a.hit() instanceof ANumber && ((ANumber) a.hit()).isOne());
        }
View Full Code Here

            return matches && !(a.hit() instanceof ANumber && ((ANumber) a.hit()).isOne());
        }

        @Override
        public Expression apply() {
            return new Subtraction(new Multiplication(a.hit(), b.hit()),
                    new Multiplication(a.hit(), c.hit()));
        }
View Full Code Here

     */
    private class RightAddition extends SubRule {

        @Override
        public boolean matches(Expression expr) {
            boolean matches = new Multiplication(new Addition(a, b), c).matches(expr);
           
            return matches && !(c.hit() instanceof ANumber && ((ANumber) c.hit()).isOne());
        }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.op.Multiplication

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.