use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testNumberOfArguments.
@Test
public void testNumberOfArguments() {
Monomial m = makeMonomial("0");
Assert.assertEquals(0, m.numberOfArguments());
m = makeMonomial("x^2*y^3");
Assert.assertEquals(2, m.numberOfArguments());
m = makeMonomial("z^4*y^2*x^3*6");
Assert.assertEquals(4, m.numberOfArguments());
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testAreLikeTermsExplicitSignatureOfFactors.
@Test
public void testAreLikeTermsExplicitSignatureOfFactors() {
Monomial m1 = makeMonomial("2");
Monomial m2 = makeMonomial("2");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
m1 = makeMonomial("2");
m2 = makeMonomial("3");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(3)").getArguments()));
m1 = makeMonomial("x");
m2 = makeMonomial("x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
m1 = makeMonomial("x");
m2 = makeMonomial("y");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(y)").getArguments()));
m1 = makeMonomial("2");
m2 = makeMonomial("2*x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
m1 = makeMonomial("2*x");
m2 = makeMonomial("2*x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
m1 = makeMonomial("2*x^1");
m2 = makeMonomial("2*x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
m1 = makeMonomial("2*x");
m2 = makeMonomial("2*x^2");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
m1 = makeMonomial("2*y^1*x");
m2 = makeMonomial("2*x^1*y");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(y)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, y)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x, y)").getArguments()));
m1 = makeMonomial("2*y^3*x^2");
m2 = makeMonomial("2*x^2*y^7");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(y)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, y)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, x, y)").getArguments()));
m1 = makeMonomial("2*y^1*x");
m2 = makeMonomial("2*x^1*y*z^4");
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(2)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("tuple(y)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, y)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, z)").getArguments()));
Assert.assertEquals(true, m1.areLikeTerms(m2, Expressions.parse("(2, x, y)").getArguments()));
Assert.assertEquals(false, m1.areLikeTerms(m2, Expressions.parse("(2, x, y, z)").getArguments()));
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testDegree.
@Test
public void testDegree() {
Monomial m = makeMonomial("2");
Assert.assertEquals(0, m.degree());
m = makeMonomial("x");
Assert.assertEquals(1, m.degree());
m = makeMonomial("2*x");
Assert.assertEquals(1, m.degree());
m = makeMonomial("2*x^3");
Assert.assertEquals(3, m.degree());
m = makeMonomial("2*x^3*y");
Assert.assertEquals(4, m.degree());
m = makeMonomial("2*x^3*y*z^5");
Assert.assertEquals(9, m.degree());
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testTimes.
@Test
public void testTimes() {
Monomial m1 = makeMonomial("2");
Monomial m2 = makeMonomial("3");
Assert.assertEquals(makeMonomial("6"), m1.times(m2));
m1 = makeMonomial("x");
m2 = makeMonomial("x");
Assert.assertEquals(makeMonomial("x^2"), m1.times(m2));
m1 = makeMonomial("3*y");
m2 = makeMonomial("y");
Assert.assertEquals(makeMonomial("3 * y^2"), m1.times(m2));
m1 = makeMonomial("2*x^2");
m2 = makeMonomial("3*x^3");
Assert.assertEquals(makeMonomial("6*x^5"), m1.times(m2));
m1 = makeMonomial("3*x^2*y");
m2 = makeMonomial("3*x^3*z^2");
Assert.assertEquals(makeMonomial("9*x^5*y*z^2"), m1.times(m2));
m1 = makeMonomial("0");
m2 = makeMonomial("3*x^3*z^2");
Assert.assertEquals(makeMonomial("0"), m1.times(m2));
m1 = makeMonomial("3*x^2*y");
m2 = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m1.times(m2));
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testExponentiate.
@Test
public void testExponentiate() {
Monomial m = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m.exponentiate(3));
m = makeMonomial("2");
Assert.assertEquals(makeMonomial("8"), m.exponentiate(3));
m = makeMonomial("2*x");
Assert.assertEquals(makeMonomial("8*x^3"), m.exponentiate(3));
m = makeMonomial("2*x^2");
Assert.assertEquals(makeMonomial("8*x^6"), m.exponentiate(3));
m = makeMonomial("2*y^2*x^3");
Assert.assertEquals(makeMonomial("8*x^9*y^6"), m.exponentiate(3));
m = makeMonomial("2*y^2*x^3");
Assert.assertEquals(makeMonomial("1"), m.exponentiate(0));
}
Aggregations