# Changeset 7231:9a53ba484dcb

Ignore:
Timestamp:
10/29/07 13:44:57 (6 years ago)
Branch:
default
Children:
7232:e054455cbf30, 7233:6c1e61faebf2
Message:

Monoids, algebras, power series, polynomials and symbolic rings all latex variable names *much* better now

Location:
sage
Files:
12 edited

Unmodified
Removed
• ## sage/algebras/free_algebra_element.py

 r7195 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()

• ## sage/misc/preparser.py

 r6510 gen_list = [s.strip() for s in line[i+2:gen_end].split(',')] for g in gen_list: if not g.isalnum() or len(g) == 0 or not g[0].isalpha(): if (not g.isalnum() and not g.replace("_","").isalnum()) or len(g) == 0 or not g[0].isalpha(): raise SyntaxError, "variable name (='%s') must be alpha-numeric and begin with a letter"%g
• ## sage/monoids/free_monoid_element.py

 r7206 from sage.rings.integer import Integer from sage.structure.element import MonoidElement from sage.misc.latex import latex, latex_varify from sage.misc.latex import latex, latex_variable_name def is_FreeMonoidElement(x): sage: z = F([(0,5),(1,2),(0,10),(0,2),(1,2)]) sage: z._latex_() '\\mbox{a0}^{5}\\mbox{a1}^{2}\\mbox{a0}^{12}\\mbox{a1}^{2}' 'a_{0}^{5}a_{1}^{2}a_{0}^{12}a_{1}^{2}' sage: F, (alpha,beta,gamma) = FreeMonoid(3, 'alpha,beta,gamma').objgens() sage: latex(alpha*beta*gamma) s = "" v = self._element_list x = self.parent().variable_names() x = self.parent().latex_variable_names() for i in range(len(v)): g = x[int(v[i][0])] e = v[i][1] if e == 1: s += "%s"%(latex_varify(g),) else: s += "%s^{%s}"%(latex_varify(g),e) s += "%s"%(g,) else: s += "%s^{%s}"%(g,e) if len(s) == 0: s = "1" return s
