def is_unit(self):
        """
        Return True if self is a unit in the quotient ring.

        EXAMPLES::

            sage: R.<x,y> = QQ[]; S.<a,b> = R.quo(1 - x*y); type(a)
            <class 'sage.rings.quotient_ring.QuotientRing_generic_with_category.element_class'>
            sage: a*b
            1
            sage: S(2).is_unit()
            True

        Check that :trac:`29469` is fixed::

            sage: a.is_unit()
            True
            sage: (a+b).is_unit()
            False
        """
        if self.__rep.is_unit():
            return True
        from sage.categories.fields import Fields
        if self.parent() in Fields():
            return not self.is_zero()
        try:
            self.__invert__()
            return True
        except ArithmeticError:
            return False
        raise NotImplementedError
Exemple #2
0
    def __init__(self, prec=53):
        """
        Initialize ``self``.

        TESTS::

            sage: C = ComplexField(200)
            sage: C.category()
            Join of Category of fields and Category of infinite sets and Category of complete metric spaces
            sage: TestSuite(C).run()

            sage: CC.is_field()
            True

            sage: CC.is_finite()
            False
        """
        self._prec = int(prec)
        from sage.categories.fields import Fields
        ParentWithGens.__init__(
            self,
            self._real_field(), ('I', ),
            False,
            category=Fields().Infinite().Metric().Complete())
        #        self._populate_coercion_lists_()
        self._populate_coercion_lists_(
            coerce_list=[RRtoCC(self._real_field(), self)])
Exemple #3
0
    def residue_ring(self):
        r"""
        Return the residue field of this valuation.

        EXAMPLES::

            sage: sys.path.append(os.getcwd()); from mac_lane import * # optional: standalone
            sage: K = QQ
            sage: R.<t> = K[]
            sage: L.<t> = K.extension(t^2 + 1)
            sage: v = pAdicValuation(QQ, 2)
            sage: w = v.extension(L)
            sage: w.residue_ring()
            Finite Field of size 2

        """
        R = self._initial_approximation.residue_ring()
        from sage.categories.fields import Fields
        if R in Fields():
            # the approximation ends in v(phi)=infty
            return R
        else:
            from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
            assert(is_PolynomialRing(R))
            return R.base_ring()
Exemple #4
0
    def __init__(self, base, constants=QQ, category=None):
        ## Checking the arguments
        if (not (constants in Fields())):
            raise TypeError("The argument 'constants' must be a Field")
        if (not (isinstance(base, Ring_w_Sequence))):
            raise TypeError("The argument 'base' must be a Ring with Sequence")

        ## Initializing the parent structures
        ConversionSystem.__init__(self, base)
        IntegralDomain.__init__(self, base, category)

        ## Initializing the attributes
        self.__constants = constants

        self.__poly_ring = None
        self._change_poly_ring(constants)

        ## Initializing the map of variables (if there is enough)
        self.__map_of_vars = {}

        ## Initializing the map of derivatives
        self.__map_of_derivatives = {}

        ## Casting and Coercion system
        self.base().register_conversion(LRSimpleMorphism(self, self.base()))

        ## Auxiliary data
        self.__var_name = "x"
        self.__version = 1
