def basis_to_ker_basis(self): C = ModMatrix(self.get_extended_ker_basis()) C.transpose() inv = C.get_inverse() if not inv: raise TypeError("the matrix is not invertible! Something went very wrong") return inv
def cohom_test(x,y,z,n): for i in range(n): AA = ModMatrix.random(y,z) BB = ModMatrix.random(x,y) if (BB * AA).is_zero(): print"BB\n", BB, "\n" print "AA\n", AA, "\n" coh = Cohomology(BB, AA) print coh.get_cohomology()
def cohom_test(x, y, z, n): for i in range(n): AA = ModMatrix.random(y, z) BB = ModMatrix.random(x, y) if (BB * AA).is_zero(): print "BB\n", BB, "\n" print "AA\n", AA, "\n" coh = Cohomology(BB, AA) print coh.get_cohomology()
def matrix_add(i, j, n): for a in range(n): xx = ModMatrix.random(i, j) yy = ModMatrix.random(i, j) print xx, "\n", yy, "\n", xx + yy, "\n" xx = ModMatrix.random(i, j) yy = ModMatrix.random(i + 1, j + 1) try: print xx + yy except TypeError: print xx, "\n", "wrong size", "\n", yy
def matrix_add(i, j, n): for a in range(n): xx = ModMatrix.random(i, j) yy = ModMatrix.random(i, j) print xx, "\n", yy, "\n", xx + yy, "\n" xx = ModMatrix.random(i, j) yy = ModMatrix.random(i+1, j+1) try: print xx + yy except TypeError: print xx, "\n", "wrong size", "\n", yy
def extend_ker_basis(self): ker_basis = self.get_kernel().get_basis() #assuming vectors are bit vectors if not ker_basis: C = ModMatrix.null(1, self.B.col_count) else: C = ModMatrix(ker_basis) comp = C.complement_row_space() tot = ker_basis[:] + comp[:] self.extended_ker_basis = tot self.extended_ker_basis_flag = True
def solve_test(x, y, n): for i in range(n): AA = ModMatrix.random(x, y) bb = ModVector.random(x) print AA.can_solve(bb) xx = AA.solve(bb) print "A\n", AA, "\n" print "rrefA\n", AA.get_rref(), "\n" print "b\n", bb, "\n" print "x\n", xx, "\n" print "Ax\n", AA * xx print AA * xx == ModMatrix([bb]).get_transpose()
def append_test(x,y,n): for i in range(n): AA = ModMatrix.random(x,y) zz = ModVector.random(x) print "AA\n", AA, "\n" print "zz\n", zz, "\n" print "append\n", AA.get_append_columns([zz,zz + zz]), "\n"
def inv_test(x,n): for i in range(n): AA = ModMatrix.random(x,x) print "AA\n", AA, "\n" print "inv\n", AA.get_inverse(), "\n" if AA.get_inverse(): print "Ix\n", AA * AA.get_inverse(), "\n"
def inv_test(x, n): for i in range(n): AA = ModMatrix.random(x, x) print "AA\n", AA, "\n" print "inv\n", AA.get_inverse(), "\n" if AA.get_inverse(): print "Ix\n", AA * AA.get_inverse(), "\n"
def append_test(x, y, n): for i in range(n): AA = ModMatrix.random(x, y) zz = ModVector.random(x) print "AA\n", AA, "\n" print "zz\n", zz, "\n" print "append\n", AA.get_append_columns([zz, zz + zz]), "\n"
def ker_test(x,y,n): for i in range(n): AA = ModMatrix.random(x,y) print AA.get_rref(), "\n" ker = AA.get_kernel() for xx in ker: print "soln\n", xx, "\n" print "result\n", AA * xx
def ker_test(x, y, n): for i in range(n): AA = ModMatrix.random(x, y) print AA.get_rref(), "\n" ker = AA.get_kernel() for xx in ker: print "soln\n", xx, "\n" print "result\n", AA * xx
def make_map(self, i): """ make matrices in all given bidegrees this needs a map defined on CobarMonomial objects does this handle 0 dim vector spaces? this is a huge timesink. try to do multiprocessing, check methods for too much simplification """ dom = self.get_cplx()[i] rng = self.get_cplx()[i+1] for bideg in dom._dict.keys(): out = [] dom_basis = dom._dict[bideg] cols = len(dom_basis) try: rng_basis = rng._dict[bideg] rows = len(rng_basis) except KeyError: rng._dict[bideg] = [] rows = 0 if cols == 0: # we must account for this later! cols = 1 #print "bideg in make maps",bideg dom._maps[bideg] = ModMatrix.null(1,cols) continue if cols == 0: cols = 1 if rows == 0: rows = 1 #print "bideg in make maps. somethings 0", bideg dom._maps[bideg] = ModMatrix.null(rows, cols) continue for mon in dom_basis: value = mon._map_reduced() vect = self.vector_from_element(value, i+1, bideg[0], bideg[1]) out.append(vect) matrix = ModMatrix(out).get_transpose() print " Made matrix: i, bideg, size", i, bideg, matrix.get_size() dom._maps[bideg] = matrix
def make_map(self, i): """ make matrices in all given bidegrees this needs a map defined on CobarMonomial objects does this handle 0 dim vector spaces? this is a huge timesink. try to do multiprocessing, check methods for too much simplification """ dom = self.get_cplx()[i] rng = self.get_cplx()[i + 1] for bideg in dom._dict.keys(): out = [] dom_basis = dom._dict[bideg] cols = len(dom_basis) try: rng_basis = rng._dict[bideg] rows = len(rng_basis) except KeyError: rng._dict[bideg] = [] rows = 0 if cols == 0: # we must account for this later! cols = 1 #print "bideg in make maps",bideg dom._maps[bideg] = ModMatrix.null(1, cols) continue if cols == 0: cols = 1 if rows == 0: rows = 1 #print "bideg in make maps. somethings 0", bideg dom._maps[bideg] = ModMatrix.null(rows, cols) continue for mon in dom_basis: value = mon._map_reduced() vect = self.vector_from_element(value, i + 1, bideg[0], bideg[1]) out.append(vect) matrix = ModMatrix(out).get_transpose() print " Made matrix: i, bideg, size", i, bideg, matrix.get_size() dom._maps[bideg] = matrix
def rref_test(x, y, n): for i in range(n): xx = ModMatrix.random(x, y) xx.compute_rref() print xx, "\n" print xx.rref, "\n" print xx.basis_change, "\n" pp = xx.basis_change print pp * xx rr = pp * xx print rr == xx.rref
def rref_test(x,y,n): for i in range(n): xx = ModMatrix.random(x,y) xx.compute_rref() print xx, "\n" print xx.rref, "\n" print xx.basis_change, "\n" pp = xx.basis_change print pp * xx rr = pp * xx print rr == xx.rref
def solve_test(x,y,n): for i in range(n): AA = ModMatrix.random(x,y) bb = ModVector.random(x) print AA.can_solve(bb) xx = AA.solve(bb) print "A\n", AA, "\n" print "rrefA\n", AA.get_rref(), "\n" print "b\n", bb, "\n" print "x\n", xx, "\n" print "Ax\n", AA * xx print AA * xx == ModMatrix([bb]).get_transpose()
def make_cohomology(self, filt, deg, wt): """ returns a cohomology object corr. to filt, deg, wt #Returns 0 cohomology object if deg, wt doesn't appera THIS MUTATES ._maps and ._dict IF NECESSARY! """ cplx = self.get_maps() if filt == 0: return "you know what this is!" try: #this checks to make sure cohom is non-zero here B = cplx[filt]._maps[(deg, wt)] B_basis = cplx[filt]._dict[(deg, wt)] except KeyError: if deg <= opts.bounds: return Cohomology(ModMatrix.identity(1), \ ModMatrix.null(1,1)) else: print filt, deg, wt raise TypeError("We aren't computing that far!") try: #this checks to see if incoming map is 0 or not A_basis = cplx[filt - 1]._dict[(deg, wt)] A = cplx[filt - 1]._maps[(deg, wt)] except KeyError: A = ModMatrix.null(len(B_basis), 1) A_basis = [] cplx[filt - 1]._maps[(deg, wt)] = A cplx[filt - 1]._dict[(deg, wt)] = [] # We must now check dimensions of A_basis and B_basis # to account for 0 diml vspaces if len(B_basis) == 0: #this means cohom is 0 diml #resulting cohom object will not match up with vect/elt #translation A = ModMatrix.null(1,1) B = ModMatrix.identity(1) elif not B.row_count: #print "B has no rows" B = ModMatrix.null(1, len(B_basis)) cohom = Cohomology(B, A) self.cohomology[filt][(deg,wt)] = cohom
def make_cohomology(self, filt, deg, wt): """ returns a cohomology object corr. to filt, deg, wt #Returns 0 cohomology object if deg, wt doesn't appera THIS MUTATES ._maps and ._dict IF NECESSARY! """ cplx = self.get_maps() if filt == 0: return "you know what this is!" try: #this checks to make sure cohom is non-zero here B = cplx[filt]._maps[(deg, wt)] B_basis = cplx[filt]._dict[(deg, wt)] except KeyError: if deg <= opts.bounds: return Cohomology(ModMatrix.identity(1), \ ModMatrix.null(1,1)) else: print filt, deg, wt raise TypeError("We aren't computing that far!") try: #this checks to see if incoming map is 0 or not A_basis = cplx[filt - 1]._dict[(deg, wt)] A = cplx[filt - 1]._maps[(deg, wt)] except KeyError: A = ModMatrix.null(len(B_basis), 1) A_basis = [] cplx[filt - 1]._maps[(deg, wt)] = A cplx[filt - 1]._dict[(deg, wt)] = [] # We must now check dimensions of A_basis and B_basis # to account for 0 diml vspaces if len(B_basis) == 0: #this means cohom is 0 diml #resulting cohom object will not match up with vect/elt #translation A = ModMatrix.null(1, 1) B = ModMatrix.identity(1) elif not B.row_count: #print "B has no rows" B = ModMatrix.null(1, len(B_basis)) cohom = Cohomology(B, A) self.cohomology[filt][(deg, wt)] = cohom
def matrix_mul(i,j,k,n): for a in range(n): xx = ModMatrix.random(i,j) yy = ModMatrix.random(j,k) print xx, "\n\n", yy, "\n\n", xx*yy, "\n"
def row_op_test(x,y,n): for i in range(n): xx = ModMatrix.random(x,y) print xx xx.el_row_op( random.randrange(opts.prime), 0, 1) print xx
def rank_test(x, y, n): for i in range(n): AA = ModMatrix.random(x, y) print "AA\n", AA, "\n" print AA.get_rank()
def row_op_test(x, y, n): for i in range(n): xx = ModMatrix.random(x, y) print xx xx.el_row_op(random.randrange(opts.prime), 0, 1) print xx
def matrix_mul(i, j, k, n): for a in range(n): xx = ModMatrix.random(i, j) yy = ModMatrix.random(j, k) print xx, "\n\n", yy, "\n\n", xx * yy, "\n"
def rank_test(x,y,n): for i in range(n): AA = ModMatrix.random(x,y) print "AA\n", AA, "\n" print AA.get_rank()