예제 #1
0
파일: test_hd_det.py 프로젝트: krisk0/razin
def test_for_dim(n):
 '''
 do with small upper-triangular matrix
 
 generate 10 non-singular matrix and one singular
 for x in range 2..100, generate matrice with determinant 2**x and y*2**x,
  where y is a random number in range 3..33
 
 for all the matrix, count its determinant two ways, compare results
 '''
 print 'dim=%s triU test start' % dim
 for i in range(10):
  test_matrice( unimodular_triU(n,5) )
  for k in range(n):
   a=unimodular_triU(n,5)
   for j in range(k+1):
    a[j,j]=randint(-7,7)
   test_matrice(a)
  
 print 'dim=%s singular-nonsingular test start' % dim
 global t0,t1
 t0=t1=0
 singular_count=i=0
 while 1:
  a,d0=generate_matrice(n)
  if d0==0 and singular_count:
   continue
  if d0==0:
   singular_count += 1
  else:
   i += 1
  if n<11 and 0:
   print 'a=\n',a
   print 'a det=%s=%s' % (d0,sage.all.factor(d0))
  test_matrice_mind_time(a)
  if i==10:
   break
 if singular_count==0:
  a=generate_singular_matrice(n)
  test_matrice_mind_time(a)
 print 'test1 t0,1=',t0,t1
 
 t0=t1=0
 for x in range(2,301):
  test_this_det( n, 1<<x )
  test_this_det( n, randint(3,34)<<x )
 print 'test2 t0,1=',t0,t1
예제 #2
0
def test_serie(dim):
 test_with( identity_matrix(dim) )
 for i in range(10):
  a=identity_matrix(dim)
  a[1,1] *= randint(2,99)
  a[dim-1,dim-1] *= randint(2,99)
  test_with( a )
 max_d=int( pow( 2**64-1, 1./dim  ) )
 if 0 and max_d>10:
  max_d=10
 for i in range(10):
  a=unimodular_triU(dim,99)
  for j in range(dim):
   a[j,j]=randint( 2, max_d )
   HNFy_col(a,j)
  test_with(a)
예제 #3
0
def check_dim(n):
 a=identity_matrix(n)
 do_with(a)
 a[0,0]=1+2*randint(-99,99)
 do_with(a)
 a[n-1,n-1]=1+2*randint(-99,99)
 do_with(a)
 a[0,0],  a[0,n-1]  =0,1
 a[n-1,0],a[n-1,n-1]=1,0
 do_with(a)
 for i in range(5):
  do_with( unimodular_triL(n,9) )
  do_with( unimodular_triU(n,9) )
  do_with( odd_hermite(n,4) )
  do_with( odd_hermite(n,4).T )
  do_with( unimodular(n)*odd_hermite(n,99) )
  do_with( unimodular(n)*unimodular_diag(n)*odd_hermite(n,99) )
예제 #4
0
def odd_hermite(dim,m):
 a=unimodular_triU(dim,m)
 for i in range(dim):
  a[i,i]=1+2*randint(1,m)
 return a