Exemple #5
0
    def Vrepresentation_space(self):
        r"""
        Return the ambient vector space.

        This is the vector space or module containing the
        Vrepresentation vectors.

        OUTPUT:

        A free module over the base ring of dimension :meth:`ambient_dim`.

        EXAMPLES::

            sage: from sage.geometry.polyhedron.parent import Polyhedra
            sage: Polyhedra(QQ, 4).Vrepresentation_space()
            Vector space of dimension 4 over Rational Field
            sage: Polyhedra(QQ, 4).ambient_space()
            Vector space of dimension 4 over Rational Field
        """
        if self.base_ring() in Fields():
            from sage.modules.free_module import VectorSpace
            return VectorSpace(self.base_ring(), self.ambient_dim())
        else:
            from sage.modules.free_module import FreeModule
            return FreeModule(self.base_ring(), self.ambient_dim())
        def extra_super_categories(self):
            r"""
            Implement Maschke's theorem.

            In characteristic 0 all finite group algebras are semisimple.

            EXAMPLES::

                sage: FiniteGroups().Algebras(QQ).is_subcategory(Algebras(QQ).Semisimple())
                True
                sage: FiniteGroups().Algebras(FiniteField(7)).is_subcategory(Algebras(FiniteField(7)).Semisimple())
                False
                sage: FiniteGroups().Algebras(ZZ).is_subcategory(Algebras(ZZ).Semisimple())
                False
                sage: FiniteGroups().Algebras(Fields()).is_subcategory(Algebras(Fields()).Semisimple())
                False

                sage: Cat = CommutativeAdditiveGroups().Finite()
                sage: Cat.Algebras(QQ).is_subcategory(Algebras(QQ).Semisimple())
                True
                sage: Cat.Algebras(GF(7)).is_subcategory(Algebras(GF(7)).Semisimple())
                False
                sage: Cat.Algebras(ZZ).is_subcategory(Algebras(ZZ).Semisimple())
                False
                sage: Cat.Algebras(Fields()).is_subcategory(Algebras(Fields()).Semisimple())
                False
            """
            from sage.categories.fields import Fields
            K = self.base_ring()
            if K in Fields() and K.characteristic() == 0:
                from sage.categories.algebras import Algebras
                return [Algebras(self.base_ring()).Semisimple()]
            else:
                return []
    def fraction_field(self):
        r"""
        Return the fraction field of this ring of Laurent series.

        If the base ring is a field, then Laurent series are already a field.
        If the base ring is a domain, then the Laurent series over its fraction
        field is returned. Otherwise, raise a ``ValueError``.

        EXAMPLES::

            sage: R = LaurentSeriesRing(ZZ, 't', 30).fraction_field()
            sage: R
            Laurent Series Ring in t over Rational Field
            sage: R.default_prec()
            30

            sage: LaurentSeriesRing(Zmod(4), 't').fraction_field()
            Traceback (most recent call last):
            ...
            ValueError: must be an integral domain
        """
        from sage.categories.integral_domains import IntegralDomains
        from sage.categories.fields import Fields
        if self in Fields():
            return self
        elif self in IntegralDomains():
            return LaurentSeriesRing(self.base_ring().fraction_field(),
                                     self.variable_names(),
                                     self.default_prec())
        else:
            raise ValueError('must be an integral domain')
Exemple #8
0
    def extra_super_categories(self):
        r"""
        Add :class:`VectorSpaces` to the super categories of ``self`` if
        the base ring is a field.

        EXAMPLES::

            sage: Modules(QQ).Filtered().is_subcategory(VectorSpaces(QQ))
            True
            sage: Modules(ZZ).Filtered().extra_super_categories()
            []

        This makes sure that ``Modules(QQ).Filtered()`` returns an
        instance of :class:`FilteredModules` and not a join category of
        an instance of this class and of ``VectorSpaces(QQ)``::

            sage: type(Modules(QQ).Filtered())
            <class 'sage.categories.vector_spaces.VectorSpaces.Filtered_with_category'>

        .. TODO::

            Get rid of this workaround once there is a more systematic
            approach for the alias ``Modules(QQ)`` -> ``VectorSpaces(QQ)``.
            Probably the latter should be a category with axiom, and
            covariant constructions should play well with axioms.
        """
        from sage.categories.modules import Modules
        from sage.categories.fields import Fields
        base_ring = self.base_ring()
        if base_ring in Fields():
            return [Modules(base_ring)]
        else:
            return []
Exemple #9
0
    def __init__(self, R, A):
        """
        Initialize ``self``.

        TESTS::

            sage: C4 = graphs.CycleGraph(4)
            sage: A = groups.misc.RightAngledArtin(C4)
            sage: H = A.cohomology()
            sage: TestSuite(H).run()
        """
        if R not in Fields():
            raise NotImplementedError(
                "only implemented with coefficients in a field")
        self._group = A

        names = tuple(['e' + name[1:] for name in A.variable_names()])
        from sage.graphs.independent_sets import IndependentSets
        from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
        indices = [tuple(ind_set) for ind_set in IndependentSets(A._graph)]
        indices = FiniteEnumeratedSet(indices)
        cat = AlgebrasWithBasis(
            R.category()).Super().Graded().FiniteDimensional()
        CombinatorialFreeModule.__init__(self,
                                         R,
                                         indices,
                                         category=cat,
                                         prefix='H')
        self._assign_names(names)
