use of com.sri.ai.grinder.polynomial.api.Polynomial in project aic-expresso by aic-sri-international.
the class DefaultPolynomialTest method testIsMonomial.
@Test
public void testIsMonomial() {
Polynomial p = makePolynomial("0", "(x, y)");
Assert.assertTrue(p.isMonomial());
p = makePolynomial("1", "(x, y)");
Assert.assertTrue(p.isMonomial());
// Note: the numeric constants should just be added up together
p = makePolynomial("1 + 2 + 4", "(x, y)");
Assert.assertTrue(p.isMonomial());
p = makePolynomial("3*x^2*y^4", "tuple(y, x)");
Assert.assertTrue(p.isMonomial());
// Note: the 0 should be dropped, so remains a monomial
p = makePolynomial("3*x^2*y^4 + 0", "tuple(y, x)");
Assert.assertTrue(p.isMonomial());
p = makePolynomial("3*x^2*y^4 + 1", "tuple(y, x)");
Assert.assertFalse(p.isMonomial());
}
use of com.sri.ai.grinder.polynomial.api.Polynomial in project aic-expresso by aic-sri-international.
the class PolynomialIntegration method definiteIntegral.
/**
* This method will return the polynomial equivalent to:<br>
* <pre>
* Q.replace(variable, end) - Q.replace(variable, start)
* </pre>
* where 'Q = indefiniteIntegral(polynomial, variable)'
*
* @param polynomial
* the polynomial the definite integral is to be found for.
* @param variable
* the variable integration is with respect to.
* @param start
* the starting limit of the integral.
* @param end
* the ending limit of the integral.
* @return the definite integral of the polynomial for the given limits.
*/
public static Polynomial definiteIntegral(Polynomial polynomial, Expression variable, Expression start, Expression end) {
Polynomial q = indefiniteIntegral(polynomial, variable);
// Note: will include variable due to calling indefiniteIntegral
Set<Expression> variableSet = new LinkedHashSet<>(q.getVariables());
if (!Expressions.isNumber(start)) {
variableSet.add(start);
}
if (!Expressions.isNumber(end)) {
variableSet.add(end);
}
List<Expression> variables = new ArrayList<>(variableSet);
Polynomial minuendPolynomial = replaceFactor(q, variable, end, variables);
Polynomial subtrahendPolynomial = replaceFactor(q, variable, start, variables);
Polynomial result = minuendPolynomial.minus(subtrahendPolynomial);
return result;
}
use of com.sri.ai.grinder.polynomial.api.Polynomial in project aic-expresso by aic-sri-international.
the class SummationOnLinearRealArithmeticAndPolynomialStepSolver method computeSummationGivenValues.
private Expression computeSummationGivenValues(Expression variable, Expression literalFreeBody, Expression values, Context context) {
Expression result;
if (values.equals(Sets.EMPTY_SET) || Sets.isExtensionalSet(values)) {
result = ZERO;
} else {
Expression lowerBound = values.get(0);
Expression upperBound = values.get(1);
Polynomial bodyPolynomial = DefaultPolynomial.make(literalFreeBody);
result = PolynomialIntegration.definiteIntegral(bodyPolynomial, variable, lowerBound, upperBound);
}
return result;
}
use of com.sri.ai.grinder.polynomial.api.Polynomial in project aic-expresso by aic-sri-international.
the class DefaultPolynomialTest method testSet.
@Test
public void testSet() {
Polynomial p = makePolynomial("x^2*y^3", "(x, y)");
assertEquals(parse("2*y^3"), p.set(0, parse("2")));
assertEquals(parse("x^5"), p.set(1, parse("x^3")));
assertEquals(parse("x^2*z^4"), p.set(1, parse("z^4")));
p = makePolynomial("x^2*y^3 + 10", "(x, y)");
assertEquals(parse("2 + 10"), p.set(0, parse("2")));
assertEquals(parse("x^2*y^3 + 0"), p.set(1, parse("0")));
assertEquals(parse("(2 + 3) + 10"), p.set(0, parse("2 + 3")));
}
use of com.sri.ai.grinder.polynomial.api.Polynomial in project aic-expresso by aic-sri-international.
the class DefaultPolynomialTest method testNumberOfArguments.
@Test
public void testNumberOfArguments() {
Polynomial p = makePolynomial("0", "(x, y)");
assertEquals(0, p.numberOfArguments());
p = makePolynomial("x^2*y^3", "(x, y)");
assertEquals(2, p.numberOfArguments());
p = makePolynomial("x^2*y^3 + 10", "(x, y)");
assertEquals(2, p.numberOfArguments());
}
Aggregations