Package jmathexpr.arithmetic

Examples of jmathexpr.arithmetic.Polynomial


    public void testPolynomials() {
        Variable x = Numbers.variable("x");
//        Logger.dump(new ExpressionParser().parse("2x^2 - 5x"));
//        System.exit(1);
//        Polynomial a = Polynomial.create(new ExpressionParser().parse("x^3 - 2x^2 - 4"), x);
        Polynomial a = Polynomial.create(new ExpressionParser().parse("x^3 - 2*x^2 - 4"), x);
        Polynomial b = Polynomial.create(new ExpressionParser().parse("x - 3"), x);
        OrderedPair quotient = a.euclideanDivision(b);
       
        System.out.printf("(%s) : (%s) = %s%n", a, b, quotient);
       
        Polynomial q = Polynomial.create(new ExpressionParser().parse("x^2 + x + 3"), x);
        Polynomial r = Polynomial.create(N.create(5), x);
       
        assertEquals(quotient, new OrderedPair(q, r));
    }
View Full Code Here


        List<Expression> terms = new ArrayList();
       
        terms.add(lhs);
        terms.add(new Negation(rhs));
       
        return new Polynomial(terms, x);
    }
View Full Code Here

     *
     * @param x the indeterminate
     * @return a newly created polynomial instance
     */
    public Polynomial toPolynomial(Variable x) {
        return new Polynomial(terms, x);
    }
View Full Code Here

            return true;
        }

        @Override
        public Expression apply() {
            Polynomial pl = Polynomial.create(((Equality) target).lhs(), x);
            Polynomial pr = Polynomial.create(((Equality) target).rhs(), x);
            Polynomial reduced;

            if (pl.degree().lt(pr.degree())) {
                reduced = pr.subtract(pl);
            } else {
                reduced = pl.subtract(pr);
            }
           
            Expression a = reduced.leadCoefficient();
           
            if (a instanceof ANumber && ((ANumber) a).isNegative()) {
                reduced = reduced.negate();
            }

            return new Equality(reduced, Naturals.zero());
        }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.Polynomial

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.