public void ReplaceTest_Integer() { // Representação dos polinómios. var polynomText = "x^5+2*x^4+3*x^3+4*x^2+5*x+6"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); // Estabelece os conversores. var integerToIntegerConv = new ElementToElementConversion <int>(); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerReplaceValues = new int[] { 0, 1, 2, 3 }; var integerExpectedValues = new int[] { 6, 21, 120, 543 }; for (int i = 0; i < integerReplaceValues.Length; ++i) { var integerActualValue = integerPolynomial.Replace(integerReplaceValues[i], integerDomain); Assert.AreEqual(integerExpectedValues[i], integerActualValue); } }
public void RunTest_BigIntegerNumbersRhoAlg() { var bigIntegerNumber = new BigIntegerDomain(); var integerNumber = new IntegerDomain(); var integerParser = new BigIntegerParser <string>(); var conversion = new BigIntegerToIntegerConversion(); var variableName = "x"; var testPols = new List <UnivariatePolynomialNormalForm <BigInteger> >(); testPols.Add(TestsHelper.ReadUnivarPolynomial("x^123+1", bigIntegerNumber, integerParser, conversion, variableName)); testPols.Add(TestsHelper.ReadUnivarPolynomial("x^452+1537*x+1", bigIntegerNumber, integerParser, conversion, variableName)); var rhoAlgorithm = new PollardRhoAlgorithm <BigInteger>( testPols, new ModularBigIntFieldFactory(), bigIntegerNumber); var factorizationTarget = new DecompositionFactorizationAlgorithm <BigInteger, int>( rhoAlgorithm, 1, integerNumber, bigIntegerNumber); var value = BigInteger.Parse("1000000000001"); var expected = new Dictionary <BigInteger, int>(); expected.Add(137, 1); expected.Add(73, 1); expected.Add(BigInteger.Parse("99990001"), 1); var actual = factorizationTarget.Run(value); CollectionAssert.AreEquivalent(expected, actual); }
public void RunTest_IntegerNumbersRhoAlg() { var integerNumber = new IntegerDomain(); var integerParser = new IntegerParser <string>(); var conversion = new ElementToElementConversion <int>(); var variableName = "x"; var testPols = new List <UnivariatePolynomialNormalForm <int> >(); testPols.Add(TestsHelper.ReadUnivarPolynomial("x^2+1", integerNumber, integerParser, conversion, variableName)); testPols.Add(TestsHelper.ReadUnivarPolynomial("x^2+x+1", integerNumber, integerParser, conversion, variableName)); var rhoAlgorithm = new PollardRhoAlgorithm <int>( testPols, new ModularIntegerFieldFactory(), integerNumber); var factorizationTarget = new DecompositionFactorizationAlgorithm <int, int>( rhoAlgorithm, 1, integerNumber, integerNumber); var value = 72; var expected = new Dictionary <int, int>(); expected.Add(2, 3); expected.Add(3, 2); var actual = factorizationTarget.Run(value); CollectionAssert.AreEqual(expected, actual); }
public void InterpolationNormalFormMultiPointTest() { var pointContainer = new PointContainer2D <double, double>(); var interpolationPoints = new double[] { 0, 1, -2, 3, -4 }; for (int i = 0; i < interpolationPoints.Length; ++i) { pointContainer.Add(interpolationPoints[i], 0); } var doubleField = new DoubleField(); var interpolator = new UnivarNormalFromInterpolator <double, double>( pointContainer, "x", new DoubleToIntegerConversion(), doubleField, doubleField, doubleField); // Verifica os valores da interpolação. for (int i = 0; i < interpolationPoints.Length; ++i) { var actual = interpolator.Interpolate(interpolationPoints[i]); Assert.AreEqual(0, actual); } var interpolationPol = interpolator.InterpolatingPolynomial; var expected = TestsHelper.ReadUnivarPolynomial( "0", doubleField, new DoubleParser <string>(), new DoubleToIntegerConversion(), "x", true); Assert.AreEqual(expected, interpolationPol); pointContainer.Add(5, -1); pointContainer.Add(-6, 1); for (int i = 0; i < interpolationPoints.Length; ++i) { var actual = interpolator.Interpolate(interpolationPoints[i]); Assert.IsTrue(Math.Abs(actual - 0) < 0.000001); } var actualValue = interpolator.Interpolate(5); Assert.IsTrue(Math.Abs(actualValue + 1) < 0.000001); actualValue = interpolator.Interpolate(-6); Assert.IsTrue(Math.Abs(actualValue - 1) < 0.000001); }
public void ReplaceTest_ReplaceByMatrixWithMatrixAlgebra() { // Representação dos polinómios. var polynomText = "x^2 + 2*x + 1"; var variableName = "x"; var integerDomain = new IntegerDomain(); var integerToIntegerConv = new ElementToElementConversion <int>(); var integerParser = new IntegerParser <string>(); var fractionField = new FractionField <int>(integerDomain); var fractionFieldParser = new FieldDrivenExpressionParser <Fraction <int> >( new SimpleElementFractionParser <int>(integerParser, integerDomain), fractionField); var polynomial = TestsHelper.ReadUnivarPolynomial <Fraction <int> >( polynomText, fractionField, fractionFieldParser, new ElementFractionConversion <int>(integerDomain), variableName); // Leitura da matriz. var matrix = TestsHelper.ReadMatrix <Fraction <int> >( 2, 2, "[[1/2+1/3,1/2-1/3],[1/5+1/4,1/5-1/4]]", (i, j) => new ArrayMathMatrix <Fraction <int> >(i, j), fractionFieldParser); var matrixAlgebra = new GeneralMatrixAlgebra <Fraction <int> >( 2, new ArrayMathMatrixFactory <Fraction <int> >(), fractionField); var actual = polynomial.Replace(matrix, matrixAlgebra); var expected = TestsHelper.ReadMatrix <Fraction <int> >( 2, 2, "[[1237/360,167/360],[501/400,391/400]]", (i, j) => new ArrayMathMatrix <Fraction <int> >(i, j), fractionFieldParser); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { Assert.AreEqual(expected[i, j], actual[i, j]); } } }
public void ReplaceTest_ReplaceByFraction() { // Representação dos polinómios. var polynomText = "x^5+2*x^4+3*x^3+4*x^2+5*x+6"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); // Estabelece os conversores. var integerToIntegerConv = new ElementToElementConversion <int>(); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); var fractionField = new FractionField <int>(integerDomain); var integerFractionAddOp = new ElementFractionAddOper <int>(integerDomain); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, integerDomain, integerParser, integerToIntegerConv, variableName); var fractionValues = new Fraction <int>[] { new Fraction <int>(0, 1, integerDomain), new Fraction <int>(1, 1, integerDomain), new Fraction <int>(1, 2, integerDomain), new Fraction <int>(1, 3, integerDomain) }; var fractionExpectedValues = new Fraction <int>[] { new Fraction <int>(6, 1, integerDomain), new Fraction <int>(21, 1, integerDomain), new Fraction <int>(321, 32, integerDomain), new Fraction <int>(2005, 243, integerDomain) }; for (int i = 0; i < fractionValues.Length; ++i) { var integerActualValue = integerPolynomial.Replace( fractionValues[i], integerFractionAddOp, fractionField); Assert.AreEqual(fractionExpectedValues[i], integerActualValue); } }
public void GetRootPowerSumsTest_IntegerFraction() { // Representação dos polinómios. var polynomText = "(x-3)*(x-2)^2*(x+1)^3"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); // Estabelece o corpo responsável pelas operações sobre as fracções. var fractionField = new FractionField <int>(integerDomain); // Estabelece os conversores. var integerToFractionConversion = new ElementFractionConversion <int>(integerDomain); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); // Estabelece o leitor de fracções. var fractionParser = new ElementFractionParser <int>(integerParser, integerDomain); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, fractionField, fractionParser, integerToFractionConversion, variableName); var integerFractionExpectedVector = new ArrayVector <Fraction <int> >(6); integerFractionExpectedVector[0] = new Fraction <int>(4, 1, integerDomain); integerFractionExpectedVector[1] = new Fraction <int>(20, 1, integerDomain); integerFractionExpectedVector[2] = new Fraction <int>(40, 1, integerDomain); integerFractionExpectedVector[3] = new Fraction <int>(116, 1, integerDomain); integerFractionExpectedVector[4] = new Fraction <int>(304, 1, integerDomain); integerFractionExpectedVector[5] = new Fraction <int>(860, 1, integerDomain); var integerFractionActualVector = integerPolynomial.GetRootPowerSums( fractionField, new SparseDictionaryMathVectorFactory <Fraction <int> >()); Assert.AreEqual( integerFractionExpectedVector.Length, integerFractionActualVector.Length, "Vector lengths aren't equal."); for (int i = 0; i < integerFractionActualVector.Length; ++i) { Assert.AreEqual(integerFractionExpectedVector[i], integerFractionActualVector[i]); } }
public void RunTest() { var mainPolText = "x^3+10*x^2-432*x+5040"; var firstFactorText = "x"; var secondFactorText = "x^2-2"; var variableName = "x"; var prime = 5; var integerDomain = new IntegerDomain(); var integerParser = new IntegerParser <string>(); var integerConversion = new ElementToElementConversion <int>(); var mainPol = TestsHelper.ReadUnivarPolynomial( mainPolText, integerDomain, integerParser, integerConversion, variableName); var firstFactor = TestsHelper.ReadUnivarPolynomial( firstFactorText, integerDomain, integerParser, integerConversion, variableName); var secondFactor = TestsHelper.ReadUnivarPolynomial( secondFactorText, integerDomain, integerParser, integerConversion, variableName); // Testa o levantamento linear. var linearLift = new LinearLiftAlgorithm <int>( new ModularSymmetricIntFieldFactory(), new UnivarPolEuclideanDomainFactory <int>(), integerDomain); var liftingStatus = new LinearLiftingStatus <int>(mainPol, firstFactor, secondFactor, prime); var result = linearLift.Run(liftingStatus, 3); Assert.AreEqual(625, liftingStatus.LiftedFactorizationModule); var expected = liftingStatus.UFactor.Multiply(liftingStatus.WFactor, new ModularIntegerField(625)); var actual = mainPol.ApplyFunction(coeff => this.GetSymmetricRemainder(coeff, 625), integerDomain); Assert.AreEqual(expected, actual); }
public void RunTest_TestFactors2() { var polText = "x^3+2"; var variableName = "x"; var prime = 5; var integerDomain = new IntegerDomain(); var integerParser = new IntegerParser <string>(); var integerConversion = new ElementToElementConversion <int>(); // Faz a leitura do polinómio. var pol = TestsHelper.ReadUnivarPolynomial( polText, integerDomain, integerParser, integerConversion, variableName); // Testa os factores. var integerModule = new ModularIntegerField(prime); var finiteFieldPolAlg = new FiniteFieldPolFactorizationAlgorithm <int>( new DenseCondensationLinSysAlgorithm <int>(integerModule), integerDomain); var result = finiteFieldPolAlg.Run(pol, integerModule); var factorsEnumerator = result.Factors.GetEnumerator(); if (factorsEnumerator.MoveNext()) { var expected = factorsEnumerator.Current; while (factorsEnumerator.MoveNext()) { expected = expected.Multiply(factorsEnumerator.Current, integerModule); } expected = expected.Multiply(result.IndependentCoeff, integerModule); Assert.AreEqual(expected, pol.ApplyFunction(coeff => this.GetSymmetricRemainder(coeff, prime), integerModule)); } else { Assert.Fail("At least the main polynomial may be regarded as a factor."); } }
public void RunTest_BigIntegerMatrix() { // A leitura é realizada por colunas. var matrixText = "[[100000,1001,20005], [32534,4245341,56134513451], [21346136,1134613,1136135613]]"; var integerDomain = new BigIntegerDomain(); var variableName = "x"; var integerParser = new BigIntegerParser <string>(); var conversion = new BigIntegerToIntegerConversion(); var matrix = TestsHelper.ReadMatrix <BigInteger>( 3, 3, matrixText, (i, j) => new ArraySquareMathMatrix <BigInteger>(i), integerParser); var fastDivFreeCharacPolAlg = new FastDivisionFreeCharPolynomCalculator <BigInteger>(variableName, integerDomain); var expected = TestsHelper.ReadUnivarPolynomial("1*x^3+-1140480954*x^2-58754054577367644*x+4689162494877443109176", integerDomain, integerParser, conversion, variableName); var actual = fastDivFreeCharacPolAlg.Run(matrix as ISquareMathMatrix <BigInteger>); Assert.AreEqual(expected, actual); }
public void RunTest_IntegerMatrix() { // A leitura é realizada por colunas. var matrixText = "[[1,-1,2], [3,4,5], [2,1,1]]"; var integerDomain = new IntegerDomain(); var variableName = "x"; var integerParser = new IntegerParser <string>(); var conversion = new ElementToElementConversion <int>(); var matrix = TestsHelper.ReadMatrix <int>( 3, 3, matrixText, (i, j) => new ArraySquareMathMatrix <int>(i), integerParser, true); var fastDivFreeCharacPolAlg = new FastDivisionFreeCharPolynomCalculator <int>(variableName, integerDomain); var expected = TestsHelper.ReadUnivarPolynomial("x^3-6*x^2+3*x+18", integerDomain, integerParser, conversion, variableName); var actual = fastDivFreeCharacPolAlg.Run(matrix as ISquareMathMatrix <int>); Assert.AreEqual(expected, actual); }
public void GetRootPowerSumsTest_Integer() { // Representação dos polinómios. var polynomText = "(x-3)*(x-2)^2*(x+1)^3"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); // Estabelece os conversores. var integerToIntegerConv = new ElementToElementConversion <int>(); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerExpectedVector = new ArrayVector <int>(6); integerExpectedVector[0] = 4; integerExpectedVector[1] = 20; integerExpectedVector[2] = 40; integerExpectedVector[3] = 116; integerExpectedVector[4] = 304; integerExpectedVector[5] = 860; var integerActualVector = integerPolynomial.GetRootPowerSums(integerDomain); Assert.AreEqual(integerExpectedVector.Length, integerActualVector.Length, "Vector lengths aren't equal."); for (int i = 0; i < integerActualVector.Length; ++i) { Assert.AreEqual(integerExpectedVector[i], integerActualVector[i]); } }
public void GetRootPowerSumsTest() { // Representação dos polinómios. var polynomText = "(x-3)*(x-2)^2*(x+1)^3"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); // Estabelece o corpo responsável pelas operações sobre as fracções. var fractionField = new FractionField <int>(integerDomain); // Estabelece os conversores. var integerToFractionConversion = new ElementFractionConversion <int>(integerDomain); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); // Estabelece o leitor de fracções. var fractionParser = new ElementFractionParser <int>(integerParser, integerDomain); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, fractionField, fractionParser, integerToFractionConversion, variableName); var number = 10; var roots = new int[] { 3, 2, 2, -1, -1, -1 }; var powerRoots = new int[] { 3, 2, 2, -1, -1, -1 }; var integerFractionExpectedVector = new ArrayVector <Fraction <int> >(number); // Primeiro cálculo var sum = powerRoots[0]; for (int i = 1; i < powerRoots.Length; ++i) { sum += powerRoots[i]; } integerFractionExpectedVector[0] = new Fraction <int>(sum, 1, integerDomain); for (int i = 1; i < number; ++i) { for (int j = 0; j < roots.Length; ++j) { powerRoots[j] *= roots[j]; } sum = powerRoots[0]; for (int j = 1; j < powerRoots.Length; ++j) { sum += powerRoots[j]; } integerFractionExpectedVector[i] = new Fraction <int>(sum, 1, integerDomain); } var integerFractionActualVector = integerPolynomial.GetRootPowerSums( number, fractionField, new SparseDictionaryMathVectorFactory <Fraction <int> >()); Assert.AreEqual( integerFractionExpectedVector.Length, integerFractionActualVector.Length, "Vector lengths aren't equal."); for (int i = 0; i < integerFractionActualVector.Length; ++i) { Assert.AreEqual(integerFractionExpectedVector[i], integerFractionActualVector[i]); } }
public void GetPolynomialDerivativeTest_SimpleInteger() { // Representação dos polinómios. var polynomText = "x^1000-2*x^550+1000*x^10+50"; var polDerivativeText = "1000*x^999-1100*x^549+10000*x^9"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Estabelece os conversores. var integerToIntegerConv = new ElementToElementConversion <int>(); var integerToLongConv = new LongToIntegerConversion(); var integerToBigIntegerConvsersion = new BigIntegerToIntegerConversion(); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerActualDerivative = integerPolynomial.GetPolynomialDerivative(integerDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(integerExpectedPolynomial, integerActualDerivative); // Estabelece os polinómios. var longPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, longDomain, longParser, integerToLongConv, variableName); var longExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, longDomain, longParser, integerToLongConv, variableName); var longActualDerivative = longPolynomial.GetPolynomialDerivative(longDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(longExpectedPolynomial, longActualDerivative); // Estabelece os polinómios. var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, bigIntegerDomain, bigIntegerParser, integerToBigIntegerConvsersion, variableName); var bigIntegerExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, bigIntegerDomain, bigIntegerParser, integerToBigIntegerConvsersion, variableName); var bigIntegerActualDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(bigIntegerExpectedPolynomial, bigIntegerActualDerivative); }
public void GetPolynomialDerivativeTest_IntegerMatrix() { // Os valores a serem lidos var polynomialText = "[[1,2],[3,4]]*x^2-[[1,0],[0,1]]*x+[[7,6],[9,8]]"; var polynomialDerivativeText = "[[2,4],[6,8]]*x+[[-1,0],[0,-1]]"; var variableName = "x"; var arrayDelimiters = new Dictionary <string, string>(); arrayDelimiters.Add("left_bracket", "right_bracket"); // Os domínios responsáveis sobre as operações sobre os inteiros. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Os leitore sde inteiros var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // As fábricas responsáveis pela instanciação de matrizes var integerSquareArrayMatrixfactory = new ArraySquareMatrixFactory <int>(); var longSquareArrayMatrixFactory = new ArraySquareMatrixFactory <long>(); var bigIntegerSquareArrayMatrixfactory = new ArraySquareMatrixFactory <BigInteger>(); // Os anéis de matrizes var integerGenericMatrixRing = new GeneralMatrixRing <int>( 2, integerSquareArrayMatrixfactory, integerDomain); var longGenericMatrixRing = new GeneralMatrixRing <long>( 2, longSquareArrayMatrixFactory, longDomain); var bigIntegerGenericMatrixRing = new GeneralMatrixRing <BigInteger>( 2, bigIntegerSquareArrayMatrixfactory, bigIntegerDomain); // Os objectos responsáveis pela conversão entre os coeficientes e o grau (inteiro) var integerMatrixConversion = new CantConvertConversion <int, IMatrix <int> >(); var longMatrixConversion = new CantConvertConversion <int, IMatrix <long> >(); var bigIntegerMatrixConversion = new CantConvertConversion <int, IMatrix <BigInteger> >(); var integerMatrixConfigParser = new ConfigMatrixParser <int, IMatrix <int> >( integerParser, 2, 2, (i, j) => integerSquareArrayMatrixfactory.CreateMatrix(i, j)); integerMatrixConfigParser.SeparatorSymbType = "comma"; integerMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); integerMatrixConfigParser.AddBlanckSymbolType("blancks"); var longMatrixConfigParser = new ConfigMatrixParser <long, IMatrix <long> >( longParser, 2, 2, (i, j) => longSquareArrayMatrixFactory.CreateMatrix(i, j)); longMatrixConfigParser.SeparatorSymbType = "comma"; longMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); longMatrixConfigParser.AddBlanckSymbolType("blancks"); var bigIntegerMatrixConfigParser = new ConfigMatrixParser <BigInteger, IMatrix <BigInteger> >( bigIntegerParser, 2, 2, (i, j) => bigIntegerSquareArrayMatrixfactory.CreateMatrix(i, j)); bigIntegerMatrixConfigParser.SeparatorSymbType = "comma"; bigIntegerMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); bigIntegerMatrixConfigParser.AddBlanckSymbolType("blancks"); // Leitura dos polinómios e subsequente teste. var integerPolynomial = TestsHelper.ReadUnivarPolynomial <IMatrix <int> >( polynomialText, integerGenericMatrixRing, integerMatrixConfigParser, integerMatrixConversion, variableName, arrayDelimiters); var integerExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, integerGenericMatrixRing, integerMatrixConfigParser, integerMatrixConversion, variableName, arrayDelimiters, true); var integerActualDerivative = integerPolynomial.GetPolynomialDerivative(integerGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <int> >(integerGenericMatrixRing).Equals(integerExpectedDerivative, integerActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); var longPolynomial = TestsHelper.ReadUnivarPolynomial( polynomialText, longGenericMatrixRing, longMatrixConfigParser, longMatrixConversion, variableName, arrayDelimiters); var longExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, longGenericMatrixRing, longMatrixConfigParser, longMatrixConversion, variableName, arrayDelimiters, true); var longActualDerivative = longPolynomial.GetPolynomialDerivative(longGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <long> >(longGenericMatrixRing).Equals(longExpectedDerivative, longActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomialText, bigIntegerGenericMatrixRing, bigIntegerMatrixConfigParser, bigIntegerMatrixConversion, variableName, arrayDelimiters); var bigIntegerExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, bigIntegerGenericMatrixRing, bigIntegerMatrixConfigParser, bigIntegerMatrixConversion, variableName, arrayDelimiters, true); var bigIntegerActualDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <BigInteger> >( bigIntegerGenericMatrixRing).Equals(bigIntegerExpectedDerivative, bigIntegerActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); }
public void GetPolynomialDerivativeTest_IntegerPolynomialAsCoefficients() { var polynomialText = "(y^2+y+1)*x^3-2*x^2*y+x*(y^5-3)+4"; var polynomialDerivativeText = "3*(y^2+y+1)*x^2-4*y*x+y^5-3"; var variableName = "x"; var coeffsVariableName = "y"; // Os domínios responsáveis pelas operações sobre os inteiros. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Os leitore sde inteiros var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // Definição das conversões. var integerConversion = new ElementToElementConversion <int>(); var longConversion = new LongToIntegerConversion(); var bigIntegerConversion = new BigIntegerToIntegerConversion(); var integerPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <int>( coeffsVariableName, integerConversion, integerDomain); var longPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <long>( coeffsVariableName, longConversion, longDomain); var bigIntegerPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <BigInteger>( coeffsVariableName, bigIntegerConversion, bigIntegerDomain); // Definição dos anéis polinomiais. var integerPolynomialRing = new UnivarPolynomRing <int>(coeffsVariableName, integerDomain); var longPolynomialRing = new UnivarPolynomRing <long>(coeffsVariableName, longDomain); var bigIntegerPolynomialRing = new UnivarPolynomRing <BigInteger>(coeffsVariableName, bigIntegerDomain); // Definição dos leitores polinomiais. var integerPolynomialParser = new UnivarPolNormalFormParser <int>( coeffsVariableName, integerConversion, integerParser, integerDomain); var longPolynomialParser = new UnivarPolNormalFormParser <long>( coeffsVariableName, longConversion, longParser, longDomain); var bigIntegerPolynomialParser = new UnivarPolNormalFormParser <BigInteger>( coeffsVariableName, bigIntegerConversion, bigIntegerParser, bigIntegerDomain); // Definição dos testes. var integerPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <int> >( polynomialText, integerPolynomialRing, integerPolynomialParser, integerPolConvertion, variableName); var integerExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <int> >( polynomialDerivativeText, integerPolynomialRing, integerPolynomialParser, integerPolConvertion, variableName); var integerActualPlynomial = integerPolynomial.GetPolynomialDerivative(integerPolynomialRing); Assert.AreEqual(integerExpectedPol, integerActualPlynomial); var longPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <long> >( polynomialText, longPolynomialRing, longPolynomialParser, longPolConvertion, variableName); var longExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <long> >( polynomialDerivativeText, longPolynomialRing, longPolynomialParser, longPolConvertion, variableName); var longActualPlynomial = longPolynomial.GetPolynomialDerivative(longPolynomialRing); Assert.AreEqual(longExpectedPol, longActualPlynomial); var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <BigInteger> >( polynomialText, bigIntegerPolynomialRing, bigIntegerPolynomialParser, bigIntegerPolConvertion, variableName); var bigIntegerExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <BigInteger> >( polynomialDerivativeText, bigIntegerPolynomialRing, bigIntegerPolynomialParser, bigIntegerPolConvertion, variableName); var bigIntegerActualPlynomial = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerPolynomialRing); Assert.AreEqual(bigIntegerExpectedPol, bigIntegerExpectedPol); }
public void PowerTest_IntegerPolynomial() { var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); var variableName = "x"; var intPolDomain = new UnivarPolynomRing <int>(variableName, integerDomain); var longPolDomain = new UnivarPolynomRing <long>(variableName, longDomain); var bigIntegerPolDomain = new UnivarPolynomRing <BigInteger>(variableName, bigIntegerDomain); // Leitores var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); var integerConversion = new ElementToElementConversion <int>(); var longToIntegerConversion = new LongToIntegerConversion(); var bigIntegerToIntegerConversion = new BigIntegerToIntegerConversion(); var intPowers = new int[3] { 2, 3, 4 }; var longPowers = new long[3] { 2, 3, 4 }; var bigIntPowers = new BigInteger[3] { 2, 3, 4 }; var polynomialsTexts = new string[3] { "x^3-2*x^2+3*x-1", "2*x^2+4*x+4", "x+1" }; var expectedPolinomialsTexts = new string[3] { "x^6-4*x^5+10*x^4-14*x^3+13*x^2-6*x+1", "8*x^6+48*x^5+144*x^4+256*x^3+288*x^2+192*x+64", "x^4+4*x^3+6*x^2+4*x+1" }; // Coeficientes inteiros. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], intPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes longos. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], longPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes correspondentes a inteiros de precisão arbitrária. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], bigIntegerPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } }