def det_flint(a,way): global t1,tx aF=flint.fmpz_mat( a ) t0=time.time() one=flint.det(aF) t1[way] += time.time()-t0 if loud: print one b=sage.all.copy(a) b[0,0] += 1 bF=flint.fmpz_mat( b ) t0=time.time() not_one=flint.det(bF) tx[way] += time.time()-t0 if loud: print not_one
def random_data(dim): ' returns matrice and absolute value of its determinant ' global coin_fell_on_the_edge n = m = dim while 1: A=sage.all.random_matrix( ZZ, dim, x=-100, y=100 ) B = A.matrix_from_rows(range(m-2)).matrix_from_columns(range(n-1)) c = A.matrix_from_rows([m-2]).matrix_from_columns (range(n-1)) d = A.matrix_from_rows([m-1]).matrix_from_columns (range(n-1)) try: (d1,d2) = double_det (B,c,d, proof=True) except: print 'coin fell on the edge, point 0' coin_fell_on_the_edge[0] += 1 continue (g,k,l) = d1._xgcd (d2, minimal=True) assert g >= 0 if not shut_up: print "Stein double-det g=%s"%g CUTOFF = 2**30 # aint not interesting to count HNF of unimodular matrice, # so disallow g=1 if g==1 or 2*g > CUTOFF: if not shut_up: print 'bad det, going back' continue W = B.stack (k*c + l*d) not_g=abs( flint.det(flint.fmpz_mat( W )) ) if not_g != g: print 'coin fell on the edge, real det=%d != %d' (not_g,g) coin_fell_on_the_edge[1] += 1 return W,g
def det_flint(a,way): global t1,tx,strange_det aF=flint.fmpz_mat( a ) t0=time.time() one=flint.det(aF) t1[way] += time.time()-t0 if abs(one) != 1: print 'bad determinant, flint' print 'a=\n',a b=sage.all.copy(a) b[0,0] += 1 bF=flint.fmpz_mat( b ) t0=time.time() not_one=flint.det(bF) tx[way] += time.time()-t0 if abs(not_one)==1: strange_det += 1
def test_m(m): a=flint.fmpz_mat( m ) dG = flint.det(a) dB = flint.det_20140704( a ) if dG==dB: #sys.stdout.write('.') return print 'test failed, det good/bad=%s/%s' % (dG,dB) print m assert 0
def test_m(m,i_m_first): global t_FLINT, t_RAZIN a=flint.fmpz_mat( m ) if i_m_first: t0=time.time() dG = flint.det(a) t1=time.time() dB = flint.det_20140704( a ) t2=time.time() t_FLINT += t1-t0 t_RAZIN += t2-t1 else: t0=time.time() dB = flint.det_20140704( a ) t1=time.time() dG = flint.det(a) t2=time.time() t_FLINT += t2-t1 t_RAZIN += t1-t0 if dG==dB: return print 'test failed, det good/bad=%s/%s' % (dG,dB) print m.__repr__() assert 0
def det_FLINT(a): return flint.det( fmpz_mat(a) )
dim=9 ZZ=sage.all.ZZ def straighten( xx ): r=[] for i in xx: for j in i: r.append(j) return r def random_matrice(): a=sage.all.random_matrix(ZZ, dim, x=-100, y = 100) return a sys.stdout.write('+') for i in range(10): a=random_matrice() # both forms of constructors work if i&1: b=flint.fmpz_mat( a ) else: b=flint.fmpz_mat( (dim, dim, straighten(list(a))) ) if 0: print 'b=',repr(b) else: sys.stdout.write('.') assert flint.det(b)==a.determinant(algorithm='ntl',proof=True) print '\ntest passed'