Package jmathexpr.arithmetic.integer

Examples of jmathexpr.arithmetic.integer.IntegerNumber


        assertEquals(a.evaluate(), N.create(6));
    }
   
    @Test(dependsOnMethods = { "testNaturalExpressions" })
    public void testIntegerExpressions() {
        IntegerNumber ten = Z.create(10);
        IntegerNumber eleven = Z.create(11)
        Expression integerExpr = new Subtraction(ten, eleven);
       
        System.out.printf("%s = %s%n", integerExpr, integerExpr.evaluate());       
        assertEquals(integerExpr.evaluate(), Z.create(-1));
    }
View Full Code Here


     * Factorize this sum (if possible).
     *
     * @return either the factorized form of this sum or this
     */
    public Expression factorize() {
        IntegerNumber l = null, r = null;
        Expression lrest = null, rrest = null;
       
        if (lhs instanceof IntegerNumber) {
            l = (IntegerNumber) lhs;
            lrest = Naturals.one();
        } else if (lhs instanceof Multiplication
                && ((Multiplication) lhs).lhs() instanceof IntegerNumber) {
            l = (IntegerNumber) ((Multiplication) lhs).lhs();
            lrest = ((Multiplication) lhs).rhs();
        } else if (lhs instanceof Division
                && ((Division) lhs).lhs() instanceof IntegerNumber) {
            l = (IntegerNumber) ((Division) lhs).lhs();
            lrest = new Division(Naturals.one(), ((Division) lhs).rhs());
        }

        if (rhs instanceof IntegerNumber) {
            r = (IntegerNumber) rhs;
            rrest = Naturals.one();
        } else if (rhs instanceof Multiplication
                && ((Multiplication) rhs).lhs() instanceof IntegerNumber) {
            r = (IntegerNumber) ((Multiplication) rhs).lhs();
            rrest = ((Multiplication) rhs).rhs();
        } else if (rhs instanceof Division
                && ((Division) rhs).lhs() instanceof IntegerNumber) {
            r = (IntegerNumber) ((Division) rhs).lhs();
            rrest = new Division(Naturals.one(), ((Division) rhs).rhs());
        }
       
        if (l != null && r != null) {
            IntegerNumber lcm = (IntegerNumber) new Lcm(l, r).evaluate();
            IntegerNumber gcd = (IntegerNumber) l.multiply(r).divide(lcm);
           
            if (!gcd.isOne()) {
                return new Multiplication(gcd, new Addition(
                        new Multiplication(l.divide(gcd), lrest),
                        new Multiplication(r.divide(gcd), rrest)).evaluate());
            }
        }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.integer.IntegerNumber

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.