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