Example #1
0
    def __init__(self, R, S=None, category=None):
        """
        Construct the affine scheme with coordinate ring `R`.

        INPUT:

        - ``R`` -- commutative ring

        - ``S`` -- (optional) commutative ring admitting a natural map
          to ``R``

        OUTPUT:

        The spectrum of `R`, i.e. the unique affine scheme with
        coordinate ring `R` as a scheme over the base ring `S`.

        EXAMPLES::

            sage: from sage.schemes.generic.scheme import AffineScheme
            sage: A.<x, y> = PolynomialRing(QQ)
            sage: X = AffineScheme(A, QQ)
            sage: X
            Spectrum of Multivariate Polynomial Ring in x, y over Rational Field
            sage: X.category()
            Category of schemes over Rational Field

        The standard way to construct an affine scheme is to use the
        :func:`~sage.schemes.generic.spec.Spec` functor::

            sage: S = Spec(ZZ)
            sage: S
            Spectrum of Integer Ring
            sage: S.category()
            Category of schemes
            sage: type(S)
            <class 'sage.schemes.generic.scheme.AffineScheme_with_category'>
        """
        from sage.categories.commutative_rings import CommutativeRings
        if not R in CommutativeRings():
            raise TypeError("R (={}) must be a commutative ring".format(R))
        self.__R = R
        if not S is None:
            if not S in CommutativeRings():
                raise TypeError("S (={}) must be a commutative ring".format(S))
            if not R.has_coerce_map_from(S):
                raise ValueError(
                    "There must be a natural map S --> R, but S = {} and R = {}"
                    .format(S, R))
        Scheme.__init__(self, S, category=category)
Example #2
0
    def base_extend(self, R):
        """
        Extend the base ring/scheme.

        INPUT:

        - ``R`` -- an affine scheme or a commutative ring

        EXAMPLES::

            sage: Spec_ZZ = Spec(ZZ);  Spec_ZZ
            Spectrum of Integer Ring
            sage: Spec_ZZ.base_extend(QQ)
            Spectrum of Rational Field
        """
        from sage.categories.commutative_rings import CommutativeRings
        if R in CommutativeRings():
            return AffineScheme(self.coordinate_ring().base_extend(R),
                                self.base_ring())
        if not self.base_scheme() == R.base_scheme():
            raise ValueError(
                'the new base scheme must be a scheme over the old base scheme'
            )
        return AffineScheme(
            self.coordinate_ring().base_extend(new_base.coordinate_ring()),
            self.base_ring())
Example #3
0
    def super_categories(self):
        """
        EXAMPLES::

            sage: IntegralDomains().super_categories()
            [Category of commutative rings, Category of domains]
        """
        return [CommutativeRings(), Domains()]
Example #4
0
    def construction(self):
        """
        Returns the functorial construction of ``self``.

        EXAMPLES::

            sage: R.<x> = PolynomialRing(ZZ,'x')
            sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2])
            sage: R.quotient_ring(I).construction()
            (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring)
            sage: F.<x,y,z> = FreeAlgebra(QQ, implementation='letterplace')
            sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F
            sage: Q = F.quo(I)
            sage: Q.construction()
            (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field)

        TESTS::

            sage: F, R = Integers(5).construction()
            sage: F(R)
            Ring of integers modulo 5
            sage: F, R = GF(5).construction()
            sage: F(R)
            Finite Field of size 5
        """
        from sage.categories.pushout import QuotientFunctor
        # Is there a better generic way to distinguish between things like Z/pZ as a field and Z/pZ as a ring?
        from sage.rings.ring import Field
        try:
            names = self.variable_names()
        except ValueError:
            try:
                names = self.cover_ring().variable_names()
            except ValueError:
                names = None
        if self in CommutativeRings():
            return QuotientFunctor(self.__I,
                                   names=names,
                                   domain=CommutativeRings(),
                                   codomain=CommutativeRings(),
                                   as_field=isinstance(self, Field)), self.__R
        else:
            return QuotientFunctor(self.__I,
                                   names=names,
                                   as_field=isinstance(self, Field)), self.__R
    def __init__(self, order, cache=None, category=None):
        """
        Create with the command ``IntegerModRing(order)``.

        TESTS::

            sage: FF = IntegerModRing(29)
            sage: TestSuite(FF).run()
            sage: F19 = IntegerModRing(19, category = Fields())
            sage: TestSuite(F19).run()
            sage: F23 = IntegerModRing(23)
            sage: F23 in Fields()
            True
            sage: TestSuite(F23).run()
            sage: Z16 = IntegerModRing(16)
            sage: TestSuite(Z16).run()
            sage: R = Integers(100000)
            sage: TestSuite(R).run()  # long time (17s on sage.math, 2011)
        """
        order = ZZ(order)
        if order <= 0:
            raise ZeroDivisionError("order must be positive")
        self.__order = order
        self._pyx_order = integer_mod.NativeIntStruct(order)
        if category is None:
            from sage.categories.commutative_rings import CommutativeRings
            from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
            from sage.categories.category import Category
            category = Category.join(
                [CommutativeRings(),
                 FiniteEnumeratedSets()])


