Weyl Algebras¶
AUTHORS:
- Travis Scrimshaw (2013-09-06): Initial version 
- class sage.algebras.weyl_algebra.DifferentialWeylAlgebra(R, names=None)[source]¶
- Bases: - UniqueRepresentation,- Parent- The differential Weyl algebra of a polynomial ring. - Let \(R\) be a commutative ring. The (differential) Weyl algebra \(W\) is the algebra generated by \(x_1, x_2, \ldots x_n, \partial_{x_1}, \partial_{x_2}, \ldots, \partial_{x_n}\) subject to the relations: \([x_i, x_j] = 0\), \([\partial_{x_i}, \partial_{x_j}] = 0\), and \(\partial_{x_i} x_j = x_j \partial_{x_i} + \delta_{ij}\). Therefore \(\partial_{x_i}\) is acting as the partial differential operator on \(x_i\). - The Weyl algebra can also be constructed as an iterated Ore extension of the polynomial ring \(R[x_1, x_2, \ldots, x_n]\) by adding \(x_i\) at each step. It can also be seen as a quantization of the symmetric algebra \(Sym(V)\), where \(V\) is a finite dimensional vector space over a field of characteristic zero, by using a modified Groenewold-Moyal product in the symmetric algebra. - The Weyl algebra (even for \(n = 1\)) over a field of characteristic 0 has many interesting properties. - It’s a non-commutative domain. 
- It’s a simple ring (but not in positive characteristic) that is not a matrix ring over a division ring. 
- It has no finite-dimensional representations. 
- It’s a quotient of the universal enveloping algebra of the Heisenberg algebra \(\mathfrak{h}_n\). 
 - REFERENCES: - INPUT: - R– a (polynomial) ring
- names– (default:- None) if- Noneand- Ris a polynomial ring, then the variable names correspond to those of- R; otherwise if- namesis specified, then- Ris the base ring
 - EXAMPLES: - There are two ways to create a Weyl algebra, the first is from a polynomial ring: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R); W Differential Weyl algebra of polynomials in x, y, z over Rational Field - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R); W Differential Weyl algebra of polynomials in x, y, z over Rational Field - We can call - W.inject_variables()to give the polynomial ring variables, now as elements of- W, and the differentials:- sage: W.inject_variables() Defining x, y, z, dx, dy, dz sage: (dx * dy * dz) * (x^2 * y * z + x * z * dy + 1) x*z*dx*dy^2*dz + z*dy^2*dz + x^2*y*z*dx*dy*dz + dx*dy*dz + x*dx*dy^2 + 2*x*y*z*dy*dz + dy^2 + x^2*z*dx*dz + x^2*y*dx*dy + 2*x*z*dz + 2*x*y*dy + x^2*dx + 2*x - >>> from sage.all import * >>> W.inject_variables() Defining x, y, z, dx, dy, dz >>> (dx * dy * dz) * (x**Integer(2) * y * z + x * z * dy + Integer(1)) x*z*dx*dy^2*dz + z*dy^2*dz + x^2*y*z*dx*dy*dz + dx*dy*dz + x*dx*dy^2 + 2*x*y*z*dy*dz + dy^2 + x^2*z*dx*dz + x^2*y*dx*dy + 2*x*z*dz + 2*x*y*dy + x^2*dx + 2*x - Or directly by specifying a base ring and variable names: - sage: W.<a,b> = DifferentialWeylAlgebra(QQ); W Differential Weyl algebra of polynomials in a, b over Rational Field - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('a', 'b',)); (a, b,) = W._first_ngens(2); W Differential Weyl algebra of polynomials in a, b over Rational Field - Todo - Implement the - graded_algebra()as a polynomial ring once they are considered to be graded rings (algebras).- Element[source]¶
- alias of - DifferentialWeylAlgebraElement
 - algebra_generators()[source]¶
- Return the algebra generators of - self.- See also - EXAMPLES: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: W.algebra_generators() Finite family {'x': x, 'y': y, 'z': z, 'dx': dx, 'dy': dy, 'dz': dz} - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> W.algebra_generators() Finite family {'x': x, 'y': y, 'z': z, 'dx': dx, 'dy': dy, 'dz': dz} 
 - basis()[source]¶
