Ticket #7797: trac7797-latex_letterplace.patch
File trac7797-latex_letterplace.patch, 6.8 KB (added by , 8 years ago) |
---|
-
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 b 224 224 return ' '.join(L) 225 225 return '0' 226 226 227 def _latex_(self): 228 """ 229 TEST:: 230 231 sage: K.<z> = GF(25) 232 sage: F.<a,b,c> = FreeAlgebra(K, implementation='letterplace', degrees=[1,2,3]) 233 sage: -(a*b*(z+1)-c)^2 234 (2*z + 1)*a*b*a*b + (z + 1)*a*b*c + (z + 1)*c*a*b - c*c 235 sage: latex(-(a*b*(z+1)-c)^2) # indirect doctest 236 \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 237 238 """ 239 cdef list L = [] 240 cdef FreeAlgebra_letterplace P = self._parent 241 cdef int ngens = P.__ngens 242 from sage.all import latex 243 if P._base.is_atomic_repr(): 244 for E,c in zip(self._poly.exponents(),self._poly.coefficients()): 245 monstr = P.exponents_to_latex(E) 246 if monstr: 247 if c==1: 248 if L: 249 L.extend(['+',monstr]) 250 else: 251 L.append(monstr) 252 elif c==-1: 253 if L: 254 L.extend(['-',monstr]) 255 else: 256 L.append('-'+monstr) 257 else: 258 if L: 259 if c>=0: 260 L.extend(['+',repr(latex(c))+' '+monstr]) 261 else: 262 L.extend(['-',repr(latex(-c))+' '+monstr]) 263 else: 264 L.append(repr(latex(c))+' '+monstr) 265 else: 266 if c>=0: 267 if L: 268 L.extend(['+',repr(latex(c))]) 269 else: 270 L.append(repr(latex(c))) 271 else: 272 if L: 273 L.extend(['-',repr(latex(-c))]) 274 else: 275 L.append(repr(c)) 276 else: 277 for E,c in zip(self._poly.exponents(),self._poly.coefficients()): 278 monstr = P.exponents_to_latex(E) 279 if monstr: 280 if c==1: 281 if L: 282 L.extend(['+',monstr]) 283 else: 284 L.append(monstr) 285 elif c==-1: 286 if L: 287 L.extend(['-',monstr]) 288 else: 289 L.append('-'+monstr) 290 else: 291 if L: 292 L.extend(['+','\\left('+repr(latex(c))+'\\right) '+monstr]) 293 else: 294 L.append('\\left('+repr(latex(c))+'\\right) '+monstr) 295 else: 296 if L: 297 L.extend(['+',repr(latex(c))]) 298 else: 299 L.append(repr(latex(c))) 300 if L: 301 return ' '.join(L) 302 return '0' 303 227 304 def degree(self): 228 305 """ 229 306 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 b 25 25 cdef object __monoid 26 26 cdef public object __custom_name 27 27 cdef str exponents_to_string(self, E) 28 cdef str exponents_to_latex(self, E) 28 29 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 b 451 451 """ 452 452 return "Free Associative Unital Algebra on %d generators %s over %s"%(self.__ngens-self._nb_slackvars,self.gens(),self._base) 453 453 454 def _latex_(self): 455 """ 456 Representation of this free algebra in LaTeX. 457 458 EXAMPLE:: 459 460 sage: F.<bla,alpha,z> = FreeAlgebra(QQ, implementation='letterplace', degrees=[1,2,3]) 461 sage: latex(F) 462 \Bold{Q}\langle \mbox{bla}, \alpha, z\rangle 463 464 """ 465 from sage.all import latex 466 return "%s\\langle %s\\rangle"%(latex(self.base_ring()),', '.join(self.latex_variable_names())) 467 454 468 def degbound(self): 455 469 """ 456 470 Return the degree bound that is currently used. … … 604 618 # out.append(s) 605 619 return '*'.join(out) 606 620 621 # Auxiliar methods 622 cdef str exponents_to_latex(self, E): 623 """ 624 This auxiliary method is used for the representation of elements of this free algebra as a latex string. 625 626 EXAMPLE:: 627 628 sage: K.<z> = GF(25) 629 sage: F.<a,b,c> = FreeAlgebra(K, implementation='letterplace', degrees=[1,2,3]) 630 sage: -(a*b*(z+1)-c)^2 631 (2*z + 1)*a*b*a*b + (z + 1)*a*b*c + (z + 1)*c*a*b - c*c 632 sage: latex(-(a*b*(z+1)-c)^2) # indirect doctest 633 \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 634 635 """ 636 cdef int ngens = self.__ngens 637 cdef int nblocks = len(E)/ngens 638 cdef int i,j,base, exp, var_ind 639 cdef list out = [] 640 cdef list tmp 641 cdef list names = self.latex_variable_names() 642 for i from 0<=i<nblocks: 643 base = i*ngens 644 tmp = [(j,E[base+j]) for j in xrange(ngens) if E[base+j]] 645 if not tmp: 646 continue 647 var_ind, exp = tmp[0] 648 if len(tmp)>1 or exp>1: 649 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." 650 651 out.append(names[var_ind]) 652 i += (self._degrees[var_ind]-1) 653 return ' '.join(out) 654 607 655 def _reductor_(self, g, d): 608 656 """ 609 657 Return a commutative ideal that can be used to compute the normal