本文整理汇总了Python中sage.rings.polynomial.polynomial_ring.is_PolynomialRing函数的典型用法代码示例。如果您正苦于以下问题:Python is_PolynomialRing函数的具体用法?Python is_PolynomialRing怎么用?Python is_PolynomialRing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_PolynomialRing函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_base_ring
def _get_base_ring(ring, var_name="d"):
r"""
Return the base ring of the given ``ring``:
If ``ring`` is of the form ``FractionField(PolynomialRing(R,'d'))``:
Return ``R``.
If ``ring`` is of the form ``FractionField(R)``:
Return ``R``.
If ``ring`` is of the form ``PolynomialRing(R,'d')``:
Return ``R``.
Otherwise return ``ring``.
The base ring is used in the construction of the correponding
``FormsRing`` or ``FormsSpace``. In particular in the construction
of holomorphic forms of degree (0, 1). For (binary)
operations a general ring element is considered (coerced to)
a (constant) holomorphic form of degree (0, 1)
whose construction should be based on the returned base ring
(and not on ``ring``!).
If ``var_name`` (default: "d") is specified then this variable
name is used for the polynomial ring.
EXAMPLES::
sage: from sage.modular.modform_hecketriangle.functors import _get_base_ring
sage: _get_base_ring(ZZ) == ZZ
True
sage: _get_base_ring(QQ) == ZZ
True
sage: _get_base_ring(PolynomialRing(CC, 'd')) == CC
True
sage: _get_base_ring(PolynomialRing(QQ, 'd')) == ZZ
True
sage: _get_base_ring(FractionField(PolynomialRing(CC, 'd'))) == CC
True
sage: _get_base_ring(FractionField(PolynomialRing(QQ, 'd'))) == ZZ
True
sage: _get_base_ring(PolynomialRing(QQ, 'x')) == PolynomialRing(QQ, 'x')
True
"""
#from sage.rings.fraction_field import is_FractionField
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.categories.pushout import FractionField as FractionFieldFunctor
base_ring = ring
#if (is_FractionField(base_ring)):
# base_ring = base_ring.base()
if (base_ring.construction() and base_ring.construction()[0] == FractionFieldFunctor()):
base_ring = base_ring.construction()[1]
if (is_PolynomialRing(base_ring) and base_ring.ngens()==1 and base_ring.variable_name()==var_name):
base_ring = base_ring.base()
if (base_ring.construction() and base_ring.construction()[0] == FractionFieldFunctor()):
base_ring = base_ring.construction()[1]
return base_ring
示例2: create_key
def create_key(self, domain, v = None):
r"""
Normalize and check the parameters to create a Gauss valuation.
TESTS::
sage: v = QQ.valuation(2)
sage: R.<x> = ZZ[]
sage: GaussValuation.create_key(R, v)
Traceback (most recent call last):
...
ValueError: the domain of v must be the base ring of domain but 2-adic valuation is not defined over Integer Ring but over Rational Field
"""
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if not is_PolynomialRing(domain):
raise TypeError("GaussValuations can only be created over polynomial rings but %r is not a polynomial ring"%(domain,))
if not domain.ngens() == 1:
raise NotImplementedError("domain must be univariate but %r is not univariate"%(domain,))
if v is None:
v = domain.base_ring().valuation()
if not v.domain() is domain.base_ring():
raise ValueError("the domain of v must be the base ring of domain but %r is not defined over %r but over %r"%(v, domain.base_ring(), v.domain()))
if not v.is_discrete_valuation():
raise ValueError("v must be a discrete valuation but %r is not"%(v,))
return (domain, v)
示例3: _coerce_map_from_
def _coerce_map_from_(self, S):
"""
A coercion from `S` exists, if `S` coerces into ``self``'s base ring,
or if `S` is a univariate polynomial or power series ring with the
same variable name as self, defined over a base ring that coerces into
``self``'s base ring.
EXAMPLES::
sage: A = GF(17)[['x']]
sage: A.has_coerce_map_from(ZZ) # indirect doctest
True
sage: A.has_coerce_map_from(ZZ['x'])
True
sage: A.has_coerce_map_from(ZZ['y'])
False
sage: A.has_coerce_map_from(ZZ[['x']])
True
"""
if self.base_ring().has_coerce_map_from(S):
return True
if (is_PolynomialRing(S) or is_PowerSeriesRing(S)) and self.base_ring().has_coerce_map_from(S.base_ring()) \
and self.variable_names()==S.variable_names():
return True
示例4: __init__
def __init__(self, coeff_ring=ZZ, group='Sp(4,Z)', weights='even', degree=2, default_prec=SMF_DEFAULT_PREC):
r"""
Initialize an algebra of Siegel modular forms of degree ``degree``
with coefficients in ``coeff_ring``, on the group ``group``.
If ``weights`` is 'even', then only forms of even weights are
considered; if ``weights`` is 'all', then all forms are
considered.
EXAMPLES::
sage: A = SiegelModularFormsAlgebra(QQ)
sage: B = SiegelModularFormsAlgebra(ZZ)
sage: A._coerce_map_from_(B)
True
sage: B._coerce_map_from_(A)
False
sage: A._coerce_map_from_(ZZ)
True
"""
self.__coeff_ring = coeff_ring
self.__group = group
self.__weights = weights
self.__degree = degree
self.__default_prec = default_prec
R = coeff_ring
from sage.algebras.all import GroupAlgebra
if isinstance(R, GroupAlgebra):
R = R.base_ring()
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(R):
self.__base_ring = R.base_ring()
else:
self.__base_ring = R
from sage.categories.all import Algebras
Algebra.__init__(self, base=self.__base_ring, category=Algebras(self.__base_ring))
示例5: _coerce_impl
def _coerce_impl(self, f):
"""
Return the canonical coercion of ``f`` into this multivariate power
series ring, if one is defined, or raise a TypeError.
The rings that canonically coerce to this multivariate power series
ring are:
- this ring itself
- a polynomial or power series ring in the same variables or a
subset of these variables (possibly empty), over any base
ring that canonically coerces into the base ring of this ring
EXAMPLES::
sage: R.<t,u,v> = PowerSeriesRing(QQ); R
Multivariate Power Series Ring in t, u, v over Rational Field
sage: S1.<t,v> = PolynomialRing(ZZ); S1
Multivariate Polynomial Ring in t, v over Integer Ring
sage: f1 = -t*v + 2*v^2 + v; f1
-t*v + 2*v^2 + v
sage: R(f1)
v - t*v + 2*v^2
sage: S2.<u,v> = PowerSeriesRing(ZZ); S2
Multivariate Power Series Ring in u, v over Integer Ring
sage: f2 = -2*v^2 + 5*u*v^2 + S2.O(6); f2
-2*v^2 + 5*u*v^2 + O(u, v)^6
sage: R(f2)
-2*v^2 + 5*u*v^2 + O(t, u, v)^6
sage: R2 = R.change_ring(GF(2))
sage: R2(f1)
v + t*v
sage: R2(f2)
u*v^2 + O(t, u, v)^6
TESTS::
sage: R.<t,u,v> = PowerSeriesRing(QQ)
sage: S1.<t,v> = PolynomialRing(ZZ)
sage: f1 = S1.random_element()
sage: g1 = R._coerce_impl(f1)
sage: f1.parent() == R
False
sage: g1.parent() == R
True
"""
P = f.parent()
if is_MPolynomialRing(P) or is_MPowerSeriesRing(P) \
or is_PolynomialRing(P) or is_PowerSeriesRing(P):
if set(P.variable_names()).issubset(set(self.variable_names())):
if self.has_coerce_map_from(P.base_ring()):
return self(f)
else:
return self._coerce_try(f,[self.base_ring()])
示例6: AffineSpace
def AffineSpace(n, R=None, names='x'):
r"""
Return affine space of dimension ``n`` over the ring ``R``.
EXAMPLES:
The dimension and ring can be given in either order::
sage: AffineSpace(3, QQ, 'x')
Affine Space of dimension 3 over Rational Field
sage: AffineSpace(5, QQ, 'x')
Affine Space of dimension 5 over Rational Field
sage: A = AffineSpace(2, QQ, names='XY'); A
Affine Space of dimension 2 over Rational Field
sage: A.coordinate_ring()
Multivariate Polynomial Ring in X, Y over Rational Field
Use the divide operator for base extension::
sage: AffineSpace(5, names='x')/GF(17)
Affine Space of dimension 5 over Finite Field of size 17
The default base ring is `\ZZ`::
sage: AffineSpace(5, names='x')
Affine Space of dimension 5 over Integer Ring
There is also an affine space associated to each polynomial ring::
sage: R = GF(7)['x, y, z']
sage: A = AffineSpace(R); A
Affine Space of dimension 3 over Finite Field of size 7
sage: A.coordinate_ring() is R
True
"""
if (is_MPolynomialRing(n) or is_PolynomialRing(n)) and R is None:
R = n
A = AffineSpace(R.ngens(), R.base_ring(), R.variable_names())
A._coordinate_ring = R
return A
if isinstance(R, integer_types + (Integer,)):
n, R = R, n
if R is None:
R = ZZ # default is the integers
if names is None:
if n == 0:
names = ''
else:
raise TypeError("you must specify the variables names of the coordinate ring")
names = normalize_names(n, names)
if R in _Fields:
if is_FiniteField(R):
return AffineSpace_finite_field(n, R, names)
else:
return AffineSpace_field(n, R, names)
return AffineSpace_generic(n, R, names)
示例7: _coerce_map_from_
def _coerce_map_from_(self, P):
"""
Return a coercion map from `P` to ``self``, or True, or None.
The following rings admit a coercion map to the Laurent series
ring `A((t))`:
- any ring that admits a coercion map to `A` (including `A`
itself);
- any Laurent series ring, power series ring or polynomial
ring in the variable `t` over a ring admitting a coercion
map to `A`.
EXAMPLES::
sage: R.<t> = LaurentSeriesRing(ZZ)
sage: S.<t> = PowerSeriesRing(QQ)
sage: R.has_coerce_map_from(S) # indirect doctest
False
sage: R.has_coerce_map_from(R)
True
sage: R.<t> = LaurentSeriesRing(QQ['x'])
sage: R.has_coerce_map_from(S)
True
sage: R.has_coerce_map_from(QQ['t'])
True
sage: R.has_coerce_map_from(ZZ['x']['t'])
True
sage: R.has_coerce_map_from(ZZ['t']['x'])
False
sage: R.has_coerce_map_from(ZZ['x'])
True
"""
A = self.base_ring()
if A is P:
return True
f = A.coerce_map_from(P)
if f is not None:
return self.coerce_map_from(A) * f
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.power_series_ring import is_PowerSeriesRing
if ((is_LaurentSeriesRing(P) or is_PowerSeriesRing(P) or is_PolynomialRing(P))
and P.variable_name() == self.variable_name()
and A.has_coerce_map_from(P.base_ring())):
return True
示例8: extensions
def extensions(self, ring):
r"""
Return the extensions of this valuation to ``ring``.
EXAMPLES::
sage: v = ZZ.valuation(2)
sage: R.<x> = ZZ[]
sage: w = GaussValuation(R, v)
sage: w.extensions(GaussianIntegers()['x'])
[Gauss valuation induced by 2-adic valuation]
"""
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(ring) and ring.ngens() == 1:
if self.domain().is_subring(ring):
return [GaussValuation(ring, w) for w in self._base_valuation.extensions(ring.base_ring())]
return super(GaussValuation_generic, self).extensions(ring)
示例9: change_domain
def change_domain(self, ring):
r"""
Return this valuation as a valuation over ``ring``.
EXAMPLES::
sage: v = ZZ.valuation(2)
sage: R.<x> = ZZ[]
sage: w = GaussValuation(R, v)
sage: w.change_domain(QQ['x'])
Gauss valuation induced by 2-adic valuation
"""
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(ring) and ring.ngens() == 1:
base_valuation = self._base_valuation.change_domain(ring.base_ring())
return GaussValuation(self.domain().change_ring(ring.base_ring()), base_valuation)
return super(GaussValuation_generic, self).change_domain(ring)
示例10: restriction
def restriction(self, ring):
r"""
Return the restriction of this valuation to ``ring``.
EXAMPLES::
sage: v = ZZ.valuation(2)
sage: R.<x> = ZZ[]
sage: w = GaussValuation(R, v)
sage: w.restriction(ZZ)
2-adic valuation
"""
if ring.is_subring(self.domain().base_ring()):
return self._base_valuation.restriction(ring)
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(ring) and ring.ngens() == 1:
if ring.base().is_subring(self.domain().base()):
return GaussValuation(ring, self._base_valuation.restriction(ring.base()))
return super(GaussValuation_generic, self).restriction(ring)
示例11: base_extend
def base_extend(self, R):
r"""
Extends the base ring of the algebra ``self`` to ``R``.
EXAMPLES::
sage: S = SiegelModularFormsAlgebra(coeff_ring=QQ)
sage: S.base_extend(RR)
Algebra of Siegel modular forms of degree 2 and even weights on Sp(4,Z) over Real Field with 53 bits of precision
"""
#B = self.base_ring()
S = self.coeff_ring()
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(S):
xS = S.base_extend(R)
elif R.has_coerce_map_from(S):
xS = R
else:
raise TypeError, "cannot extend to %s" %R
return SiegelModularFormsAlgebra(coeff_ring=xS, group=self.group(), weights=self.weights(), degree=self.degree(), default_prec=self.default_prec())
示例12: __init__
def __init__(self, parent, phi):
r"""
TESTS::
sage: R.<x> = QQ[]
sage: v = GaussValuation(R, QQ.valuation(7))
sage: from sage.rings.valuation.developing_valuation import DevelopingValuation
sage: isinstance(v, DevelopingValuation)
True
"""
DiscretePseudoValuation.__init__(self, parent)
domain = parent.domain()
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if not is_PolynomialRing(domain) or not domain.ngens() == 1:
raise TypeError("domain must be a univariate polynomial ring but %r is not"%(domain,))
phi = domain.coerce(phi)
if phi.is_constant() or not phi.is_monic():
raise ValueError("phi must be a monic non-constant polynomial but %r is not"%(phi,))
self._phi = phi
示例13: field_format
def field_format(field):
"""Print a nice representation of the given field object. This works
correctly for number fields, but for fraction fields of polynomial
rings we just pretend the base field are the complex numbers (for
now)."""
# print("debug field = {0}".format(field))
if field == QQ:
return ll("\\Q")
elif is_NumberField(field):
minpoly = field.defining_polynomial()
g, = field.gens()
# G, = minpoly.parent().gens()
return (ll("K = \\Q(", g, ")") + ", where " +
ll(g) + " has minimal polynomial " + ll(minpoly))
elif is_FractionField(field):
ring = field.ring_of_integers()
if is_PolynomialRing(ring):
return ll("\\C(", ring.gens()[0], ")")
else:
print("debug ring = {0}".format(ring))
raise UnknownField()
else:
raise UnknownField()
示例14: extensions
def extensions(self, ring):
r"""
Return the extensions of this valuation to ``ring``.
EXAMPLES::
sage: v = GaussianIntegers().valuation(2)
sage: u = v._base_valuation
sage: u.extensions(QQ['x'])
[[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 , … ]]
"""
if self.domain() is ring:
return [self]
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
if is_PolynomialRing(ring) and self.domain().base_ring().is_subring(ring.base_ring()):
if self.domain().base_ring().fraction_field() is ring.base_ring():
return [LimitValuation(self._initial_approximation.change_domain(ring),
self._G.change_ring(ring.base_ring()))]
else:
# we need to recompute the mac lane approximants over this base
# ring because it could split differently
pass
return super(MacLaneLimitValuation, self).extensions(ring)
示例15: residue_ring
def residue_ring(self):
r"""
Return the residue ring of this valuation, which is always a field.
EXAMPLES::
sage: K = QQ
sage: R.<t> = K[]
sage: L.<t> = K.extension(t^2 + 1)
sage: v = QQ.valuation(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()