- Return a basis of - self.- EXAMPLES: - sage: W.<x,y> = DifferentialWeylAlgebra(QQ) sage: B = W.basis() sage: it = iter(B) sage: [next(it) for i in range(20)] [1, x, y, dx, dy, x^2, x*y, x*dx, x*dy, y^2, y*dx, y*dy, dx^2, dx*dy, dy^2, x^3, x^2*y, x^2*dx, x^2*dy, x*y^2] sage: dx, dy = W.differentials() sage: sorted((dx*x).monomials(), key=str) [1, x*dx] sage: B[(x*y).support()[0]] x*y sage: sorted((dx*x).monomial_coefficients().items()) [(((0, 0), (0, 0)), 1), (((1, 0), (1, 0)), 1)] - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('x', 'y',)); (x, y,) = W._first_ngens(2) >>> B = W.basis() >>> it = iter(B) >>> [next(it) for i in range(Integer(20))] [1, x, y, dx, dy, x^2, x*y, x*dx, x*dy, y^2, y*dx, y*dy, dx^2, dx*dy, dy^2, x^3, x^2*y, x^2*dx, x^2*dy, x*y^2] >>> dx, dy = W.differentials() >>> sorted((dx*x).monomials(), key=str) [1, x*dx] >>> B[(x*y).support()[Integer(0)]] x*y >>> sorted((dx*x).monomial_coefficients().items()) [(((0, 0), (0, 0)), 1), (((1, 0), (1, 0)), 1)] 
 - degree_on_basis(i)[source]¶
- Return the degree of the basis element indexed by - i.- EXAMPLES: - sage: W.<a,b> = DifferentialWeylAlgebra(QQ) sage: W.degree_on_basis( ((1, 3, 2), (0, 1, 3)) ) 10 sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ) sage: dx,dy,dz = W.differentials() sage: elt = y*dy - (3*x - z)*dx sage: elt.degree() 2 - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('a', 'b',)); (a, b,) = W._first_ngens(2) >>> W.degree_on_basis( ((Integer(1), Integer(3), Integer(2)), (Integer(0), Integer(1), Integer(3))) ) 10 >>> W = DifferentialWeylAlgebra(QQ, names=('x', 'y', 'z',)); (x, y, z,) = W._first_ngens(3) >>> dx,dy,dz = W.differentials() >>> elt = y*dy - (Integer(3)*x - z)*dx >>> elt.degree() 2 
 - diff_action()[source]¶
- Left action of this Weyl algebra on the underlying polynomial ring by differentiation. - EXAMPLES: - sage: R.<x,y> = QQ[] sage: W = R.weyl_algebra() sage: dx, dy = W.differentials() sage: W.diff_action Left action by Differential Weyl algebra of polynomials in x, y over Rational Field on Multivariate Polynomial Ring in x, y over Rational Field sage: W.diff_action(dx^2 + dy + 1, x^3*y^3) x^3*y^3 + 3*x^3*y^2 + 6*x*y^3 - >>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> W = R.weyl_algebra() >>> dx, dy = W.differentials() >>> W.diff_action Left action by Differential Weyl algebra of polynomials in x, y over Rational Field on Multivariate Polynomial Ring in x, y over Rational Field >>> W.diff_action(dx**Integer(2) + dy + Integer(1), x**Integer(3)*y**Integer(3)) x^3*y^3 + 3*x^3*y^2 + 6*x*y^3 
 - differentials()[source]¶
- Return the differentials of - self.- See also - EXAMPLES: - sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ) sage: W.differentials() Finite family {'dx': dx, 'dy': dy, 'dz': dz} - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('x', 'y', 'z',)); (x, y, z,) = W._first_ngens(3) >>> W.differentials() Finite family {'dx': dx, 'dy': dy, 'dz': dz} 
 - gen(i)[source]¶
- Return the - i-th generator of- self.- See also - EXAMPLES: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: [W.gen(i) for i in range(6)] [x, y, z, dx, dy, dz] - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> [W.gen(i) for i in range(Integer(6))] [x, y, z, dx, dy, dz] 
 - gens()[source]¶
- Return the algebra generators of - self.- See also - EXAMPLES: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: W.algebra_generators() Finite family {'x': x, 'y': y, 'z': z, 'dx': dx, 'dy': dy, 'dz': dz} - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> W.algebra_generators() Finite family {'x': x, 'y': y, 'z': z, 'dx': dx, 'dy': dy, 'dz': dz} 
 - ngens()[source]¶
