Skip to content

Commit

Permalink
This fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
PoslavskySV committed Sep 16, 2018
1 parent e960bcd commit 004c718
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ public final lPoly increment() {

@Override
public final lPoly add(lPoly oth) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return self;
if (isZero())
Expand Down Expand Up @@ -520,6 +522,8 @@ public final lPoly addMonomial(long coefficient, int exponent) {
* @return {@code this + oth * factor} modulo {@code modulus}
*/
public final lPoly addMul(lPoly oth, long factor) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return self;

Expand All @@ -537,6 +541,8 @@ public final lPoly addMul(lPoly oth, long factor) {

@Override
public final lPoly subtract(lPoly oth) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return self;
if (isZero())
Expand All @@ -559,6 +565,8 @@ public final lPoly subtract(lPoly oth) {
* @return {@code this - factor * x^exponent * oth}
*/
public final lPoly subtract(lPoly oth, long factor, int exponent) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static <Poly extends IUnivariatePolynomial<Poly>> boolean irreducibleQ(Po
if (poly.isOverFiniteField())
return finiteFieldIrreducibleQ(poly);
else
return UnivariateFactorization.Factor(poly).isTrivial();
return !poly.isMonomial() && UnivariateFactorization.Factor(poly).isTrivial();
}

/**
Expand All @@ -55,6 +55,9 @@ public static <Poly extends IUnivariatePolynomial<Poly>> boolean finiteFieldIrre
finiteFieldIrreducibleViaModularComposition(Poly poly) {
Util.ensureOverFiniteField(poly);

if (poly.isMonomial())
return false;

if (canConvertToZp64(poly))
return finiteFieldIrreducibleViaModularComposition(asOverZp64(poly));

Expand Down Expand Up @@ -129,6 +132,9 @@ static <Poly extends IUnivariatePolynomial<Poly>> Poly composition(
finiteFieldIrreducibleBenOr(Poly poly) {
Util.ensureOverFiniteField(poly);

if (poly.isMonomial())
return false;

if (canConvertToZp64(poly))
return finiteFieldIrreducibleBenOr(asOverZp64(poly));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ public UnivariatePolynomial<E> increment() {

@Override
public UnivariatePolynomial<E> add(UnivariatePolynomial<E> oth) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return this;
if (isZero())
Expand Down Expand Up @@ -877,6 +879,8 @@ public UnivariatePolynomial<E> addMonomial(E coefficient, int exponent) {
* @return {@code this + oth * factor} modulo {@code modulus}
*/
public UnivariatePolynomial<E> addMul(UnivariatePolynomial<E> oth, E factor) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return this;

Expand All @@ -894,6 +898,8 @@ public UnivariatePolynomial<E> addMul(UnivariatePolynomial<E> oth, E factor) {

@Override
public UnivariatePolynomial<E> subtract(UnivariatePolynomial<E> oth) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return this;
if (isZero())
Expand All @@ -916,6 +922,8 @@ public UnivariatePolynomial<E> subtract(UnivariatePolynomial<E> oth) {
* @return {@code this - factor * x^exponent * oth}
*/
public UnivariatePolynomial<E> subtract(UnivariatePolynomial<E> oth, E factor, int exponent) {
assertSameCoefficientRingWith(oth);

if (oth.isZero())
return this;

Expand Down Expand Up @@ -1048,6 +1056,8 @@ public UnivariatePolynomial<E> multiplyByBigInteger(BigInteger factor) {
@Override
@SuppressWarnings("unchecked")
public UnivariatePolynomial<E> multiply(UnivariatePolynomial<E> oth) {
assertSameCoefficientRingWith(oth);

if (isZero())
return this;
if (oth.isZero())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public UnivariatePolynomialZp64 multiplyByBigInteger(BigInteger factor) {

@Override
public UnivariatePolynomialZp64 multiply(UnivariatePolynomialZp64 oth) {
assertSameCoefficientRingWith(oth);

if (isZero())
return this;
if (oth.isZero())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void testBrown1_random() throws Exception {
brown.addValue(System.nanoTime() - start);

SingularResult<MonomialZp64, MultivariatePolynomialZp64> expected = SingularResultant(a, b, variable);
singular.addValue(expected.nanotime);
if (expected != null)
singular.addValue(expected.nanotime);

assertEquals(expected.resultant, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public void testNumberField3_random() {
.mapCoefficients(Q, cf -> Q.mkNumerator(cf.mod(10)));

minimalPoly.setLC(Q.mkNumerator(rndd.nextInt(1, 10)));
if (!IrreduciblePolynomials.irreducibleQ(minimalPoly)) {
if (minimalPoly.isMonomial() || !IrreduciblePolynomials.irreducibleQ(minimalPoly)) {
--i;
continue;
}
Expand Down

0 comments on commit 004c718

Please sign in to comment.