#            category = default_category
# If the category is given then we trust that is it right.
# Give the generator a 'name' to make quotients work.  The
# name 'x' is used because it's also used for the ring of
# integers: see the __init__ method for IntegerRing_class in
# sage/rings/integer_ring.pyx.
        quotient_ring.QuotientRing_generic.__init__(self,
                                                    ZZ,
                                                    ZZ.ideal(order),
                                                    names=('x', ),
                                                    category=category)
        # Calling ParentWithGens is not needed, the job is done in
        # the quotient ring initialisation.
        #ParentWithGens.__init__(self, self, category = category)
        # We want that the ring is its own base ring.
        self._base = self
        if cache is None:
            cache = order < 500
        if cache:
            self._precompute_table()
        self._zero_element = integer_mod.IntegerMod(self, 0)
        self._one_element = integer_mod.IntegerMod(self, 1)
Example #6
0
    def __init__(self, R):
        """
        EXAMPLES::

            sage: CommutativeRingIdeals(ZZ)
            Category of commutative ring ideals in Integer Ring
            sage: CommutativeRingIdeals(IntegerModRing(4))
            Category of commutative ring ideals in Ring of integers modulo 4

        TESTS::

            sage: CommutativeRingIdeals(Partitions(4))
            Traceback (most recent call last):
            ...
            TypeError: R (=Partitions of the integer 4) must be a commutative ring
            sage: TestSuite(CommutativeRingIdeals(ZZ)).run()
        """
        if R not in CommutativeRings():
            raise TypeError, "R (=%s) must be a commutative ring" % R
        Category_ideal.__init__(self, R)
#                  http://www.gnu.org/licenses/
#*****************************************************************************

from sage.rings.commutative_ring import is_CommutativeRing, CommutativeRing
from sage.rings.polynomial.all import PolynomialRing, is_MPolynomialRing, is_PolynomialRing
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.power_series_ring import PowerSeriesRing, PowerSeriesRing_generic, is_PowerSeriesRing

from sage.rings.infinity import infinity
import sage.misc.latex as latex
from sage.structure.nonexact import Nonexact

from sage.rings.multi_power_series_ring_element import MPowerSeries
from sage.categories.commutative_rings import CommutativeRings

_CommutativeRings = CommutativeRings()
from sage.categories.integral_domains import IntegralDomains

_IntegralDomains = IntegralDomains()


def is_MPowerSeriesRing(x):
    """
    Return true if input is a multivariate power series ring.

    TESTS::

        sage: from sage.rings.power_series_ring import is_PowerSeriesRing
        sage: from sage.rings.multi_power_series_ring import is_MPowerSeriesRing
        sage: M = PowerSeriesRing(ZZ,4,'v');
        sage: is_PowerSeriesRing(M)
Example #8
0
        sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F
        sage: Q = F.quo(I)
        sage: is_QuotientRing(Q)
        True
        sage: is_QuotientRing(F)
        False

    """
    return isinstance(x, QuotientRing_nc)


from sage.categories.rings import Rings
_Rings = Rings()
_RingsQuotients = Rings().Quotients()
from sage.categories.commutative_rings import CommutativeRings
_CommutativeRingsQuotients = CommutativeRings().Quotients()
from sage.structure.category_object import check_default_category


