Reduces the size of a matrix through division-free elimination of variables. Returns matrix with dim >= 1 and a multiplication factor for the determinant. :param M: sympy matrix :type M: sympy.Matrix() :return: (M, factor) - The returned matrix M is either a
(M, method)
| 70 | return D |
| 71 | |
| 72 | def _eliminateVars(M, method): |
| 73 | """ |
| 74 | Reduces the size of a matrix through division-free elimination of variables. |
| 75 | Returns matrix with dim >= 1 and a multiplication factor for the determinant. |
| 76 | |
| 77 | :param M: sympy matrix |
| 78 | :type M: sympy.Matrix() |
| 79 | |
| 80 | :return: (M, factor) |
| 81 | |
| 82 | - The returned matrix M is either a 1x1 matrix, a matrix of which |
| 83 | its entries are either zero or contain at least one symbol. |
| 84 | - The returned factor is a nonzero (numeric) multiplication factor |
| 85 | for the determinant of the returned matrix to equal the |
| 86 | determinant of the original matrix. |
| 87 | |
| 88 | :rtype: tuple |
| 89 | |
| 90 | The returned factor |
| 91 | """ |
| 92 | factor = 1 # Scaling factor for determinant |
| 93 | dim = M.shape[0] |
| 94 | k, l = _find_numeric_entry(M) |
| 95 | while k >= 0 and dim > 1: |
| 96 | factor *= M[k, l] |
| 97 | if (k+l) % 2: |
| 98 | factor *= -1 |
| 99 | for i in range(dim): |
| 100 | if M[i, l] != 0 and i != k: # Test on zero increases speed |
| 101 | for j in range(dim): |
| 102 | if M[k, j] != 0 and j != l: # Test on zero increases speed |
| 103 | M[i, j] = sp.expand(M[i, j] - M[i, l]*M[k, j]/M[k, l]) |
| 104 | # remove row k and column l |
| 105 | M = M.minor_submatrix(k, l) |
| 106 | # reduce dimension |
| 107 | dim -= 1 |
| 108 | k, l = _find_numeric_entry(M) |
| 109 | return M, factor |
| 110 | |
| 111 | def _find_numeric_entry(M): |
| 112 | """ |
no test coverage detected