From 7b2bc2111be3b834518fababf658dc997075d925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Tu=C4=8Dek?= Date: Tue, 10 May 2016 19:44:55 +0000 Subject: [PATCH] Fix latex representation for elements of Weyl Algebras --- src/doc/en/reference/conf_sub.py | 0 src/sage/algebras/weyl_algebra.py | 68 +++++++++++++++++++------------ 2 files changed, 41 insertions(+), 27 deletions(-) mode change 100644 => 100755 src/doc/en/reference/conf_sub.py diff --git a/src/doc/en/reference/conf_sub.py b/src/doc/en/reference/conf_sub.py old mode 100644 new mode 100755 diff --git a/src/sage/algebras/weyl_algebra.py b/src/sage/algebras/weyl_algebra.py index bda7479174c..5e1b3ccf73e 100644 --- a/src/sage/algebras/weyl_algebra.py +++ b/src/sage/algebras/weyl_algebra.py @@ -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