Search in sources :

Example 1 with Exponentiation

use of com.sri.ai.grinder.sgdpllt.library.number.Exponentiation in project aic-expresso by aic-sri-international.

the class DefaultMonomial method computeInnerExpression.

//
// PROTECTED
//
@Override
protected Expression computeInnerExpression() {
    Expression result;
    if (isNumericConstant()) {
        result = numericConstantFactorExpression;
    } else {
        List<Expression> args = new ArrayList<>(1 + orderedNonNumericFactors.size());
        if (!getNumericConstantFactor().equals(Rational.ONE)) {
            args.add(numericConstantFactorExpression);
        }
        args.addAll(zipWith((base, power) -> {
            Expression arg;
            if (power.equals(Rational.ONE)) {
                // No need to include exponentiation
                arg = base;
            } else {
                arg = Exponentiation.make(base, power);
            }
            return arg;
        }, orderedNonNumericFactors, orderedNonNumericFactorPowers));
        if (args.size() == 1) {
            // simplified to a single argument 
            // (i.e. numeric constant was 1 as we know we have at least one 
            //  non-numeric constant term here).
            result = args.get(0);
        } else {
            result = new DefaultFunctionApplication(MONOMIAL_FUNCTOR, args);
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) EXPONENTIATION_FUNCTOR(com.sri.ai.grinder.sgdpllt.library.number.Exponentiation.EXPONENTIATION_FUNCTOR) Monomial(com.sri.ai.grinder.polynomial.api.Monomial) Exponentiation(com.sri.ai.grinder.sgdpllt.library.number.Exponentiation) Expressions(com.sri.ai.expresso.helper.Expressions) Rational(com.sri.ai.util.math.Rational) Util.zipWith(com.sri.ai.util.Util.zipWith) Set(java.util.Set) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) Beta(com.google.common.annotations.Beta) AbstractExpressionWrapper(com.sri.ai.expresso.helper.AbstractExpressionWrapper) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ExpressionComparator(com.sri.ai.expresso.helper.ExpressionComparator) Times(com.sri.ai.grinder.sgdpllt.library.number.Times) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) Map(java.util.Map) MINUS(com.sri.ai.grinder.sgdpllt.library.FunctorConstants.MINUS) DefaultFunctionApplication(com.sri.ai.expresso.core.DefaultFunctionApplication) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) FunctorConstants(com.sri.ai.grinder.sgdpllt.library.FunctorConstants) Pair(com.sri.ai.util.base.Pair) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) DefaultFunctionApplication(com.sri.ai.expresso.core.DefaultFunctionApplication)

Aggregations

Beta (com.google.common.annotations.Beta)1 Expression (com.sri.ai.expresso.api.Expression)1 DefaultFunctionApplication (com.sri.ai.expresso.core.DefaultFunctionApplication)1 AbstractExpressionWrapper (com.sri.ai.expresso.helper.AbstractExpressionWrapper)1 ExpressionComparator (com.sri.ai.expresso.helper.ExpressionComparator)1 Expressions (com.sri.ai.expresso.helper.Expressions)1 Expressions.apply (com.sri.ai.expresso.helper.Expressions.apply)1 Monomial (com.sri.ai.grinder.polynomial.api.Monomial)1 FunctorConstants (com.sri.ai.grinder.sgdpllt.library.FunctorConstants)1 MINUS (com.sri.ai.grinder.sgdpllt.library.FunctorConstants.MINUS)1 Exponentiation (com.sri.ai.grinder.sgdpllt.library.number.Exponentiation)1 EXPONENTIATION_FUNCTOR (com.sri.ai.grinder.sgdpllt.library.number.Exponentiation.EXPONENTIATION_FUNCTOR)1 Times (com.sri.ai.grinder.sgdpllt.library.number.Times)1 Util.zipWith (com.sri.ai.util.Util.zipWith)1 Pair (com.sri.ai.util.base.Pair)1 Rational (com.sri.ai.util.math.Rational)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1