- Return the number of generators of - self.- EXAMPLES: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: W.ngens() 6 - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> W.ngens() 6 
 - one()[source]¶
- Return the multiplicative identity element \(1\). - EXAMPLES: - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: W.one() 1 - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> W.one() 1 
 - polynomial_ring()[source]¶
- Return the associated polynomial ring of - self.- EXAMPLES: - sage: W.<a,b> = DifferentialWeylAlgebra(QQ) sage: W.polynomial_ring() Multivariate Polynomial Ring in a, b over Rational Field - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('a', 'b',)); (a, b,) = W._first_ngens(2) >>> W.polynomial_ring() Multivariate Polynomial Ring in a, b over Rational Field - sage: R.<x,y,z> = QQ[] sage: W = DifferentialWeylAlgebra(R) sage: W.polynomial_ring() == R True - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> W = DifferentialWeylAlgebra(R) >>> W.polynomial_ring() == R True 
 - variables()[source]¶
- Return the variables of - self.- See also - EXAMPLES: - sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ) sage: W.variables() Finite family {'x': x, 'y': y, 'z': z} - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('x', 'y', 'z',)); (x, y, z,) = W._first_ngens(3) >>> W.variables() Finite family {'x': x, 'y': y, 'z': z} 
 
- class sage.algebras.weyl_algebra.DifferentialWeylAlgebraAction(G)[source]¶
- Bases: - Action- Left action of a Weyl algebra on its underlying polynomial ring by differentiation. - EXAMPLES: - sage: R.<x,y> = QQ[] sage: W = R.weyl_algebra() sage: dx, dy = W.differentials() sage: W.diff_action Left action by Differential Weyl algebra of polynomials in x, y over Rational Field on Multivariate Polynomial Ring in x, y over Rational Field - >>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> W = R.weyl_algebra() >>> dx, dy = W.differentials() >>> W.diff_action Left action by Differential Weyl algebra of polynomials in x, y over Rational Field on Multivariate Polynomial Ring in x, y over Rational Field - sage: g = dx^2 + x*dy sage: p = x^5 + x^3 + y^2*x^2 + 1 sage: W.diff_action(g, p) 2*x^3*y + 20*x^3 + 2*y^2 + 6*x - >>> from sage.all import * >>> g = dx**Integer(2) + x*dy >>> p = x**Integer(5) + x**Integer(3) + y**Integer(2)*x**Integer(2) + Integer(1) >>> W.diff_action(g, p) 2*x^3*y + 20*x^3 + 2*y^2 + 6*x - The action is a left action: - sage: h = dx*x + x*y sage: W.diff_action(h, W.diff_action(g, p)) == W.diff_action(h*g, p) True - >>> from sage.all import * >>> h = dx*x + x*y >>> W.diff_action(h, W.diff_action(g, p)) == W.diff_action(h*g, p) True - The action endomorphism of a differential operator: - sage: dg = W.diff_action(g); dg Action of dx^2 + x*dy on Multivariate Polynomial Ring in x, y over Rational Field under Left action by Differential Weyl algebra... sage: dg(p) == W.diff_action(g, p) == g.diff(p) True - >>> from sage.all import * >>> dg = W.diff_action(g); dg Action of dx^2 + x*dy on Multivariate Polynomial Ring in x, y over Rational Field under Left action by Differential Weyl algebra... >>> dg(p) == W.diff_action(g, p) == g.diff(p) True 
- class sage.algebras.weyl_algebra.DifferentialWeylAlgebraElement[source]¶
- Bases: - IndexedFreeModuleElement- An element in a differential Weyl algebra. - diff(p)[source]¶
- Apply this differential operator to a polynomial. - INPUT: - p– polynomial of the underlying polynomial ring
 - OUTPUT: - The result of the left action of the Weyl algebra on the polynomial ring via differentiation. - EXAMPLES: - sage: R.<x,y> = QQ[] sage: W = R.weyl_algebra() sage: dx, dy = W.differentials() sage: dx.diff(x^3) 3*x^2 sage: (dx*dy).diff(W(x^3*y^3)) 9*x^2*y^2 sage: (x*dx + dy + 1).diff(x^4*y^4 + 1) 5*x^4*y^4 + 4*x^4*y^3 + 1 - >>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> W = R.weyl_algebra() >>> dx, dy = W.differentials() >>> dx.diff(x**Integer(3)) 3*x^2 >>> (dx*dy).diff(W(x**Integer(3)*y**Integer(3))) 9*x^2*y^2 >>> (x*dx + dy + Integer(1)).diff(x**Integer(4)*y**Integer(4) + Integer(1)) 5*x^4*y^4 + 4*x^4*y^3 + 1 
 - factor_differentials()[source]¶