class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens):
    """
    The quotient ring of `R` by a twosided ideal `I`.

    This class is for rings that do not inherit from
    :class:`~sage.rings.ring.CommutativeRing`.

    EXAMPLES:

    Here is a quotient of a free algebra by a twosided homogeneous ideal::

        sage: F.<x,y,z> = FreeAlgebra(QQ, implementation='letterplace')
Example #9
0
        sage: is_IntegerModRing(GF(13))
        True
        sage: is_IntegerModRing(GF(4, 'a'))
        False
        sage: is_IntegerModRing(10)
        False
        sage: is_IntegerModRing(ZZ)
        False
    """
    return isinstance(x, IntegerModRing_generic)


from sage.categories.commutative_rings import CommutativeRings
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.category import JoinCategory
default_category = JoinCategory((CommutativeRings(), FiniteEnumeratedSets()))
ZZ = integer_ring.IntegerRing()


def _unit_gens_primepowercase(p, r):
    r"""
    Return a list of generators for `(\ZZ/p^r\ZZ)^*` and their orders.

    EXAMPLES::

        sage: from sage.rings.finite_rings.integer_mod_ring import _unit_gens_primepowercase
        sage: _unit_gens_primepowercase(2, 3)
        [(7, 2), (5, 2)]
        sage: _unit_gens_primepowercase(17, 1)
        [(3, 16)]
        sage: _unit_gens_primepowercase(3, 3)
Example #10
0
    def __init__(self, order, cache=None, category=None):
        """
        Create with the command IntegerModRing(order)
        
        INPUT:
        
        
        -  ``order`` - an integer 1

        - ``category`` - a subcategory of ``CommutativeRings()`` (the default)
          (currently only available for subclasses)

        OUTPUT:
        
        
        -  ``IntegerModRing`` - the ring of integers modulo
           N.
        
        
        EXAMPLES:
        
        First we compute with integers modulo `29`.
        
        ::
        
            sage: FF = IntegerModRing(29)
            sage: FF
            Ring of integers modulo 29
            sage: FF.category()
            Join of Category of commutative rings and Category of subquotients of monoids and Category of quotients of semigroups and Category of finite enumerated sets
            sage: FF.is_field()
            True
            sage: FF.characteristic()
            29
            sage: FF.order()
            29
            sage: gens = FF.unit_gens()
            sage: a = gens[0]
            sage: a
            2
            sage: a.is_square()
            False
            sage: def pow(i): return a**i
            sage: [pow(i) for i in range(16)]
            [1, 2, 4, 8, 16, 3, 6, 12, 24, 19, 9, 18, 7, 14, 28, 27]
            sage: TestSuite(FF).run()

        We have seen above that an integer mod ring is, by default, not
        initialised as an object in the category of fields. However, one
        can force it to be. Moreover, testing containment in the category
        of fields my re-initialise the category of the integer mod ring::

            sage: F19 = IntegerModRing(19, category = Fields())
            sage: F19.category().is_subcategory(Fields())
            True
            sage: F23 = IntegerModRing(23)
            sage: F23.category().is_subcategory(Fields())
            False
            sage: F23 in Fields()
            True
            sage: F23.category().is_subcategory(Fields())
            True
            sage: TestSuite(F19).run()
            sage: TestSuite(F23).run()
        
        Next we compute with the integers modulo `16`.
        
        ::
        
            sage: Z16 = IntegerModRing(16)
            sage: Z16.category()
            Join of Category of commutative rings and Category of subquotients of monoids and Category of quotients of semigroups and Category of finite enumerated sets
            sage: Z16.is_field()
            False
            sage: Z16.order()
            16
            sage: Z16.characteristic() 
            16
            sage: gens = Z16.unit_gens()
            sage: gens
            [15, 5]
            sage: a = gens[0]
            sage: b = gens[1]
            sage: def powa(i): return a**i
            sage: def powb(i): return b**i
            sage: gp_exp = FF.unit_group_exponent()
            sage: gp_exp
            28
            sage: [powa(i) for i in range(15)]
            [1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1]
            sage: [powb(i) for i in range(15)]
            [1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9]
            sage: a.multiplicative_order()
            2
            sage: b.multiplicative_order()
            4
            sage: TestSuite(Z16).run()
        
        Saving and loading::
        
            sage: R = Integers(100000)
            sage: TestSuite(R).run()  # long time (17s on sage.math, 2011)

        Testing ideals and quotients::

            sage: Z10 = Integers(10)
            sage: I = Z10.principal_ideal(0)
            sage: Z10.quotient(I) == Z10
            True
            sage: I = Z10.principal_ideal(2)
            sage: Z10.quotient(I) == Z10
            False
            sage: I.is_prime()
            True
        """
        order = ZZ(order)
        if order <= 0:
            raise ZeroDivisionError, "order must be positive"
        self.__order = order
        self._pyx_order = integer_mod.NativeIntStruct(order)
        self.__unit_group_exponent = None
        self.__factored_order = None
        self.__factored_unit_order = None
        if category is None:
            from sage.categories.commutative_rings import CommutativeRings
            from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
            from sage.categories.category import Category
            category = Category.join(
                [CommutativeRings(),
                 FiniteEnumeratedSets()])


#            category = default_category
# If the category is given then we trust that is it right.
# Give the generator a 'name' to make quotients work.  The
# name 'x' is used because it's also used for the ring of
# integers: see the __init__ method for IntegerRing_class in
# sage/rings/integer_ring.pyx.
        quotient_ring.QuotientRing_generic.__init__(self,
                                                    ZZ,
                                                    ZZ.ideal(order),
                                                    names=('x', ),
                                                    category=category)
        # Calling ParentWithGens is not needed, the job is done in
        # the quotient ring initialisation.
        #ParentWithGens.__init__(self, self, category = category)
        # We want that the ring is its own base ring.
        self._base = self
        if cache is None:
            cache = order < 500
        if cache:
            self._precompute_table()
        self._zero_element = integer_mod.IntegerMod(self, 0)
        self._one_element = integer_mod.IntegerMod(self, 1)
Example #11
0
    def __classcall_private__(cls,
                              R=None,
                              arg0=None,
                              index_set=None,
                              central_elements=None,
                              category=None,
                              prefix=None,
                              names=None,
                              latex_names=None,
                              parity=None,
                              weights=None,
                              **kwds):
        """
        Lie conformal algebra factory.

        EXAMPLES::

            sage: betagamma_dict = {('b','a'):{0:{('K',0):1}}}
            sage: V = LieConformalAlgebra(QQ, betagamma_dict, names=('a','b'), weights=(1,0), central_elements=('K',))
            sage: type(V)
            <class 'sage.algebras.lie_conformal_algebras.graded_lie_conformal_algebra.GradedLieConformalAlgebra_with_category'>
        """
        if not R in CommutativeRings():
            raise ValueError(
                "arg0 must be a commutative ring got {}".format(R))

        #This is the only exposed class so we clean keywords here
        known_keywords = [
            'category', 'prefix', 'bracket', 'latex_bracket', 'string_quotes',
            'sorting_key', 'graded', 'super'
        ]
        for key in kwds:
            if key not in known_keywords:
                raise ValueError("got an unexpected keyword argument '%s'" %
                                 key)

        if isinstance(arg0, dict) and arg0:
            graded = kwds.pop("graded", False)
            if weights is not None or graded:
                from .graded_lie_conformal_algebra import \
                                                    GradedLieConformalAlgebra
                return GradedLieConformalAlgebra(
                    R,
                    Family(arg0),
                    index_set=index_set,
                    central_elements=central_elements,
                    category=category,
                    prefix=prefix,
                    names=names,
                    latex_names=latex_names,
                    parity=parity,
                    weights=weights,
                    **kwds)
            else:
                from .lie_conformal_algebra_with_structure_coefs import \
                        LieConformalAlgebraWithStructureCoefficients
                return LieConformalAlgebraWithStructureCoefficients(
                    R,
                    Family(arg0),
                    index_set=index_set,
                    central_elements=central_elements,
                    category=category,
                    prefix=prefix,
                    names=names,
                    latex_names=latex_names,
                    parity=parity,
                    **kwds)
        raise NotImplementedError("not implemented")
Example #12
0
    def __init__(self, base, prec, names, element_class):
        """
        Initializes self.

        EXAMPLES::

            sage: R = Zp(5) #indirect doctest
            sage: R.precision_cap()
            20
        """
        self._prec = prec
        Parent.__init__(self, base, element_constructor=element_class, names=(names,), normalize=False, category=CommutativeRings())
    def __classcall_private__(cls,
                              base_ring,
                              twist=None,
                              names=None,
                              sparse=False):
        r"""
        Construct the Ore polynomial ring associated to the given parameters.

        TESTS::

            sage: R.<t> = QQ[]
            sage: der = R.derivation()
            sage: A.<d> = OrePolynomialRing(R, der)
            sage: A
            Ore Polynomial Ring in d over Univariate Polynomial Ring in t over Rational Field twisted by d/dt
            sage: type(A)
            <class 'sage.rings.polynomial.ore_polynomial_ring.OrePolynomialRing_with_category'>

        We check the uniqueness property of parents::

            sage: der2 = R.derivation()
            sage: B.<d> = OrePolynomialRing(R, der2)
            sage: A is B
            True

        When there is no twisting derivation, a special class is used::

            sage: k.<t> = ZZ[]
            sage: theta = k.hom([t+1])
            sage: S.<x> = OrePolynomialRing(k, theta)
            sage: S
            Ore Polynomial Ring in x over Univariate Polynomial Ring in t over Integer Ring twisted by t |--> t + 1
            sage: type(S)
            <class 'sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_with_category'>

        In certain situations (e.g. when the twisting morphism is the Frobenius
        over a finite field), even more specialized classes are used::

            sage: k.<a> = GF(7^5)
            sage: Frob = k.frobenius_endomorphism(2)
            sage: S.<x> = SkewPolynomialRing(k, Frob)
            sage: type(S)
            <class 'sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_finite_field_with_category'>
        """
        if base_ring not in CommutativeRings():
            raise TypeError('base_ring must be a commutative ring')
        if isinstance(twist, Morphism):
            if (twist.domain() is not base_ring
                    or twist.codomain() is not base_ring):
                raise TypeError(
                    "the twisting morphism must be an endomorphism of base_ring (=%s)"
                    % base_ring)
            if twist.is_identity():
                morphism = None
            else:
                morphism = twist
            derivation = None
        elif isinstance(twist, RingDerivation):
            if (twist.domain() is not base_ring
                    or twist.codomain() is not base_ring):
                raise TypeError(
                    "the twisting derivation must be an endomorphism of base_ring (=%s)"
                    % base_ring)
            morphism = twist.parent().twisting_morphism()
            if twist:
                derivation = twist
            else:
                derivation = None
        else:
            raise TypeError(
                "the twisting map must be a ring morphism or a derivation")
        if names is None:
            raise TypeError("you must specify the name of the variable")
        try:
            names = normalize_names(1, names)[0]
        except IndexError:
            raise NotImplementedError(
                "multivariate Ore polynomials rings not supported")

        # If there is no twisting morphism and no twisting derivation
        # we return a classical polynomial ring
        if derivation is None and morphism is None:
            return PolynomialRing(base_ring, names, sparse=sparse)

        # We find the best constructor
        if sparse:
            raise NotImplementedError(
                "sparse Ore polynomial rings are not implemented")

        from sage.rings.polynomial import skew_polynomial_ring
        constructors = []
        if derivation is None:
            if base_ring in _Fields:
                try:
                    order = morphism.order()
                    if order is not Infinity:
                        if base_ring.is_finite():
                            constructors.append(
                                skew_polynomial_ring.
                                SkewPolynomialRing_finite_field)
                        else:
                            constructors.append(
                                skew_polynomial_ring.
                                SkewPolynomialRing_finite_order)
                except (AttributeError, NotImplementedError):
                    pass
            constructors.append(skew_polynomial_ring.SkewPolynomialRing)

        for constructor in constructors:
            try:
                return constructor(base_ring, morphism, derivation, names,
                                   sparse)
            except (AttributeError, NotImplementedError):
                pass

        # We fallback to generic implementation
        return cls.__classcall__(cls, base_ring, morphism, derivation, names,
                                 sparse)