Exemple #10
0
    def __init__(self, R):
        r"""
        Initialization of ``self``.

        INPUT:

        - ``R`` -- a ring

        EXAMPLES::

            sage: Sym = SymmetricFunctions(QQ)

        TESTS::

            sage: Sym1 = SymmetricFunctions(FiniteField(23))
            sage: Sym2 = SymmetricFunctions(Integers(23))
            sage: TestSuite(Sym).run()

        """
        # change the line below to assert(R in Rings()) once MRO issues from #15536, #15475 are resolved
        assert (R in Fields() or R in Rings()
                )  # side effect of this statement assures MRO exists for R
        self._base = R  # Won't be needed when CategoryObject won't override anymore base_ring
        Parent.__init__(self,
                        category=GradedHopfAlgebras(R).WithRealizations())
Exemple #11
0
 def __init__(self, prec=53):
     self._prec = int(prec)
     from sage.categories.fields import Fields
     ParentWithGens.__init__(self,
                             self._real_field(), ('I', ),
                             False,
                             category=Fields())
Exemple #12
0
    def __init__(self, base_field, length, designed_distance,
                 primitive_root=None, offset=1, jump_size=1, b=0):
        """
        TESTS:

        ``designed_distance`` must be between 1 and ``length`` (inclusive),
        otherwise an exception is raised::

            sage: C = codes.BCHCode(GF(2), 15, 16)
            Traceback (most recent call last):
            ...
            ValueError: designed_distance must belong to [1, n]
        """
        if not (0 < designed_distance <= length):
            raise ValueError("designed_distance must belong to [1, n]")

        if base_field not in Fields() or not base_field.is_finite():
            raise ValueError("base_field has to be a finite field")

        q = base_field.cardinality()
        s = Zmod(length)(q).multiplicative_order()
        if gcd(jump_size, q ** s - 1) != 1:
            raise ValueError("jump_size must be coprime with the order of "
                             "the multiplicative group of the splitting field")

        D = [(offset + jump_size * i) % length
             for i in range(designed_distance - 1)]

        super(BCHCode, self).__init__(field=base_field, length=length,
                                      D=D, primitive_root=primitive_root)
        self._default_decoder_name = "UnderlyingGRS"
        self._jump_size = jump_size
        self._offset = offset
        self._designed_distance = designed_distance
Exemple #13
0
    def __init__(self,
                 base_ring,
                 name=None,
                 default_prec=20,
                 sparse=False,
                 category=None):
        """
        Initialization

        EXAMPLES::

            sage: K.<q> = LaurentSeriesRing(QQ,default_prec=4); K
            Laurent Series Ring in q over Rational Field
            sage: 1 / (q-q^2)
            q^-1 + 1 + q + q^2 + O(q^3)
        """
        commutative_ring.CommutativeRing.__init__(self,
                                                  base_ring,
                                                  names=name,
                                                  category=getattr(
                                                      self,
                                                      '_default_category',
                                                      Fields()))
        self._polynomial_ring = polynomial.polynomial_ring_constructor.PolynomialRing(
            self.base_ring(), self.variable_name(), sparse=sparse)
        self._power_series_ring = power_series_ring.PowerSeriesRing(
            self.base_ring(),
            self.variable_name(),
            default_prec=default_prec,
            sparse=sparse)
