# Ticket #7797: trac7797-latex_letterplace.patch

File trac7797-latex_letterplace.patch, 6.8 KB (added by SimonKing, 8 years ago)

Implement latex for letterplace polynomials and letterplace algebras

• ## sage/algebras/letterplace/free_algebra_element_letterplace.pyx

# HG changeset patch
# User Simon King <simon.king@uni-jena.de>
# Date 1306404242 -7200
# Node ID f917ff51fe1d688cab1d0351483eab6117f59a56
# Parent  f3746a9fdf6936a4840aff9188af5653829c85ac
#7797: Latex for letterplace polynomials and free algebras in letterplace implementation.

diff --git a/sage/algebras/letterplace/free_algebra_element_letterplace.pyx b/sage/algebras/letterplace/free_algebra_element_letterplace.pyx
 a return ' '.join(L) return '0' def _latex_(self): """ TEST:: sage: K. = GF(25) sage: F. = FreeAlgebra(K, implementation='letterplace', degrees=[1,2,3]) sage: -(a*b*(z+1)-c)^2 (2*z + 1)*a*b*a*b + (z + 1)*a*b*c + (z + 1)*c*a*b - c*c sage: latex(-(a*b*(z+1)-c)^2)     # indirect doctest \left(2 z + 1\right) a b a b + \left(z + 1\right) a b c + \left(z + 1\right) c a b - c c """ cdef list L = [] cdef FreeAlgebra_letterplace P = self._parent cdef int ngens = P.__ngens from sage.all import latex if P._base.is_atomic_repr(): for E,c in zip(self._poly.exponents(),self._poly.coefficients()): monstr = P.exponents_to_latex(E) if monstr: if c==1: if L: L.extend(['+',monstr]) else: L.append(monstr) elif c==-1: if L: L.extend(['-',monstr]) else: L.append('-'+monstr) else: if L: if c>=0: L.extend(['+',repr(latex(c))+' '+monstr]) else: L.extend(['-',repr(latex(-c))+' '+monstr]) else: L.append(repr(latex(c))+' '+monstr) else: if c>=0: if L: L.extend(['+',repr(latex(c))]) else: L.append(repr(latex(c))) else: if L: L.extend(['-',repr(latex(-c))]) else: L.append(repr(c)) else: for E,c in zip(self._poly.exponents(),self._poly.coefficients()): monstr = P.exponents_to_latex(E) if monstr: if c==1: if L: L.extend(['+',monstr]) else: L.append(monstr) elif c==-1: if L: L.extend(['-',monstr]) else: L.append('-'+monstr) else: if L: L.extend(['+','\\left('+repr(latex(c))+'\\right) '+monstr]) else: L.append('\\left('+repr(latex(c))+'\\right) '+monstr) else: if L: L.extend(['+',repr(latex(c))]) else: L.append(repr(latex(c))) if L: return ' '.join(L) return '0' def degree(self): """ Return the degree of this element.
• ## sage/algebras/letterplace/free_algebra_letterplace.pxd

diff --git a/sage/algebras/letterplace/free_algebra_letterplace.pxd b/sage/algebras/letterplace/free_algebra_letterplace.pxd
 a cdef object __monoid cdef public object __custom_name cdef str exponents_to_string(self, E) cdef str exponents_to_latex(self, E) cdef tuple _degrees
• ## sage/algebras/letterplace/free_algebra_letterplace.pyx

diff --git a/sage/algebras/letterplace/free_algebra_letterplace.pyx b/sage/algebras/letterplace/free_algebra_letterplace.pyx
 a """ return "Free Associative Unital Algebra on %d generators %s over %s"%(self.__ngens-self._nb_slackvars,self.gens(),self._base) def _latex_(self): """ Representation of this free algebra in LaTeX. EXAMPLE:: sage: F. = FreeAlgebra(QQ, implementation='letterplace', degrees=[1,2,3]) sage: latex(F) \Bold{Q}\langle \mbox{bla}, \alpha, z\rangle """ from sage.all import latex return "%s\\langle %s\\rangle"%(latex(self.base_ring()),', '.join(self.latex_variable_names())) def degbound(self): """ Return the degree bound that is currently used. #    out.append(s) return '*'.join(out) # Auxiliar methods cdef str exponents_to_latex(self, E): """ This auxiliary method is used for the representation of elements of this free algebra as a latex string. EXAMPLE:: sage: K. = GF(25) sage: F. = FreeAlgebra(K, implementation='letterplace', degrees=[1,2,3]) sage: -(a*b*(z+1)-c)^2 (2*z + 1)*a*b*a*b + (z + 1)*a*b*c + (z + 1)*c*a*b - c*c sage: latex(-(a*b*(z+1)-c)^2)     # indirect doctest \left(2 z + 1\right) a b a b + \left(z + 1\right) a b c + \left(z + 1\right) c a b - c c """ cdef int ngens = self.__ngens cdef int nblocks = len(E)/ngens cdef int i,j,base, exp, var_ind cdef list out = [] cdef list tmp cdef list names = self.latex_variable_names() for i from 0<=i1 or exp>1: raise NotImplementedError, "\n  Apparently you tried to view the letterplace algebra with\n  shift-multiplication as the free algebra over a finitely\n  generated free abelian monoid.\n  In principle, this is correct, but it is not implemented, yet." out.append(names[var_ind]) i += (self._degrees[var_ind]-1) return ' '.join(out) def _reductor_(self, g, d): """ Return a commutative ideal that can be used to compute the normal