Examples of evaluate()


Examples of jmathexpr.Variable.evaluate()

        Variable x = Numbers.variable("x");
        x.setValue(parser.parse("(15 + sqrt(249)) / 4"));
        ExpressionContext.getInstance().addVariable(x);
        Expression quadratic = parser.parse("x^2 - 6x + 1");
        evaluated = quadratic.evaluate();
        System.out.printf("%s (%s = %s) = %s%n", quadratic, x.name(), x.evaluate(), evaluated);
       
        expected = parser.parse("(3 sqrt(249) + 65) / 8");
        assertEquals(evaluated, expected);
    }
   

Examples of jmathexpr.arithmetic.func.Exp.evaluate()

        Variable x = Numbers.variable("x");
        Function exp = new Exp(x);
        System.out.printf("%s%n", exp);
       
        x.setValue(R.create(0));
        evaluated = exp.evaluate();
        System.out.printf("  %s%n", evaluated);
        assertEquals(evaluated, Naturals.one());
       
        x.setValue(R.create(1));
        System.out.printf("  %s%n", exp.evaluate());

Examples of jmathexpr.arithmetic.func.Log.evaluate()

       
        x.setValue(R.create(1));
        System.out.printf("  %s%n", exp.evaluate());
       
        Function log = new Log(N.create(10), N.create(1000));
        evaluated = log.evaluate();
        System.out.printf("%s = %s%n", log, evaluated);
        assertEquals(evaluated, N.create(3));
    }
   
    @Test(dependsOnMethods = { "testExponentiation" })

Examples of jmathexpr.arithmetic.func.Sqrt.evaluate()

        evaluated = elementOf.evaluate();
        System.out.printf("%s : %s%n", elementOf, evaluated);
        assertEquals(evaluated, TruthValue.True);
       
        Expression sqrt = new Sqrt(N.create(45));
        evaluated = sqrt.evaluate();
        System.out.printf("%s = %s%n", sqrt, evaluated);
        assertEquals(evaluated, new Multiplication(N.create(3), new Sqrt(N.create(5))));
    }
}

Examples of jmathexpr.arithmetic.op.Addition.evaluate()

        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();

Examples of jmathexpr.arithmetic.op.Division.evaluate()

           
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 1), x1));
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 2), x2));
           
            x1 = x1.evaluate();
            x2 = x2.evaluate();
           
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 1), x1));
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 2), x2));
           
            return new FiniteSet(x1, x2);

Examples of jmathexpr.arithmetic.op.Exponentiation.evaluate()

    }
   
    @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));
    }

    @Test(dependsOnMethods = { "testRationalExpressions" })

Examples of jmathexpr.arithmetic.op.Multiplication.evaluate()

        assertEquals(evaluated, new LongRationalNumber(1, 2));
       
        Expression product = new Multiplication(new LongRationalNumber(2, 3), new LongRationalNumber(9, 2));
        ElementOf isNatural = new ElementOf(product, N);
        evaluated = isNatural.evaluate();
        System.out.printf("%s = %s : %s%n", product.evaluate(), isNatural, evaluated);
        assertEquals(evaluated, TruthValue.True);
       
        System.out.println(Q.create("-3.750"));
    }
   

Examples of jmathexpr.arithmetic.op.Negation.evaluate()

           
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 1), x1));
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 2), x2));
           
            x1 = x1.evaluate();
            x2 = x2.evaluate();
           
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 1), x1));
            ExpressionContext.getInstance().addExpression(new Equality(Numbers.variable("x", 2), x2));
           
            return new FiniteSet(x1, x2);

Examples of jmathexpr.arithmetic.op.Subtraction.evaluate()

        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();
        System.out.printf("%s = %s%n", difference, evaluated);
        assertEquals(evaluated, new LongRationalNumber(1, 6));
       
        RationalNumber sixEighth = new LongRationalNumber(6, 8);
        evaluated = sixEighth.evaluate();
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.