Esempio n. 1
0
        public int DetMod(int prime_number)
        {
            IntegerSquareMatrix triangleMatrix = new IntegerSquareMatrix(Rows, elements);
            int signOfDet = 0;

            for (int i = 0; i < triangleMatrix.Rows; i++)
            {
                for (int j = i; j < triangleMatrix.Columns; j++)
                {
                    if (triangleMatrix[j, i] != 0)
                    {
                        int reverselement = NumberFunctions.GetMulInverse(triangleMatrix[j, i], prime_number);
                        for (int k = j; k < triangleMatrix.Columns; k++)
                        {
                            triangleMatrix[j, k] *= reverselement;
                            triangleMatrix[j, k] %= prime_number;
                        }
                        if (i != j)
                        {
                            triangleMatrix = triangleMatrix.SwapLine(j, i);
                            signOfDet++;
                            signOfDet %= 2;                                            //ОПРЕДЕЛЯЮ ЗНАК det
                        }
                        for (int k = j + 1; k < triangleMatrix.Columns; k++)
                        {
                            while (triangleMatrix[k, j] != 0)
                            {
                                if (triangleMatrix[k, j] > 0)
                                {
                                    triangleMatrix = triangleMatrix.SubtractionOfLines(k, j);
                                }
                                else
                                {
                                    triangleMatrix = triangleMatrix.AdditionOfLines(k, j);
                                }
                            }
                        }
                    }
                }
            }
            int det = 1;

            for (int i = 0; i < triangleMatrix.Columns; i++)
            {
                det *= triangleMatrix[i, i];
            }
            if (signOfDet == 0)
            {
                return(det);
            }
            else
            {
                return(-1 * det);
            }
        }
Esempio n. 2
0
        public IntegerSquareMatrix ToTopTriangleMatrixModPrime(int primeNumber, int degree)
        {
            IntegerSquareMatrix triangleMatrix = new IntegerSquareMatrix(Rows, elements);
            int sign_of_det  = 0;
            int primeNumber1 = Convert.ToInt32(Math.Pow(primeNumber, degree));

            for (int i = 0; i < triangleMatrix.Rows; i++)
            {
                for (int j = i; j < triangleMatrix.Columns; j++)
                {
                    if (triangleMatrix[j, i] != 0)
                    {
                        int reverselement = NumberFunctions.GetMulInverse(triangleMatrix[j, i], primeNumber1);
                        for (int k = j; k < triangleMatrix.Columns; k++)
                        {
                            triangleMatrix[j, k] *= reverselement;
                            triangleMatrix[j, k] %= primeNumber1;
                        }
                        if (i != j)
                        {
                            triangleMatrix = triangleMatrix.SwapLine(j, i);
                            sign_of_det++;
                            sign_of_det %= 2;                                            //ОПРЕДЕЛЯЮ ЗНАК det
                        }
                        for (int k = j + 1; k < triangleMatrix.Columns; k++)
                        {
                            while (triangleMatrix[k, j] != 0)
                            {
                                if (triangleMatrix[k, j] > 0)
                                {
                                    triangleMatrix = triangleMatrix.SubtractionOfLines(k, j);
                                }
                                else
                                {
                                    triangleMatrix = triangleMatrix.AdditionOfLines(k, j);
                                }
                            }
                        }
                    }
                }
            }
            return(triangleMatrix);
        }