compositedomain.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. """Implementation of :class:`CompositeDomain` class. """
  2. from sympy.polys.domains.domain import Domain
  3. from sympy.polys.polyerrors import GeneratorsError
  4. from sympy.utilities import public
  5. @public
  6. class CompositeDomain(Domain):
  7. """Base class for composite domains, e.g. ZZ[x], ZZ(X). """
  8. is_Composite = True
  9. gens, ngens, symbols, domain = [None]*4
  10. def inject(self, *symbols):
  11. """Inject generators into this domain. """
  12. if not (set(self.symbols) & set(symbols)):
  13. return self.__class__(self.domain, self.symbols + symbols, self.order)
  14. else:
  15. raise GeneratorsError("common generators in %s and %s" % (self.symbols, symbols))
  16. def drop(self, *symbols):
  17. """Drop generators from this domain. """
  18. symset = set(symbols)
  19. newsyms = tuple(s for s in self.symbols if s not in symset)
  20. domain = self.domain.drop(*symbols)
  21. if not newsyms:
  22. return domain
  23. else:
  24. return self.__class__(domain, newsyms, self.order)