本文整理汇总了Python中sage.rings.commutative_ring.is_CommutativeRing函数的典型用法代码示例。如果您正苦于以下问题:Python is_CommutativeRing函数的具体用法?Python is_CommutativeRing怎么用?Python is_CommutativeRing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_CommutativeRing函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_key_and_extra_args
def create_key_and_extra_args(self, X, Y, category=None, base=ZZ,
check=True):
"""
Create a key that uniquely determines the Hom-set.
INPUT:
- ``X`` -- a scheme. The domain of the morphisms.
- ``Y`` -- a scheme. The codomain of the morphisms.
- ``category`` -- a category for the Hom-sets (default: schemes over
given base).
- ``base`` -- a scheme or a ring. The base scheme of domain
and codomain schemes. If a ring is specified, the spectrum
of that ring will be used as base scheme.
- ``check`` -- boolean (default: ``True``).
EXAMPLES::
sage: A2 = AffineSpace(QQ,2)
sage: A3 = AffineSpace(QQ,3)
sage: A3.Hom(A2) # indirect doctest
Set of morphisms
From: Affine Space of dimension 3 over Rational Field
To: Affine Space of dimension 2 over Rational Field
sage: from sage.schemes.generic.homset import SchemeHomsetFactory
sage: SHOMfactory = SchemeHomsetFactory('test')
sage: key, extra = SHOMfactory.create_key_and_extra_args(A3,A2,check=False)
sage: key
(..., ..., Category of schemes over Integer Ring)
sage: extra
{'Y': Affine Space of dimension 2 over Rational Field,
'X': Affine Space of dimension 3 over Rational Field,
'base_ring': Integer Ring, 'check': False}
"""
if not is_Scheme(X) and is_CommutativeRing(X):
X = Spec(X)
if not is_Scheme(Y) and is_CommutativeRing(Y):
Y = Spec(Y)
if is_Spec(base):
base_spec = base
base_ring = base.coordinate_ring()
elif is_CommutativeRing(base):
base_spec = Spec(base)
base_ring = base
else:
raise ValueError(
'The base must be a commutative ring or its spectrum.')
if not category:
from sage.categories.schemes import Schemes
category = Schemes(base_spec)
key = tuple([id(X), id(Y), category])
extra = {'X':X, 'Y':Y, 'base_ring':base_ring, 'check':check}
return key, extra
示例2: __init__
def __init__(self, A):
"""
EXAMPLES::
sage: CommutativeAlgebraIdeals(ZZ['x'])
Category of commutative algebra ideals in Univariate Polynomial Ring in x over Integer Ring
sage: CommutativeAlgebraIdeals(ZZ)
Traceback (most recent call last):
...
TypeError: A (=Integer Ring) must be a commutative algebra
sage: CommutativeAlgebraIdeals(IntegerModRing(4))
Traceback (most recent call last):
...
TypeError: A (=Ring of integers modulo 4) must be a commutative algebra
sage: CommutativeAlgebraIdeals(Partitions(4))
Traceback (most recent call last):
...
TypeError: A (=Partitions of the integer 4) must be a commutative algebra
TESTS::
sage: TestSuite(CommutativeAlgebraIdeals(QQ[x])).run()
"""
# TODO: replace by ``A in CommutativeAlgebras(*)`` once a
# suitable mantra has been implemented for this.
from sage.algebras.algebra import is_Algebra
from sage.rings.commutative_ring import is_CommutativeRing
if not (is_Algebra(A) and is_CommutativeRing(A)):
raise TypeError("A (=%s) must be a commutative algebra"%A)
Category_in_ambient.__init__(self, A)
示例3: __init__
def __init__(self, R, S=None):
"""
Construct the spectrum of the ring ``R``.
See :class:`Spec` for details.
EXAMPLES::
sage: Spec(ZZ)
Spectrum of Integer Ring
"""
if not is_CommutativeRing(R):
raise TypeError, "R (=%s) must be a commutative ring"%R
self.__R = R
if not S is None:
if not is_CommutativeRing(S):
raise TypeError, "S (=%s) must be a commutative ring"%S
try:
S.hom(R)
except TypeError:
raise ValueError, "There must be a natural map S --> R, but S = %s and R = %s"%(S,R)
AffineScheme.__init__(self, S)
示例4: canonical_parameters
def canonical_parameters(group, weight, sign, base_ring):
"""
Return the canonically normalized parameters associated to a choice
of group, weight, sign, and base_ring. That is, normalize each of
these to be of the correct type, perform all appropriate type
checking, etc.
EXAMPLES::
sage: p1 = sage.modular.modsym.modsym.canonical_parameters(5,int(2),1,QQ) ; p1
(Congruence Subgroup Gamma0(5), 2, 1, Rational Field)
sage: p2 = sage.modular.modsym.modsym.canonical_parameters(Gamma0(5),2,1,QQ) ; p2
(Congruence Subgroup Gamma0(5), 2, 1, Rational Field)
sage: p1 == p2
True
sage: type(p1[1])
<type 'sage.rings.integer.Integer'>
"""
sign = rings.Integer(sign)
if not (sign in [-1,0,1]):
raise ValueError, "sign must be -1, 0, or 1"
weight = rings.Integer(weight)
if weight <= 1:
raise ValueError, "the weight must be at least 2"
if isinstance(group, (int, rings.Integer)):
group = arithgroup.Gamma0(group)
elif isinstance(group, dirichlet.DirichletCharacter):
try:
eps = group.minimize_base_ring()
except NotImplementedError:
# TODO -- implement minimize_base_ring over finite fields
eps = group
G = eps.parent()
if eps.is_trivial():
group = arithgroup.Gamma0(eps.modulus())
else:
group = (eps, G)
if base_ring is None: base_ring = eps.base_ring()
if base_ring is None: base_ring = rational_field.RationalField()
if not is_CommutativeRing(base_ring):
raise TypeError, "base_ring (=%s) must be a commutative ring"%base_ring
if not base_ring.is_field():
raise TypeError, "(currently) base_ring (=%s) must be a field"%base_ring
return group, weight, sign, base_ring
示例5: __call__
def __call__(self, x):
"""
Call syntax for Spec.
INPUT/OUTPUT:
The argument ``x`` must be one of the following:
- a prime ideal of the coordinate ring; the output will
be the corresponding point of X
- an element (or list of elements) of the coordinate ring
which generates a prime ideal; the output will be the
corresponding point of X
- a ring or a scheme S; the output will be the set X(S) of
S-valued points on X
EXAMPLES::
sage: S = Spec(ZZ)
sage: P = S(3); P
Point on Spectrum of Integer Ring defined by the Principal ideal (3) of Integer Ring
sage: type(P)
<class 'sage.schemes.generic.point.SchemeTopologicalPoint_prime_ideal'>
sage: S(ZZ.ideal(next_prime(1000000)))
Point on Spectrum of Integer Ring defined by the Principal ideal (1000003) of Integer Ring
sage: R.<x, y, z> = QQ[]
sage: S = Spec(R)
sage: P = S(R.ideal(x, y, z)); P
Point on Spectrum of Multivariate Polynomial Ring
in x, y, z over Rational Field defined by the Ideal (x, y, z)
of Multivariate Polynomial Ring in x, y, z over Rational Field
This indicates the fix of :trac:`12734`::
sage: S = Spec(ZZ)
sage: S(ZZ)
Set of rational points of Spectrum of Integer Ring
sage: S(S)
Set of rational points of Spectrum of Integer Ring
"""
if is_CommutativeRing(x):
return self.point_homset(x)
from sage.schemes.all import is_Scheme
if is_Scheme(x):
return x.Hom(self)
return SchemeTopologicalPoint_prime_ideal(self, x)
示例6: __init__
def __init__(self, N, R = QQ, names = None):
r"""
The Python constructor
INPUT:
- ``N`` - a list or tuple of positive integers
- ``R`` - a ring
- ``names`` - a tuple or list of strings. This must either be a single variable name
or the complete list of variables.
EXAMPLES::
sage: T.<x,y,z,u,v,w> = ProductProjectiveSpaces([2,2],QQ)
sage: T
Product of projective spaces P^2 x P^2 over Rational Field
sage: T.coordinate_ring()
Multivariate Polynomial Ring in x, y, z, u, v, w over Rational Field
sage: T[1].coordinate_ring()
Multivariate Polynomial Ring in u, v, w over Rational Field
::
sage: ProductProjectiveSpaces([1,1,1],ZZ, ['x','y','z','u','v','w'])
Product of projective spaces P^1 x P^1 x P^1 over Integer Ring
::
sage: T = ProductProjectiveSpaces([1,1],QQ,'z')
sage: T.coordinate_ring()
Multivariate Polynomial Ring in z0, z1, z2, z3 over Rational Field
"""
assert isinstance(N, (tuple, list))
N = [Integer(n) for n in N]
assert is_CommutativeRing(R)
if len(N) < 2:
raise ValueError("Must be at least two components for a product")
AmbientSpace.__init__(self, sum(N), R)
self._dims = N
start = 0
self._components = []
for i in range(len(N)):
self._components.append(ProjectiveSpace(N[i],R,names[start:start+N[i]+1]))
start += N[i]+1
#Note that the coordinate ring should really be the tensor product of the component
#coordinate rings. But we just deal with them as multihomogeneous polynomial rings
self._coordinate_ring = PolynomialRing(R,sum(N)+ len(N),names)
示例7: __init__
def __init__(self, n, R=ZZ):
"""
TEST::
sage: from sage.schemes.generic.ambient_space import AmbientSpace
sage: A = AmbientSpace(5, ZZ)
sage: TestSuite(A).run() # not tested (abstract scheme with no elements?)
"""
if not is_CommutativeRing(R):
raise TypeError("R (=%s) must be a commutative ring"%R)
n = Integer(n)
if n < 0:
raise ValueError("n (=%s) must be nonnegative"%n)
self._dimension_relative = n
Scheme.__init__(self, R)
示例8: __init__
def __init__(self, X=None, category=None):
"""
Construct a scheme.
TESTS:
The full test suite works since :trac:`7946`::
sage: R.<x, y> = QQ[]
sage: I = (x^2 - y^2)*R
sage: RmodI = R.quotient(I)
sage: X = Spec(RmodI)
sage: TestSuite(X).run()
"""
from sage.schemes.generic.morphism import is_SchemeMorphism
if X is None:
self._base_ring = ZZ
elif is_Scheme(X):
self._base_scheme = X
elif is_SchemeMorphism(X):
self._base_morphism = X
elif is_CommutativeRing(X):
self._base_ring = X
elif is_RingHomomorphism(X):
self._base_ring = X.codomain()
else:
raise ValueError('The base must be define by a scheme, '
'scheme morphism, or commutative ring.')
from sage.categories.schemes import Schemes
if X is None:
default_category = Schemes()
else:
default_category = Schemes(self.base_scheme())
if category is None:
category = default_category
else:
assert category.is_subcategory(default_category), \
"%s is not a subcategory of %s"%(category, default_category)
Parent.__init__(self, self.base_ring(), category = category)
示例9: base_extend
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
"""
if is_CommutativeRing(R):
return Spec(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 Spec(self.coordinate_ring().base_extend(new_base.coordinate_ring()), self.base_ring())
示例10: base_extend
def base_extend(self, R):
"""
Return the natural extension of ``self`` over ``R``.
INPUT:
- ``R`` -- a commutative ring, such that there is a natural map from
the base ring of self to ``R``.
OUTPUT:
- an ambient space over ``R`` of the same structure as ``self``.
.. NOTE::
A ``ValueError`` is raised if there is no such natural map. If
you need to drop this condition, use ``self.change_ring(R)``.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: PQ = P.base_extend(QQ); PQ
Projective Space of dimension 2 over Rational Field
sage: PQ.base_extend(GF(5))
Traceback (most recent call last):
...
ValueError: no natural map from the base ring (=Rational Field)
to R (=Finite Field of size 5)!
"""
if is_CommutativeRing(R):
if self.base_ring() == R:
return self
if not R.has_coerce_map_from(self.base_ring()):
raise ValueError(
"no natural map from the base ring (=%s) to R (=%s)!"
% (self.base_ring(), R))
return self.change_ring(R)
else:
raise NotImplementedError(
"extension of spaces over %s to %s is not implemented!"
% (self.base_ring(), R))
示例11: __init__
def __init__(self, abvar, base):
"""
This is an abstract base class, so it is called implicitly in the
following examples.
EXAMPLES::
sage: H = J0(43).integral_homology()
sage: type(H)
<class 'sage.modular.abvar.homology.IntegralHomology_with_category'>
TESTS::
sage: H = J0(43).integral_homology()
sage: loads(dumps(H)) == H
True
"""
if not is_CommutativeRing(base):
raise TypeError, "base ring must be a commutative ring"
HeckeModule_free_module.__init__(
self, base, abvar.level(), weight=2)
self.__abvar = abvar
示例12: __call__
def __call__(self, *args):
"""
Call syntax for schemes.
INPUT/OUTPUT:
The arguments must be one of the following:
- a ring or a scheme `S`. Output will be the set `X(S)` of
`S`-valued points on `X`.
- If `S` is a list or tuple or just the coordinates, return a
point in `X(T)`, where `T` is the base scheme of self.
EXAMPLES::
sage: A = AffineSpace(2, QQ)
We create some point sets::
sage: A(QQ)
Set of rational points of Affine Space of dimension 2 over Rational Field
sage: A(RR)
Set of rational points of Affine Space of dimension 2 over Real Field
with 53 bits of precision
Space of dimension 2 over Rational Field::
sage: R.<x> = PolynomialRing(QQ)
sage: A(NumberField(x^2+1, 'a'))
Set of rational points of Affine Space of dimension 2 over Number Field
in a with defining polynomial x^2 + 1
sage: A(GF(7))
Traceback (most recent call last):
...
ValueError: There must be a natural map S --> R, but
S = Rational Field and R = Finite Field of size 7
We create some points::
sage: A(QQ)([1,0])
(1, 0)
We create the same point by giving the coordinates of the point
directly::
sage: A( 1,0 )
(1, 0)
"""
if len(args) == 0:
raise TypeError('You need to specify at least one argument.')
S = args[0]
if is_CommutativeRing(S):
return self.point_homset(S)
if is_Scheme(S):
return S.Hom(self)
from sage.schemes.generic.morphism import SchemeMorphism_point
if isinstance(S, (list, tuple)):
args = S
elif isinstance(S, SchemeMorphism_point):
if S.codomain() == self:
return S
else:
# TODO: fix circular import resulting from non-multiple inheritance
from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field
if isinstance(S, EllipticCurvePoint_field):
if S.codomain() == self:
return S
else:
return self.point(S)
return self.point(args)
示例13: _is_valid_homomorphism_
def _is_valid_homomorphism_(self, codomain, im_gens):
"""
Replacement for method of PowerSeriesRing_generic.
To be valid, a homomorphism must send generators to elements of
positive valuation or to nilpotent elements.
Note that the method is_nilpotent doesn't (as of sage 4.4) seem to
be defined for obvious examples (matrices, quotients of polynomial
rings).
EXAMPLES::
sage: R.<a,b,c> = PowerSeriesRing(Zmod(8)); R
Multivariate Power Series Ring in a, b, c over Ring of integers
modulo 8
sage: M = PowerSeriesRing(ZZ,3,'x,y,z');
sage: M._is_valid_homomorphism_(R,[a,c,b])
True
sage: M._is_valid_homomorphism_(R,[0,c,b])
True
2 is nilpotent in `ZZ/8`, but 3 is not::
sage: M._is_valid_homomorphism_(R,[2,c,b])
True
sage: M._is_valid_homomorphism_(R,[3,c,b])
False
Over `ZZ`, 2 is not nilpotent::
sage: S = R.change_ring(ZZ); S
Multivariate Power Series Ring in a, b, c over Integer Ring
sage: M._is_valid_homomorphism_(S,[a,c,b])
True
sage: M._is_valid_homomorphism_(S,[0,c,b])
True
sage: M._is_valid_homomorphism_(S,[2,c,b])
False
sage: g = [S.random_element(10)*v for v in S.gens()]
sage: M._is_valid_homomorphism_(S,g)
True
"""
try:
im_gens = [codomain(v) for v in im_gens]
except TypeError:
raise TypeError("The given generator images do not coerce to codomain.")
if len(im_gens) is not self.ngens():
raise ValueError("You must specify the image of each generator.")
if all(v == 0 for v in im_gens):
return True
if is_MPowerSeriesRing(codomain) or is_PowerSeriesRing(codomain):
try:
B = all(v.valuation() > 0 or v.is_nilpotent() for v in im_gens)
except NotImplementedError:
B = all(v.valuation() > 0 for v in im_gens)
return B
if is_CommutativeRing(codomain):
return all(v.is_nilpotent() for v in im_gens)
示例14: canonical_parameters
def canonical_parameters(group, level, weight, base_ring):
"""
Given a group, level, weight, and base_ring as input by the user,
return a canonicalized version of them, where level is a Sage
integer, group really is a group, weight is a Sage integer, and
base_ring a Sage ring. Note that we can't just get the level from
the group, because we have the convention that the character for
Gamma1(N) is None (which makes good sense).
INPUT:
- ``group`` - int, long, Sage integer, group,
dirichlet character, or
- ``level`` - int, long, Sage integer, or group
- ``weight`` - coercible to Sage integer
- ``base_ring`` - commutative Sage ring
OUTPUT:
- ``level`` - Sage integer
- ``group`` - congruence subgroup
- ``weight`` - Sage integer
- ``ring`` - commutative Sage ring
EXAMPLES::
sage: from sage.modular.modform.constructor import canonical_parameters
sage: v = canonical_parameters(5, 5, int(7), ZZ); v
(5, Congruence Subgroup Gamma0(5), 7, Integer Ring)
sage: type(v[0]), type(v[1]), type(v[2]), type(v[3])
(<type 'sage.rings.integer.Integer'>,
<class 'sage.modular.arithgroup.congroup_gamma0.Gamma0_class_with_category'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer_ring.IntegerRing_class'>)
sage: canonical_parameters( 5, 7, 7, ZZ )
Traceback (most recent call last):
...
ValueError: group and level do not match.
"""
weight = rings.Integer(weight)
if weight <= 0:
raise NotImplementedError, "weight must be at least 1"
if isinstance(group, dirichlet.DirichletCharacter):
if ( group.level() != rings.Integer(level) ):
raise ValueError, "group.level() and level do not match."
group = group.minimize_base_ring()
level = rings.Integer(level)
elif arithgroup.is_CongruenceSubgroup(group):
if ( rings.Integer(level) != group.level() ):
raise ValueError, "group.level() and level do not match."
# normalize the case of SL2Z
if arithgroup.is_SL2Z(group) or \
arithgroup.is_Gamma1(group) and group.level() == rings.Integer(1):
group = arithgroup.Gamma0(rings.Integer(1))
elif group is None:
pass
else:
try:
m = rings.Integer(group)
except TypeError:
raise TypeError, "group of unknown type."
level = rings.Integer(level)
if ( m != level ):
raise ValueError, "group and level do not match."
group = arithgroup.Gamma0(m)
if not is_CommutativeRing(base_ring):
raise TypeError, "base_ring (=%s) must be a commutative ring"%base_ring
# it is *very* important to include the level as part of the data
# that defines the key, since dirichlet characters of different
# levels can compare equal, but define much different modular
# forms spaces.
return level, group, weight, base_ring
示例15: __call__
def __call__(self, *args):
"""
Call syntax for schemes.
INPUT/OUTPUT:
The arguments must be one of the following:
- a ring or a scheme `S`. Output will be the set `X(S)` of
`S`-valued points on `X`.
- If `S` is a list or tuple or just the coordinates, return a
point in `X(T)`, where `T` is the base scheme of self.
EXAMPLES::
sage: A = AffineSpace(2, QQ)
We create some point sets::
sage: A(QQ)
Set of rational points of Affine Space of dimension 2 over Rational Field
sage: A(RR)
Set of rational points of Affine Space of dimension 2 over Real Field
with 53 bits of precision
Space of dimension 2 over Rational Field::
sage: R.<x> = PolynomialRing(QQ)
sage: A(NumberField(x^2+1, 'a'))
Set of rational points of Affine Space of dimension 2 over Number Field
in a with defining polynomial x^2 + 1
sage: A(GF(7))
Traceback (most recent call last):
...
ValueError: There must be a natural map S --> R, but
S = Rational Field and R = Finite Field of size 7
We create some points::
sage: A(QQ)([1, 0])
(1, 0)
We create the same point by giving the coordinates of the point
directly::
sage: A(1, 0)
(1, 0)
Check that :trac:`16832` is fixed::
sage: P.<x,y,z> = ProjectiveSpace(ZZ, 2)
sage: X=P.subscheme(x^2 - y^2)
sage: X(P([4, 4, 1]))
(4 : 4 : 1)
"""
if len(args) == 1:
from sage.schemes.generic.morphism import SchemeMorphism_point
S = args[0]
if is_CommutativeRing(S):
return self.point_homset(S)
elif is_Scheme(S):
return S.Hom(self)
elif isinstance(S, (list, tuple)):
args = S
elif isinstance(S, SchemeMorphism_point):
if S.codomain() is self:
return S
args = S
return self.point(args)