- Return a dict representing - selfwith the differentials factored out.- EXAMPLES: - sage: R.<t> = QQ[] sage: D = DifferentialWeylAlgebra(R) sage: t, dt = D.gens() sage: x = dt^3*t^3 + dt^2*t^4 sage: x t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6 sage: x.factor_differentials() {(0,): 12*t^2 + 6, (1,): 8*t^3 + 18*t, (2,): t^4 + 9*t^2, (3,): t^3} sage: D.zero().factor_differentials() {} sage: R.<x,y,z> = QQ[] sage: D = DifferentialWeylAlgebra(R) sage: x, y, z, dx, dy, dz = D.gens() sage: elt = dx^3*x^3 + (y^3-z*x)*dx^3 + dy^3*x^3 + dx*dy*dz*x*y*z sage: elt x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7 sage: elt.factor_differentials() {(0, 0, 0): 7, (0, 0, 1): z, (0, 1, 0): y, (0, 1, 1): y*z, (0, 3, 0): x^3, (1, 0, 0): 19*x, (1, 0, 1): x*z, (1, 1, 0): x*y, (1, 1, 1): x*y*z, (2, 0, 0): 9*x^2, (3, 0, 0): x^3 + y^3 - x*z} - >>> from sage.all import * >>> R = QQ['t']; (t,) = R._first_ngens(1) >>> D = DifferentialWeylAlgebra(R) >>> t, dt = D.gens() >>> x = dt**Integer(3)*t**Integer(3) + dt**Integer(2)*t**Integer(4) >>> x t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6 >>> x.factor_differentials() {(0,): 12*t^2 + 6, (1,): 8*t^3 + 18*t, (2,): t^4 + 9*t^2, (3,): t^3} >>> D.zero().factor_differentials() {} >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> D = DifferentialWeylAlgebra(R) >>> x, y, z, dx, dy, dz = D.gens() >>> elt = dx**Integer(3)*x**Integer(3) + (y**Integer(3)-z*x)*dx**Integer(3) + dy**Integer(3)*x**Integer(3) + dx*dy*dz*x*y*z >>> elt x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7 >>> elt.factor_differentials() {(0, 0, 0): 7, (0, 0, 1): z, (0, 1, 0): y, (0, 1, 1): y*z, (0, 3, 0): x^3, (1, 0, 0): 19*x, (1, 0, 1): x*z, (1, 1, 0): x*y, (1, 1, 1): x*y*z, (2, 0, 0): 9*x^2, (3, 0, 0): x^3 + y^3 - x*z} 
 - list()[source]¶
- Return - selfas a list.- This list consists of pairs \((m, c)\), where \(m\) is a pair of tuples indexing a basis element of - self, and \(c\) is the coordinate of- selfcorresponding to this basis element. (Only nonzero coordinates are shown.)- EXAMPLES: - sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ) sage: dx,dy,dz = W.differentials() sage: elt = dy - (3*x - z)*dx sage: elt.list() [(((0, 0, 0), (0, 1, 0)), 1), (((0, 0, 1), (1, 0, 0)), 1), (((1, 0, 0), (1, 0, 0)), -3)] - >>> from sage.all import * >>> W = DifferentialWeylAlgebra(QQ, names=('x', 'y', 'z',)); (x, y, z,) = W._first_ngens(3) >>> dx,dy,dz = W.differentials() >>> elt = dy - (Integer(3)*x - z)*dx >>> elt.list() [(((0, 0, 0), (0, 1, 0)), 1), (((0, 0, 1), (1, 0, 0)), 1), (((1, 0, 0), (1, 0, 0)), -3)] 
 
