Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def nb_changes(a,b):
- s = 1
- for x in a:
- for y in b:
- if x > y:
- s *= -1
- return s
- def helper(A, B, as1, as2, bs1, bs2):
- M = A[as1,as2]
- N = B[bs1,bs2]
- return nb_changes(as1,bs1) * nb_changes(as2,bs2) * det(M) * det(N)
- def det_sum(A,B,n):
- rn = Set(range(n))
- result = 0
- for ss1,ss2 in cartesian_product([Subsets(rn),Subsets(rn)]):
- if ss1.cardinality() != ss2.cardinality():
- continue
- Css1 = rn.difference(ss1)
- Css2 = rn.difference(ss2)
- r1 = result
- result += helper(A,B,list(ss1),list(ss2),list(Css1),list(Css2))
- return result
- n = 7
- A = random_matrix(ZZ,n,n)
- B = random_matrix(ZZ,n,n)
- print det_sum(A,B,n)
- print det(A+B)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement