Ejemplo n.º 1
0
        public void ShouldFindEmptySolution(FieldElement[,] a, FieldElement[] b, SystemSolution expectedSolution)
        {
            // When
            var actualSolution = _gausSolver.Solve(a, b);

            // Then
            Assert.Equal(expectedSolution, actualSolution);
        }
Ejemplo n.º 2
0
        public static void PrintSolution(SystemSolution sln, string prefix, string separator)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < sln.DimensionsCount; i++)
            {
                if (sb.Length > 0)
                {
                    sb.Append(separator);
                }
                sb.Append($"{prefix}[{sln.Indexes[i]}]={sln.Values[i]}");
            }

            Console.WriteLine(sb.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method for creation interpolation polynomial from linear system solution
        /// </summary>
        /// <param name="field">Finite field from which system coefficients were taken</param>
        /// <param name="systemSolution">Solution of the linear equations system</param>
        /// <param name="monomialByVariableIndex">Mapping from numbers to bivariate monomials</param>
        /// <returns>Interpolation polynomial</returns>
        private static BiVariablePolynomial ConstructInterpolationPolynomial(
            GaloisField field,
            SystemSolution systemSolution,
            IReadOnlyDictionary <int, Tuple <int, int> > monomialByVariableIndex)
        {
            var interpolationPolynomial = new BiVariablePolynomial(field);

            for (var i = 0; i < systemSolution.VariablesValues.Length; i++)
            {
                interpolationPolynomial[monomialByVariableIndex[i]] = systemSolution.VariablesValues[i];
            }

            if (interpolationPolynomial.IsZero)
            {
                throw new NonTrivialPolynomialNotFoundException();
            }
            return(interpolationPolynomial);
        }
Ejemplo n.º 4
0
 private static LinearSystemSolverTestCase PrepareTestCaseForInfiniteSolution(GaloisField field, int[,] a, IEnumerable <int> b, IEnumerable <int> variablesValues) =>
 PrepareTestCase(field, a, b, SystemSolution.InfiniteSolution(variablesValues.Select(field.CreateElement).ToArray()));
Ejemplo n.º 5
0
 private static LinearSystemSolverTestCase PrepareTestCaseForEmptySolution(GaloisField field, int[,] a, IEnumerable <int> b) =>
 PrepareTestCase(field, a, b, SystemSolution.EmptySolution());
Ejemplo n.º 6
0
        private static LinearSystemSolverTestCase PrepareTestCase(GaloisField field, int[,] a, IEnumerable <int> b, SystemSolution expectedSolution)
        {
            var matrix = new FieldElement[a.GetLength(0), a.GetLength(1)];

            for (var i = 0; i < a.GetLength(0); i++)
            {
                for (var j = 0; j < a.GetLength(1); j++)
                {
                    matrix[i, j] = new FieldElement(field, a[i, j]);
                }
            }

            var remainders = b.Select(field.CreateElement).ToArray();

            return(new LinearSystemSolverTestCase {
                A = matrix, B = remainders, Expected = expectedSolution
            });
        }
Ejemplo n.º 7
0
        private static object[] PrepareTestCase(GaloisField field, int[,] a, IEnumerable <int> b, SystemSolution expectedSolution)
        {
            var matrix = new FieldElement[a.GetLength(0), a.GetLength(1)];

            for (var i = 0; i < a.GetLength(0); i++)
            {
                for (var j = 0; j < a.GetLength(1); j++)
                {
                    matrix[i, j] = new FieldElement(field, a[i, j]);
                }
            }

            var remainders = b.Select(x => new FieldElement(field, x)).ToArray();

            return(new object[] { matrix, remainders, expectedSolution });
        }
Ejemplo n.º 8
0
 private static object[] PrepareTestCaseForInfiniteSolution(GaloisField field, int[,] a, IEnumerable <int> b, IEnumerable <int> variablesValues)
 {
     return(PrepareTestCase(field, a, b,
                            SystemSolution.InfiniteSolution(variablesValues.Select(x => new FieldElement(field, x)).ToArray())));
 }
Ejemplo n.º 9
0
 private static object[] PrepareTestCaseForEmptySolution(GaloisField field, int[,] a, IEnumerable <int> b)
 {
     return(PrepareTestCase(field, a, b, SystemSolution.EmptySolution()));
 }