Package jmathexpr.arithmetic.op

Examples of jmathexpr.arithmetic.op.Exponentiation


        assertEquals(evaluated, expected);
    }
   
    @Test(dependsOnMethods = { "testRealExpressions" })
    public void testExponentiation() {
        Exponentiation exp3 = new Exponentiation(N.create(5), N.create(3));
        Expression evaluated = exp3.evaluate();
        System.out.printf("%s = %s%n", exp3, evaluated);
        assertEquals(evaluated, N.create(125));
    }
View Full Code Here


        }
       
        List<Exponentiation> explist = new ArrayList();
       
        for (long p : powers.keySet()) {
            explist.add(new Exponentiation(
                    new LongNaturalNumber(p), new LongNaturalNumber(powers.get(p))));
        }
       
        return new PrimeFactorization(n, explist);
    }
View Full Code Here

        @Override
        public Expression apply() {
            ANumber two = Naturals.getInstance().create(2);
            Equality eq = (Equality) target;
           
            return new Equality(new Exponentiation(eq.lhs(), two),
                    new Exponentiation(eq.rhs(), two));
        }
View Full Code Here

        Expression sum = null;
        Expression c, term;
       
        for (NaturalNumber n : coeffs.descendingKeySet()) {
            c = coeffs.get(n).evaluate();
            term = new Multiplication(c, new Exponentiation(xvalue, n));
           
            if (sum == null) {
                sum = new Sum(term);
            } else {
                sum = Sum.add(sum, term);
View Full Code Here

        if (degree().equals(two)) {
            Expression a = coeffs.get(two);
            Expression b = coeffs.get(ONE);
            Expression c = coeffs.get(ZERO);
           
            return new Subtraction(new Exponentiation(b, two),
                    new Multiplication(four, new Multiplication(a, c)));
        } else {
            throw new UnsupportedOperationException("Cannot compute discriminant: " + this);
        }
    }
View Full Code Here

            if (degree.equals(ZERO)) {
                return c;
            } else if (degree.equals(ONE)) {
                return new Multiplication(c, x);
            } else {
                return new Multiplication(c, new Exponentiation(x, degree));
            }
        } else {
            return ZERO;
        }
    }
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 boolean matchesPower(Expression expr) {
        if (x.matches(expr) && (degree == null || degree.isOne())) { // x
            return n.matches(Naturals.one());
        } else {
            Exponentiation xn = new Exponentiation(x, n);
           
            if (xn.matches(expr) && (degree == null || degree.equals(n.hit()))) { // x^n
                return true;
            }           
        }
       
        return false;
View Full Code Here

            if (exp.value == 0) {
                if (value != 0) {
                    return new LongNaturalNumber(1);
                } else {
                    throw new ArithmeticException(
                            String.format("Result is undefined: %s", new Exponentiation(this, exponent)));
                }
            } else if (exp.value == 1) {
                return this;
            } else {
                return new LongIntegerNumber(pow(value, exp.value));
View Full Code Here

    @Override
    public void exitExponentiation(ExpressionsParser.ExponentiationContext ctx) {
        Expression rhs = stack.pop();
        Expression lhs = stack.pop();
       
        stack.push(new Exponentiation(lhs, rhs));
    }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.op.Exponentiation

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.