def _repr_(self): r""" Return a string representation of ``self``. Supports printing in exponential coordinates of the first and second kinds, depending on the default coordinate system. EXAMPLES:: sage: L = LieAlgebra(QQ, 2, step=2) sage: G = L.lie_group('H') sage: g = G.point([1, 2, 3]); g exp(X_1 + 2*X_2 + 3*X_12) sage: G.set_default_chart(G.chart_exp2()) sage: g exp(4*X_12)exp(2*X_2)exp(X_1) """ G = self.parent() chart = G.default_chart() if chart != G._Exp1: if chart != G.chart_exp2(): chart = G._Exp1 x = self.coordinates(chart=chart) B = G.lie_algebra().basis() nonzero_pairs = [(Xk, xk) for Xk, xk in zip(B, x) if xk] if chart == G._Exp1: s = repr_lincomb(nonzero_pairs) else: s = ")exp(".join(repr_lincomb([(Xk, xk)]) for Xk, xk in reversed(nonzero_pairs)) if not s: s = "0" return "exp(%s)" % s
def _repr_(self): r""" Return a string representation of ``self``. Supports printing in exponential coordinates of the first and second kinds, depending on the default coordinate system. EXAMPLES: sage: L = LieAlgebra(QQ, 2, step=2) sage: G = L.lie_group('H') sage: g = G.point([1, 2, 3]); g exp(X_1 + 2*X_2 + 3*X_12) sage: G.set_default_chart(G.chart_exp2()) sage: g exp(4*X_12)exp(2*X_2)exp(X_1) """ G = self.parent() chart = G.default_chart() if chart != G._Exp1: if chart != G.chart_exp2(): chart = G._Exp1 x = self.coordinates(chart=chart) B = G.lie_algebra().basis() nonzero_pairs = [(Xk, xk) for Xk, xk in zip(B, x) if xk] if chart == G._Exp1: s = repr_lincomb(nonzero_pairs) else: s = ")exp(".join(repr_lincomb([(Xk, xk)]) for Xk, xk in reversed(nonzero_pairs)) if not s: s = "0" return "exp(%s)" % s
def __repr__(self): """ EXAMPLES:: sage: L = LazyPowerSeriesRing(QQ) sage: s = L(); s._name = 's'; s s :: sage: L() Uninitialized lazy power series :: sage: a = L([1,2,3]) sage: a O(1) sage: a.compute_coefficients(2) sage: a 1 + 2*x + 3*x^2 + O(x^3) sage: a.compute_coefficients(4) sage: a 1 + 2*x + 3*x^2 + 3*x^3 + 3*x^4 + 3*x^5 + ... :: sage: a = L([1,2,3,0]) sage: a.compute_coefficients(5) sage: a 1 + 2*x + 3*x^2 """ if self._name is not None: return self._name if self.is_initialized: n = len(self._stream) x = self.parent()._name baserepr = repr_lincomb(self._get_repr_info(x)) if self._stream.is_constant(): if self._stream[n - 1] == 0: l = baserepr else: l = ( baserepr + " + " + repr_lincomb([(x + "^" + str(i), self._stream[n - 1]) for i in range(n, n + 3)]) + " + ..." ) else: l = baserepr + " + O(x^%s)" % n if n > 0 else "O(1)" else: l = "Uninitialized lazy power series" return l
def __repr__(self): """ EXAMPLES:: sage: L = LazyPowerSeriesRing(QQ) sage: s = L(); s._name = 's'; s s :: sage: L() Uninitialized lazy power series :: sage: a = L([1,2,3]) sage: a O(1) sage: a.compute_coefficients(2) sage: a 1 + 2*x + 3*x^2 + O(x^3) sage: a.compute_coefficients(4) sage: a 1 + 2*x + 3*x^2 + 3*x^3 + 3*x^4 + 3*x^5 + ... :: sage: a = L([1,2,3,0]) sage: a.compute_coefficients(5) sage: a 1 + 2*x + 3*x^2 """ if self._name is not None: return self._name if self.is_initialized: n = len(self._stream) x = self.parent()._name baserepr = repr_lincomb(self._get_repr_info(x)) if self._stream.is_constant(): if self._stream[n - 1] == 0: l = baserepr else: l = baserepr + " + " + repr_lincomb( [(x + "^" + str(i), self._stream[n - 1]) for i in range(n, n + 3)]) + " + ..." else: l = baserepr + " + O(x^%s)" % n if n > 0 else "O(1)" else: l = 'Uninitialized lazy power series' return l
def _latex_(self): r""" Return a LaTeX representation of ``self``. OUTPUT: - string. TESTS:: sage: R.<x, y> = ZZ[] sage: S = Spec(R) sage: from sage.schemes.generic.divisor import Divisor_generic sage: from sage.schemes.generic.divisor_group import DivisorGroup sage: Div = DivisorGroup(S) sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div) sage: D._latex_() '\\mathrm{V}\\left(x + 2 y\\right) + 4\\mathrm{V}\\left(x\\right) + \\left(-5\\right)\\mathrm{V}\\left(y\\right)' """ # The code is copied from _repr_ with latex adjustments terms = list(self) # We sort the terms by variety. The order is "reversed" to keep it # straight - as the test above demonstrates, it results in the first # generator being in front of the second one terms.sort(key=lambda x: x[1], reverse=True) return repr_lincomb([(r"\mathrm{V}\left(%s\right)" % latex(v), c) for c,v in terms], is_latex=True)
def _repr_(self): r""" Return a string representation of ``self``. OUTPUT: - string. TESTS:: sage: R.<x, y> = ZZ[] sage: S = Spec(R) sage: from sage.schemes.generic.divisor import Divisor_generic sage: from sage.schemes.generic.divisor_group import DivisorGroup sage: Div = DivisorGroup(S) sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div) sage: D._repr_() 'V(x + 2*y) + 4*V(x) - 5*V(y)' """ # The default representation coming from formal sums does not look # very nice for divisors terms = list(self) # We sort the terms by variety. The order is "reversed" to keep it # straight - as the test above demonstrates, it results in the first # generator being in front of the second one terms.sort(key=lambda x: x[1], reverse=True) return repr_lincomb([("V(%s)" % v, c) for c,v in terms])
def _repr_(self): """ Return string representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: repr(-x+3*y*z) '-x + 3*y*z' Trac ticket #11068 enables the use of local variable names:: sage: from sage.structure.parent_gens import localvars sage: with localvars(A, ['a','b','c']): ... print -x+3*y*z ... -a + 3*b*c """ v = self.__monomial_coefficients.items() v.sort() mons = [m for (m, _) in v] cffs = [x for (_, x) in v] P = self.parent() M = P.monoid() from sage.structure.parent_gens import localvars with localvars(M, P.variable_names(), normalize=False): x = repr_lincomb(mons, cffs).replace("*1 ", " ") if x[len(x) - 2:] == "*1": return x[:len(x) - 2] else: return x
def _repr_(self): """ Return string representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: repr(-x+3*y*z) # indirect doctest '-x + 3*y*z' Trac ticket :trac:`11068` enables the use of local variable names:: sage: from sage.structure.parent_gens import localvars sage: with localvars(A, ['a','b','c']): ....: print(-x+3*y*z) -a + 3*b*c """ v = sorted(self._monomial_coefficients.items()) P = self.parent() M = P.monoid() from sage.structure.parent_gens import localvars with localvars(M, P.variable_names(), normalize=False): x = repr_lincomb(v, strip_one=True) return x
def _latex_(self): r""" Return a LaTeX representation of ``self``. OUTPUT: - string. TESTS:: sage: R.<x, y> = ZZ[] sage: S = Spec(R) sage: from sage.schemes.generic.divisor import Divisor_generic sage: from sage.schemes.generic.divisor_group import DivisorGroup sage: Div = DivisorGroup(S) sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div) sage: D._latex_() '\\mathrm{V}\\left(x + 2 y\\right) + 4\\mathrm{V}\\left(x\\right) - 5\\mathrm{V}\\left(y\\right)' """ # The code is copied from _repr_ with latex adjustments terms = list(self) # We sort the terms by variety. The order is "reversed" to keep it # straight - as the test above demonstrates, it results in the first # generator being in front of the second one terms.sort(key=lambda x: x[1], reverse=True) return repr_lincomb([(r"\mathrm{V}\left(%s\right)" % latex(v), c) for c, v in terms], is_latex=True)
def _repr_(self): r""" Return a string representation of ``self``. OUTPUT: - string. TESTS:: sage: R.<x, y> = ZZ[] sage: S = Spec(R) sage: from sage.schemes.generic.divisor import Divisor_generic sage: from sage.schemes.generic.divisor_group import DivisorGroup sage: Div = DivisorGroup(S) sage: D = Divisor_generic([(4, x), (-5, y), (1, x+2*y)], Div) sage: D._repr_() 'V(x + 2*y) + 4*V(x) - 5*V(y)' """ # The default representation coming from formal sums does not look # very nice for divisors terms = list(self) # We sort the terms by variety. The order is "reversed" to keep it # straight - as the test above demonstrates, it results in the first # generator being in front of the second one terms.sort(key=lambda x: x[1], reverse=True) return repr_lincomb([("V(%s)" % v, c) for c, v in terms])
def _repr_(self): r""" String representation of self. The output will depend on the global modular symbols print mode setting controlled by the function ``set_modsym_print_mode``. EXAMPLE:: sage: M = ModularSymbols(13, 4) sage: set_modsym_print_mode('manin'); M.0._repr_() '[X^2,(0,1)]' sage: set_modsym_print_mode('modular'); M.0._repr_() 'X^2*{0, Infinity}' sage: set_modsym_print_mode('vector'); M.0._repr_() '(1, 0, 0, 0, 0, 0, 0, 0)' sage: set_modsym_print_mode() """ if _print_mode == "vector": return str(self.element()) elif _print_mode == "manin": m = self.manin_symbol_rep() elif _print_mode == "modular": m = self.modular_symbol_rep() c = [x[0] for x in m] v = [x[1] for x in m] return misc.repr_lincomb(v, c)
def _repr_(self): """ Return string representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: repr(-x+3*y*z) '-x + 3*y*z' Trac ticket #11068 enables the use of local variable names:: sage: from sage.structure.parent_gens import localvars sage: with localvars(A, ['a','b','c']): ... print -x+3*y*z ... -a + 3*b*c """ v = self.__monomial_coefficients.items() v.sort() mons = [ m for (m, _) in v ] cffs = [ x for (_, x) in v ] P = self.parent() M = P.monoid() from sage.structure.parent_gens import localvars with localvars(M, P.variable_names(), normalize=False): x = repr_lincomb(mons, cffs).replace("*1 "," ") if x[len(x)-2:] == "*1": return x[:len(x)-2] else: return x
def __repr__(self): """ EXAMPLES:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: a = 2 + s([3,2,1]) sage: print a.__repr__() 2*s[] + s[3, 2, 1] """ v = sorted(self._monomial_coefficients.items()) prefix = self.parent().prefix() retur = repr_lincomb( [(prefix + repr(m), c) for m,c in v ], strip_one = True)
def __repr__(self): """ EXAMPLES:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: a = 2 + s([3,2,1]) sage: print(a.__repr__()) 2*s[] + s[3, 2, 1] """ v = sorted(self._monomial_coefficients.items()) prefix = self.parent().prefix() retur = repr_lincomb( [(prefix + repr(m), c) for m,c in v ], strip_one = True)
def _repr_(self): """ Return the string representation of self. EXAMPLES:: sage: ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0))._repr_() '[0]' sage: (-6*ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0)))._repr_() '-6*[0]' """ return repr_lincomb([ ('[' + repr(self.parent()._known_gens[i]) + ']', c) for i,c in self.__x.items() ])
def _repr_(self): """ Return the string representation of ``self``. EXAMPLES:: sage: ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0))._repr_() '[0]' sage: (-6*ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0)))._repr_() '-6*[0]' """ return repr_lincomb([('[' + repr(self.parent()._known_gens[i]) + ']', c) for i, c in sorted(self.__x.items())])
def _repr_(self): """ Return the string representation of self. EXAMPLES:: sage: ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0))._repr_() '[0]' sage: (-6*ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0)))._repr_() '-6*[0]' """ g = self.parent()._known_gens_repr return repr_lincomb([ (g[i], c) for i,c in self.__x.items() ])
def _repr_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ) sage: i._repr_() 'i' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() return repr_lincomb(zip(mons, cffs), strip_one=True)
def _latex_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) sage: ((2/3)*i - j)._latex_() '\\frac{2}{3}i + \\left(-1\\right)j' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = tuple(self.__vector) mons = Q.monomial_basis() return repr_lincomb(zip(mons, cffs), is_latex=True, strip_one=True)
def _latex_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) sage: ((2/3)*i - j)._latex_() '\\frac{2}{3}i - j' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = tuple(self.__vector) mons = Q.monomial_basis() return repr_lincomb(zip(mons, cffs), is_latex=True, strip_one=True)
def _latex_(self): r""" Return latex representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: latex(-x+3*y^20*z) # indirect doctest -x + 3y^{20}z sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens() sage: latex(alpha-beta) \alpha - \beta """ v = sorted(self._monomial_coefficients.items()) return repr_lincomb(v, strip_one=True, is_latex=True)
def _repr_(self): r""" Return a string representation. OUTPUT: A string. EXAMPLES:: sage: E = EllipticCurve([0, 0, 1, -1, 0]) sage: E.divisor( E(0,0) )._repr_() '(x, y)' """ return repr_lincomb([(tuple(I.gens()), c) for c, I in self])
def _repr_(self): """ Return the string representation of self. EXAMPLES:: sage: ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0))._repr_() '[0]' sage: (-6*ModularSymbols(Gamma0(11), 2).boundary_space()(Cusp(0)))._repr_() '-6*[0]' """ g = self.parent()._known_gens_repr z = [0 for _ in xrange(len(g))] for i, c in self.__x.items(): z[i] = c return repr_lincomb(g, z)
def _latex_(self): r""" Return latex representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: latex(-x+3*y^20*z) \left(-1\right)x + 3y^{20}z sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens() sage: latex(alpha-beta) \alpha + \left(-1\right)\beta """ v = self.__monomial_coefficients.items() v.sort() return repr_lincomb(v, strip_one=True, is_latex=True)
def _repr_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ) sage: i._repr_() 'i' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() x = repr_lincomb(mons, cffs).replace("*1 "," ") if x[len(x)-2:] == "*1": return x[:len(x)-2] else: return x
def _latex_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) sage: ((2/3)*i - j)._latex_() '\\frac{2}{3}i + \\left(-1\\right)j' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() x = repr_lincomb(mons, cffs, True).replace("*1 ", " ") if x[len(x) - 2:] == "*1": return x[:len(x) - 2] else: return x
def _repr_(self): r""" Return a string representation. OUTPUT: A string. EXAMPLES:: sage: E = EllipticCurve([0, 0, 1, -1, 0]) sage: E.divisor( E(0,0) )._repr_() '(x, y)' """ ideals = [ z[1] for z in self ] coeffs = [ z[0] for z in self ] polys = [ tuple(I.gens()) for I in ideals ] return repr_lincomb(polys, coeffs)
def _latex_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ) sage: ((2/3)*i - j)._latex_() '\\frac{2}{3}i + \\left(-1\\right)j' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() x = repr_lincomb(mons, cffs, True).replace("*1 "," ") if x[len(x)-2:] == "*1": return x[:len(x)-2] else: return x
def _repr_(self): """ EXAMPLES:: sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ) sage: i._repr_() 'i' """ Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() x = repr_lincomb(mons, cffs).replace("*1 ", " ") if x[len(x) - 2:] == "*1": return x[:len(x) - 2] else: return x
def covector_latex(covec, m=0): r""" Return a latex string of the covector. INPUT: - ``covec`` -- a dictionary in the format of :meth:`extract_a_solution` - ``m`` -- the stopping degree of the factorization of the covector """ data = [] for X in covec: Xs = X.leading_support() fstr, final = factorstr_withfinal(Xs, m) data.append(("\\lambda_{%s}" % fstr, covec[X], final, Xs)) sortkey = lambda d: (getattr(d[3], '_grade', 1), d[2], d[3]) sortedterms = [(l, c) for l, c, f, Xs in sorted(data, key=sortkey)] return repr_lincomb(sortedterms, is_latex=True)
def _repr_(self): r""" Return a string representation. OUTPUT: A string. EXAMPLES:: sage: E = EllipticCurve([0, 0, 1, -1, 0]) sage: E.divisor( E(0,0) )._repr_() '(x, y)' """ ideals = [z[1] for z in self] coeffs = [z[0] for z in self] polys = [tuple(I.gens()) for I in ideals] return repr_lincomb(polys, coeffs)
def _latex_(self): r""" Return latex representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: latex(-x+3*y^20*z) \left(-1\right)x + 3y^{20}z sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens() sage: latex(alpha-beta) \alpha + \left(-1\right)\beta """ v = self.__monomial_coefficients.items() v.sort() mons = [ m for (m, _) in v ] cffs = [ x for (_, x) in v ] x = repr_lincomb(mons, cffs,is_latex=True) return x
def __repr__(self): """ EXAMPLES:: sage: R.<u,v,w,z> = = FormalMultivariatePowerSeriesRing(QQ) sage: L = R([[],[(1,[1,0,0,0]),(3,[0,0,1,0])],[(1,[1,1,0,0]),(-5,[0,0,0,2])],[],[(1,[0,3,0,2])],[]]) sage: L.coefficients(5) sage: L u + 3*w + u*v + (-5)*z^2 + v^3*z^2 """ if self._name is not None: return self._name if self.is_initialized: n = len(self._stream) x = self.parent()._names l = repr_lincomb(self._get_repr_info()) else: l = 'Uninitialized formal multivariate power series' return l
def _latex_(self): r""" Return latex representation of self. EXAMPLES:: sage: A.<x,y,z>=FreeAlgebra(ZZ,3) sage: latex(-x+3*y^20*z) \left(-1\right)x + 3y^{20}z sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens() sage: latex(alpha-beta) \alpha + \left(-1\right)\beta """ v = self.__monomial_coefficients.items() v.sort() mons = [m for (m, _) in v] cffs = [x for (_, x) in v] x = repr_lincomb(mons, cffs, is_latex=True) return x
def __repr__(self): """ EXAMPLES:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: a = 2 + s([3,2,1]) sage: print a.__repr__() 2*s[] + s[3, 2, 1] """ v = self._monomial_coefficients.items() v.sort() prefix = self.parent().prefix() mons = [prefix + repr(m) for (m, _) in v] cffs = [x for (_, x) in v] x = repr_lincomb(mons, cffs).replace("*1 ", " ") if x[len(x) - 2:] == "*1": return x[:len(x) - 2] else: return x
def __repr__(self): """ EXAMPLES:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: a = 2 + s([3,2,1]) sage: print a.__repr__() 2*s[] + s[3, 2, 1] """ v = self._monomial_coefficients.items() v.sort() prefix = self.parent().prefix() mons = [ prefix + repr(m) for (m, _) in v ] cffs = [ x for (_, x) in v ] x = repr_lincomb(mons, cffs).replace("*1 "," ") if x[len(x)-2:] == "*1": return x[:len(x)-2] else: return x