Package jmathexpr.util.parser

Examples of jmathexpr.util.parser.ExpressionParser


    public ParserTest() {
    }
   
    @Test
    public void testPolynomials() {
        ExpressionParser parser = new ExpressionParser();
       
        Expression expression = parser.parse("let x in R");
       
        Logger.dump(expression);
    }
View Full Code Here


    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

        assertEquals(evaluated, N.create(3));
    }
   
    @Test(dependsOnMethods = { "testExponentiation" })
    public void testSum() {
        ExpressionParser parser = new ExpressionParser();
        Expression sum = parser.parse("45/2 + 3/2 * sqrt(249) + 15/8 * sqrt(249) + 237/8 + 1");
        Expression evaluated = sum.evaluate();
        System.out.printf("%s = %s%n", sum, evaluated);
       
        Expression expected = parser.parse("(27sqrt(249) + 425) / 8");
        assertEquals(evaluated, expected);
       
        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);
    }
View Full Code Here

        assertEquals(evaluated, TruthValue.True);
       
        Division division = new Division(R.create(10.0), R.create(2.0));
        System.out.printf("Division domain: %s%n", division.domain());
       
        ExpressionParser parser = new ExpressionParser();
        Expression fraction = parser.parse("(6 sqrt(249) + 130) / 16");
        evaluated = fraction.evaluate();
        System.out.printf("%s : %s%n", fraction, evaluated);
       
        Expression expected = parser.parse("(3 sqrt(249) + 65) / 8");
        assertEquals(evaluated, expected);
    }
View Full Code Here

    public AbsoluteValueEquationTest() {
    }

    @Test
    public void linear() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|2x - 1| = 5");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
View Full Code Here

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "linear" })
    public void toIsolate() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|5x - 6| + 3 = 10");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
View Full Code Here

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "toIsolate" })
    public void twoAbsExpressions() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|2x - 1| = |4x + 3|");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
View Full Code Here

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "twoAbsExpressions" })
    public void quadratic() throws EquationSolveException {
        ExpressionParser parser = new ExpressionParser();
        Equation abs = (Equation) parser.parse("|x^2 - 6x + 1| = |(3x + 5)/2|");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression x1 = parser.parse("(15 + sqrt(249)) / 4");
        Expression x2 = parser.parse("(15 - sqrt(249)) / 4");
        Expression expected = new FiniteSet(x1, x2, Rationals.getInstance().create(7, 2), Naturals.one());
        assertEquals(expected, roots);
    }
View Full Code Here

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "quadratic" })
    public void anotherQuadratic() throws EquationSolveException {
        ExpressionParser parser = new ExpressionParser();
        Equation abs = (Equation) parser.parse("|x| = x^2 + x - 3");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression x1 = parser.parse("sqrt(3)");
        Expression x2 = Integers.getInstance().create("-3");
        Expression expected = new FiniteSet(x1, x2);
        assertEquals(expected, roots);
    }
View Full Code Here

    public LinearEquationTest() {
    }

    @Test
    public void simple() throws EquationSolveException {
        Equation lineq = (Equation) new ExpressionParser().parse("4*x + 3 = x + 27");
        Variable x = lineq.variable();
        System.out.printf("%s : %s = ?%n", lineq, x);
       
        Set    roots = lineq.solve();
        System.out.printf("  %s = %s%n", x, roots);
View Full Code Here

TOP

Related Classes of jmathexpr.util.parser.ExpressionParser

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.