Package jmathexpr

Examples of jmathexpr.Expression


    public static boolean isConvertible(Expression expr, Variable x) {
        if (!(expr instanceof Equality)) {
            return false;
        }
       
        Expression lhs = ((Equality) expr).lhs();
        Expression rhs = ((Equality) expr).rhs();
        boolean lhsIsQuadratic = isQuadratic(lhs, x);
        boolean rhsIsQuadratic = isQuadratic(rhs, x);
       
        return (lhsIsQuadratic
                && (rhs.isConstant() || LinearEquation.isLinear(rhs, x) || rhsIsQuadratic))
                || (rhsIsQuadratic
                && (lhs.isConstant() || LinearEquation.isLinear(lhs, x) || lhsIsQuadratic));
    }
View Full Code Here


        if (pattern.matches(expr)) {
            return true;
        } else if (expr instanceof Negation) {
            return isQuadratic(((Negation) expr).getChild(), x);
        } else if (expr instanceof Division) {
            Expression lhs = ((Division) expr).lhs();
            Expression rhs = ((Division) expr).rhs();
           
            return rhs.isConstant() && isQuadratic(lhs, x);
        } else if (expr instanceof Operation
                && expr.getPrecedence() == Precedence.Addition) {
            boolean isQuadratic = false;

            for (Expression t : ((Operation) expr).operands()) {
View Full Code Here

        super("sqrt", arg);
    }

    @Override
    public Expression evaluate() {
        Expression x = arg.evaluate();
       
        if (x instanceof ANumber) {
            ANumber a = (ANumber) x;
           
            if (a instanceof NaturalNumber) {
                return Naturals.sqrt((NaturalNumber) a);
            } else if (!a.isNegative()) {
                if (a instanceof IntegerNumber) {
                    return Naturals.sqrt(a.toNatural());
                } else if (a instanceof RationalNumber) {
                    return sqrt((RationalNumber) a);
                }
            }
        } else if (x instanceof Multiplication) {
            Expression e = sqrt((Multiplication) x);
           
            if (e instanceof Multiplication) {
                return e;
            }
        } else if (x instanceof Addition) {
            Expression factorized = ((Addition) x).factorize();
           
            if (factorized instanceof Multiplication) {
                Expression e = sqrt((Multiplication) factorized);

                if (e instanceof Multiplication) {
                    return e;
                }
            }
View Full Code Here

       
        return new Sqrt(x);
    }
   
    private Expression sqrt(Multiplication product) {
        Expression l = new Sqrt(product.lhs()).evaluate();
        Expression r = new Sqrt(product.rhs()).evaluate();

        if (!(l instanceof Sqrt && r instanceof Sqrt)) {
            return new Multiplication(l, r).evaluate();
        } else {
            return new Sqrt(product);
View Full Code Here

            return new Sqrt(product);
        }
    }
   
    private Expression sqrt(RationalNumber r) {
        Expression sqrtn = Naturals.sqrt(r.numerator().toNatural());
        Expression sqrtd = Naturals.sqrt(r.denominator());

        if (sqrtn instanceof NaturalNumber || sqrtd instanceof NaturalNumber) {
            return new Division(sqrtn, sqrtd).evaluate();
        } else {
            return new Sqrt(r);
View Full Code Here

            return false;
        }
   
        private boolean hasMatchingTerm() {
            ExpressionPattern p;
            Expression e;
           
            for (int i = 0; i < terms.size(); i++) { // looping over the patterns...
                if (matchingPatterns.containsKey(i)) {
                    continue;
                }
View Full Code Here

                reduced = pr.subtract(pl);
            } else {
                reduced = pl.subtract(pr);
            }
           
            Expression a = reduced.leadCoefficient();
           
            if (a instanceof ANumber && ((ANumber) a).isNegative()) {
                reduced = reduced.negate();
            }
View Full Code Here

            return fraction.matches(expr) && pattern.matches(fraction.denominator());
        }

        @Override
        public Expression apply() {
            Expression sqrt = new Sqrt(arg.hit());
           
            return new Division(new Multiplication(fraction.numerator(), sqrt),
                       new Multiplication(fraction.denominator(), sqrt));
        }
View Full Code Here

        this.base = base;
    }

    @Override
    public Expression evaluate() {
        Expression b = base.evaluate();
        Expression x = arg.evaluate();
       
        if (b instanceof ANumber && x instanceof ANumber) {
            if (b instanceof NaturalNumber && x instanceof NaturalNumber) {
                return Naturals.log((NaturalNumber) b, (NaturalNumber) x);
            } else if (b instanceof RealNumber && x instanceof RealNumber) {
View Full Code Here

        @Override
        public boolean matches(Expression expr) {
            p = (Polynomial) ((Equality) expr).lhs();
           
            Expression a = p.leadCoefficient();

            return new Sqrt(arg).matches(a);
        }
View Full Code Here

TOP

Related Classes of jmathexpr.Expression

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.