• ## sage/rings/laurent_series_ring_element.pyx

 r6990 sage: f = (17/2)*x^-2 + x + x^2 + 3*x^4 + O(x^7) sage: latex(f) \frac{\frac{17}{2}}{x^{2}} + x + x^{2} + 3x^{4} + O(\text{x}^{7}) \frac{\frac{17}{2}}{x^{2}} + x + x^{2} + 3x^{4} + O(x^{7}) """ if self.is_zero(): valuation = self.__n m = len(v) X = self._parent.variable_name() X = self._parent.latex_variable_names()[0] atomic_repr = self._parent.base_ring().is_atomic_repr() first = True bigoh = "O(1)" elif pr == 1: bigoh = "O(%s)"%sage.misc.latex.latex(self._parent.variable_name()) bigoh = "O(%s)"%(X,) else: bigoh = "O(%s^{%s})"%(sage.misc.latex.latex(self._parent.variable_name()),pr) bigoh = "O(%s^{%s})"%(X,pr) if s == " ": return bigoh
• ## sage/rings/polynomial/multi_polynomial_ring_generic.pyx

 r6606 from sage.rings.integer_ring import ZZ from sage.rings.polynomial.polydict import PolyDict from sage.misc.latex import latex_variable_name import multi_polynomial_element import polynomial_ring def _latex_(self): vars = str(self.latex_variable_names()).replace('\n','').replace("'",'') return "%s[%s]"%(sage.misc.latex.latex(self.base_ring()), vars[1:-1]) vars = ', '.join(self.latex_variable_names()) return "%s[%s]"%(sage.misc.latex.latex(self.base_ring()), vars) def _ideal_class_(self): raise NotImplementedError def latex_variable_names(self): """ Returns the list of variable names suitable for latex output. All '_SOMETHING' substrings are replaced by '_{SOMETHING}' recursively so that subscripts of subscripts work. EXAMPLES: sage: R, x = PolynomialRing(QQ,'x',12).objgens() sage: x (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) sage: print R.latex_variable_names () ['x_{0}', 'x_{1}', 'x_{2}', 'x_{3}', 'x_{4}', 'x_{5}', 'x_{6}', 'x_{7}', 'x_{8}', 'x_{9}', 'x_{10}', 'x_{11}'] sage: f = x[0]^3 + 15/3 * x[1]^10 sage: print latex(f) 5 x_{1}^{10} + x_{0}^{3} """ if self._latex_names is not None: return self._latex_names names = [] for g in self.variable_names(): i = len(g)-1 while i >= 0 and g[i].isdigit(): i -= 1 if i < len(g)-1: g = '%s_{%s}'%(g[:i+1], g[i+1:]) names.append(g) self._latex_names = names return names def __reduce__(self): """ names = self.variable_names() order = self.term_order() return unpickle_MPolynomialRing_generic_v1,(base_ring, n, names, order) r""" Return a random polynomial in this polynomial ring. INPUT: degree -- maximum total degree of resulting polynomial
• ## sage/rings/polynomial/polynomial_element.pyx

 r6990 r = reversed(xrange(m)) if name is None: name = self.parent().variable_name() name = self.parent().latex_variable_names()[0] atomic_repr = self.parent().base_ring().is_atomic_repr() for n in reversed(xrange(m)):
• ## sage/rings/polynomial/polynomial_ring.py

 r7177 def _latex_(self): return "%s[%s]"%(latex.latex(self.base_ring()), latex.latex(self.variable_name())) """ EXAMPLES: sage: S.=ZZ[] sage: latex(S) \mathbf{Z}[\alpha_{12}] """ return "%s[%s]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0]) def __set_polynomial_class(self, cls=None): from sage.rings.padics.padic_ring_capped_relative import pAdicRingCappedRelative
• ## sage/rings/power_series_ring.py

 r7000 sage: R. = PowerSeriesRing(QQ, sparse=True) sage: latex(-2/3*(1/t^3) + 1/t + 3/5*t^2 + O(t^5)) \frac{-\frac{2}{3}}{t^{3}} + \frac{1}{t} + \frac{3}{5}t^{2} + O(\text{t}^{5}) \frac{-\frac{2}{3}}{t^{3}} + \frac{1}{t} + \frac{3}{5}t^{2} + O(t^{5}) sage: S = parent(1/t); S Sparse Laurent Series Ring in t over Rational Field sage: latex(R) \mathbf{F}_{17}[[y]] """ return "%s[[%s]]"%(latex.latex(self.base_ring()), self.variable_name()) sage: R = GF(17)[['y12']] sage: latex(R) \mathbf{F}_{17}[[y_{12}]] """ return "%s[[%s]]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0]) def __call__(self, f, prec=infinity, check=True):
• ## sage/rings/power_series_ring_element.pyx

 r6990 v = self.list() m = len(v) X = self._parent.variable_name() X = self._parent.latex_variable_names()[0] atomic_repr = self._parent.base_ring().is_atomic_repr() first = True bigoh = "O(1)" elif self._prec == 1: bigoh = "O(%s)"%sage.misc.latex.latex(self._parent.gen()) bigoh = "O(%s)"%(X,) else: bigoh = "O(%s^{%s})"%(sage.misc.latex.latex(self._parent.gen()),self._prec) bigoh = "O(%s^{%s})"%(X,self._prec) if s == " ": return bigoh
• ## sage/structure/parent_gens.pyx

 r6778 import sage.misc.defaults import sage.misc.latex from sage.misc.latex import latex_variable_name import gens_py import parent if len(N) == 0: raise ValueError, "variable name must be nonempty" if not N.isalnum(): if not N.isalnum() and not N.replace("_","").isalnum(): # We must be alphanumeric, but we make an exception for non-leading '_' characters. raise ValueError, "variable names must be alphanumeric, but one is '%s' which is not."%N if not N[0].isalpha(): def latex_variable_names(self): """ Returns the list of variable names suitable for latex output. All '_SOMETHING' substrings are replaced by '_{SOMETHING}' recursively so that subscripts of subscripts work. EXAMPLES: sage: R, x = PolynomialRing(QQ,'x',12).objgens() sage: x (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) sage: print R.latex_variable_names () ['x_{0}', 'x_{1}', 'x_{2}', 'x_{3}', 'x_{4}', 'x_{5}', 'x_{6}', 'x_{7}', 'x_{8}', 'x_{9}', 'x_{10}', 'x_{11}'] sage: f = x[0]^3 + 15/3 * x[1]^10 sage: print latex(f) 5 x_{1}^{10} + x_{0}^{3} """ if self._latex_names != None: return self._latex_names # Compute the latex versions of the variable names. self._latex_names = [] for x in self.variable_names(): self._latex.append(sage.misc.latex.latex_variable_name(x)) self._latex_names = [latex_variable_name(x) for x in self.variable_names()] return self._latex_names
Note: See TracChangeset for help on using the changeset viewer.