Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Example code

Project: Math
Views: 20
# The following code computes a basis for the center (up to a given degree) # of a graded (noncommutative) algebra over the rational numbers # with relations as specified. # The center consists of elements a in A such that a x = x a for all x in A import time, string F.<s,v,u,t> = FreeAlgebra(QQ, implementation='letterplace', order='lex', degrees = [3,2,1,3]) I = F*[t*s-s*t, t*v-v*t, t*u-u*t, u*v+v*u-6*t, u*s+s*u-4*v^2, s*v+v*s-4*u^2*t, u^2*v^2+s^2+3*t^2 ]*F # The Hilbert series of the above algebra is given by H(t) = ((1-t^6)/(1-t)/(1-t^2)/(1-t^3)^2) def intersect_row_span_map(list_of_matrices): eqs_for_row_span = lambda m : matrix(m.transpose().kernel().basis()) return matrix(reduce(lambda a, b : a.stack(b), [z for z in map(eqs_for_row_span, list_of_matrices) if z != matrix([])]).transpose().kernel().basis()) import itertools def gen_A_diff_degrees(n): list_of_basis = [[1]] gb = I.groebner_basis(n).gens_reduced() pr = lambda a, l : [a*z for z in l] for k in range(1, n): new_gens = [z for z in F.gens() if z.degree() == k] multipliers = reduce(lambda a, b : a + b,[pr(z, list_of_basis[-z.degree()]) for z in F.gens() if z.degree() <= len(list_of_basis)]) basis_elts = list(set([z for z in multipliers + new_gens if sum([zz.lm_divides(z) for zz in gb]) ==0])) list_of_basis.append(basis_elts) return list_of_basis start = time.time() Gen = gen_A_diff_degrees(20) # print time.time()-start # Assume that input is already in normal form def homog_elt_to_vector(elt): d = elt.degree() if d <= 0: print "input cannot have degree <= 0" sys.exit(1) vv = Gen[d] result = [0]*len(vv) e = elt while e != 0: result[vv.index(e.lt()/e.lc())] = e.lc() e = e - e.lt() return result def commutator(elt,nn): def ff(r): temp = (r*elt - elt*r).normal_form(I) return homog_elt_to_vector(temp) if temp != 0 else [0] * len(Gen[nn + elt.degree()]) return matrix(map(ff,Gen[nn])) def find_central_elements_of_degree(n): Mat = lambda z : matrix(commutator(z, n).kernel().basis()) start = time.time() M = intersect_row_span_map(map(Mat,[z for z in F.gens() if z != t])) end = time.time() print "Computation finished! Time taken ", end - start, " seconds" central = [] for i in M.rows(): central.append(sum([aa*bb for aa,bb in zip(i, Gen[n])])) return central # Prints the central elements in degrees 2 to 9 for i in range(2,9): print "\nDegree ",i print find_central_elements_of_degree(i)
Degree 2 Computation finished! Time taken 0.850368976593 seconds [u*u] Degree 3 Computation finished! Time taken 0.830105066299 seconds [t] Degree 4 Computation finished! Time taken 0.810693025589 seconds [u*u*u*u, v*v] Degree 5 Computation finished! Time taken 0.40895986557 seconds [t*u*u] Degree 6 Computation finished! Time taken 0.997430086136 seconds [-2/3*v*v*v - 1/3*u*v*s + t*s + 2/3*t*u*u*u, u*u*u*u*u*u, u*u*v*v, t*t] Degree 7 Computation finished! Time taken 0.442250013351 seconds [t*u*u*u*u, t*v*v] Degree 8 Computation finished! Time taken 0.841259002686 seconds [-2/3*u*u*v*v*v - 1/3*u*u*u*v*s + t*u*u*s + 2/3*t*u*u*u*u*u, u*u*u*u*u*u*u*u, u*u*u*u*v*v, v*v*v*v, t*t*u*u]