From 70f45fcf837a76af96f0dd18317698ae9a760e1a Mon Sep 17 00:00:00 2001 From: axexlck Date: Sun, 3 Dec 2023 03:34:08 +0100 Subject: [PATCH] Improve/refactor gaussian integer methods --- .../matheclipse/core/builtin/Arithmetic.java | 8 +- .../core/builtin/NumberTheory.java | 34 ++-- .../matheclipse/core/builtin/PredicateQ.java | 52 +++--- .../core/expression/AbstractIntegerSym.java | 5 +- .../core/expression/ComplexSym.java | 7 +- .../matheclipse/core/interfaces/IExpr.java | 5 +- .../core/numbertheory/GaussianInteger.java | 52 +++++- .../core/expression/ComplexSymTest.java | 161 +++++++++--------- 8 files changed, 181 insertions(+), 143 deletions(-) diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java index e47277dcdb..c82f5f05d0 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java @@ -1818,12 +1818,12 @@ public IExpr eComIntArg(final IComplex c0, final IInteger i1) { @Override public IExpr e2ComArg(final IComplex c0, final IComplex c1) { // TODO implement GCD for gaussian integers - IInteger[] gi0 = c0.gaussianIntegers(); - IInteger[] gi1 = c1.gaussianIntegers(); + Optional gi0 = c0.gaussianIntegers(); + Optional gi1 = c1.gaussianIntegers(); - if (gi0 != null && gi1 != null) { + if (gi0.isPresent() && gi1.isPresent()) { // ComplexSym devidend = ComplexSym.valueOf(c0.getRealPart(), c0.getImaginaryPart()); - IInteger[] result = GaussianInteger.gcd(gi0, gi1); + IInteger[] result = GaussianInteger.gcd(gi0.get(), gi1.get()); if (result != null) { return F.complex(result[0], result[1]); } diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/NumberTheory.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/NumberTheory.java index 67c6a497d9..8553d37f20 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/NumberTheory.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/NumberTheory.java @@ -2698,15 +2698,15 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { BigInteger re = BigInteger.ONE; if (arg1.isInteger()) { re = ((IInteger) arg1).toBigNumerator(); - return GaussianInteger.factorize(re, BigInteger.ZERO, arg1); + return GaussianInteger.factorize((IInteger) arg1, re, BigInteger.ZERO); } else if (arg1.isComplex()) { IComplex c = (IComplex) arg1; - IRational rer = c.getRealPart(); - IRational imr = c.getImaginaryPart(); - if (rer.isInteger() && imr.isInteger()) { - re = ((IInteger) rer).toBigNumerator(); - BigInteger im = ((IInteger) imr).toBigNumerator(); - return GaussianInteger.factorize(re, im, arg1); + IRational real = c.getRealPart(); + IRational imaginary = c.getImaginaryPart(); + if (real.isInteger() && imaginary.isInteger()) { + re = ((IInteger) real).toBigNumerator(); + BigInteger im = ((IInteger) imaginary).toBigNumerator(); + return GaussianInteger.factorize((IComplex) arg1, re, im); } } } @@ -5202,24 +5202,10 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) { if (re.isInteger()) { IRational im = ((IComplex) arg1).im(); if (im.isInteger()) { - IAST factors = GaussianInteger.factorize(((IInteger) re).toBigNumerator(), - ((IInteger) im).toBigNumerator(), arg1); - if (factors.isListOfLists()) { - for (int i = 1; i < factors.size(); i++) { - IAST subList = factors.getAST(i); - if (!subList.isList2()) { - return S.False; - } - if (subList.second().isInteger()) { - IInteger exponent = (IInteger) subList.second(); - if (exponent.isGE(F.C2)) { - return S.False; - } - } - } - return S.True; - } + return F.booleSymbol( + GaussianInteger.isSquareFree((IComplex) arg1, (IInteger) re, (IInteger) im)); } + } } return S.False; diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PredicateQ.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PredicateQ.java index 1dfeb183ba..d5250d6167 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PredicateQ.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/PredicateQ.java @@ -1,5 +1,6 @@ package org.matheclipse.core.builtin; +import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; import java.util.function.Predicate; import org.hipparchus.linear.FieldMatrix; @@ -480,17 +481,18 @@ public boolean evalArg1Boole(final IExpr arg1, EvalEngine engine, OptionArgs opt if (!option.isTrue()) { return evalArg1Boole(arg1, engine); } - IInteger[] reImParts = arg1.gaussianIntegers(); - if (reImParts == null) { + Optional reImParts = arg1.gaussianIntegers(); + if (reImParts.isEmpty()) { return false; } - if (reImParts[1].isZero()) { - return reImParts[0].isEven(); + IInteger[] gaussian = reImParts.get(); + if (gaussian[1].isZero()) { + return gaussian[0].isEven(); } - if (reImParts[0].isZero()) { - return reImParts[1].isEven(); + if (gaussian[0].isZero()) { + return gaussian[1].isEven(); } - return reImParts[0].isEven() && reImParts[1].isEven(); + return gaussian[0].isEven() && gaussian[1].isEven(); } @Override @@ -951,20 +953,21 @@ public boolean evalArg1Boole(final IExpr arg1, EvalEngine engine, OptionArgs opt if (!option.isTrue()) { return evalArg1Boole(arg1, engine); } - IInteger[] reImParts = arg1.gaussianIntegers(); - if (reImParts == null) { + Optional reImParts = arg1.gaussianIntegers(); + if (reImParts.isEmpty()) { return false; } - if (reImParts[1].isZero()) { - return reImParts[0].isOdd(); + IInteger[] gaussian = reImParts.get(); + if (gaussian[1].isZero()) { + return gaussian[0].isOdd(); } - if (reImParts[0].isZero()) { - return reImParts[1].isOdd(); + if (gaussian[0].isZero()) { + return gaussian[1].isOdd(); } - if (reImParts[0].isOdd() && reImParts[1].isOdd()) { + if (gaussian[0].isOdd() && gaussian[1].isOdd()) { return false; } - return reImParts[0].isOdd() || reImParts[1].isOdd(); + return gaussian[0].isOdd() || gaussian[1].isOdd(); } @Override @@ -1241,24 +1244,25 @@ public boolean evalArg1Boole(final IExpr arg1, EvalEngine engine, OptionArgs opt if (!option.isTrue()) { return evalArg1Boole(arg1, engine); } - IInteger[] reImParts = arg1.gaussianIntegers(); - if (reImParts == null) { + Optional reImParts = arg1.gaussianIntegers(); + if (reImParts.isEmpty()) { return false; } - if (reImParts[1].isZero()) { - if (reImParts[0].isProbablePrime()) { - return reImParts[0].abs().mod(F.C4).equals(F.C3); + IInteger[] gaussian = reImParts.get(); + if (gaussian[1].isZero()) { + if (gaussian[0].isProbablePrime()) { + return gaussian[0].abs().mod(F.C4).equals(F.C3); } return false; } - if (reImParts[0].isZero()) { - if (reImParts[1].isProbablePrime()) { - return reImParts[1].abs().mod(F.C4).equals(F.C3); + if (gaussian[0].isZero()) { + if (gaussian[1].isProbablePrime()) { + return gaussian[1].abs().mod(F.C4).equals(F.C3); } return false; } // re^2 + im^2 is probable prime? - return reImParts[0].powerRational(2L).add(reImParts[1].powerRational(2L)).isProbablePrime(); + return gaussian[0].powerRational(2L).add(gaussian[1].powerRational(2L)).isProbablePrime(); } @Override diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractIntegerSym.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractIntegerSym.java index e4c888efbd..d3977d4c04 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractIntegerSym.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractIntegerSym.java @@ -5,6 +5,7 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.SortedSet; import java.util.Stack; @@ -695,8 +696,8 @@ public IInteger factorial() { /** {@inheritDoc} */ @Override - public IInteger[] gaussianIntegers() { - return new IInteger[] {this, F.C0}; + public Optional gaussianIntegers() { + return Optional.of(new IInteger[] {this, F.C0}); } /** {@inheritDoc} */ diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java index fdbc7d53ad..2dcbfbc095 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java @@ -9,6 +9,7 @@ import static org.matheclipse.core.expression.F.Times; import static org.matheclipse.core.expression.S.Pi; import java.math.BigInteger; +import java.util.Optional; import java.util.function.Function; import org.apfloat.Apcomplex; import org.apfloat.Apfloat; @@ -408,11 +409,11 @@ public String fullFormString() { /** {@inheritDoc} */ @Override - public IInteger[] gaussianIntegers() { + public Optional gaussianIntegers() { if (fReal.isInteger() && fImaginary.isInteger()) { - return new IInteger[] {((IInteger) fReal), ((IInteger) fImaginary)}; + return Optional.of(new IInteger[] {((IInteger) fReal), ((IInteger) fImaginary)}); } - return null; + return Optional.empty(); } @Override diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java index 8c5a01b429..668455cbac 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IExpr.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -1078,8 +1079,8 @@ default String fullFormString() { * * @return null if this is not a Gaussian integer */ - default IInteger[] gaussianIntegers() { - return null; + default Optional gaussianIntegers() { + return Optional.empty(); } @Override diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/GaussianInteger.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/GaussianInteger.java index aa7006f99e..5e0400755a 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/GaussianInteger.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/GaussianInteger.java @@ -19,6 +19,8 @@ import org.matheclipse.core.expression.F; import org.matheclipse.core.interfaces.IAST; import org.matheclipse.core.interfaces.IASTAppendable; +import org.matheclipse.core.interfaces.IBigNumber; +import org.matheclipse.core.interfaces.IComplex; import org.matheclipse.core.interfaces.IExpr; import org.matheclipse.core.interfaces.IInteger; @@ -29,10 +31,20 @@ public final class GaussianInteger { private BigInteger ValA, ValB; private int Ind; - public static IAST factorize(BigInteger re, BigInteger im, IExpr num) { + /** + * Factor a gaussian integer number. + * + * @param gaussianInteger gaussian integer represented by an {@link IBigNumber} instance (i.e. + * instance of {@link IComplex} or {@link IInteger}) + * @param realPart the real part of the gaussian integer + * @param imaginaryPart the imaginary part of the gaussian integer + * @return + */ + public static IAST factorize(IBigNumber gaussianInteger, BigInteger realPart, + BigInteger imaginaryPart) { GaussianInteger g = new GaussianInteger(); SortedMap complexMap = new TreeMap(); - g.gaussianFactorization2(re, im, complexMap); + g.gaussianFactorization2(realPart, imaginaryPart, complexMap); IASTAppendable list = F.ListAlloc(complexMap.size() + 1); IExpr factor = F.C1; IASTAppendable ast = F.TimesAlloc(complexMap.size()); @@ -46,7 +58,7 @@ public static IAST factorize(BigInteger re, BigInteger im, IExpr num) { ast.append(F.Power(key, is)); } } - factor = F.eval(F.Divide(num, ast)); + factor = F.eval(F.Divide(gaussianInteger, ast)); if (!factor.isOne()) { list.append(F.list(factor, F.C1)); } @@ -58,6 +70,38 @@ public static IAST factorize(BigInteger re, BigInteger im, IExpr num) { return list; } + /** + * Test if the gaussian integer is square free. + * + * @param gaussianInteger gaussian integer represented by an {@link IBigNumber} instance (i.e. + * instance of {@link IComplex} or {@link IInteger}) + * @param realPart the real part of the gaussian integer + * @param imaginaryPart the imaginary part of the gaussian integer + * + * @return + */ + public static boolean isSquareFree(IBigNumber gaussianInteger, IInteger realPart, + IInteger imaginaryPart) { + IAST factors = + factorize(gaussianInteger, realPart.toBigNumerator(), imaginaryPart.toBigNumerator()); + if (factors.isListOfLists()) { + for (int i = 1; i < factors.size(); i++) { + IAST subList = factors.getAST(i); + if (!subList.isList2()) { + return false; + } + if (subList.second().isInteger()) { + IInteger exponent = (IInteger) subList.second(); + if (exponent.isGE(F.C2)) { + return false; + } + } + } + return true; + } + return false; + } + void gaussianFactorization2(BigInteger re, BigInteger im, SortedMap complexMap) { BigInteger BigInt2; @@ -218,7 +262,7 @@ public static IInteger[] quotientRemainder(final IInteger[] c1, final IInteger[] } /** - * Greatest common divisor of the gaussian IInteger numbers g1, g2. + * Greatest common divisor of the gaussian {@link IInteger} numbers g1, g2. * * @param g1 * @param g2 diff --git a/symja_android_library/matheclipse-io/src/test/java/org/matheclipse/core/expression/ComplexSymTest.java b/symja_android_library/matheclipse-io/src/test/java/org/matheclipse/core/expression/ComplexSymTest.java index 20ed793ba8..b80ccde290 100644 --- a/symja_android_library/matheclipse-io/src/test/java/org/matheclipse/core/expression/ComplexSymTest.java +++ b/symja_android_library/matheclipse-io/src/test/java/org/matheclipse/core/expression/ComplexSymTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.math.BigInteger; +import java.util.Optional; import org.junit.Test; import org.matheclipse.core.interfaces.IExpr; import org.matheclipse.core.interfaces.IInteger; @@ -14,26 +15,26 @@ public class ComplexSymTest { public void testSqrt1() { // https://math.stackexchange.com/a/44414 ComplexSym c1 = ComplexSym.valueOf(BigInteger.valueOf(-7), BigInteger.valueOf(24)); - IInteger[] parm1 = c1.gaussianIntegers(); + Optional parm1 = c1.gaussianIntegers(); // c + d*I - IInteger c = parm1[0]; - IInteger d = parm1[1]; + IInteger c = parm1.get()[0]; + IInteger d = parm1.get()[1]; ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(3), BigInteger.valueOf(4)); - IInteger[] expected = c2.gaussianIntegers(); + Optional expected = c2.gaussianIntegers(); IExpr val1 = c.multiply(c).add(d.multiply(d)).sqrt(); if (val1.isInteger()) { IExpr a = c.add((IInteger) val1).divide(F.C2).sqrt(); if (a.isInteger()) { - assertEquals(expected[0], a); + assertEquals(expected.get()[0], a); IExpr val2 = ((IInteger) val1).subtract(c).divide(F.C2).sqrt(); if (val2.isInteger()) { // Sqrt(c + d*I) -> a + b*I IExpr b = ((IInteger) val2).multiply(d.complexSign()); - assertEquals(expected[1], b); + assertEquals(expected.get()[1], b); return; } } @@ -49,10 +50,10 @@ public void testIntegerPartDivisionGaussian1() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(-1)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(2), BigInteger.valueOf(-4)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -70,10 +71,10 @@ public void testIntegerPartDivisionGaussian2() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(2), BigInteger.valueOf(-2)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(2), BigInteger.valueOf(-5)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -91,10 +92,10 @@ public void testIntegerPartDivisionGaussian3() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(-2), BigInteger.valueOf(1)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(3), BigInteger.valueOf(-1)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -112,10 +113,10 @@ public void testIntegerPartDivisionGaussian4() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(-1)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(-1)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -133,10 +134,10 @@ public void testIntegerPartDivisionGaussian5() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(3)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -154,10 +155,10 @@ public void testIntegerPartDivisionGaussian6() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -175,10 +176,10 @@ public void testIntegerPartDivisionGaussian7() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -196,10 +197,10 @@ public void testIntegerPartDivisionGaussian8() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -217,10 +218,10 @@ public void testIntegerPartDivisionGaussian9() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(-1)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -238,10 +239,10 @@ public void testIntegerPartDivisionGaussian10() { ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(-11), BigInteger.valueOf(0)); ComplexSym c4 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] expected = c3.gaussianIntegers(); - IInteger[] expected2 = c4.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] expected = c3.gaussianIntegers().get(); + IInteger[] expected2 = c4.gaussianIntegers().get(); IInteger[] result = GaussianInteger.quotientRemainder(parm1, parm2); @@ -258,9 +259,9 @@ public void testGcd1() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -276,9 +277,9 @@ public void testGcd2() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -294,9 +295,9 @@ public void testGcd3() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(0), BigInteger.valueOf(-1)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -312,9 +313,9 @@ public void testGcd4() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(-1)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(-1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -330,9 +331,9 @@ public void testGcd5() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(-1), BigInteger.valueOf(-1)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -348,9 +349,9 @@ public void testGcd6() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(4), BigInteger.valueOf(11)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -366,9 +367,9 @@ public void testGcd7() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(8)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(-2)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -384,9 +385,9 @@ public void testGcd8() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(14), BigInteger.valueOf(21)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(-3), BigInteger.valueOf(2)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); IInteger expected = parm3[1]; @@ -401,9 +402,9 @@ public void testGcd9() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(10), BigInteger.valueOf(11)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(-2), BigInteger.valueOf(3)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -419,9 +420,9 @@ public void testGcd10() { ComplexSym c2 = ComplexSym.valueOf(BigInteger.valueOf(-10), BigInteger.valueOf(11)); ComplexSym c3 = ComplexSym.valueOf(BigInteger.valueOf(1), BigInteger.valueOf(0)); - IInteger[] parm1 = c1.gaussianIntegers(); - IInteger[] parm2 = c2.gaussianIntegers(); - IInteger[] parm3 = c3.gaussianIntegers(); + IInteger[] parm1 = c1.gaussianIntegers().get(); + IInteger[] parm2 = c2.gaussianIntegers().get(); + IInteger[] parm3 = c3.gaussianIntegers().get(); IInteger[] result = GaussianInteger.gcd(parm1, parm2); @@ -433,12 +434,12 @@ public void testGcd10() { @Test public void testGcd11() { - IInteger[] one = ComplexSym.valueOf(BigInteger.ONE, BigInteger.ZERO).gaussianIntegers(); + IInteger[] one = ComplexSym.valueOf(BigInteger.ONE, BigInteger.ZERO).gaussianIntegers().get(); IInteger[] minusOne = - ComplexSym.valueOf(BigInteger.ONE.negate(), BigInteger.ZERO).gaussianIntegers(); - IInteger[] I = ComplexSym.valueOf(BigInteger.ZERO, BigInteger.ONE).gaussianIntegers(); + ComplexSym.valueOf(BigInteger.ONE.negate(), BigInteger.ZERO).gaussianIntegers().get(); + IInteger[] I = ComplexSym.valueOf(BigInteger.ZERO, BigInteger.ONE).gaussianIntegers().get(); IInteger[] minusI = - ComplexSym.valueOf(BigInteger.ZERO, BigInteger.ONE.negate()).gaussianIntegers(); + ComplexSym.valueOf(BigInteger.ZERO, BigInteger.ONE.negate()).gaussianIntegers().get(); // gcd(1,1) ==> 1 IInteger[] result = GaussianInteger.gcd(one, one);