Exemple #14
0
    def __init__(self, R):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: NCSymD1 = SymmetricFunctionsNonCommutingVariablesDual(FiniteField(23))
            sage: NCSymD2 = SymmetricFunctionsNonCommutingVariablesDual(Integers(23))
            sage: TestSuite(SymmetricFunctionsNonCommutingVariables(QQ).dual()).run()
        """
        # change the line below to assert(R in Rings()) once MRO issues from #15536, #15475 are resolved
        assert(R in Fields() or R in Rings()) # side effect of this statement assures MRO exists for R
        self._base = R # Won't be needed once CategoryObject won't override base_ring
        category = GradedHopfAlgebras(R)  # TODO: .Commutative()
        Parent.__init__(self, category=category.WithRealizations())

        # Bases
        w = self.w()

        # Embedding of Sym in the homogeneous bases into DNCSym in the w basis
        Sym = SymmetricFunctions(self.base_ring())
        Sym_h_to_w = Sym.h().module_morphism(w.sum_of_partitions,
                                             triangular='lower',
                                             inverse_on_support=w._set_par_to_par,
                                             codomain=w, category=category)
        Sym_h_to_w.register_as_coercion()
        self.to_symmetric_function = Sym_h_to_w.section()
Exemple #15
0
    def __init__(self, ring, category=None):
        r"""
        Initialize this Ore function field.

        TESTS::

            sage: k.<a> = GF(11^3)
            sage: Frob = k.frobenius_endomorphism()
            sage: der = k.derivation(a, twist=Frob)
            sage: S.<x> = k['x', der]
            sage: K = S.fraction_field()
            sage: TestSuite(K).run()
        """
        if self.Element is None:
            import sage.rings.polynomial.ore_function_element
            self.Element = sage.rings.polynomial.ore_function_element.OreFunction
        if not isinstance(ring, OrePolynomialRing):
            raise TypeError("not a Ore Polynomial Ring")
        if ring.base_ring() not in Fields():
            raise TypeError("the base ring must be a field")
        try:
            _ = ring.twisting_morphism(-1)
            self._simplification = True
        except (TypeError, ZeroDivisionError, NotImplementedError):
            self._simplification = False
        self._ring = ring
        base = ring.base_ring()
        category = Algebras(base).or_subcategory(category)
        Algebra.__init__(self, base, names=ring.variable_name(), normalize=True, category=category)
Exemple #16
0
def FilteredVectorSpace(arg1, arg2=None, base_ring=QQ, check=True):
    r"""
    Construct a filtered vector space.

    INPUT:

    This function accepts various input that determines the vector space and filtration.

    - Just the dimensionFilteredVectorSpace(dimension): Return the trivial filtration
      (where all vector spaces are isomorphic).

    - Dimension and maximal degree, see
      :func:`constructor_from_dim_degree` for arguments. Construct a
      filtration with only one non-trivial step `V\supset 0` at the
      given cutoff degree.

    - A dictionary containing the degrees as keys and a list of vector
      space generators as values, see
      :func:`FilteredVectorSpace_from_generators`

    - Generators and a dictionary containing the degrees as keys and
      the indices of vector space generators as values, see
      :func:`FilteredVectorSpace_from_generators_indices`

    In addition, the following keyword arguments are supported:

    - ``base_ring`` -- a field (optional, default `\QQ`). The base
      field of the vector space. Must be a field.

    EXAMPLES:

    Just the dimension for the trivial filtration::

        sage: FilteredVectorSpace(2)
        QQ^2

    Dimension and degree::

        sage: FilteredVectorSpace(2, 1)
        QQ^2 >= 0

    Dictionary of generators::

        sage: FilteredVectorSpace({1:[(1,0), (0,1)], 3:[(1,0)]})
        QQ^2 >= QQ^1 >= QQ^1 >= 0

    Generators and a dictionary referring to them by index::

        sage: FilteredVectorSpace([(1,0), (0,1)], {1:[0,1], 3:[0]})
        QQ^2 >= QQ^1 >= QQ^1 >= 0
    """
    if base_ring not in Fields():
        raise ValueError('the base_ring argument must be a field')
    if arg1 in ZZ:
        return construct_from_dim_degree(arg1, arg2, base_ring, check)
    elif arg2 is None:
        return construct_from_generators(arg1, base_ring, check)
    else:
        return construct_from_generators_indices(arg1, arg2, base_ring, check)
    def super_categories(self):
        """
        EXAMPLES::

            sage: QuotientFields().super_categories()
            [Category of fields]
        """
        return [Fields()]
Exemple #18
0
    def super_categories(self):
        """
        EXAMPLES::

            sage: FiniteFields().super_categories()
            [Category of fields, Category of finite enumerated sets]
        """
        return [Fields(), FiniteEnumeratedSets()]
Exemple #19
0
    def super_categories(self):
        """
        EXAMPLES::

            sage: DiscreteValuationFields().super_categories()
            [Category of fields]
        """
        return [Fields()]
    def __init__(self, space, rank_error, relative_field=None):
        r"""
        TESTS:

        If the number of errors exceeds the dimension of the input space,
        it will return an error::

            sage: n_err = 42
            sage: Chan = channels.StaticRankErrorChannel(GF(59)^40, n_err)
            Traceback (most recent call last):
            ...
            ValueError: There might be more errors than the dimension of the input space

        If ``relative_field`` is specified and is not a subfield of the base field,
        it will return an error::

            sage: n_err = 2
            sage: Chan = channels.StaticRankErrorChannel(GF(16)^6, n_err, GF(8))
            Traceback (most recent call last):
            ...
            ValueError: Finite Field in z4 of size 2^4 is not an extension of
            Finite Field in z3 of size 2^3

        If ``relative_field`` is specified and is not a field,
        it will return an error::

            sage: n_err = 2
            sage: Chan = channels.StaticRankErrorChannel(GF(16)^6, n_err, GF(4)^2)
            Traceback (most recent call last):
            ...
            ValueError: relative_field must be a Field and
            Vector space of dimension 2 over Finite Field in z2
            of size 2^2 is not.
        """
        if isinstance(rank_error, (Integer, int)):
            rank_error = (rank_error, rank_error)
        if not isinstance(rank_error, (tuple, list)):
            raise ValueError(
                "rank_error must be a tuple, a list, an Integer or a Python int"
            )
        super(StaticRankErrorChannel, self).__init__(space, space)
        if rank_error[1] > space.dimension():
            raise ValueError(
                "There might be more errors than the dimension of the input space"
            )
        self._rank_error = rank_error
        self._base_field = space.base_field()
        if not relative_field:
            self._relative_field = self._base_field.prime_subfield()
        else:
            if not relative_field in Fields():
                raise ValueError(
                    "relative_field must be a Field and %s is not." %
                    relative_field)
            if not relative_field.is_subring(self._base_field):
                raise ValueError("%s is not an extension of %s" %
                                 (self._base_field, relative_field))
            self._relative_field = relative_field
    def super_categories(self):
        """
        EXAMPLES::

            sage: QuotientFields().super_categories()
            [Category of fields]
        """
        from sage.categories.fields import Fields
        return [Fields()]
    def __init__(self, power_series):
        """
        Initialization

        EXAMPLES::

            sage: K.<q> = LaurentSeriesRing(QQ, default_prec=4); K
            Laurent Series Ring in q over Rational Field
            sage: 1 / (q-q^2)
            q^-1 + 1 + q + q^2 + O(q^3)

            sage: RZZ = LaurentSeriesRing(ZZ, 't')
            sage: RZZ.category()
            Category of infinite integral domains
            sage: TestSuite(RZZ).run()

            sage: R1 = LaurentSeriesRing(Zmod(1), 't')
            sage: R1.category()
            Category of finite commutative rings
            sage: TestSuite(R1).run()

            sage: R2 = LaurentSeriesRing(Zmod(2), 't')
            sage: R2.category()
            Category of infinite complete discrete valuation fields
            sage: TestSuite(R2).run()

            sage: R4 = LaurentSeriesRing(Zmod(4), 't')
            sage: R4.category()
            Category of infinite commutative rings
            sage: TestSuite(R4).run()

            sage: RQQ = LaurentSeriesRing(QQ, 't')
            sage: RQQ.category()
            Category of infinite complete discrete valuation fields
            sage: TestSuite(RQQ).run()
        """
        base_ring = power_series.base_ring()
        if base_ring in Fields():
            category = CompleteDiscreteValuationFields()
        elif base_ring in IntegralDomains():
            category = IntegralDomains()
        elif base_ring in Rings().Commutative():
            category = Rings().Commutative()
        else:
            raise ValueError('unrecognized base ring')

        if base_ring.is_zero():
            category = category.Finite()
        else:
            category = category.Infinite()

        CommutativeRing.__init__(self,
                                 base_ring,
                                 names=power_series.variable_names(),
                                 category=category)

        self._power_series_ring = power_series
Exemple #23
0
    def singular_points(self, F=None):
        r"""
        Return the set of singular points of this curve.

        INPUT:

        - ``F`` -- (default: None) field over which to find the singular points. If not given,
          the base ring of this curve is used.

        OUTPUT:

        - a list of points in the ambient space of this curve.

        EXAMPLES::

            sage: A.<x,y,z> = AffineSpace(QQ, 3)
            sage: C = Curve([y^2 - x^5, x - z], A)
            sage: C.singular_points()
            [(0, 0, 0)]

        ::

            sage: R.<a> = QQ[]
            sage: K.<b> = NumberField(a^8 - a^4 + 1)
            sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
            sage: C = Curve([359/12*x*y^2*z^2 + 2*y*z^4 + 187/12*y^3*z^2 + x*z^4\
            + 67/3*x^2*y*z^2 + 117/4*y^5 + 9*x^5 + 6*x^3*z^2 + 393/4*x*y^4\
            + 145*x^2*y^3 + 115*x^3*y^2 + 49*x^4*y], P)
            sage: C.singular_points(K)
            [(b^6 : -b^6 : 1),
             (-b^6 : b^6 : 1),
             (1/2*b^5 + 1/2*b^3 - 1/2*b - 1 : 1 : 0),
             (-1/2*b^5 - 1/2*b^3 + 1/2*b - 1 : 1 : 0),
             (2/3*b^4 - 1/3 : 0 : 1),
             (-2/3*b^4 + 1/3 : 0 : 1)]
        """
        if F is None:
            if not self.base_ring() in Fields():
                raise TypeError("curve must be defined over a field")
            F = self.base_ring()
        elif not F in Fields():
            raise TypeError("(=%s) must be a field" % F)
        X = self.singular_subscheme()
        return X.rational_points(F=F)
    def __init__(self, power_series):
        """
        Initialization

        EXAMPLES::

            sage: K.<q> = LaurentSeriesRing(QQ, default_prec=4); K
            Laurent Series Ring in q over Rational Field
            sage: 1 / (q-q^2)
            q^-1 + 1 + q + q^2 + O(q^3)

            sage: RZZ = LaurentSeriesRing(ZZ, 't')
            sage: RZZ.category()
            Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces)
            sage: TestSuite(RZZ).run()

            sage: R1 = LaurentSeriesRing(Zmod(1), 't')
            sage: R1.category()
            Category of finite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets)
            sage: TestSuite(R1).run()

            sage: R2 = LaurentSeriesRing(Zmod(2), 't')
            sage: R2.category()
            Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets
            sage: TestSuite(R2).run()

            sage: R4 = LaurentSeriesRing(Zmod(4), 't')
            sage: R4.category()
            Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets)
            sage: TestSuite(R4).run()

            sage: RQQ = LaurentSeriesRing(QQ, 't')
            sage: RQQ.category()
            Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets
            sage: TestSuite(RQQ).run()
        """
        base_ring = power_series.base_ring()
        category = Algebras(base_ring.category())
        if base_ring in Fields():
            category &= CompleteDiscreteValuationFields()
        elif base_ring in IntegralDomains():
            category &= IntegralDomains()
        elif base_ring in Rings().Commutative():
            category = category.Commutative()

        if base_ring.is_zero():
            category = category.Finite()
        else:
            category = category.Infinite()

        self._power_series_ring = power_series
        self._one_element = self.element_class(self, power_series.one())
        CommutativeRing.__init__(self,
                                 base_ring,
                                 names=power_series.variable_names(),
                                 category=category)
    def __init__(self, base_ring, name=None, default_prec=None, sparse=False,
                 category=None):
        CommutativeRing.__init__(
            self, base_ring, names=name,
            category=getattr(self, '_default_category', Fields()))

        # If self is R(( x^(1/e) )) then the corresponding Laurent series
        # ring will be R(( x ))
        self._laurent_series_ring = LaurentSeriesRing(
            base_ring, name=name, default_prec=default_prec, sparse=sparse)
    def _convert_map_from_(self, R):
        """
        Finds conversion maps from R to this ring.

        Currently, a conversion exists if the defining polynomial is the same.

        EXAMPLES::

            sage: R.<a> = Zq(125)
            sage: S = R.change(type='capped-abs', prec=40, print_mode='terse', print_pos=False)
            sage: S(a - 15)
            -15 + a + O(5^20)

        We get conversions from the exact field::

            sage: K = R.exact_field(); K
            Number Field in a with defining polynomial x^3 + 3*x + 3
            sage: R(K.gen())
            a + O(5^20)

        and its maximal order::

            sage: OK = K.maximal_order()
            sage: R(OK.gen(1))
            a + O(5^20)
        """
        cat = None
        if self._implementation == 'NTL' and R == QQ:
            # Want to use DefaultConvertMap_unique
            return None
        if isinstance(R, pAdicExtensionGeneric) and R.prime() == self.prime(
        ) and R.defining_polynomial(exact=True) == self.defining_polynomial(
                exact=True):
            if R.is_field() and not self.is_field():
                cat = SetsWithPartialMaps()
            elif R.category() is self.category():
                cat = R.category()
            else:
                cat = EuclideanDomains() & MetricSpaces().Complete()
        elif isinstance(R, Order) and R.number_field().defining_polynomial(
        ) == self.defining_polynomial():
            cat = IntegralDomains()
        elif isinstance(R, NumberField) and R.defining_polynomial(
        ) == self.defining_polynomial():
            if self.is_field():
                cat = Fields()
            else:
                cat = SetsWithPartialMaps()
        else:
            k = self.residue_field()
            if R is k:
                return ResidueLiftingMap._create_(R, self)
        if cat is not None:
            H = Hom(R, self, cat)
            return H.__make_element_class__(DefPolyConversion)(H)
Exemple #27
0
def ChamanaraPolygon(alpha):
    from sage.categories.fields import Fields
    field = alpha.parent()
    if not field in Fields():
        ValueError("The value of alpha must lie in a field.")
    if alpha <= 0 or alpha >= 1:
        ValueError("The value of alpha must be between zero and one.")
    # The value of x is $\sum_{n=0}^\infty \alpha^n$.
    x = 1 / (1 - alpha)
    from .polygon import polygons
    return polygons((1, 0), (-x, x), (0, -1), (x - 1, 1 - x))
    def __init__(self, names=None):
        r"""
        TESTS::

            sage: UCF = UniversalCyclotomicField()
            sage: TestSuite(UCF).run()
        """
        from sage.categories.fields import Fields
        Field.__init__(self, base_ring=QQ, category=Fields().Infinite())
        self._populate_coercion_lists_(embedding=UCFtoQQbar(self))
        late_import()
Exemple #29
0
def AlgebraicClosureFiniteField(base_ring,
                                name,
                                category=None,
                                implementation=None,
                                **kwds):
    """
    Construct an algebraic closure of a finite field.

    The recommended way to use this functionality is by calling the
    :meth:`~sage.rings.finite_rings.finite_field_base.FiniteField.algebraic_closure`
    method of the finite field.

    .. NOTE::

        Algebraic closures of finite fields in Sage do not have the
        unique representation property, because they are not
        determined up to unique isomorphism by their defining data.

    EXAMPLES::

        sage: from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField
        sage: F = GF(2).algebraic_closure()
        sage: F1 = AlgebraicClosureFiniteField(GF(2), 'z')
        sage: F1 is F
        False

    In the pseudo-Conway implementation, non-identical instances never
    compare equal::

        sage: F1 == F
        False
        sage: loads(dumps(F)) == F
        False

    This is to ensure that the result of comparing two instances
    cannot change with time.

    """
    if category is None:
        from sage.categories.fields import Fields
        category = Fields().Infinite()

    if implementation is None:
        implementation = 'pseudo_conway'

    if implementation == 'pseudo_conway':
        return AlgebraicClosureFiniteField_pseudo_conway(
            base_ring, name, category, **kwds)
    else:
        raise ValueError(
            'unknown implementation for algebraic closure of finite field: %s'
            % implementation)
    def __contains__(self, x):
        """
        EXAMPLES::

            sage: GF(4, "a") in FiniteFields()
            True
            sage: QQ in FiniteFields()
            False
            sage: IntegerModRing(4) in FiniteFields()
            False
        """
        from sage.categories.fields import Fields
        return x in Fields() and x.is_finite()