use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testGetPowersOfOrderedNonNumericConstantFactors.
@Test
public void testGetPowersOfOrderedNonNumericConstantFactors() {
Monomial m = makeMonomial("2");
Assert.assertEquals(0, m.getPowersOfNonNumericFactors().size());
m = makeMonomial("2*x");
Assert.assertEquals(1, m.getPowersOfNonNumericFactors().size());
Assert.assertEquals(Arrays.asList(new Rational(1)), m.getPowersOfNonNumericFactors());
m = makeMonomial("2*x^3*y^7*z^11");
Assert.assertEquals(3, m.getPowersOfNonNumericFactors().size());
Assert.assertEquals(Arrays.asList(new Rational(3), new Rational(7), new Rational(11)), m.getPowersOfNonNumericFactors());
m = makeMonomial("2*z^3*y^7*x^11");
Assert.assertEquals(3, m.getPowersOfNonNumericFactors().size());
Assert.assertEquals(Arrays.asList(new Rational(11), new Rational(7), new Rational(3)), m.getPowersOfNonNumericFactors());
m = makeMonomial("2*z^3*x^7*y^11");
Assert.assertEquals(3, m.getPowersOfNonNumericFactors().size());
Assert.assertEquals(Arrays.asList(new Rational(7), new Rational(11), new Rational(3)), m.getPowersOfNonNumericFactors());
m = makeMonomial("2*z^3*x^7*x^11");
Assert.assertEquals(2, m.getPowersOfNonNumericFactors().size());
Assert.assertEquals(Arrays.asList(new Rational(18), new Rational(3)), m.getPowersOfNonNumericFactors());
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testDivideIllegalArgumentException.
@Test(expected = IllegalArgumentException.class)
public void testDivideIllegalArgumentException() {
Monomial m1 = makeMonomial("2*x^3");
Monomial m2 = makeMonomial("0*x");
m1.divide(m2);
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testGetOrderedNonNumericConstantFactors.
@Test
public void testGetOrderedNonNumericConstantFactors() {
Monomial m = makeMonomial("2");
Assert.assertEquals(0, m.getOrderedNonNumericFactors().size());
m = makeMonomial("2*x");
Assert.assertEquals(1, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("tuple(x)").getArguments(), m.getOrderedNonNumericFactors());
m = makeMonomial("2*x^3*y^7*z^11");
Assert.assertEquals(3, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("(x, y, z)").getArguments(), m.getOrderedNonNumericFactors());
m = makeMonomial("2*z^3*y^7*x^11");
Assert.assertEquals(3, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("(x, y, z)").getArguments(), m.getOrderedNonNumericFactors());
m = makeMonomial("2*z^3*x^7*y^11");
Assert.assertEquals(3, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("(x, y, z)").getArguments(), m.getOrderedNonNumericFactors());
m = makeMonomial("2*z^3*x^7*x^11");
Assert.assertEquals(2, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("(x, z)").getArguments(), m.getOrderedNonNumericFactors());
// Note: z is dropped as we know is = 1
m = makeMonomial("2*x^3*y^7*z^0");
Assert.assertEquals(2, m.getOrderedNonNumericFactors().size());
Assert.assertEquals(Expressions.parse("(x, y)").getArguments(), m.getOrderedNonNumericFactors());
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testGetCoefficient.
@Test
public void testGetCoefficient() {
Monomial m = makeMonomial("0");
Assert.assertEquals(makeMonomial("0"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("0"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("1");
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("x");
Assert.assertEquals(makeMonomial("x"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
m = makeMonomial("3*x^2");
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(makeMonomial("3*x^2"), m.getCoefficient(Expressions.parse("tuple(z)").getArguments()));
Assert.assertEquals(makeMonomial("x^2"), m.getCoefficient(Expressions.parse("tuple(3)").getArguments()));
Assert.assertEquals(makeMonomial("3"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
Assert.assertEquals(makeMonomial("1"), m.getCoefficient(Expressions.parse("(3, x)").getArguments()));
m = makeMonomial("3*x^2*y^4");
Assert.assertEquals(makeMonomial("3*x^2*y^4"), m.getCoefficient(Collections.emptyList()));
Assert.assertEquals(makeMonomial("3*x^2*y^4"), m.getCoefficient(Expressions.parse("tuple(1)").getArguments()));
Assert.assertEquals(makeMonomial("3*y^4"), m.getCoefficient(Expressions.parse("tuple(x)").getArguments()));
}
use of com.sri.ai.grinder.polynomial.api.Monomial in project aic-expresso by aic-sri-international.
the class DefaultMonomialTest method testAreLikeTermsUnionOfFactors.
@Test
public void testAreLikeTermsUnionOfFactors() {
Monomial m1 = makeMonomial("2");
Monomial m2 = makeMonomial("2");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("2");
m2 = makeMonomial("3");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("x");
m2 = makeMonomial("x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("x");
m2 = makeMonomial("y");
Assert.assertEquals(false, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(false, m1.areLikeTerms(m2));
m1 = makeMonomial("2");
m2 = makeMonomial("2*x");
Assert.assertEquals(false, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(false, m1.areLikeTerms(m2));
m1 = makeMonomial("2*x");
m2 = makeMonomial("2*x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("2*x^1");
m2 = makeMonomial("2*x");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("2*x");
m2 = makeMonomial("2*x^2");
Assert.assertEquals(false, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(false, m1.areLikeTerms(m2));
m1 = makeMonomial("2*y^1*x");
m2 = makeMonomial("2*x^1*y");
Assert.assertEquals(true, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(true, m1.areLikeTerms(m2));
m1 = makeMonomial("2*y^3*x^2");
m2 = makeMonomial("2*x^2*y^7");
Assert.assertEquals(false, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(false, m1.areLikeTerms(m2));
m1 = makeMonomial("2*y^1*x");
m2 = makeMonomial("2*x^1*y*z^4");
Assert.assertEquals(false, m1.areLikeTerms(m2, Monomial.orderedUnionOfNonNumericFactors(m1, m2)));
Assert.assertEquals(false, m1.areLikeTerms(m2));
}
Aggregations