Package jmathexpr.arithmetic.op

Examples of jmathexpr.arithmetic.op.Addition


    @Test(dependsOnMethods = { "testVariables" })
    public void testRationalExpressions() {
        Expression evaluated;
        RationalNumber oneHalf = new LongRationalNumber(1, 2);
        RationalNumber oneThird = new LongRationalNumber(1, 3);
        Expression sum = new Addition(oneHalf, oneThird);
       
        evaluated = sum.evaluate();
        System.out.printf("%s = %s%n", sum, evaluated);
        assertEquals(evaluated, new LongRationalNumber(5, 6));
       
        Expression difference = new Subtraction(oneHalf, oneThird);
        evaluated = difference.evaluate();
View Full Code Here


    @Test
    public void testNaturalExpressions() {
        Expression evaluated;
        NaturalNumber five = N.create(5);
        NaturalNumber two = N.create(2);
        Addition seven = new Addition(five, two);
        NaturalNumber six = N.create("6");
        Expression naturalExpr = new Multiplication(six, seven);
       
        evaluated = naturalExpr.evaluate();
        System.out.printf("%s = %s%n", naturalExpr, evaluated);       
View Full Code Here

         */
        private class AdditionC extends SubRule {

            @Override
            public boolean matches(Expression expr) {
                return new Equality(new Addition(ax, b), c).matches(expr);
            }
View Full Code Here

            }
           
            c0 = map.get(n);
           
            if (c0 != null) {
                c = new Addition(c0, c).evaluate();
            }
           
            map.put(n, c);
        }
       
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 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

            return matches && !(c.hit() instanceof ANumber && ((ANumber) c.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 AdditionAddition extends SubRule {

        @Override
        public boolean matches(Expression expr) {
            Addition apb = new Addition(a, b);
            Addition bpc = new Addition(b, c);
           
            return new Addition(apb, c).matches(expr) ||
                   new Addition(a, bpc).matches(expr);
        }
View Full Code Here

                   new Addition(a, bpc).matches(expr);
        }

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

TOP

Related Classes of jmathexpr.arithmetic.op.Addition

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.