def __init__(self, A, gens=None, given_by_matrix=False): """ EXAMPLES:: sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) sage: I = A.ideal(A([0,1])) sage: TestSuite(I).run(skip="_test_category") # Currently ideals are not using the category framework """ k = A.base_ring() n = A.degree() if given_by_matrix: self._basis_matrix = gens gens = gens.rows() elif gens is None: self._basis_matrix = Matrix(k, 0, n) elif isinstance(gens, (list, tuple)): B = [ FiniteDimensionalAlgebraIdeal(A, x).basis_matrix() for x in gens ] B = reduce(lambda x, y: x.stack(y), B, Matrix(k, 0, n)) self._basis_matrix = B.echelon_form().image().basis_matrix() elif is_Matrix(gens): gens = FiniteDimensionalAlgebraElement(A, gens) elif isinstance(gens, FiniteDimensionalAlgebraElement): gens = gens.vector() B = Matrix([gens * b for b in A.table()]) self._basis_matrix = B.echelon_form().image().basis_matrix() Ideal_generic.__init__(self, A, gens)
def init_sdp(self): """ This method simply initializes the semidefinite program, corresponding to the input data. """ n = self.NumVars N = self.NumMonomials(n, 2 * self.Relaxation) self.MatSize = [self.NumMonomials(n, self.Relaxation), N] Blck = [[] for i in range(N)] C = [] for idx in range(self.NumberOfConstraints): d = self.NumMonomials(n, self.Relaxation - self.HalfDegs[idx]) h = Matrix(self.Field, d, d, 0) C.append(h) Mmnt = self.LocalizedMomentMatrix(idx) for i in range(N): p = self.Monomials[i] A = self.Calpha(p, Mmnt) Blck[i].append(A) for i in range(N): Blck[i].append(Matrix(self.Field, 1, 1, 0)) Blck[i].append(Matrix(self.Field, 1, 1, 0)) Blck[0][self.NumberOfConstraints][0] = 1 Blck[0][self.NumberOfConstraints + 1][0] = -1 C.append(Matrix(self.Field, 1, 1, 1)) C.append(Matrix(self.Field, 1, 1, -1)) self.Matrice = [C, self.PolyCoefFullVec(), Blck]
def __init__(self, F, Nbound = 50,Tbound = 5, prec = 500): self._F = F self._solved = False self._disc = self._F.discriminant() self._w = self._F.maximal_order().ring_generators()[0] self._eps = self._F.units()[0] self._Phi = self._F.real_embeddings(prec=prec) a = F.gen() self.Pointxy = namedtuple('Pointxy', 'x y') if self._disc % 2 ==0 : self._changebasismatrix = 1 else: self._changebasismatrix = Matrix(IntegerRing(),2,2,[1,-1,0,2]) # We assume here that Phi orders the embeddings to that # Phi[1] is the largest self._Rw = self._Phi[1](self._w) self._Rwconj = self._Phi[0](self._w) self._used_regions = [] self._Nboundmin = 2 self._Nboundmax = Nbound self._Nboundinc = 1 self._Nbound = Nbound self._epsto = [self._F(1)] self._Dmax = self.embed(self._w) self._Tbound = Tbound self._ranget = sorted(range(-self._Tbound,self._Tbound+2),key=abs) self._M = ~Matrix(RealField(), 2, 2, [1,self._Rw,1,self._Rwconj]) self.initialize_fundom() self._master_regs = Regions(self) self._maxdepth = 0
def find_correct_matrix(M, N): r""" Given a matrix M1 that maps infinity to a/c this returns a matrix M2 Matrix([[A,B],[C,D]]) that maps infinity to a Gamma0(N)-equivalent cusp A/C and satisfies, C|N, C>0, (A,N)=1 and N|B. It also returns T^n = Matrix([[1,n],[0,1]]) such that M2*T^n*M1**(-1) is in Gamma0(N). """ a, b, c, d = list(map(lambda x: ZZ(x), M.list())) if (c > 0 and c.divides(N) and gcd(a, N) == 1 and b % N == 0): return M, identity_matrix(2) if c == 0: return Matrix([[1, 0], [N, 1]]), identity_matrix(2) cusps = cusps_of_gamma0(N) for cusp in cusps: if Cusp(QQ(a) / QQ(c)).is_gamma0_equiv(cusp, N): break A, C = cusp.numerator(), cusp.denominator() _, D, b = xgcd(A, N * C) M2 = Matrix([[A, -N * b], [C, D]]) n = 0 T = Matrix([[1, 1], [0, 1]]) tmp = identity_matrix(2) while True: if N.divides((M2 * tmp * M**(-1))[1][0]): return M2, tmp elif N.divides((M2 * tmp**(-1) * M**(-1))[1][0]): return M2, tmp**(-1) tmp = tmp * T
def symmetric_matrix(self): r""" The symmetric matrix `M` such that `(x y z) M (x y z)^t` is the defining equation of ``self``. EXAMPLES :: sage: R.<x, y, z> = QQ[] sage: C = Conic(x^2 + x*y/2 + y^2 + z^2) sage: C.symmetric_matrix() [ 1 1/4 0] [1/4 1 0] [ 0 0 1] sage: C = Conic(x^2 + 2*x*y + y^2 + 3*x*z + z^2) sage: v = vector([x, y, z]) sage: v * C.symmetric_matrix() * v x^2 + 2*x*y + y^2 + 3*x*z + z^2 """ a, b, c, d, e, f = self.coefficients() if self.base_ring().characteristic() == 2: if b == 0 and c == 0 and e == 0: return Matrix([[a,0,0],[0,d,0],[0,0,f]]) raise ValueError("The conic self (= %s) has no symmetric matrix " \ "because the base field has characteristic 2" % \ self) return Matrix([[ a , b/2, c/2 ], [ b/2, d , e/2 ], [ c/2, e/2, f ]])
def __init__(self,F,Nbound=_sage_const_50 ,Tbound=_sage_const_5 ): self._F=F self._solved=False self._disc=self._F.discriminant() self._w=self._F.maximal_order().ring_generators()[_sage_const_0 ] self._eps=self._F.units()[_sage_const_0 ] self._Phi=self._F.real_embeddings(prec=_sage_const_500 ) a=F.gen() self.Pointxy=namedtuple('Pointxy','x y') if(self._disc%_sage_const_2 ==_sage_const_0 ): self._changebasismatrix=_sage_const_1 else: self._changebasismatrix=Matrix(IntegerRing(),_sage_const_2 ,_sage_const_2 ,[_sage_const_1 ,-_sage_const_1 ,_sage_const_0 ,_sage_const_2 ]) # We assume here that Phi orders the embeddings to that # Phi[1] is the largest self._Rw=self._Phi[_sage_const_1 ](self._w) self._Rwconj=self._Phi[_sage_const_0 ](self._w) self._used_regions=[] self._Nboundmin=_sage_const_2 self._Nboundmax=Nbound self._Nboundinc=_sage_const_1 self._Nbound=Nbound self._epsto=[self._F(_sage_const_1 )] self._Dmax=self.embed(self._w) self._Tbound=Tbound self._ranget=sorted(range(-self._Tbound,self._Tbound+_sage_const_2 ),key=abs) self._M=Matrix(RealField(),_sage_const_2 ,_sage_const_2 ,[_sage_const_1 ,self._Rw,_sage_const_1 ,self._Rwconj]).inverse() self.initialize_fundom() self._master_regs=Regions(self) self._maxdepth=_sage_const_0
def __init__(self, A, elt=None, check=True): """ TESTS:: sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1,0], [0,1]]), Matrix([[0,1], [0,0]])]) sage: A(QQ(4)) Traceback (most recent call last): ... TypeError: elt should be a vector, a matrix, or an element of the base field sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]), Matrix([[0,1], [-1,0]])]) sage: elt = B(Matrix([[1,1], [-1,1]])); elt e0 + e1 sage: TestSuite(elt).run() sage: B(Matrix([[0,1], [1,0]])) Traceback (most recent call last): ... ValueError: matrix does not define an element of the algebra """ AlgebraElement.__init__(self, A) k = A.base_ring() n = A.degree() if elt is None: self._vector = vector(k, n) self._matrix = Matrix(k, n) else: if isinstance(elt, int): elt = Integer(elt) elif isinstance(elt, list): elt = vector(elt) if A == elt.parent(): self._vector = elt._vector.base_extend(k) self._matrix = elt._matrix.base_extend(k) elif k.has_coerce_map_from(elt.parent()): e = k(elt) if e == 0: self._vector = vector(k, n) self._matrix = Matrix(k, n) elif A.is_unitary(): self._vector = A._one * e self._matrix = Matrix.identity(k, n) * e else: raise TypeError("algebra is not unitary") elif is_Vector(elt): self._vector = elt.base_extend(k) self._matrix = Matrix( k, sum([elt[i] * A.table()[i] for i in range(n)])) elif is_Matrix(elt): if not A.is_unitary(): raise TypeError("algebra is not unitary") self._vector = A._one * elt if not check or sum( [self._vector[i] * A.table()[i] for i in range(n)]) == elt: self._matrix = elt else: raise ValueError( "matrix does not define an element of the algebra") else: raise TypeError("elt should be a vector, a matrix, " + "or an element of the base field")
def decompose(self): """ Gives an SOS decomposition of f if exists as a list of polynomials of at most half degree of f. This method also fills the 'Info' as 'minimize' does. In addition, returns Info['is sos'] which is Boolean depending on the status of sdp solver. """ n = self.NumVars N0 = self.NumMonomials(n, self.MainPolyHlfDeg) N1 = self.NumMonomials(n, self.MainPolyTotDeg) self.MatSize = [N0, N1] vec = self.MonomialsVec(self.MainPolyHlfDeg) m = Matrix(1, N0, vec) Mmnt = m.transpose() * m Blck = [[] for i in range(N1)] C = [] h = Matrix(self.Field, N0, N0, 0) C.append(h) decomp = [] for i in range(N1): p = self.Monomials[i] A = self.Calpha(p, Mmnt) Blck[i].append(A) from SDP import SDP sos_sdp = SDP.sdp(solver=self.solver, Settings={'detail': self.detail}) sos_sdp.solve(C, self.PolyCoefFullVec(), Blck) if sos_sdp.Info['Status'] == 'Optimal': self.Info['status'] = 'Feasible' GramMtx = Matrix(sos_sdp.Info['X'][0]) try: self.Info[ 'Message'] = "A SOS decomposition of the polynomial were found." self.Info['is sos'] = True H1 = GramMtx.cholesky() tmpM = Matrix(1, N0, vec) decomp = list(tmpM * H1)[0] self.Info['Wall'] = sos_sdp.Info['Wall'] self.Info['CPU'] = sos_sdp.Info['CPU'] except: self.Info[ 'Message'] = "The given polynomial seems to be a sum of squares, but no SOS decomposition were extracted." self.Info['is sos'] = False self.Info['Wall'] = sos_sdp.Info['Wall'] self.Info['CPU'] = sos_sdp.Info['CPU'] else: self.Info[ 'Message'] = "The given polynomial is not a sum of squares." self.Info['status'] = 'Infeasible' self.Info['is sos'] = False self.Info["Size"] = self.MatSize return decomp
def projection_to_homology(tri,angle): non_tree_as_cycles = non_tree_edge_cycles(tri, angle) Q = Matrix(non_tree_as_cycles) S, U, V = faces_in_smith(tri,angle,[]) rank, dimU, dimV = rank_of_quotient(S) U = Matrix(U) P = U.transpose().inverse() P = P.delete_rows(range(0, dimU-rank)) A = P*Q return A
def Eij(i, j, N): #The matrix which just has one non-zero entry, 1, at (i+1,j+1). ei, ej = [], [] for k in range(N): if k == i: ei.append([1]) else: ei.append([0]) if k == j: ej.append([1]) else: ej.append([0]) return Matrix(ei) * Matrix(ej).T
def qexp_to_basis(f, E, p=None, check=True): ncols = len(list(f)) try: R = f.parent().base_ring() except (AttributeError,TypeError): R = E.parent().base_ring() try: fmat = Matrix(R,1,len(f), f.list()) except AttributeError: fmat = Matrix(R,1,len(f), f) verbose('R = %s'%R) verbose('E.parent() = %s'%E.parent()) return vector(solve_xAb_echelon(E.submatrix(0,0,ncols = ncols),fmat,p,check=check).list())
def _get_powers_and_mult(self, a, b, c, d, lambd, vect): r""" Compute the action of a matrix on the basis elements. EXAMPLES: :: """ try: xnew = self._powers[(a, b, c, d)] except KeyError: R = self._PowerSeries r = R([b, a]) s = R([d, c]) n = self._n if self._depth == n + 1: rpows = [R(1)] spows = [R(1)] for ii in range(n): rpows.append(r * rpows[ii]) spows.append(s * spows[ii]) x = Matrix(self._Rmod, n + 1, n + 1, 0) for ii in range(n + 1): y = rpows[ii] * spows[n - ii] for jj in range(self._depth): x[ii, jj] = y[jj] else: ratio = r * (s**(-1)) y = s**n x = Matrix(self._Rmod, self._depth, self._depth, 0) for jj in range(self._depth): x[0, jj] = y[jj] for ii in range(1, self._depth): y *= ratio for jj in range(self._depth): x[ii, jj] = y[jj] xnew = x.change_ring(self._R) #ZZ) # if self._Rmod is self._R: # xnew = x # else: # #xnew = x.change_ring(self._R) # xnew = x.change_ring(ZZ) self._powers[(a, b, c, d)] = xnew tmp = xnew * vect return self._R(lambd) * tmp #.change_ring(self._R)
def solve_xAb_echelon(A,b, p=None, prec=None, check=False): r''' TESTS:: sage: from functions import * sage: A = Matrix(ZZ,2,3,[1,0,2,0,2,3]) sage: is_echelon(A) True sage: b = vector(QQ,3,[4,5,6]) sage: solve_xAb_echelon(A,b) (4, 5/2) sage: _ * A - b (0, 0, 19/2) ''' R = b.parent().base_ring() try: R = R.fraction_field() except (AttributeError,TypeError): pass if p is None: try: p = R.cardinality().factor()[0][0] # DEBUG except AttributeError: p = 0 if check and not is_echelon(A): raise ValueError("Not in echelon form") hnew = try_lift(b.parent()(b)) ell = A.nrows() A = try_lift(A) col_list = [] for j in range(ell): ej = A.row(j) ejleadpos, val = first_nonzero_pos(ej,return_val=True) newcol = [hnew[i,ejleadpos] / val for i in range(hnew.nrows())] tmp1 = Matrix(hnew.parent().base_ring(), hnew.nrows(),1, newcol) tmp2 = Matrix(ej.parent().base_ring(),1,len(ej),ej.list()) hnew -= tmp1 * tmp2 col_list.append(newcol) alphas = Matrix(R,ell,hnew.nrows(),col_list).transpose() verbose('Check = %s, p = %s'%(check,p)) if check and p > 0: verbose('Check with p = %s'%p) err = min([o.valuation(p) for o in (alphas * try_lift(A) - try_lift(b)).list()]) if err < 5: verbose('Check not passed!') raise RuntimeError("System appears not to be solvable. Minimal valuation is %s"%err) return alphas
def analyze_deeply(tri, angle): N = edge_equation_matrix_taut(tri, angle) N = Matrix(N) M = snappy.Manifold(tri.snappystring()) # look at it alex = alex_is_monic(M) hyper = hyper_is_monic(M) non_triv, non_triv_sol = non_trivial_solution(N) full, full_sol = fully_carried_solution(N) try: assert non_triv or not full # full => non_triv assert alex or not full # full => fibered => alex is monic assert hyper or not full # full => fibered => hyper is monic assert alex or not hyper # hyper is monic => alex is monic except AssertError: print("contradiction in maths") raise if full: pass elif non_triv: print("non-triv sol (but not full)") print((alex, hyper)) elif not alex or not hyper: print("no sol") print((alex, hyper)) return None
def unitary_reflection(self, r, alpha=-1): S = self.complex_gram_matrix() r_conj = vector([x.galois_conjugate() for x in r]) r_norm = r * S * r_conj if not r_norm: raise ValueError('Not a valid reflection') d = self._hds_to_ds() d_inv = self._ds_to_hds() r0 = ((1 - alpha) / r_norm) * (S * r_conj) g = self.base_field().gens()[0] w = self._w() w_conj = w.galois_conjugate() M = Matrix(ZZ, [[2, w + w_conj], [0, (w - w_conj) * g]]).inverse() def f(x): v = vector(d_inv[tuple(x)]) v = v - (v * r0) * r x = [0] * (2 * len(v)) for i, v in enumerate(v): v_conj = v.galois_conjugate() a, b = (v + v_conj), (v - v_conj) * g x[i + i], x[i + i + 1] = M * vector([a, b]) return tuple(map(frac, x)) return WeilRepAutomorphism(self, f)
def incidence_matrix(self): """ Return the incidence matrix `A` of the design. A is a `(v \times b)` matrix defined by: ``A[i,j] = 1`` if ``i`` is in block ``B_j`` and 0 otherwise. EXAMPLES:: sage: BD = IncidenceStructure(range(7),[[0,1,2],[0,3,4],[0,5,6],[1,3,5],[1,4,6],[2,3,6],[2,4,5]]) sage: BD.block_sizes() [3, 3, 3, 3, 3, 3, 3] sage: BD.incidence_matrix() [1 1 1 0 0 0 0] [1 0 0 1 1 0 0] [1 0 0 0 0 1 1] [0 1 0 1 0 1 0] [0 1 0 0 1 0 1] [0 0 1 1 0 0 1] [0 0 1 0 1 1 0] """ if not self._incidence_matrix is None: return self._incidence_matrix else: from sage.matrix.constructor import Matrix v = len(self.points()) blks = self.blocks() b = len(blks) A = Matrix(ZZ, v, b, sparse=True) for j, b in enumerate(blks): for i in b: A[i, j] = 1 self._incidence_matrix = A return A
def reflections(self): """ Return the reflections of ``self``. The reflections of a Coxeter group `W` are the conjugates of the simple reflections. They are in bijection with the positive roots, for given a positive root, we may have the reflection in the hyperplane orthogonal to it. This method returns a family indexed by the positive roots taking values in the reflections. This requires ``self`` to be a finite Weyl group. .. NOTE:: Prior to :trac:`20027`, the reflections were the keys of the family and the values were the positive roots. EXAMPLES:: sage: W = WeylGroup("B2", prefix="s") sage: refdict = W.reflections(); refdict Finite family {(1, -1): s1, (1, 1): s2*s1*s2, (1, 0): s1*s2*s1, (0, 1): s2} sage: [r+refdict[r].action(r) for r in refdict.keys()] [(0, 0), (0, 0), (0, 0), (0, 0)] """ ret = {} try: for alp in self.domain().positive_roots(): m = Matrix([self.domain().reflection(alp)(x).to_vector() for x in self.domain().basis()]) r = self(m) ret[alp] = r return Family(ret) except Exception: raise NotImplementedError("reflections are only implemented for finite Weyl groups")
def godement_sheaf(self): """ Returns the Godement sheaf of ``self``. """ g0_stalks = dict() g0_res = dict() for p in self._domain_poset.list(): g0_stalks[p] = sum(self._stalk_dict[x] for x in self._domain_poset.order_filter([p])) for relation in self._domain_poset.cover_relations(): frombase = sorted(self._domain_poset.order_filter([relation[0]])) tobase = sorted(self._domain_poset.order_filter([relation[1]])) rows = [] for row in tobase: m = self._stalk_dict[row] blocks = [] for x in frombase: if x == row: blocks.append(identity_matrix(m)) else: blocks.append(Matrix(m, self._stalk_dict[x])) rows.append(blocks) g0_res[tuple(relation)] = block_matrix(rows, subdivide=False) G0 = LocallyFreeSheafFinitePoset(g0_stalks, g0_res, self._base_ring, self._domain_poset) hom = Hom(self, G0) eps_dict = dict() for p in self._domain_poset.list(): rows = [] for x in sorted(self._domain_poset.order_filter([p])): if x == p: rows.append([identity_matrix(self._base_ring, self._stalk_dict[p])]) else: rows.append([self.restriction(p, x).matrix()]) eps_dict[p] = block_matrix(rows, subdivide=False) epsilon = hom(eps_dict) return epsilon, G0
def hecke_matrix_on_ord(ll, ord_basis, weight = 2, level = 1, eps = None, p=None, prec=None, check_is_operator=True): R = ord_basis.parent().base_ring() if prec is None: try: prec = R.precision_cap() except AttributeError: pass ncols = ZZ(floor( (ord_basis.ncols() - 1) / ll)) + 1 if ncols < ord_basis.nrows(): raise ValueError("Cannot compute the matrix of T_ell with ell=%s because of lack of precision. (nrows = %s, ncols = %s)"%(ll, ord_basis.nrows(), ncols)) M = Matrix(R, ord_basis.nrows(), ncols, 0) if eps is None: eps = lambda ll : ZZ(1) if gcd(level,ll) == 1 else ZZ(0) if weight is None: assert eps(ll) == 0 llpow_eps = 0 else: llpow_eps = ll**(weight-1) * eps(ll) for i, b in enumerate(ord_basis): for j in range(ncols): M[i, j] = b[j * ll] if j % ll == 0: M[i, j] += R(llpow_eps) * b[j // ll] small_mat = ord_basis.submatrix(0,0,ncols = ncols) assert is_echelon(small_mat) ans = solve_xAb_echelon(small_mat,M,p, prec, check=check_is_operator) return ans
def left_table(self): """ Return the list of matrices for left multiplication by the basis elements. EXAMPLES:: sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]), Matrix([[0,1],[-1,0]])]) sage: T = B.left_table(); T ( [1 0] [ 0 1] [0 1], [-1 0] ) We check immutability:: sage: T[0] = "vandalized by h4xx0r" Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment sage: T[1][0] = [13, 37] Traceback (most recent call last): ... ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M). """ B = self.table() n = self.degree() table = [Matrix([B[j][i] for j in range(n)]) for i in range(n)] for b in table: b.set_immutable() return tuple(table)
def _an_element_(self): r""" """ return OCVnElement(self, Matrix(self._R, self._depth, 1, range(1, self._depth + 1)), check=False)
def basis(self): r""" A basis of the module. INPUT: - ``x`` - integer (default: 1) the description of the argument x goes here. If it contains multiple lines, all the lines after the first need to be indented. - ``y`` - integer (default: 2) the ... """ try: return self._basis except: pass self._basis = [ OCVnElement(self, Matrix(self._R, self._depth, 1, {(jj, 0): 1}, sparse=False), check=False) for jj in range(self._depth) ] return self._basis
def _get_powers(self, abcd, emb=None): abcd = tuple(abcd.list()) try: return self._cache_powers[abcd] except KeyError: pass R = self._PowerSeries if emb is None: a, b, c, d = abcd else: a, b, c, d = emb(abcd).list() r = R([b, a]) s = R([d, c]) ratio = r * s**-1 ratio = ratio.change_ring(ZZ) y = R(1).change_ring(ZZ) xlist = [1] + [0 for o in range(self._depth - 1)] for ii in range(1, self._depth): y *= ratio ylist = y.list()[:self._depth] xlist.extend(ylist) xlist.extend([ZZ(0) for o in range(self._depth - len(ylist))]) x = Matrix(R.base_ring(), self._depth, self._depth, xlist).apply_map(ZZ) self._cache_powers[abcd] = x return x
def automorphy_factor_matrix(p, a, c, k, chi, p_prec, var_prec, R): """ EXAMPLES:: sage: from sage.modular.pollack_stevens.families_util import automorphy_factor_matrix sage: automorphy_factor_matrix(3, 1, 3, 0, None, 4, 3, PowerSeriesRing(ZpCA(3), 'w')) [ 1 + O(3^20) 0 0 0] [O(3^20) + (3 + 3^2 + 2*3^3 + O(3^20))*w + (3^2 + 2*3^3 + O(3^20))*w^2 1 + O(3^20) 0 0] [ O(3^20) + (3^2 + 2*3^3 + O(3^20))*w + (2*3^2 + O(3^20))*w^2 O(3^20) + (3 + 3^2 + 2*3^3 + O(3^20))*w + (3^2 + 2*3^3 + O(3^20))*w^2 1 + O(3^20) 0] [ O(3^20) + (3^2 + 3^3 + O(3^20))*w + (2*3^3 + O(3^20))*w^2 O(3^20) + (3^2 + 2*3^3 + O(3^20))*w + (2*3^2 + O(3^20))*w^2 O(3^20) + (3 + 3^2 + 2*3^3 + O(3^20))*w + (3^2 + 2*3^3 + O(3^20))*w^2 1 + O(3^20)] sage: p, a, c, k, chi, p_prec, var_prec, R = 11, -3, 11, 2, None, 6, 4, PowerSeriesRing(ZpCA(11, 6), 'w') sage: afm = automorphy_factor_matrix(p, a, c, k, chi, p_prec, var_prec, R) sage: for e in afm: ... print e (9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3, 0, 0, 0, 0, 0) (O(11^6) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + O(11^6))*w + (7*11^2 + 4*11^3 + 5*11^4 + O(11^6))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + O(11^6))*w^3, 9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3, 0, 0, 0, 0) (O(11^6) + (5*11^2 + 2*11^3 + 10*11^4 + 3*11^5 + O(11^6))*w + (6*11^2 + 3*11^3 + 5*11^4 + 11^5 + O(11^6))*w^2 + (5*11^3 + 6*11^4 + 5*11^5 + O(11^6))*w^3, O(11^6) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + O(11^6))*w + (7*11^2 + 4*11^3 + 5*11^4 + O(11^6))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + O(11^6))*w^3, 9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3, 0, 0, 0) (O(11^6) + (6*11^3 + 11^5 + O(11^6))*w + (2*11^3 + 8*11^4 + 4*11^5 + O(11^6))*w^2 + (3*11^3 + 11^4 + 3*11^5 + O(11^6))*w^3, O(11^6) + (5*11^2 + 2*11^3 + 10*11^4 + 3*11^5 + O(11^6))*w + (6*11^2 + 3*11^3 + 5*11^4 + 11^5 + O(11^6))*w^2 + (5*11^3 + 6*11^4 + 5*11^5 + O(11^6))*w^3, O(11^6) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + O(11^6))*w + (7*11^2 + 4*11^3 + 5*11^4 + O(11^6))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + O(11^6))*w^3, 9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3, 0, 0) (O(11^6) + (7*11^4 + 5*11^5 + O(11^6))*w + (10*11^5 + O(11^6))*w^2 + (7*11^4 + 11^5 + O(11^6))*w^3, O(11^6) + (6*11^3 + 11^5 + O(11^6))*w + (2*11^3 + 8*11^4 + 4*11^5 + O(11^6))*w^2 + (3*11^3 + 11^4 + 3*11^5 + O(11^6))*w^3, O(11^6) + (5*11^2 + 2*11^3 + 10*11^4 + 3*11^5 + O(11^6))*w + (6*11^2 + 3*11^3 + 5*11^4 + 11^5 + O(11^6))*w^2 + (5*11^3 + 6*11^4 + 5*11^5 + O(11^6))*w^3, O(11^6) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + O(11^6))*w + (7*11^2 + 4*11^3 + 5*11^4 + O(11^6))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + O(11^6))*w^3, 9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3, 0) (O(11^6) + (7*11^5 + O(11^6))*w + (11^5 + O(11^6))*w^2 + (7*11^5 + O(11^6))*w^3, O(11^6) + (7*11^4 + 5*11^5 + O(11^6))*w + (10*11^5 + O(11^6))*w^2 + (7*11^4 + 11^5 + O(11^6))*w^3, O(11^6) + (6*11^3 + 11^5 + O(11^6))*w + (2*11^3 + 8*11^4 + 4*11^5 + O(11^6))*w^2 + (3*11^3 + 11^4 + 3*11^5 + O(11^6))*w^3, O(11^6) + (5*11^2 + 2*11^3 + 10*11^4 + 3*11^5 + O(11^6))*w + (6*11^2 + 3*11^3 + 5*11^4 + 11^5 + O(11^6))*w^2 + (5*11^3 + 6*11^4 + 5*11^5 + O(11^6))*w^3, O(11^6) + (8*11 + 3*11^2 + 6*11^3 + 11^4 + 6*11^5 + O(11^6))*w + (7*11^2 + 4*11^3 + 5*11^4 + O(11^6))*w^2 + (10*11^3 + 3*11^4 + 4*11^5 + O(11^6))*w^3, 9 + 6*11^2 + 11^3 + 9*11^4 + 8*11^5 + O(11^6) + (8*11^2 + 8*11^3 + 10*11^4 + 6*11^5 + O(11^6))*w + (7*11^3 + 11^4 + 8*11^5 + O(11^6))*w^2 + (10*11^4 + 7*11^5 + O(11^6))*w^3) """ #RH: there's a problem when p_prec = 1 aut = automorphy_factor_vector(p, a, c, k, chi, p_prec, var_prec, R) M = Matrix(R, p_prec) for c in range(min(p_prec, len(aut))): for r in range(min(p_prec, len(aut) - c)): M[r + c, c] = aut[r] return M
def __init__(self, parent, val=0, check=True, normalize=False): ModuleElement.__init__(self, parent) self._parent = parent self._depth = self._parent._depth if not check: self._val = val else: if isinstance(val, self.__class__): if val._parent._depth == parent._depth: self._val = val._val else: d = min([val._parent._depth, parent._depth]) self._val = val._val.submatrix(0, 0, nrows=d) elif isinstance(val, Vector_integer_dense) or isinstance( val, FreeModuleElement_generic_dense): self._val = MatrixSpace(self._parent._R, self._depth, 1)(0) for i, o in enumerate(val.list()): self._val[i, 0] = o else: try: self._val = Matrix(self._parent._R, self._depth, 1, val) except (TypeError, ValueError): self._val = self._parent._R(val) * MatrixSpace( self._parent._R, self._depth, 1)(1) self._moments = self._val
def is_start_of_basis_new(self, List): r""" Determines if the inputed list of OMS's can be extended to a basis of this space INPUT: - ``list`` -- a list of OMS's OUTPUT: - True/False """ for Phi in List: assert Phi.valuation() >= 0, "Symbols must be integral" d = len(List) if d == 1: L = List[0].list_of_total_measures() for mu in L: if not mu.is_zero(): return True return False R = self.base() List = [Phi.list_of_total_measures() for Phi in List] A = Matrix(R.residue_field(), d, len(List[0]), List) return A.rank() == d
def __call__(self, f, check=True, unitary=True): """ Construct a homomorphism. .. TODO:: Implement taking generator images and converting them to a matrix. EXAMPLES:: sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])]) sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) sage: H = Hom(A, B) sage: H(Matrix([[1, 0]])) Morphism from Finite-dimensional algebra of degree 1 over Rational Field to Finite-dimensional algebra of degree 2 over Rational Field given by matrix [1 0] """ if isinstance(f, FiniteDimensionalAlgebraMorphism): if f.parent() is self: return f if f.parent() == self: return FiniteDimensionalAlgebraMorphism( self, f._matrix, check, unitary) elif is_Matrix(f): return FiniteDimensionalAlgebraMorphism(self, f, check, unitary) try: from sage.matrix.constructor import Matrix return FiniteDimensionalAlgebraMorphism(self, Matrix(f), check, unitary) except Exception: return RingHomset_generic.__call__(self, f, check)
def reflections(self): """ The reflections of W are the conjugates of the simple reflections. They are in bijection with the positive roots, for given a positive root, we may have the reflection in the hyperplane orthogonal to it. This method returns a dictionary indexed by the reflections taking values in the positive roots. This requires self to be a finite Weyl group. EXAMPLES:: sage: W = WeylGroup("B2", prefix="s") sage: refdict = W.reflections(); refdict Finite family {s1: (1, -1), s2*s1*s2: (1, 1), s1*s2*s1: (1, 0), s2: (0, 1)} sage: [refdict[r]+r.action(refdict[r]) for r in refdict.keys()] [(0, 0), (0, 0), (0, 0), (0, 0)] """ ret = {} try: for alp in self.domain().positive_roots(): m = Matrix([self.domain().reflection(alp)(x).to_vector() for x in self.domain().basis()]) r = self(m) ret[r] = alp return Family(ret) except StandardError: raise NotImplementedError, "reflections are only implemented for finite Weyl groups"
def discriminant(self): """ Return the discriminant of this ring, which is the discriminant of the trace pairing. .. note:: One knows that for modular abelian varieties, the endomorphism ring should be isomorphic to an order in a number field. However, the discriminant returned by this function will be `2^n` ( `n =` self.dimension()) times the discriminant of that order, since the elements are represented as 2d x 2d matrices. Notice, for example, that the case of a one dimensional abelian variety, whose endomorphism ring must be ZZ, has discriminant 2, as in the example below. EXAMPLES:: sage: J0(33).endomorphism_ring().discriminant() -64800 sage: J0(46).endomorphism_ring().discriminant() # long time (6s on sage.math, 2011) 24200000000 sage: J0(11).endomorphism_ring().discriminant() 2 """ g = self.gens() M = Matrix(ZZ,len(g), [ (g[i]*g[j]).trace() for i in range(len(g)) for j in range(len(g)) ]) return M.determinant()
def _godement_complex_differential(self, start_base, end_base): """ Construct the differential of the godement cochain complex from the free module with basis ``start_base`` to the free module with basis ``end_base``. """ rows = [] for to_chain in end_base: blocks = [] m = self._stalk_dict[to_chain[-1]] for from_chain in start_base: n = self._stalk_dict[from_chain[-1]] if all(x in to_chain for x in from_chain): for point in to_chain: if point not in from_chain: index = to_chain.index(point) sign = 1 if index % 2 == 0 else - 1 if index != len(to_chain) - 1: blocks.append(sign*identity_matrix(self._base_ring, m)) else: mat = self.restriction(from_chain[-1], point).matrix() blocks.append(sign*mat) break else: blocks.append(Matrix(self._base_ring, m, n)) rows.append(blocks) return block_matrix(rows, subdivide=False)