- sage.algebras.weyl_algebra.repr_factored(w, latex_output=False)[source]¶
- Return a string representation of - wwith the \(dx_i\) generators factored on the right.- EXAMPLES: - sage: from sage.algebras.weyl_algebra import repr_factored sage: R.<t> = QQ[] sage: D = DifferentialWeylAlgebra(R) sage: t, dt = D.gens() sage: x = dt^3*t^3 + dt^2*t^4 sage: x t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6 sage: print(repr_factored(x)) (12*t^2 + 6) + (8*t^3 + 18*t)*dt + (t^4 + 9*t^2)*dt^2 + (t^3)*dt^3 sage: repr_factored(x, True) (12 t^{2} + 6) + (8 t^{3} + 18 t) \frac{\partial}{\partial t} + (t^{4} + 9 t^{2}) \frac{\partial^{2}}{\partial t^{2}} + (t^{3}) \frac{\partial^{3}}{\partial t^{3}} sage: repr_factored(D.zero()) '0' - >>> from sage.all import * >>> from sage.algebras.weyl_algebra import repr_factored >>> R = QQ['t']; (t,) = R._first_ngens(1) >>> D = DifferentialWeylAlgebra(R) >>> t, dt = D.gens() >>> x = dt**Integer(3)*t**Integer(3) + dt**Integer(2)*t**Integer(4) >>> x t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6 >>> print(repr_factored(x)) (12*t^2 + 6) + (8*t^3 + 18*t)*dt + (t^4 + 9*t^2)*dt^2 + (t^3)*dt^3 >>> repr_factored(x, True) (12 t^{2} + 6) + (8 t^{3} + 18 t) \frac{\partial}{\partial t} + (t^{4} + 9 t^{2}) \frac{\partial^{2}}{\partial t^{2}} + (t^{3}) \frac{\partial^{3}}{\partial t^{3}} >>> repr_factored(D.zero()) '0' - With multiple variables: - sage: R.<x,y,z> = QQ[] sage: D = DifferentialWeylAlgebra(R) sage: x, y, z, dx, dy, dz = D.gens() sage: elt = dx^3*x^3 + (y^3-z*x)*dx^3 + dy^3*x^3 + dx*dy*dz*x*y*z sage: elt x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7 sage: print(repr_factored(elt)) (7) + (z)*dz + (y)*dy + (y*z)*dy*dz + (x^3)*dy^3 + (19*x)*dx + (x*z)*dx*dz + (x*y)*dx*dy + (x*y*z)*dx*dy*dz + (9*x^2)*dx^2 + (x^3 + y^3 - x*z)*dx^3 sage: repr_factored(D.zero(), True) 0 - >>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> D = DifferentialWeylAlgebra(R) >>> x, y, z, dx, dy, dz = D.gens() >>> elt = dx**Integer(3)*x**Integer(3) + (y**Integer(3)-z*x)*dx**Integer(3) + dy**Integer(3)*x**Integer(3) + dx*dy*dz*x*y*z >>> elt x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7 >>> print(repr_factored(elt)) (7) + (z)*dz + (y)*dy + (y*z)*dy*dz + (x^3)*dy^3 + (19*x)*dx + (x*z)*dx*dz + (x*y)*dx*dy + (x*y*z)*dx*dy*dz + (9*x^2)*dx^2 + (x^3 + y^3 - x*z)*dx^3 >>> repr_factored(D.zero(), True) 0 
- sage.algebras.weyl_algebra.repr_from_monomials(monomials, term_repr, use_latex=False)[source]¶
- Return a string representation of an element of a free module from the dictionary - monomials.- INPUT: - monomials– list of pairs- [m, c]where- mis the index and- cis the coefficient
- term_repr– a function which returns a string given an index (can be- repror- latex, for example)
- use_latex– boolean (default:- False); if- Truethen the output is in latex format
 - EXAMPLES: - sage: from sage.algebras.weyl_algebra import repr_from_monomials sage: R.<x,y,z> = QQ[] sage: d = [(z, 4/7), (y, sqrt(2)), (x, -5)] # needs sage.symbolic sage: repr_from_monomials(d, lambda m: repr(m)) # needs sage.symbolic '4/7*z + sqrt(2)*y - 5*x' sage: a = repr_from_monomials(d, lambda m: latex(m), True); a # needs sage.symbolic \frac{4}{7} z + \sqrt{2} y - 5 x sage: type(a) # needs sage.symbolic <class 'sage.misc.latex.LatexExpr'> - >>> from sage.all import * >>> from sage.algebras.weyl_algebra import repr_from_monomials >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> d = [(z, Integer(4)/Integer(7)), (y, sqrt(Integer(2))), (x, -Integer(5))] # needs sage.symbolic >>> repr_from_monomials(d, lambda m: repr(m)) # needs sage.symbolic '4/7*z + sqrt(2)*y - 5*x' >>> a = repr_from_monomials(d, lambda m: latex(m), True); a # needs sage.symbolic \frac{4}{7} z + \sqrt{2} y - 5 x >>> type(a) # needs sage.symbolic <class 'sage.misc.latex.LatexExpr'> - The zero element: - sage: repr_from_monomials([], lambda m: repr(m)) '0' sage: a = repr_from_monomials([], lambda m: latex(m), True); a 0 sage: type(a) <class 'sage.misc.latex.LatexExpr'> - >>> from sage.all import * >>> repr_from_monomials([], lambda m: repr(m)) '0' >>> a = repr_from_monomials([], lambda m: latex(m), True); a 0 >>> type(a) <class 'sage.misc.latex.LatexExpr'> - A “unity” element: - sage: repr_from_monomials([(1, 1)], lambda m: repr(m)) '1' sage: a = repr_from_monomials([(1, 1)], lambda m: latex(m), True); a 1 sage: type(a) <class 'sage.misc.latex.LatexExpr'> - >>> from sage.all import * >>> repr_from_monomials([(Integer(1), Integer(1))], lambda m: repr(m)) '1' >>> a = repr_from_monomials([(Integer(1), Integer(1))], lambda m: latex(m), True); a 1 >>> type(a) <class 'sage.misc.latex.LatexExpr'> - sage: repr_from_monomials([(1, -1)], lambda m: repr(m)) '-1' sage: a = repr_from_monomials([(1, -1)], lambda m: latex(m), True); a -1 sage: type(a) <class 'sage.misc.latex.LatexExpr'> - >>> from sage.all import * >>> repr_from_monomials([(Integer(1), -Integer(1))], lambda m: repr(m)) '-1' >>> a = repr_from_monomials([(Integer(1), -Integer(1))], lambda m: latex(m), True); a -1 >>> type(a) <class 'sage.misc.latex.LatexExpr'> - Leading minus signs are dealt with appropriately: - sage: # needs sage.symbolic sage: d = [(z, -4/7), (y, -sqrt(2)), (x, -5)] sage: repr_from_monomials(d, lambda m: repr(m)) '-4/7*z - sqrt(2)*y - 5*x' sage: a = repr_from_monomials(d, lambda m: latex(m), True); a -\frac{4}{7} z - \sqrt{2} y - 5 x sage: type(a) <class 'sage.misc.latex.LatexExpr'> - >>> from sage.all import * >>> # needs sage.symbolic >>> d = [(z, -Integer(4)/Integer(7)), (y, -sqrt(Integer(2))), (x, -Integer(5))] >>> repr_from_monomials(d, lambda m: repr(m)) '-4/7*z - sqrt(2)*y - 5*x' >>> a = repr_from_monomials(d, lambda m: latex(m), True); a -\frac{4}{7} z - \sqrt{2} y - 5 x >>> type(a) <class 'sage.misc.latex.LatexExpr'> - Indirect doctests using a class that uses this function: - sage: R.<x,y> = QQ[] sage: A = CliffordAlgebra(QuadraticForm(R, 3, [x,0,-1,3,-4,5])) sage: a,b,c = A.gens() sage: a*b*c e0*e1*e2 sage: b*c e1*e2 sage: (a*a + 2) x + 2 sage: c*(a*a + 2)*b (-x - 2)*e1*e2 - 4*x - 8 sage: latex(c*(a*a + 2)*b) \left( -x - 2 \right) e_{1} e_{2} - 4 x - 8 - >>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> A = CliffordAlgebra(QuadraticForm(R, Integer(3), [x,Integer(0),-Integer(1),Integer(3),-Integer(4),Integer(5)])) >>> a,b,c = A.gens() >>> a*b*c e0*e1*e2 >>> b*c e1*e2 >>> (a*a + Integer(2)) x + 2 >>> c*(a*a + Integer(2))*b (-x - 2)*e1*e2 - 4*x - 8 >>> latex(c*(a*a + Integer(2))*b) \left( -x - 2 \right) e_{1} e_{2} - 4 x - 8