pascal matrix determinant

1484 days 전, jhlee2chn 작성

1. Generate a Pascal Matrix. 

# Pascal matrix 생성 def pascal_matrix(n): A=matrix(n,n,0) for i in range(1, n): A[i,0]=1 A[i,i-1]=1 for j in range(1,i-1): A[i,j]=((A[i-1,j-1] % 2) + (A[i-1,j] % 2)) % 2 A=A+A.transpose() return A 
       

2. Test 1

A=pascal_matrix(683) # size of matrices without zero eigenvalues list=[3, 7, 11, 23, 43, 87, 171, 343, 683] m=len(list) for i in range(m-1): n=list[i] s=list[i+1]-list[i] print "n= ", n B=A.submatrix(0,0,n,n) D=A.submatrix(n,n,s,s) alp=A.submatrix(n,0,s,n) print D[0,:]-alp[0,:]*B.inverse()*alp.transpose() print "det =", (D-alp*B.inverse()*alp.transpose()).det() 
       
n=  3
[ 0  0  0 -1]
det = 1
n=  7
[ 0  0  0 -1]
det = 1
n=  11
[0 0 0 0 0 0 0 0 0 0 0 1]
det = 1
n=  23
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
det = 1
n=  43
[ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 -1]
det = 1
n=  87
1 x 84 dense matrix over Rational Field
det = 1
n=  171
1 x 172 dense matrix over Rational Field
det = 1
n=  343
1 x 340 dense matrix over Rational Field
det = 1
n=  3
[ 0  0  0 -1]
det = 1
n=  7
[ 0  0  0 -1]
det = 1
n=  11
[0 0 0 0 0 0 0 0 0 0 0 1]
det = 1
n=  23
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
det = 1
n=  43
[ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 -1]
det = 1
n=  87
1 x 84 dense matrix over Rational Field
det = 1
n=  171
1 x 172 dense matrix over Rational Field
det = 1
n=  343
1 x 340 dense matrix over Rational Field
det = 1

3. Test 2

list=[6, 10, 22, 42, 86, 170, 342, 682] m=len(list) for i in range(m): n=list[i] A=pascal_matrix(n) s=n+1 A1=pascal_matrix(s) alp=A1.submatrix(n,0,1,n) loc=[] for j in range(n): if alp[0,j] > 0: loc.append(j+1) print loc print 
       
[1, 2, 5, 6]

[1, 2, 9, 10]

[1, 2, 5, 6, 17, 18, 21, 22]

[1, 2, 9, 10, 33, 34, 41, 42]

[1, 2, 5, 6, 17, 18, 21, 22, 65, 66, 69, 70, 81, 82, 85, 86]

[1, 2, 9, 10, 33, 34, 41, 42, 129, 130, 137, 138, 161, 162, 169, 170]

[1, 2, 5, 6, 17, 18, 21, 22, 65, 66, 69, 70, 81, 82, 85, 86, 257, 258,
261, 262, 273, 274, 277, 278, 321, 322, 325, 326, 337, 338, 341, 342]

[1, 2, 9, 10, 33, 34, 41, 42, 129, 130, 137, 138, 161, 162, 169, 170,
513, 514, 521, 522, 545, 546, 553, 554, 641, 642, 649, 650, 673, 674,
681, 682]
[1, 2, 5, 6]

[1, 2, 9, 10]

[1, 2, 5, 6, 17, 18, 21, 22]

[1, 2, 9, 10, 33, 34, 41, 42]

[1, 2, 5, 6, 17, 18, 21, 22, 65, 66, 69, 70, 81, 82, 85, 86]

[1, 2, 9, 10, 33, 34, 41, 42, 129, 130, 137, 138, 161, 162, 169, 170]

[1, 2, 5, 6, 17, 18, 21, 22, 65, 66, 69, 70, 81, 82, 85, 86, 257, 258, 261, 262, 273, 274, 277, 278, 321, 322, 325, 326, 337, 338, 341, 342]

[1, 2, 9, 10, 33, 34, 41, 42, 129, 130, 137, 138, 161, 162, 169, 170, 513, 514, 521, 522, 545, 546, 553, 554, 641, 642, 649, 650, 673, 674, 681, 682]

4. Test 3

list=[6, 10, 22, 42, 86, 170, 342, 682] m=len(list) for i in range(m): n=list[i] A=pascal_matrix(n) s=n+1 A1=pascal_matrix(s) alp=A1.submatrix(n,0,1,n) loc=[] for j in range(n): if alp[0,j] > 0: loc.append(j) t=len(loc) d=0 print for k in range(t): C=pascal_matrix(n) C[loc[k], :]=alp c=C.det() d += c print c print "d=", d 
       
WARNING: Output truncated!  
full_output.txt




0
-2
0
0
d= -2

0
-2
0
0
d= -2

0
0
0
-2
0
0
0
0
d= -2

0
0
0
-2
0
0
0
0
d= -2

0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
d= -2

0
0
0
0
0
0
0
-2

...

0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
d= -2

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
d= -2
WARNING: Output truncated!  
full_output.txt




0
-2
0
0
d= -2

0
-2
0
0
d= -2

0
0
0
-2
0
0
0
0
d= -2

0
0
0
-2
0
0
0
0
d= -2

0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
d= -2

0
0
0
0
0
0
0
-2

...

0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
d= -2

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
d= -2
pascal_matrix(7) 
       
[0 1 1 1 1 1 1]
[1 0 1 0 1 0 1]
[1 1 0 1 1 0 0]
[1 0 1 0 1 0 0]
[1 1 1 1 0 1 1]
[1 0 0 0 1 0 1]
[1 1 0 0 1 1 0]
[0 1 1 1 1 1 1]
[1 0 1 0 1 0 1]
[1 1 0 1 1 0 0]
[1 0 1 0 1 0 0]
[1 1 1 1 0 1 1]
[1 0 0 0 1 0 1]
[1 1 0 0 1 1 0]
show(pascal_matrix(23))