Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/vittucek/latex_representation_of_weylalgebras_omits_p…
Browse files Browse the repository at this point in the history
…olynomial_parts' of trac.sagemath.org:sage into public/algebras/fix_weyl_algebra_latex-20582
  • Loading branch information
Travis Scrimshaw committed May 19, 2016
2 parents f76401f + 7b2bc21 commit ab48f85
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
Empty file modified src/doc/en/reference/conf_sub.py 100644 → 100755
Empty file.
68 changes: 41 additions & 27 deletions src/sage/algebras/weyl_algebra.py
Expand Up @@ -209,37 +209,51 @@ def _latex_(self):
sage: x0,x1,x2,dx0,dx1,dx2 = W.gens()
sage: latex( ((x0^3-x2)*dx0 + dx1)^2 )
\frac{\partial^{2}}{\partial x_{1}^{2}}
+ 2 \frac{\partial^{2}}{\partial x_{0}\partial x_{1}}
- 2 \frac{\partial^{2}}{\partial x_{0}\partial x_{1}}
+ \frac{\partial^{2}}{\partial x_{0}^{2}}
- 2 \frac{\partial^{2}}{\partial x_{0}^{2}}
+ \frac{\partial^{2}}{\partial x_{0}^{2}}
+ 3 \frac{\partial}{\partial x_{0}}
- 3 \frac{\partial}{\partial x_{0}}
+ 2 x_{0}^{3} \frac{\partial^{2}}{\partial x_{0}\partial x_{1}}
- 2 x_{2} \frac{\partial^{2}}{\partial x_{0}\partial x_{1}}
+ x_{0}^{6} \frac{\partial^{2}}{\partial x_{0}^{2}}
- 2 x_{0}^{3} x_{2} \frac{\partial^{2}}{\partial x_{0}^{2}}
+ x_{2}^{2} \frac{\partial^{2}}{\partial x_{0}^{2}}
+ 3 x_{0}^{5} \frac{\partial}{\partial x_{0}}
- 3 x_{0}^{2} x_{2} \frac{\partial}{\partial x_{0}}
"""
def term(m):
# Variable part
R = self.parent()._poly_ring
ret = repr( R.sum(R.gen(i)**e for i,e in enumerate(m[0])) )
# Differential part
m = m[1]
total = sum(m)
if total == 0:
def half_term(m, polynomial=True):
R = self.parent()._poly_ring
total = sum(m)
ret = ''
if total == 0:
return '1'
if not polynomial:
if total == 1:
ret += '\\frac{\\partial}{'
else:
ret += '\\frac{\\partial^{' + repr(total) + '}}{'
for i, power in enumerate(m):
if power == 0:
continue
name = R.gen(i)
if power == 1:
if polynomial:
ret += latex(name)
else:
ret += '\\partial {0}'.format(latex(name))
else:
if polynomial:
ret += '{0}^{{{1}}}'.format(latex(name), power)
else:
ret += '\\partial {0}^{{{1}}}'.format(latex(name), power)
if not polynomial:
ret += '}' # closing \frac
return ret
ret += ' '
if total == 1:
ret = '\\frac{\\partial}{'
p = half_term(m[0], True)
d = half_term(m[1], False)
if p == '1':
return d
elif d == '1':
return p
else:
ret = '\\frac{\\partial^{' + repr(total) + '}}{'
for i, power in enumerate(m):
if power == 0:
continue
name = R.gen(i)
if power == 1:
ret += '\\partial {0}'.format(latex(name))
else:
ret += '\\partial {0}^{{{1}}}'.format(latex(name), power)
return ret + '}'
return p + ' ' + d
return repr_from_monomials(self.list(), term, True)

# Copied from CombinatorialFreeModuleElement
Expand Down

0 comments on commit ab48f85

Please sign in to comment.