Package jmathexpr.arithmetic

Examples of jmathexpr.arithmetic.ANumber.negate()


            ANumber ca = (ANumber) ax.coefficient();
            ANumber cc = (ANumber) cx.coefficient();
            ANumber coef = ca.lt(cc) ? ca : cc;

            if (coef.isNegative()) {
                coef = coef.negate();
               
                Expression cx = coef.isOne() ? x.evaluate() : new Multiplication(coef, x.evaluate());
               
                return new Equality(Sum.add(((Equality) target).lhs(), cx),
                    Sum.add(((Equality) target).rhs(), cx));
View Full Code Here


       
        if (x instanceof ANumber) {
            ANumber a = (ANumber) x;
           
            if (a.isNegative()) {
                return a.negate();
            } else {
                return a;
            }
        } else if (x instanceof Negation) { // |-x| = x
            return ((Negation) x).getChild();
View Full Code Here

            if (sum.isOne()) {
                combined.add(c);
            } else if (!sum.isZero()) {
                if (c instanceof ANumber) { // c = 1
                    combined.add(sum);
                } else if (sum.negate().isOne()) {
                    combined.add(new Negation(c));
                } else {
                    combined.add(new Multiplication(sum, c));
                }
            }
View Full Code Here

        Expression two = Naturals.getInstance().create(2);
       
        if (l instanceof ANumber) {
            ANumber a = (ANumber) l;
           
            if (a.negate().isOne()) {
                return new Negation(r).evaluate();
            } else if (r instanceof Division) {
                Division d = (Division) r;
               
                if (d.rhs() instanceof ANumber) { // a x/b = a/b x
View Full Code Here

                } else if (m.rhs instanceof ANumber) { // a (xb) = (ab) x
                    l = a.multiply((ANumber) m.rhs);
                    r = m.lhs;
                }
            } else if (r instanceof Negation) { // a (-x) = -ax
                l = a.negate();
                r = ((Negation) r).getChild();
               
                return new Multiplication(l, r).evaluate();
            } else if (a.isNegative()) { // -a x = -(ax)
                return new Negation(new Multiplication(a.negate(), r)).evaluate();
View Full Code Here

                l = a.negate();
                r = ((Negation) r).getChild();
               
                return new Multiplication(l, r).evaluate();
            } else if (a.isNegative()) { // -a x = -(ax)
                return new Negation(new Multiplication(a.negate(), r)).evaluate();
            }
        } else if (l instanceof Negation) { // (-a)b = -(ab)
            return new Negation(new Multiplication(((Negation) l).getChild(), r)).evaluate();
        } else if (l instanceof Multiplication) { // (ab) c
            Multiplication m = (Multiplication) l;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.