1 | initial version |
Here is a function
def matrice_2d(self, variables=None):
"""
EXAMPLES::
sage: x, y = PolynomialRing(QQ,['x', 'y']).gens()
sage: matrice_2d(x**2+x*y+y**3)
[1 0 0]
[0 0 0]
[0 1 0]
[0 0 1]
sage: x, y, z = PolynomialRing(QQ,['x','y','z']).gens()
sage: matrice_2d(x**2+z*x*y+z*y**3+z*x,[y,z])
[ x x 0 1]
[x^2 0 0 0]
sage: matrice_2d(x**2+z*x*y+z*y**3+z*x,[x,z])
[ y^3 y + 1 0]
[ 0 0 1]
"""
if variables is None:
ring = self.parent().base_ring()
x, y = self.parent().gens()
ix = 0
iy = 1
else:
x, y = variables
ring = self.parent()
toutes_vars = x.parent().gens()
ix = toutes_vars.index(x)
iy = toutes_vars.index(y)
support = self.exponents()
minx = min(u[ix] for u in support)
maxx = max(u[ix] for u in support)
miny = min(u[iy] for u in support)
maxy = max(u[iy] for u in support)
mat = matrix(ring, maxy - miny + 1, maxx - minx + 1)
for u in support:
ex = u[ix]
ey = u[iy]
i, j = (maxy - ey, ex - minx)
mat[i, j] = self.coefficient({x: ex, y: ey})
return mat