Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sagemathgh-37303: use Parent in Weyl algebra
    
replace the auld-class `Algebra` by `Parent` in Weyl algebras

this requires a tweak in the `_first_n_gens` mechanism to handle
families

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#37303
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Feb 17, 2024
2 parents 74f84bc + c817c06 commit eaf5863
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/sage/algebras/weyl_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from sage.categories.algebras_with_basis import AlgebrasWithBasis
from sage.sets.family import Family
import sage.data_structures.blas_dict as blas
from sage.rings.ring import Algebra
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.multi_polynomial_ring_base import MPolynomialRing_base
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
Expand Down Expand Up @@ -655,7 +654,7 @@ def diff(self, p):
return self.parent().diff_action(self, p)


class DifferentialWeylAlgebra(Algebra, UniqueRepresentation):
class DifferentialWeylAlgebra(UniqueRepresentation, Parent):
r"""
The differential Weyl algebra of a polynomial ring.
Expand Down Expand Up @@ -780,7 +779,7 @@ def _repr_(self) -> str:
sage: DifferentialWeylAlgebra(R)
Differential Weyl algebra of polynomials in x, y, z over Rational Field
"""
poly_gens = ', '.join(repr(x) for x in self.gens()[:self._n])
poly_gens = ', '.join(repr(x) for x in self.variables())
return "Differential Weyl algebra of polynomials in {} over {}".format(
poly_gens, self.base_ring())

Expand Down Expand Up @@ -986,6 +985,8 @@ def algebra_generators(self):
d = {x: self.gen(i) for i, x in enumerate(self.variable_names())}
return Family(self.variable_names(), lambda x: d[x])

gens = algebra_generators

@cached_method
def variables(self):
"""
Expand Down
7 changes: 6 additions & 1 deletion src/sage/structure/category_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ cdef class CategoryObject(SageObject):
sage: z.minpoly() # needs sage.rings.number_field
x^2 + 3
"""
return self._defining_names()[:n]
names = self._defining_names()
if isinstance(names, (list, tuple)):
return names[:n]
# case of Family
it = iter(names)
return tuple(next(it) for i in range(n))

@cached_method
def _defining_names(self):
Expand Down

0 comments on commit eaf5863

Please sign in to comment.