public void ExtractTermsContainingNthRoot( BigInteger radicand, int index, out Polynomial p_reduced, out Polynomial p_extract) { p_reduced = Polynomial.Zero; p_extract = Polynomial.Zero; for (int i = 0; i < Terms.Length; i++) { var coeff = Terms[i].Coefficient; RadicalSum coeff_reduced = coeff; RadicalSum coeff_target = RadicalSum.Zero; for (int j = 0; j < coeff.Radicals.Length; j++) { if (coeff.Radicals[j].Index == index) { if (coeff.Radicals[j].Radicand % radicand == 0) { coeff_target += coeff.Radicals[j]; coeff_reduced -= coeff.Radicals[j]; } } } p_reduced += new PolynomialTerm(coeff_reduced, Terms[i].Degree); p_extract += new PolynomialTerm(coeff_target, Terms[i].Degree); } }
public void ConversionTests() { // [3*sqrt(2) + (7/2)*sqrt(3)] / [(-9/3)*sqrt(2) + (-14/4)*sqrt(3)] = -1 var b11 = new Radical(3, 2); var b12 = new Radical(new Rational(7, 2), 3); var b13 = new Radical(new Rational(-9, 3), 2); var b14 = new Radical(new Rational(-14, 4), 3); var c11 = new RadicalSum(new Radical[2] { b11, b12 }); var c12 = new RadicalSum(new Radical[2] { b13, b14 }); var cr1 = new RadicalSumRatio(c11, c12); bool actual11 = cr1.IsRational; var actual12 = cr1.ToRational(); bool expected11 = true; var expected12 = new Rational(-1); // (3*sqrt(2)) / ((5/3)*sqrt(3)) = (9/5)*sqrt(2/3) = (3/5)*sqrt(6) var b21 = new RadicalSumRatio(3, 2); var b22 = new RadicalSumRatio(new Rational(5, 3), 3); var b23 = b21 / b22; var actual21 = b23.IsRational; var actual22 = b23.ToDouble(); var expected21 = false; double expected22 = 1.4696938456699068589183704448235; Assert.Equal(expected11, actual11); Assert.Equal(expected12, actual12); Assert.Equal(expected21, actual21); Assert.Equal(expected22.ToString("0.000000"), actual22.ToString("0.000000")); }
public void ConstructorTests() { // (3/4) * sqrt(12) // = (2*3/4) * sqrt(3) // = (3/2) * sqrt(3) var actual1 = new RadicalSum(new Rational(3, 4), 12); var expected1 = new RadicalSum(new Rational(3, 2), 3); // sqrt(2/9) = (1/3)sqrt(2) var actual2 = new RadicalSum(new Rational(2, 9)); var expected2 = new RadicalSum(new Rational(1, 3), 2); // sqrt(1/2) = (1/2)sqrt(2) var actual3 = new RadicalSum(new Rational(1, 2)); var expected3 = new RadicalSum(new Rational(1, 2), 2); // 0 = 0 RadicalSum actual41 = 0; var actual42 = new RadicalSum(0); var actual43 = new RadicalSum(0, 0); var actual44 = new RadicalSum(); var actual45 = new RadicalSum(3, 0); var actual46 = new RadicalSum(0, 5); var expected4 = RadicalSum.Zero; // 1 = 1 RadicalSum actual51 = 1; var actual52 = new RadicalSum(1, 1); var actual53 = new RadicalSum(1); var expected5 = RadicalSum.One; // assert Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual41); Assert.Equal(expected4, actual42); Assert.Equal(expected4, actual43); Assert.Equal(expected4, actual44); Assert.Equal(expected4, actual45); Assert.Equal(expected4, actual46); Assert.True(actual41.IsZero); Assert.True(actual42.IsZero); Assert.True(actual43.IsZero); Assert.True(actual44.IsZero); Assert.True(actual45.IsZero); Assert.True(actual46.IsZero); Assert.Equal(expected5, actual51); Assert.Equal(expected5, actual52); Assert.Equal(expected5, actual53); Assert.True(actual51.IsOne); Assert.True(actual52.IsOne); Assert.True(actual53.IsOne); }
public RadicalSum EvaluateAt(RadicalSum value) { RadicalSum result = RadicalSum.Zero; for (int i = 0; i < Terms.Length; i++) { RadicalSum termValue = Terms[i].Coefficient; for (int j = 0; j < Terms[i].Degree; j++) { termValue *= value; } result += termValue; } return(result); }
public PolynomialTerm(RadicalSum coefficient, int degree) { if (degree < 0) { throw new ArgumentException("Degree cannot be negative", nameof(degree)); } _coefficient = coefficient; if (coefficient == RadicalSum.Zero) { _degree = 0; } else { _degree = degree; } }
public static Polynomial Pow(Polynomial value, int exponent) { // Naive implementation is SLOW // Attempt to make more efficient using multinomial theorem: // https://en.wikipedia.org/wiki/Multinomial_theorem // Replace x1, x2, ..., xm with polynomial terms X^0, X^1, ..., X^m-1 // Need to partition exponent as a sum of at most value.Terms.Length === m integers // Pre-calculate powers of each term's coefficient in the polynomial, and cache them // Item1: term index // Item2: power var polynomialTermCoefficientPowers = new Dictionary <Tuple <int, int>, RadicalSum>(); for (int termIndex = 0; termIndex < value.Terms.Length; termIndex++) { for (int power = 0; power <= exponent; power++) { var key = new Tuple <int, int>(termIndex, power); var termPower = RadicalSum.Pow(value.Terms[termIndex].Coefficient, power); polynomialTermCoefficientPowers.Add(key, termPower); } } // Get the unique partitions first, along with the multinomial coefficient associated with them // These correspond to unique integers k1, k2, ..., km such that k1 + k2 + ... + km = n var maxTerms = Math.Min(exponent, value.Terms.Length); var degreePartitions = Combinatorics.IntegerPartition.GetIntegerPartitions(exponent, maxTerms); var degreePartitionsWithMultinomialCoefficient = degreePartitions .Select(p => new Tuple <Combinatorics.IntegerPartition, BigInteger>( p, GetMultinomialCoefficient(p.Values, exponent))) .ToList(); // From the unique partitions, get all permutations // These correspond to all possible k1 + k2 + ... + km = n in the multinomial theorem // For each permutation, calculate the degree in X; this will be used to help group terms later // Item1: permutation // Item2: multinomial coefficient // Item3: degree in X (e.g., X^2, X^3, etc) var termDescriptions = new List <Tuple <Combinatorics.Permutation, BigInteger, int> >(); foreach (Tuple <Combinatorics.IntegerPartition, BigInteger> partition in degreePartitionsWithMultinomialCoefficient) { var permutations = Combinatorics.Permutation.ArrangeInSlots(partition.Item1.Values, value.Terms.Length, false); foreach (Combinatorics.Permutation p in permutations) { var degreeX = GetPermutationDegree(p.Values, value); var termDescription = new Tuple <Combinatorics.Permutation, BigInteger, int>( p, partition.Item2, degreeX); termDescriptions.Add(termDescription); } } // Start multithreading block // Initialize dictionary of terms for each degree in X var degreeRadicalSumDictionary = new Dictionary <int, List <RadicalSum> >(); int processCount = termDescriptions.Count; var doneEvent = new ManualResetEvent(false); for (int termDescriptionIndex = 0; termDescriptionIndex < termDescriptions.Count; termDescriptionIndex++) { ThreadPool.QueueUserWorkItem(new WaitCallback((obj) => { var termDescription = (Tuple <Combinatorics.Permutation, BigInteger, int>)obj; // Calculate term for this permutation in multinomial formula var coefficient = RadicalSum.One; for (int i = 0; i < value.Terms.Length; i++) { // term index, coefficient degree var key = new Tuple <int, int>(i, termDescription.Item1.Values[i]); var polynomialTermCoefficientPower = polynomialTermCoefficientPowers[key]; coefficient *= polynomialTermCoefficientPower; } coefficient *= termDescription.Item2; lock (degreeRadicalSumDictionary) { if (degreeRadicalSumDictionary.ContainsKey(termDescription.Item3)) { var existingTermList = degreeRadicalSumDictionary[termDescription.Item3]; existingTermList.Add(coefficient); } else { var termList = new List <RadicalSum>(); termList.Add(coefficient); degreeRadicalSumDictionary.Add(termDescription.Item3, termList); } } if (Interlocked.Decrement(ref processCount) == 0) { doneEvent.Set(); } }), termDescriptions[termDescriptionIndex]); } doneEvent.WaitOne(); // Combine terms for each degree in X var polynomialTerms = new List <PolynomialTerm>(); doneEvent = new ManualResetEvent(false); processCount = degreeRadicalSumDictionary.Count; foreach (KeyValuePair <int, List <RadicalSum> > kvp in degreeRadicalSumDictionary) { ThreadPool.QueueUserWorkItem(new WaitCallback((obj) => { var key = (KeyValuePair <int, List <RadicalSum> >)obj; // Combine terms var coefficient = RadicalSum.Zero; foreach (RadicalSum radicalSum in key.Value) { coefficient += radicalSum; } var term = new PolynomialTerm(coefficient, key.Key); lock (polynomialTerms) { polynomialTerms.Add(term); } if (Interlocked.Decrement(ref processCount) == 0) { doneEvent.Set(); } }), kvp); } doneEvent.WaitOne(); var result = new Polynomials.Polynomial(polynomialTerms.OrderBy(p => p.Degree).ToArray()); return(result); }
public void AdditionTests() { // sqrt(2) + sqrt(3) var b11 = new RadicalSum(1, 2); var b12 = new RadicalSum(1, 3); var actual1 = b11 + b12; var expected1 = new RadicalSum(new Radical[2] { new Radical(1, 2), new Radical(1, 3) }); // sqrt(2) + 2 * sqrt(2) = 3 * sqrt(2) var b21 = new RadicalSum(1, 2); var b22 = new RadicalSum(2, 2); var actual2 = b21 + b22; var expected2 = new RadicalSum(new Radical(3, 2)); // 5*sqrt(27) + 7*sqrt(12) = 15*sqrt(3) + 14*sqrt(3) = 29*sqrt(3) var b31 = new RadicalSum(5, 27); var b32 = new RadicalSum(7, 12); var actual3 = b31 + b32; var expected3 = new RadicalSum(new Radical(29, 3)); // 3*sqrt(2) + 2*sqrt(3) var b41 = new RadicalSum(3, 2); var b42 = new RadicalSum(2, 3); var actual4 = b41 + b42; var expected4 = new RadicalSum(new Radical[2] { new Radical(3, 2), new Radical(2, 3) }); // 2*sqrt(2) + 5*sqrt(28) + sqrt(1/2) + 3 + sqrt(7/9) + 11*sqrt(4) = 25 + (5/2)sqrt(2) + (31/3)*sqrt(7) var b51 = new RadicalSum(2, 2); var b52 = new RadicalSum(5, 28); var b53 = new RadicalSum(new Rational(1, 2)); var b54 = new RadicalSum(3, 1); var b55 = new RadicalSum(new Rational(7, 9)); var b56 = new RadicalSum(11, 4); var actual5 = b51 + b52 + b53 + b54 + b55 + b56; var expected5 = new RadicalSum(new Radical[3] { new Radical(25, 1), new Radical(new Rational(5, 2), 2), new Radical(new Rational(31, 3), 7) }); // (3/2)*sqrt(5) + 0 = (3/2)*sqrt(5) // 0 + (3/2)*sqrt(5) = (3/2)*sqrt(5) var b61 = new RadicalSum(new Rational(3, 2), 5); var b62 = RadicalSum.Zero; var actual61 = b61 + b62; var actual62 = b62 + b61; var expected6 = new RadicalSum(new Radical(new Rational(3, 2), 5)); // (3/2)*sqrt(5) + (-3/2)*sqrt(5) = 0 var b71 = new RadicalSum(new Rational(3, 2), 5); var b72 = new RadicalSum(new Rational(-3, 2), 5); var actual7 = b71 + b72; var expected7 = RadicalSum.Zero; Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected7, actual7); }
public PolynomialTerm(RadicalSum constant) : this(constant, 0) { }
public void MultiplicationTests() { // (3*sqrt(2)) * ((5/3)*sqrt(3)) = (15/3)*sqrt(6) = 5*sqrt(6) var b11 = new RadicalSum(3, 2); var b12 = new RadicalSum(new Rational(5, 3), 3); var actual1 = b11 * b12; var expected1 = new RadicalSum(5, 6); // 11 * sqrt(4/9) = 22/3 var b21 = new RadicalSum(11, 1); var b22 = new RadicalSum(new Rational(4, 9)); var actual2 = b21 * b22; var expected2 = new RadicalSum(new Rational(22, 3), 1); // 11 * sqrt(4/9) = 22/3 var b31 = 11; var b32 = new RadicalSum(new Rational(4, 9)); var actual31 = b31 * b32; var actual32 = b32 * b31; var expected3 = new RadicalSum(new Rational(22, 3), 1); // [(3/2)*sqrt(2) - (7/3)*sqrt(5) + (1/3)*sqrt(2) - (7/5)*sqrt(5)] * (11/4)*sqrt(2) // = [(11/6)*sqrt(2) - (56/15)*sqrt(5)] * (11/4)*sqrt(2) // = (121/24)*2 - (154/15)*sqrt(10) // = (121/12) - (56/15)*sqrt(10) var b41 = new RadicalSum(new Rational(3, 2), 2); var b42 = new RadicalSum(new Rational(7, 3), 5); var b43 = new RadicalSum(new Rational(1, 3), 2); var b44 = new RadicalSum(new Rational(7, 5), 5); var b45 = new RadicalSum(new Rational(11, 4), 2); var actual41 = (b41 - b42 + b43 - b44) * b45; var actual42 = b45 * (b41 - b42 + b43 - b44); var expected4 = new RadicalSum(new Radical[2] { new Radical(new Rational(121, 12), 1), new Radical(new Rational(-154, 15), 10) }); // (3/2)*sqrt(5) * 1 = (3/2)*sqrt(5) var b51 = new RadicalSum(new Rational(3, 2), 5); var b52 = new RadicalSum(1, 1); var b53 = 1; var b54 = new RadicalSum(1); var b55 = RadicalSum.One; var actual51 = b51 * b52; var actual52 = b51 * b53; var actual53 = b51 * b54; var actual54 = b51 * b55; var actual55 = b52 * b51; var actual56 = b53 * b51; var actual57 = b54 * b51; var actual58 = b55 * b51; var expected5 = new RadicalSum(new Rational(3, 2), 5); // (3/2)*sqrt(5) * -1 = (-3/2)*sqrt(5) var b61 = new RadicalSum(new Rational(3, 2), 5); var b62 = -RadicalSum.One; var b63 = -1; var b64 = new RadicalSum(-1, 1); var actual61 = b61 * b62; var actual62 = b61 * b63; var actual63 = b61 * b64; var actual64 = b62 * b61; var actual65 = b63 * b61; var actual66 = b64 * b61; var expected6 = new RadicalSum(new Rational(-3, 2), 5); // (3/2)*sqrt(5) * 0 = 0 var b71 = new RadicalSum(new Rational(3, 2), 5); var b72 = 0; var b73 = RadicalSum.Zero; var b74 = new RadicalSum(0); var b75 = new RadicalSum(0, 0); var actual71 = b71 * b72; var actual72 = b71 * b73; var actual73 = b71 * b74; var actual74 = b71 * b75; var actual75 = b72 * b71; var actual76 = b73 * b71; var actual77 = b74 * b71; var actual78 = b75 * b71; var expected7 = RadicalSum.Zero; // [(5/3)*sqrt(7) - (2/9)*sqrt(11) - 6*sqrt(13)] * [2*sqrt(6) - 3*sqrt(8)] // = (10/3)*sqrt(42) - (4/9)*sqrt(66) - 12*sqrt(78) - 5*sqrt(56) + (2/3)*sqrt(88) + 18*sqrt(104) // = (10/3)*sqrt(42) - 5*sqrt(56) - (4/9)*sqrt(66) - (34/3)*sqrt(88) + 18*sqrt(104) - 12*sqrt(78) // = -10*sqrt(14) + (4/3)*sqrt(22) + 36*sqrt(26) + (10/3)*sqrt(42) - (4/9)*sqrt(66) - 12*sqrt(78) var b81 = new RadicalSum(new Rational(5, 3), 7); var b82 = new RadicalSum(new Rational(2, 9), 11); var b83 = new RadicalSum(6, 13); var b84 = new RadicalSum(2, 6); var b85 = new RadicalSum(3, 8); var c81 = b81 - b82 - b83; var c82 = b84 - b85; var actual8 = c81 * c82; var expected8 = new RadicalSum(new Radical[6] { new Radical(-10, 14), new Radical(new Rational(4, 3), 22), new Radical(36, 26), new Radical(new Rational(10, 3), 42), new Radical(new Rational(-4, 9), 66), new Radical(-12, 78) }); Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual31); Assert.Equal(expected3, actual32); Assert.Equal(expected4, actual41); Assert.Equal(expected4, actual42); Assert.Equal(expected5, actual51); Assert.Equal(expected5, actual52); Assert.Equal(expected5, actual53); Assert.Equal(expected5, actual54); Assert.Equal(expected5, actual55); Assert.Equal(expected5, actual56); Assert.Equal(expected5, actual57); Assert.Equal(expected5, actual58); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected6, actual63); Assert.Equal(expected6, actual64); Assert.Equal(expected6, actual65); Assert.Equal(expected6, actual66); Assert.Equal(expected7, actual71); Assert.Equal(expected7, actual72); Assert.Equal(expected7, actual73); Assert.Equal(expected7, actual74); Assert.Equal(expected7, actual75); Assert.Equal(expected7, actual76); Assert.Equal(expected7, actual77); Assert.Equal(expected7, actual78); Assert.Equal(expected8, actual8); }
public void DivisionTests() { // (3*sqrt(2)) / ((5/3)*sqrt(3)) = (9/5)*sqrt(2/3) = (3/5)*sqrt(6) var b11 = new RadicalSum(3, 2); var b12 = new Radical(new Rational(5, 3), 3); var actual1 = b11 / b12; var expected1 = new RadicalSum(new Rational(3, 5), 6); // 11 / sqrt(4/9) = 33/2 var b21 = new RadicalSum(11, 1); var b22 = new Radical(new Rational(4, 9)); var actual2 = b21 / b22; var expected2 = new RadicalSum(new Rational(33, 2), 1); // sqrt(4/9) / 11 = 2/33 var b41 = new RadicalSum(new Rational(4, 9)); var b42 = 11; var actual4 = b41 / b42; var expected4 = new RadicalSum(new Rational(2, 33), 1); // [(3/2)*sqrt(2) - (7/3)*sqrt(5) + (1/3)*sqrt(2) - (7/5)*sqrt(5)] / (11/4)*sqrt(2) // = [(11/6)*sqrt(2) - (56/15)*sqrt(5)] / (11/4)*sqrt(2) // = (2/3) - (224/165)*sqrt(5/2) // = (2/3) - (112/165)*sqrt(10) var b51 = new RadicalSum(new Rational(3, 2), 2); var b52 = new RadicalSum(new Rational(7, 3), 5); var b53 = new RadicalSum(new Rational(1, 3), 2); var b54 = new RadicalSum(new Rational(7, 5), 5); var b55 = new Radical(new Rational(11, 4), 2); var actual5 = (b51 - b52 + b53 - b54) / b55; var expected5 = new RadicalSum(new Radical[2] { new Radical(new Rational(2, 3), 1), new Radical(new Rational(-112, 165), 10) }); // (3/2)*sqrt(5) / 1 = (3/2)*sqrt(5) var b61 = new RadicalSum(new Rational(3, 2), 5); var b62 = new Radical(1, 1); var b63 = 1; var b64 = new Radical(1); var b65 = Radical.One; var actual61 = b61 / b62; var actual62 = b61 / b63; var actual63 = b61 / b64; var actual64 = b61 / b65; var expected6 = new RadicalSum(new Rational(3, 2), 5); // (3/2)*sqrt(5) / -1 = (-3/2)*sqrt(5) var b71 = new RadicalSum(new Rational(3, 2), 5); var b72 = new Radical(-1, 1); var b73 = -1; var b74 = -Radical.One; var actual71 = b71 / b72; var actual72 = b71 / b73; var actual73 = b71 / b74; var expected7 = new RadicalSum(new Rational(-3, 2), 5); // 3*sqrt(2) + 2*sqrt(3) var b81 = new RadicalSum(3, 2); var b82 = new RadicalSum(2, 3); var s81 = b81 + b82; var rationalizer81 = RadicalSum.GetRationalizer(s81); var actual81 = s81 * rationalizer81; // sqrt(2) + sqrt(3) + sqrt(11) var b91 = new RadicalSum(1, 2); var b92 = new RadicalSum(1, 3); var b93 = new RadicalSum(1, 11); var s91 = b91 + b92 + b93; var rationalizer91 = RadicalSum.GetRationalizer(s91); var actual91 = s91 * rationalizer91; // 8*sqrt(6) - 3*sqrt(10) - 5*sqrt(12) + 2*sqrt(14) var b10_1 = new RadicalSum(8, 6); var b10_2 = new RadicalSum(-3, 10); var b10_3 = new RadicalSum(-5, 12); var b10_4 = new RadicalSum(2, 14); var s10_1 = b10_1 + b10_2 + b10_3 + b10_4; var rationalizer10_1 = RadicalSum.GetRationalizer(s10_1); var actual10_1 = s10_1 * rationalizer10_1; // [3*sqrt(2) + (7/2)*sqrt(3)] / [(-9/3)*sqrt(2) + (-14/4)*sqrt(3)] = -1 var b11_1 = new Radical(3, 2); var b11_2 = new Radical(new Rational(7, 2), 3); var b11_3 = new Radical(new Rational(-9, 3), 2); var b11_4 = new Radical(new Rational(-14, 4), 3); var c11_1 = new RadicalSum(new Radical[2] { b11_1, b11_2 }); var c11_2 = new RadicalSum(new Radical[2] { b11_3, b11_4 }); var actual11 = c11_1 / c11_2; var expected11 = -1; // Multiplicative inverse of sqrt(2) * Root[3](5) // Inverse: (10/17) + (-4/17)*Sqrt(2) + (4/17)*Root[3](5) + (5/17)*Root[3](25) + (-5/17)*Root[6](200) + (-2/17)*Root[6](5000) var b12_1 = Radical.Sqrt(2); var b12_2 = Radical.NthRoot(5, 3); var c12_1 = b12_1 + b12_2; var c12_2 = RadicalSum.GetRationalizer(c12_1); var actual12 = c12_1 * c12_2; var expected12 = RadicalSum.One; // Multiplicative inverse of sqrt(2) + root[3](3) var b13_1 = Radical.Sqrt(2); var b13_2 = Radical.NthRoot(3, 3); var c13_1 = b13_1 + b13_2; var c13_2 = RadicalSum.GetRationalizer(c13_1); var actual13 = c13_1 * c13_2; var expected13 = RadicalSum.One; // Group division: sqrt(7) / [sqrt(2) * root[3](5)] // = Sqrt(7) * [(10/17) + (-4/17)*Sqrt(2) + (4/17)*Root[3](5) + (5/17)*Root[3](25) + (-5/17)*Root[6](200) + (-2/17)*Root[6](5000)] // = (10/17)*Sqrt(7) + (-4/17)*Sqrt(14) + (4/17)*Root[6](8575) + (5/17)*Root[6](214375) + (-5/17)*Root[6](68600) + (-2/17)*Root[6](1715000) var b14_1 = Radical.Sqrt(7); var b14_2 = Radical.Sqrt(2); var b14_3 = Radical.NthRoot(5, 3); RadicalSum c14_1 = b14_1; var c14_2 = b14_2 + b14_3; var actual14 = RadicalSum.GroupDivide(c14_1, c14_2); var expected14 = ((Rational)10 / 17) * Radical.Sqrt(7) + ((Rational)(-4) / 17) * Radical.Sqrt(14) + ((Rational)4 / 17) * Radical.NthRoot(8575, 6) + ((Rational)5 / 17) * Radical.NthRoot(214375, 6) + ((Rational)(-5) / 17) * Radical.NthRoot(68600, 6) + ((Rational)(-2) / 17) * Radical.NthRoot(1715000, 6); //// sqrt(2) + sqrt(3) + sqrt(6) + root[3](3) + root[3](4) + root[6](2) + root[6](3) //// Warning: was not able to complete due to memory/cpu/time constraints //var b15_1 = Radical.Sqrt(2); //var b15_2 = Radical.Sqrt(3); //var b15_3 = Radical.Sqrt(6); //var b15_4 = Radical.NthRoot(3, 3); //var b15_5 = Radical.NthRoot(4, 3); //var b15_6 = Radical.NthRoot(2, 6); //var b15_7 = Radical.NthRoot(3, 6); //var c15_1 = b15_1 + b15_2 + b15_3 + b15_4 + b15_5 + b15_6 + b15_7; //var c15_2 = RadicalSum.GetRationalizer(c15_1); //var actual15 = c15_1 * c15_2; //var expected15 = RadicalSum.One; Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); //Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected6, actual63); Assert.Equal(expected6, actual64); Assert.Equal(expected7, actual71); Assert.Equal(expected7, actual72); Assert.Equal(expected7, actual73); Assert.True(actual81.IsRational); Assert.True(actual91.IsRational); Assert.True(actual10_1.IsRational); Assert.Equal(expected11, actual11); Assert.Equal(expected12, actual12); Assert.Equal(actual13, expected13); Assert.Equal(actual14, expected14); //Assert.Equal(actual15, expected15); }
public void MultiplicationTests() { // (3*sqrt(2)) * ((5/3)*sqrt(3)) = (15/3)*sqrt(6) = 5*sqrt(6) var b11 = new Radical(3, 2); var b12 = new Radical(new Rational(5, 3), 3); var actual1 = b11 * b12; var expected1 = new Radical(5, 6); // 11 * sqrt(4/9) = 22/3 var b21 = new Radical(11, 1); var b22 = new Radical(new Rational(4, 9)); var actual2 = b21 * b22; var expected2 = new Radical(new Rational(22, 3), 1); // 11 * sqrt(4/9) = 22/3 var b31 = 11; var b32 = new Radical(new Rational(4, 9)); var actual31 = b31 * b32; var actual32 = b32 * b31; var expected3 = new Radical(new Rational(22, 3), 1); // [(3/2)*sqrt(2) - (7/3)*sqrt(5) + (1/3)*sqrt(2) - (7/5)*sqrt(5)] * (11/4)*sqrt(2) // = [(11/6)*sqrt(2) - (56/15)*sqrt(5)] * (11/4)*sqrt(2) // = (121/24)*2 - (154/15)*sqrt(10) // = (121/12) - (56/15)*sqrt(10) var b41 = new Radical(new Rational(3, 2), 2); var b42 = new Radical(new Rational(7, 3), 5); var b43 = new Radical(new Rational(1, 3), 2); var b44 = new Radical(new Rational(7, 5), 5); var b45 = new Radical(new Rational(11, 4), 2); var actual41 = (b41 - b42 + b43 - b44) * b45; var actual42 = b45 * (b41 - b42 + b43 - b44); var expected4 = new RadicalSum(new Radical[2] { new Radical(new Rational(121, 12), 1), new Radical(new Rational(-154, 15), 10) }); // (3/2)*sqrt(5) * 1 = (3/2)*sqrt(5) var b51 = new Radical(new Rational(3, 2), 5); var b52 = new Radical(1, 1); var b53 = 1; var b54 = new Radical(1); var b55 = Radical.One; var actual51 = b51 * b52; var actual52 = b51 * b53; var actual53 = b51 * b54; var actual54 = b51 * b55; var actual55 = b52 * b51; var actual56 = b53 * b51; var actual57 = b54 * b51; var actual58 = b55 * b51; var expected5 = new Radical(new Rational(3, 2), 5); // (3/2)*sqrt(5) * -1 = (-3/2)*sqrt(5) var b61 = new Radical(new Rational(3, 2), 5); var b62 = -Radical.One; var b63 = -1; var b64 = new Radical(-1, 1); var actual61 = b61 * b62; var actual62 = b61 * b63; var actual63 = b61 * b64; var actual64 = b62 * b61; var actual65 = b63 * b61; var actual66 = b64 * b61; var expected6 = new Radical(new Rational(-3, 2), 5); // (3/2)*sqrt(5) * 0 = 0 var b71 = new Radical(new Rational(3, 2), 5); var b72 = 0; var b73 = Radical.Zero; var b74 = new Radical(0); var b75 = new Radical(0, 0); var actual71 = b71 * b72; var actual72 = b71 * b73; var actual73 = b71 * b74; var actual74 = b71 * b75; var actual75 = b72 * b71; var actual76 = b73 * b71; var actual77 = b74 * b71; var actual78 = b75 * b71; var expected7 = Radical.Zero; // (3/2)*sqrt(5) Inverse var b8_1 = new Radical((Rational)3 / 2, 5); var b8_2 = Radical.Invert(b8_1); var actual8 = b8_1 * b8_2; var expected8 = Radical.One; // Sqrt(2) * Root[3](5) = Root[6](2^3) * Root[6](5^2) // = Root[6](8*25) = Root[6](200) var b9_1 = new Radical(2); var b9_2 = Radical.NthRoot(5, 3); var actual9 = b9_1 * b9_2; var expected9 = new Radical(1, 200, 6); Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual31); Assert.Equal(expected3, actual32); Assert.Equal(expected4, actual41); Assert.Equal(expected4, actual42); Assert.Equal(expected5, actual51); Assert.Equal(expected5, actual52); Assert.Equal(expected5, actual53); Assert.Equal(expected5, actual54); Assert.Equal(expected5, actual55); Assert.Equal(expected5, actual56); Assert.Equal(expected5, actual57); Assert.Equal(expected5, actual58); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected6, actual63); Assert.Equal(expected6, actual64); Assert.Equal(expected6, actual65); Assert.Equal(expected6, actual66); Assert.Equal(expected7, actual71); Assert.Equal(expected7, actual72); Assert.Equal(expected7, actual73); Assert.Equal(expected7, actual74); Assert.Equal(expected7, actual75); Assert.Equal(expected7, actual76); Assert.Equal(expected7, actual77); Assert.Equal(expected7, actual78); Assert.Equal(expected8, actual8); Assert.Equal(expected9, actual9); }
public void SubtractionTests() { // sqrt(2) - sqrt(3) var b11 = new RadicalSum(1, 2); var b12 = new RadicalSum(1, 3); var actual1 = b11 - b12; var expected1 = new RadicalSum(new Radical[2] { new Radical(1, 2), new Radical(-1, 3) }); // sqrt(2) - 2 * sqrt(2) = -1 * sqrt(2) var b21 = new RadicalSum(1, 2); var b22 = new RadicalSum(2, 2); var actual2 = b21 - b22; var expected2 = new RadicalSum(new Radical(-1, 2)); // 5*sqrt(27) - 7*sqrt(12) = 15*sqrt(3) - 14*sqrt(3) = 1*sqrt(3) var b31 = new RadicalSum(5, 27); var b32 = new RadicalSum(7, 12); var actual3 = b31 - b32; var expected3 = new RadicalSum(new Radical(1, 3)); // 3*sqrt(2) - 2*sqrt(3) var b41 = new RadicalSum(3, 2); var b42 = new RadicalSum(2, 3); var actual4 = b41 - b42; var expected4 = new RadicalSum(new Radical[2] { new Radical(3, 2), new Radical(-2, 3) }); // 2*sqrt(2) + 5*sqrt(28) - sqrt(1/2) + 3 - sqrt(7/9) + 11*sqrt(4) = 25 + (3/2)sqrt(2) + (29/3)*sqrt(7) var b51 = new RadicalSum(2, 2); var b52 = new RadicalSum(5, 28); var b53 = new RadicalSum(new Rational(1, 2)); var b54 = new RadicalSum(3, 1); var b55 = new RadicalSum(new Rational(7, 9)); var b56 = new RadicalSum(11, 4); var actual5 = b51 + b52 - b53 + b54 - b55 + b56; var expected5 = new RadicalSum(new Radical[3] { new Radical(25, 1), new Radical(new Rational(3, 2), 2), new Radical(new Rational(29, 3), 7) }); // (3/2)*sqrt(5) - 0 = (3/2)*sqrt(5) var b61 = new RadicalSum(new Rational(3, 2), 5); var b62 = RadicalSum.Zero; var actual6 = b61 - b62; var expected6 = new RadicalSum(new Radical(new Rational(3, 2), 5)); // 0 - (3/2)*sqrt(5) = (-3/2)*sqrt(5) var b71 = RadicalSum.Zero; var b72 = new RadicalSum(new Rational(3, 2), 5); var actual7 = b71 - b72; var expected7 = new RadicalSum(new Radical(new Rational(-3, 2), 5)); // (3/2)*sqrt(5) - (3/2)*sqrt(5) = 0 var b81 = new RadicalSum(new Rational(3, 2), 5); var b82 = new RadicalSum(new Rational(3, 2), 5); var actual8 = b81 - b82; var expected8 = RadicalSum.Zero; Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual6); Assert.Equal(expected7, actual7); Assert.Equal(expected8, actual8); }
public void AdditionTests() { // sqrt(2) + sqrt(3) var b11 = new RadicalSumRatio(1, 2); var b12 = new RadicalSumRatio(1, 3); var actual1 = b11 + b12; var expected1 = new RadicalSumRatio(new Radical[2] { new Radical(1, 2), new Radical(1, 3) }); // sqrt(2) + 2 * sqrt(2) = 3 * sqrt(2) var b21 = new RadicalSumRatio(1, 2); var b22 = new RadicalSumRatio(2, 2); var actual2 = b21 + b22; var expected2 = new RadicalSumRatio(new Radical(3, 2)); // 5*sqrt(27) + 7*sqrt(12) = 15*sqrt(3) + 14*sqrt(3) = 29*sqrt(3) var b31 = new RadicalSumRatio(5, 27); var b32 = new RadicalSumRatio(7, 12); var actual3 = b31 + b32; var expected3 = new RadicalSumRatio(new Radical(29, 3)); // 3*sqrt(2) + 2*sqrt(3) var b41 = new RadicalSumRatio(3, 2); var b42 = new RadicalSumRatio(2, 3); var actual4 = b41 + b42; var expected4 = new RadicalSumRatio(new Radical[2] { new Radical(3, 2), new Radical(2, 3) }); // 2*sqrt(2) + 5*sqrt(28) + sqrt(1/2) + 3 + sqrt(7/9) + 11*sqrt(4) = 25 + (5/2)sqrt(2) + (31/3)*sqrt(7) var b51 = new RadicalSumRatio(2, 2); var b52 = new RadicalSumRatio(5, 28); var b53 = new RadicalSumRatio(new Rational(1, 2)); var b54 = new RadicalSumRatio(3, 1); var b55 = new RadicalSumRatio(new Rational(7, 9)); var b56 = new RadicalSumRatio(11, 4); var actual5 = b51 + b52 + b53 + b54 + b55 + b56; var expected5 = new RadicalSumRatio(new Radical[3] { new Radical(25, 1), new Radical(new Rational(5, 2), 2), new Radical(new Rational(31, 3), 7) }); // (3/2)*sqrt(5) + 0 = (3/2)*sqrt(5) // 0 + (3/2)*sqrt(5) = (3/2)*sqrt(5) var b61 = new RadicalSumRatio(new Rational(3, 2), 5); var b62 = RadicalSumRatio.Zero; var actual61 = b61 + b62; var actual62 = b62 + b61; var expected6 = new RadicalSumRatio(new Radical(new Rational(3, 2), 5)); // (3/2)*sqrt(5) + (-3/2)*sqrt(5) = 0 var b71 = new RadicalSumRatio(new Rational(3, 2), 5); var b72 = new RadicalSumRatio(new Rational(-3, 2), 5); var actual7 = b71 + b72; var expected7 = RadicalSumRatio.Zero; // {[(2/3)*sqrt(3) - (3/2)*sqrt(2)] / [(2/3)*sqrt(3) + (3/2)*sqrt(2)]} + {[(5/6)*sqrt(3) + (7/3)*sqrt(2)] / [(4/3)*sqrt(3) - (5/7)*sqrt(2)]} // = [(8/9)*3 - (10/21)*sqrt(6) - (12/6)*sqrt(6) + (15/14)*2 + (10/18)*3 + (14/9)*sqrt(6) + (15/12)*sqrt(6) + (21/6)*2] / [(8/9)*3 - (10/21)*sqrt(6) + (12/6)*sqrt(6) - (15/14)*2] // = [(8/3) + (83/252)*sqrt(6) + (15/7) + (10/6) + (21/3)] / [(8/3) + (32/21)*sqrt(6) - (15/7)] // = [(283/21) + (83/252)*sqrt(6)] / [(11/21) + (32/21)*sqrt(6)] // = [(283) + (83/12)*sqrt(6)] / [(11) + 32*sqrt(6)] var b81 = new Radical(new Rational(2, 3), 3); var b82 = new Radical(new Rational(3, 2), 2); var b83 = new Radical(new Rational(2, 3), 3); var b84 = new Radical(new Rational(3, 2), 2); var b85 = new Radical(new Rational(5, 6), 3); var b86 = new Radical(new Rational(7, 3), 2); var b87 = new Radical(new Rational(4, 3), 3); var b88 = new Radical(new Rational(5, 7), 2); var c81 = b81 - b82; var c82 = b83 + b84; var c83 = b85 + b86; var c84 = b87 - b88; var cr81 = new RadicalSumRatio(c81, c82); var cr82 = new RadicalSumRatio(c83, c84); var actual8 = cr81 + cr82; var expected8 = new RadicalSumRatio( new RadicalSum(new Radical[2] { new Radical(new Rational(283), 1), new Radical(new Rational(83, 12), 6) }), new RadicalSum(new Radical[2] { new Radical(new Rational(11), 1), new Radical(new Rational(32), 6) })); // (2/3) + (1/3) = 1 var b91 = new Radical(2, 1); var b92 = new Radical(3, 1); var b93 = new Radical(1, 1); var b94 = new Radical(3, 1); var c91 = new RadicalSum(b91); var c92 = new RadicalSum(b92); var c93 = new RadicalSum(b93); var c94 = new RadicalSum(b94); var cr91 = new RadicalSumRatio(c91, c92); var cr92 = new RadicalSumRatio(c93, c94); var actual9 = cr91 + cr92; var expected9 = RadicalSumRatio.One; Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected7, actual7); Assert.Equal(expected8, actual8); Assert.Equal(expected9, actual9); }
public Polynomial(RadicalSum constant) : this(new PolynomialTerm[1] { new PolynomialTerm(constant) }) { }
public void SubtractionTests() { // sqrt(2) - sqrt(3) var b11 = new RadicalSumRatio(1, 2); var b12 = new RadicalSumRatio(1, 3); var actual1 = b11 - b12; var expected1 = new RadicalSumRatio(new Radical[2] { new Radical(1, 2), new Radical(-1, 3) }); // sqrt(2) - 2 * sqrt(2) = -1 * sqrt(2) var b21 = new RadicalSumRatio(1, 2); var b22 = new RadicalSumRatio(2, 2); var actual2 = b21 - b22; var expected2 = new RadicalSumRatio(new Radical(-1, 2)); // 5*sqrt(27) - 7*sqrt(12) = 15*sqrt(3) - 14*sqrt(3) = 1*sqrt(3) var b31 = new RadicalSumRatio(5, 27); var b32 = new RadicalSumRatio(7, 12); var actual3 = b31 - b32; var expected3 = new RadicalSumRatio(new Radical(1, 3)); // 3*sqrt(2) - 2*sqrt(3) var b41 = new RadicalSumRatio(3, 2); var b42 = new RadicalSumRatio(2, 3); var actual4 = b41 - b42; var expected4 = new RadicalSumRatio(new Radical[2] { new Radical(3, 2), new Radical(-2, 3) }); // 2*sqrt(2) + 5*sqrt(28) - sqrt(1/2) + 3 - sqrt(7/9) + 11*sqrt(4) = 25 + (3/2)sqrt(2) + (29/3)*sqrt(7) var b51 = new RadicalSumRatio(2, 2); var b52 = new RadicalSumRatio(5, 28); var b53 = new RadicalSumRatio(new Rational(1, 2)); var b54 = new RadicalSumRatio(3, 1); var b55 = new RadicalSumRatio(new Rational(7, 9)); var b56 = new RadicalSumRatio(11, 4); var actual5 = b51 + b52 - b53 + b54 - b55 + b56; var expected5 = new RadicalSumRatio(new Radical[3] { new Radical(25, 1), new Radical(new Rational(3, 2), 2), new Radical(new Rational(29, 3), 7) }); // (3/2)*sqrt(5) - 0 = (3/2)*sqrt(5) var b61 = new RadicalSumRatio(new Rational(3, 2), 5); var b62 = RadicalSumRatio.Zero; var actual6 = b61 - b62; var expected6 = new RadicalSumRatio(new Radical(new Rational(3, 2), 5)); // 0 - (3/2)*sqrt(5) = (-3/2)*sqrt(5) var b71 = RadicalSumRatio.Zero; var b72 = new RadicalSumRatio(new Rational(3, 2), 5); var actual7 = b71 - b72; var expected7 = new RadicalSumRatio(new Radical(new Rational(-3, 2), 5)); // (3/2)*sqrt(5) - (3/2)*sqrt(5) = 0 var b81 = new RadicalSumRatio(new Rational(3, 2), 5); var b82 = new RadicalSumRatio(new Rational(3, 2), 5); var actual8 = b81 - b82; var expected8 = RadicalSumRatio.Zero; // {[(2/3)*sqrt(3) - (3/2)*sqrt(2)] / [(2/3)*sqrt(3) + (3/2)*sqrt(2)]} - {[(5/6)*sqrt(3) + (7/3)*sqrt(2)] / [(4/3)*sqrt(3) - (5/7)*sqrt(2)]} // = [(8/9)*3 - (10/21)*sqrt(6) - (12/6)*sqrt(6) + (15/14)*2 - (10/18)*3 - (14/9)*sqrt(6) - (15/12)*sqrt(6) - (21/6)*2] / [(8/9)*3 - (10/21)*sqrt(6) + (12/6)*sqrt(6) - (15/14)*2] // = [(8/3) - (1331/252)*sqrt(6) + (15/7) - (10/6) - (21/3)] / [(8/3) + (32/21)*sqrt(6) - (15/7)] // = [(-27/7) - (1331/252)*sqrt(6)] / [(11/21) + (32/21)*sqrt(6)] // = [(-81) - (1331/12)*sqrt(6)] / [(11) + 32*sqrt(6)] var b91 = new Radical(new Rational(2, 3), 3); var b92 = new Radical(new Rational(3, 2), 2); var b93 = new Radical(new Rational(2, 3), 3); var b94 = new Radical(new Rational(3, 2), 2); var b95 = new Radical(new Rational(5, 6), 3); var b96 = new Radical(new Rational(7, 3), 2); var b97 = new Radical(new Rational(4, 3), 3); var b98 = new Radical(new Rational(5, 7), 2); var c91 = b91 - b92; var c92 = b93 + b94; var c93 = b95 + b96; var c94 = b97 - b98; var cr91 = new RadicalSumRatio(c91, c92); var cr92 = new RadicalSumRatio(c93, c94); var actual9 = cr91 - cr92; var expected9 = new RadicalSumRatio( new RadicalSum(new Radical[2] { new Radical(new Rational(-81), 1), new Radical(new Rational(-1331, 12), 6) }), new RadicalSum(new Radical[2] { new Radical(new Rational(11), 1), new Radical(new Rational(32), 6) })); // (2/3) - (1/3) = 1/3 var b101 = new Radical(2, 1); var b102 = new Radical(3, 1); var b103 = new Radical(1, 1); var b104 = new Radical(3, 1); var c101 = new RadicalSum(b101); var c102 = new RadicalSum(b102); var c103 = new RadicalSum(b103); var c104 = new RadicalSum(b104); var cr101 = new RadicalSumRatio(c101, c102); var cr102 = new RadicalSumRatio(c103, c104); var actual10 = cr101 - cr102; var expected10 = new RadicalSumRatio( new RadicalSum(new Radical(1, 1)), new RadicalSum(new Radical(3, 1)) ); Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual6); Assert.Equal(expected7, actual7); Assert.Equal(expected8, actual8); Assert.Equal(expected9, actual9); Assert.Equal(expected10, actual10); }
public void ConstructorTests() { // (3/4) * sqrt(12) // = (2*3/4) * sqrt(3) // = (3/2) * sqrt(3) var actual1 = new RadicalSumRatio(new Rational(3, 4), 12); var expected1 = new RadicalSumRatio(new Rational(3, 2), 3); // sqrt(2/9) = (1/3)sqrt(2) var actual2 = new RadicalSumRatio(new Rational(2, 9)); var expected2 = new RadicalSumRatio(new Rational(1, 3), 2); // sqrt(1/2) = (1/2)sqrt(2) var actual3 = new RadicalSumRatio(new Rational(1, 2)); var expected3 = new RadicalSumRatio(new Rational(1, 2), 2); // 0 = 0 RadicalSumRatio actual41 = 0; var actual42 = new RadicalSumRatio(0); var actual43 = new RadicalSumRatio(0, 0); var actual44 = new RadicalSumRatio(); var actual45 = new RadicalSumRatio(3, 0); var actual46 = new RadicalSumRatio(0, 5); var expected4 = RadicalSumRatio.Zero; // 1 = 1 RadicalSumRatio actual51 = 1; var actual52 = new RadicalSumRatio(1, 1); var actual53 = new RadicalSumRatio(1); var expected5 = RadicalSumRatio.One; // [(3/2)*sqrt(7) - (2/3)*sqrt(5)] / [(1/2)*sqrt(7) + (4/5)*sqrt(6)] var c61 = new RadicalSum(new Radical[2] { new Radical(new Rational(3, 2), 7), new Radical(new Rational(-2, 3), 5) }); var c62 = new RadicalSum(new Radical[2] { new Radical(new Rational(1, 2), 7), new Radical(new Rational(4, 5), 6) }); var actual6 = (RadicalSumRatio)c61 / c62; var expected6 = new RadicalSumRatio(c61, c62); // assert Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual41); Assert.Equal(expected4, actual42); Assert.Equal(expected4, actual43); Assert.Equal(expected4, actual44); Assert.Equal(expected4, actual45); Assert.Equal(expected4, actual46); Assert.True(actual41.IsZero); Assert.True(actual42.IsZero); Assert.True(actual43.IsZero); Assert.True(actual44.IsZero); Assert.True(actual45.IsZero); Assert.True(actual46.IsZero); Assert.Equal(expected5, actual51); Assert.Equal(expected5, actual52); Assert.Equal(expected5, actual53); Assert.True(actual51.IsOne); Assert.True(actual52.IsOne); Assert.True(actual53.IsOne); Assert.Equal(expected6, actual6); }
public void DivisionTests() { // (3*sqrt(2)) / ((5/3)*sqrt(3)) = (9/5)*sqrt(2/3) = (3/5)*sqrt(6) var b11 = new Radical(3, 2); var b12 = new Radical(new Rational(5, 3), 3); var actual1 = b11 / b12; var expected1 = new Radical(new Rational(3, 5), 6); // 11 / sqrt(4/9) = 33/2 var b21 = new Radical(11, 1); var b22 = new Radical(new Rational(4, 9)); var actual2 = b21 / b22; var expected2 = new Radical(new Rational(33, 2), 1); // 11 / sqrt(4/9) = 33/2 var b31 = 11; var b32 = new Radical(new Rational(4, 9)); var actual3 = b31 / b32; var expected3 = new Radical(new Rational(33, 2), 1); // sqrt(4/9) / 11 = 2/33 var b41 = new Radical(new Rational(4, 9)); var b42 = 11; var actual4 = b41 / b42; var expected4 = new Radical(new Rational(2, 33), 1); // [(3/2)*sqrt(2) - (7/3)*sqrt(5) + (1/3)*sqrt(2) - (7/5)*sqrt(5)] / (11/4)*sqrt(2) // = [(11/6)*sqrt(2) - (56/15)*sqrt(5)] / (11/4)*sqrt(2) // = (2/3) - (224/165)*sqrt(5/2) // = (2/3) - (112/165)*sqrt(10) var b51 = new Radical(new Rational(3, 2), 2); var b52 = new Radical(new Rational(7, 3), 5); var b53 = new Radical(new Rational(1, 3), 2); var b54 = new Radical(new Rational(7, 5), 5); var b55 = new Radical(new Rational(11, 4), 2); var actual5 = (b51 - b52 + b53 - b54) / b55; var expected5 = new RadicalSum(new Radical[2] { new Radical(new Rational(2, 3), 1), new Radical(new Rational(-112, 165), 10) }); // (3/2)*sqrt(5) / 1 = (3/2)*sqrt(5) var b61 = new Radical(new Rational(3, 2), 5); var b62 = new Radical(1, 1); var b63 = 1; var b64 = new Radical(1); var b65 = Radical.One; var actual61 = b61 / b62; var actual62 = b61 / b63; var actual63 = b61 / b64; var actual64 = b61 / b65; var expected6 = new Radical(new Rational(3, 2), 5); // (3/2)*sqrt(5) / -1 = (-3/2)*sqrt(5) var b71 = new Radical(new Rational(3, 2), 5); var b72 = new Radical(-1, 1); var b73 = -1; var b74 = -Radical.One; var actual71 = b71 / b72; var actual72 = b71 / b73; var actual73 = b71 / b74; var expected7 = new Radical(new Rational(-3, 2), 5); // Sqrt(2) / Root[3](5) = Sqrt(2) * (1/5)*Root[3](5^2) = Root[6](2^3) * (1/5)*Root[6](5^4) // = (1/5)*Root[6](8*625) = Root[6](5000) var b9_1 = new Radical(2); var b9_2 = Radical.NthRoot(5, 3); var actual9 = b9_1 / b9_2; var expected9 = new Radical((Rational)1 / 5, 5000, 6); Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); Assert.Equal(expected5, actual5); Assert.Equal(expected6, actual61); Assert.Equal(expected6, actual62); Assert.Equal(expected6, actual63); Assert.Equal(expected6, actual64); Assert.Equal(expected7, actual71); Assert.Equal(expected7, actual72); Assert.Equal(expected7, actual73); Assert.Equal(expected9, actual9); }