n | def det3x3(matrix): | n | def det3(m): |
| return matrix[0][0] * (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1]) - matrix[0][1] * (matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0]) + matrix[0][2] * (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) | | return m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]) |
| | | |
| def det4(r0, r1, r2, r3): | | def det4(r0, r1, r2, r3): |
t | matrix = [r0, r1, r2, r3] | t | m = (r0, r1, r2, r3) |
| determinant = 0 | | det = 0 |
| for j in range(4): | | for i in range(4): |
| sub_matrix = [row[:j] + row[j + 1:] for row in matrix[1:]] | | sub = [row[:i] + row[i + 1:] for row in m[1:]] |
| determinant += (-1) ** j * r0[j] * det3x3(sub_matrix) | | det += (-1) ** i * m[0][i] * det3(sub) |
| return determinant | | return det |