def __init__(self, base, p, prec, print_mode, names, element_class, category=None): """ Initialization. INPUT: - base -- Base ring. - p -- prime - print_mode -- dictionary of print options - names -- how to print the uniformizer - element_class -- the class for elements of this ring EXAMPLES:: sage: R = Zp(17) #indirect doctest """ if category is None: if self.is_field(): category = Fields() else: category = PrincipalIdealDomains() category = category.Metric().Complete() LocalGeneric.__init__(self, base, prec, names, element_class, category) self._printer = pAdicPrinter(self, print_mode)
def super_categories(self): """ EXAMPLES:: sage: EuclideanDomains().super_categories() [Category of principal ideal domains] """ return [PrincipalIdealDomains()]
def super_categories(self): """ EXAMPLES:: sage: DiscreteValuationRings().super_categories() [Category of principal ideal domains] """ return [PrincipalIdealDomains()]
def ideal(self, *args, **kwds): """ Create an ideal of this ring. NOTE: The code is copied from the base class :class:`~sage.rings.ring.Ring`. This is because there are rings that do not inherit from that class, such as matrix algebras. See :trac:`7797`. INPUT: - An element or a list/tuple/sequence of elements. - ``coerce`` (optional bool, default ``True``): First coerce the elements into this ring. - ``side``, optional string, one of ``"twosided"`` (default), ``"left"``, ``"right"``: determines whether the resulting ideal is twosided, a left ideal or a right ideal. EXAMPLE:: sage: MS = MatrixSpace(QQ,2,2) sage: isinstance(MS,Ring) False sage: MS in Rings() True sage: MS.ideal(2) Twosided Ideal ( [2 0] [0 2] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: MS.ideal([MS.0,MS.1],side='right') Right Ideal ( [1 0] [0 0], <BLANKLINE> [0 1] [0 0] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field """ if kwds.has_key('coerce'): coerce = kwds['coerce'] del kwds['coerce'] else: coerce = True from sage.rings.ideal import Ideal_generic from types import GeneratorType if len(args) == 0: gens = [self(0)] else: gens = args while isinstance( gens, (list, tuple, GeneratorType)) and len(gens) == 1: first = gens[0] if isinstance(first, Ideal_generic): R = first.ring() m = self.convert_map_from(R) if m is not None: gens = [m(g) for g in first.gens()] coerce = False else: m = R.convert_map_from(self) if m is not None: raise NotImplementedError else: raise TypeError break elif isinstance(first, (list, tuple, GeneratorType)): gens = first else: try: if self.has_coerce_map_from(first): gens = first.gens( ) # we have a ring as argument elif hasattr(first, 'parent'): gens = [first] else: raise ArithmeticError, "There is no coercion from %s to %s" % ( first, self) except TypeError: # first may be a ring element pass break if coerce: gens = [self(g) for g in gens] from sage.categories.principal_ideal_domains import PrincipalIdealDomains if self in PrincipalIdealDomains(): # Use GCD algorithm to obtain a principal ideal g = gens[0] if len(gens) == 1: try: g = g.gcd( g ) # note: we set g = gcd(g, g) to "canonicalize" the generator: make polynomials monic, etc. except (AttributeError, NotImplementedError): pass else: for h in gens[1:]: g = g.gcd(h) gens = [g] if kwds.has_key('ideal_class'): C = kwds['ideal_class'] del kwds['ideal_class'] else: C = self._ideal_class_(len(gens)) if len(gens) == 1 and isinstance(gens[0], (list, tuple)): gens = gens[0] return C(self, gens, **kwds)