本文整理汇总了Python中sage.rings.polynomial.multi_polynomial_ring.is_MPolynomialRing函数的典型用法代码示例。如果您正苦于以下问题:Python is_MPolynomialRing函数的具体用法?Python is_MPolynomialRing怎么用?Python is_MPolynomialRing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_MPolynomialRing函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _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()])
开发者ID:saraedum,项目名称:sage-renamed,代码行数:58,代码来源:multi_power_series_ring.py
示例2: 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)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:56,代码来源:affine_space.py
示例3: PolynomialSequence
def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None):
"""
Construct a new polynomial sequence object.
INPUT:
- ``arg1`` - a multivariate polynomial ring, an ideal or a matrix
- ``arg2`` - an iterable object of parts or polynomials
(default:``None``)
- ``immutable`` - if ``True`` the sequence is immutable (default: ``False``)
- ``cr`` - print a line break after each element (default: ``False``)
- ``cr_str`` - print a line break after each element if 'str' is
called (default: ``None``)
EXAMPLES::
sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
sage: I = sage.rings.ideal.Katsura(P)
If a list of tuples is provided, those form the parts::
sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest
[a + 2*b + 2*c + 2*d - 1,
a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a,
2*a*b + 2*b*c + 2*c*d - b,
b^2 + 2*a*c + 2*b*d - c,
a + 2*b + 2*c + 2*d - 1,
a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a,
2*a*b + 2*b*c + 2*c*d - b,
b^2 + 2*a*c + 2*b*d - c]
sage: F.nparts()
2
If an ideal is provided, the generators are used::
sage: Sequence(I)
[a + 2*b + 2*c + 2*d - 1,
a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a,
2*a*b + 2*b*c + 2*c*d - b,
b^2 + 2*a*c + 2*b*d - c]
If a list of polynomials is provided, the system has only one
part::
sage: F = Sequence(I.gens(), I.ring()); F
[a + 2*b + 2*c + 2*d - 1,
a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a,
2*a*b + 2*b*c + 2*c*d - b,
b^2 + 2*a*c + 2*b*d - c]
sage: F.nparts()
1
"""
from sage.matrix.matrix import is_Matrix
if is_MPolynomialRing(arg1) or is_QuotientRing(arg1):
ring = arg1
gens = arg2
elif is_MPolynomialRing(arg2) or is_QuotientRing(arg2):
ring = arg2
gens = arg1
elif is_Matrix(arg1) and arg2 is None:
ring = arg1.base_ring()
gens = arg1.list()
elif isinstance(arg1, MPolynomialIdeal) and arg2 is None:
ring = arg1.ring()
gens = arg1.gens()
elif isinstance(arg1, (list,tuple,GeneratorType)) and arg2 is None:
gens = arg1
try:
e = iter(gens).next()
except StopIteration:
raise ValueError("Cannot determine ring from provided information.")
if is_MPolynomial(e) or isinstance(e, QuotientRingElement):
ring = e.parent()
else:
ring = iter(e).next().parent()
else:
raise TypeError("Cannot understand input.")
try:
e = iter(gens).next()
if is_MPolynomial(e) or isinstance(e, QuotientRingElement):
gens = tuple(gens)
parts = (gens,)
if not all(f.parent() is ring for f in gens):
parts = ((ring(f) for f in gens),)
else:
parts = []
#.........这里部分代码省略.........
开发者ID:NitikaAgarwal,项目名称:sage,代码行数:101,代码来源:multi_polynomial_sequence.py
示例4: Conic
#.........这里部分代码省略.........
base_field = None
if isinstance(F, (list,tuple)):
if len(F) == 1:
return Conic(base_field, F[0], names)
if names is None:
names = 'x,y,z'
if len(F) == 5:
L=[]
for f in F:
if isinstance(f, SchemeMorphism_point_affine):
C = Sequence(f, universe = base_field)
if len(C) != 2:
raise TypeError("points in F (=%s) must be planar"%F)
C.append(1)
elif isinstance(f, SchemeMorphism_point_projective_field):
C = Sequence(f, universe = base_field)
elif isinstance(f, (list, tuple)):
C = Sequence(f, universe = base_field)
if len(C) == 2:
C.append(1)
else:
raise TypeError("F (=%s) must be a sequence of planar " \
"points" % F)
if len(C) != 3:
raise TypeError("points in F (=%s) must be planar" % F)
P = C.universe()
if not isinstance(P, IntegralDomain):
raise TypeError("coordinates of points in F (=%s) must " \
"be in an integral domain" % F)
L.append(Sequence([C[0]**2, C[0]*C[1], C[0]*C[2], C[1]**2,
C[1]*C[2], C[2]**2], P.fraction_field()))
M=Matrix(L)
if unique and M.rank() != 5:
raise ValueError("points in F (=%s) do not define a unique " \
"conic" % F)
con = Conic(base_field, Sequence(M.right_kernel().gen()), names)
con.point(F[0])
return con
F = Sequence(F, universe = base_field)
base_field = F.universe().fraction_field()
temp_ring = PolynomialRing(base_field, 3, names)
(x,y,z) = temp_ring.gens()
if len(F) == 3:
return Conic(F[0]*x**2 + F[1]*y**2 + F[2]*z**2)
if len(F) == 6:
return Conic(F[0]*x**2 + F[1]*x*y + F[2]*x*z + F[3]*y**2 + \
F[4]*y*z + F[5]*z**2)
raise TypeError("F (=%s) must be a sequence of 3 or 6" \
"coefficients" % F)
if is_QuadraticForm(F):
F = F.matrix()
if is_Matrix(F) and F.is_square() and F.ncols() == 3:
if names is None:
names = 'x,y,z'
temp_ring = PolynomialRing(F.base_ring(), 3, names)
F = vector(temp_ring.gens()) * F * vector(temp_ring.gens())
if not is_MPolynomial(F):
raise TypeError("F (=%s) must be a three-variable polynomial or " \
"a sequence of points or coefficients" % F)
if F.total_degree() != 2:
raise TypeError("F (=%s) must have degree 2" % F)
if base_field is None:
base_field = F.base_ring()
if not isinstance(base_field, IntegralDomain):
raise ValueError("Base field (=%s) must be a field" % base_field)
base_field = base_field.fraction_field()
if names is None:
names = F.parent().variable_names()
pol_ring = PolynomialRing(base_field, 3, names)
if F.parent().ngens() == 2:
(x,y,z) = pol_ring.gens()
F = pol_ring(F(x/z,y/z)*z**2)
if F == 0:
raise ValueError("F must be nonzero over base field %s" % base_field)
if F.total_degree() != 2:
raise TypeError("F (=%s) must have degree 2 over base field %s" % \
(F, base_field))
if F.parent().ngens() == 3:
P2 = ProjectiveSpace(2, base_field, names)
if is_PrimeFiniteField(base_field):
return ProjectiveConic_prime_finite_field(P2, F)
if is_FiniteField(base_field):
return ProjectiveConic_finite_field(P2, F)
if is_RationalField(base_field):
return ProjectiveConic_rational_field(P2, F)
if is_NumberField(base_field):
return ProjectiveConic_number_field(P2, F)
if is_FractionField(base_field) and (is_PolynomialRing(base_field.ring()) or is_MPolynomialRing(base_field.ring())):
return ProjectiveConic_rational_function_field(P2, F)
return ProjectiveConic_field(P2, F)
raise TypeError("Number of variables of F (=%s) must be 2 or 3" % F)
开发者ID:drupel,项目名称:sage,代码行数:101,代码来源:constructor.py
示例5: chord_and_tangent
def chord_and_tangent(F, P):
"""
Use the chord and tangent method to get another point on a cubic.
INPUT:
- ``F`` -- a homogeneous cubic in three variables with rational
coefficients, as a polynomial ring element, defining a smooth
plane cubic curve.
- ``P`` -- a 3-tuple `(x,y,z)` defining a projective point on the
curve `F=0`.
OUTPUT:
Another point satisfying the equation ``F``.
EXAMPLES::
sage: R.<x,y,z> = QQ[]
sage: from sage.schemes.elliptic_curves.constructor import chord_and_tangent
sage: F = x^3+y^3+60*z^3
sage: chord_and_tangent(F, [1,-1,0])
[1, -1, 0]
sage: F = x^3+7*y^3+64*z^3
sage: p0 = [2,2,-1]
sage: p1 = chord_and_tangent(F, p0); p1
[-5, 3, -1]
sage: p2 = chord_and_tangent(F, p1); p2
[1265, -183, -314]
TESTS::
sage: F(p2)
0
sage: map(type, p2)
[<type 'sage.rings.rational.Rational'>,
<type 'sage.rings.rational.Rational'>,
<type 'sage.rings.rational.Rational'>]
See :trac:`16068`::
sage: F = x**3 - 4*x**2*y - 65*x*y**2 + 3*x*y*z - 76*y*z**2
sage: chord_and_tangent(F, [0, 1, 0])
[0, 0, -1]
"""
# check the input
R = F.parent()
if not is_MPolynomialRing(R):
raise TypeError('equation must be a polynomial')
if R.ngens() != 3:
raise TypeError('%s is not a polynomial in three variables'%F)
if not F.is_homogeneous():
raise TypeError('%s is not a homogeneous polynomial'%F)
x, y, z = R.gens()
if len(P) != 3:
raise TypeError('%s is not a projective point'%P)
K = R.base_ring()
try:
P = [K(c) for c in P]
except TypeError:
raise TypeError('cannot coerce %s into %s'%(P,K))
if F(P) != 0:
raise ValueError('%s is not a point on %s'%(P,F))
# find the tangent to F in P
dx = K(F.derivative(x)(P))
dy = K(F.derivative(y)(P))
dz = K(F.derivative(z)(P))
# if dF/dy(P) = 0, change variables so that dF/dy != 0
if dy == 0:
if dx != 0:
g = F.substitute({x:y, y:x})
Q = [P[1], P[0], P[2]]
R = chord_and_tangent(g, Q)
return [R[1], R[0], R[2]]
elif dz != 0:
g = F.substitute({y:z, z:y})
Q = [P[0], P[2], P[1]]
R = chord_and_tangent(g, Q)
return [R[0], R[2], R[1]]
else:
raise ValueError('%s is singular at %s'%(F, P))
# t will be our choice of parmeter of the tangent plane
# dx*(x-P[0]) + dy*(y-P[1]) + dz*(z-P[2])
# through the point P
t = rings.PolynomialRing(K, 't').gen(0)
Ft = F(dy*t+P[0], -dx*t+P[1], P[2])
if Ft == 0: # (dy, -dx, 0) is projectively equivalent to P
# then (0, -dz, dy) is not projectively equivalent to P
g = F.substitute({x:z, z:x})
Q = [P[2], P[1], P[0]]
R = chord_and_tangent(g, Q)
return [R[2], R[1], R[0]]
# Ft has a double zero at t=0 by construction, which we now remove
Ft = Ft // t**2
# first case: the third point is at t=infinity
#.........这里部分代码省略.........
开发者ID:Etn40ff,项目名称:sage,代码行数:101,代码来源:constructor.py
示例6: EllipticCurve_from_cubic
#.........这里部分代码省略.........
-4055/112896*a^2 - 4787/40320*a*b - 91/1280*b^2 - 7769/35280*a*c
- 1993/5040*b*c - 724/2205*c^2 :
1/4572288000*a^2 + 1/326592000*a*b + 1/93312000*b^2 + 1/142884000*a*c
+ 1/20412000*b*c + 1/17860500*c^2)
sage: finv = f.inverse(); finv
Scheme morphism:
From: Elliptic Curve defined by y^2 - 722*x*y - 21870000*y =
x^3 + 23579*x^2 over Rational Field
To: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
a^3 + 7*b^3 + 64*c^3
Defn: Defined on coordinates by sending (x : y : z) to
(2*x^2 + 227700*x*z - 900*y*z :
2*x^2 - 32940*x*z + 540*y*z :
-x^2 - 56520*x*z - 180*y*z)
sage: cubic(finv.defining_polynomials()) * finv.post_rescaling()
-x^3 - 23579*x^2*z - 722*x*y*z + y^2*z - 21870000*y*z^2
sage: E.defining_polynomial()(f.defining_polynomials()) * f.post_rescaling()
a^3 + 7*b^3 + 64*c^3
TESTS::
sage: R.<x,y,z> = QQ[]
sage: cubic = x^2*y + 4*x*y^2 + x^2*z + 8*x*y*z + 4*y^2*z + 9*x*z^2 + 9*y*z^2
sage: EllipticCurve_from_cubic(cubic, [1,-1,1], morphism=False)
Elliptic Curve defined by y^2 - 882*x*y - 2560000*y = x^3 - 127281*x^2 over Rational Field
"""
import sage.matrix.all as matrix
# check the input
R = F.parent()
if not is_MPolynomialRing(R):
raise TypeError('equation must be a polynomial')
if R.ngens() != 3:
raise TypeError('equation must be a polynomial in three variables')
if not F.is_homogeneous():
raise TypeError('equation must be a homogeneous polynomial')
K = F.parent().base_ring()
try:
P = [K(c) for c in P]
except TypeError:
raise TypeError('cannot convert %s into %s'%(P,K))
if F(P) != 0:
raise ValueError('%s is not a point on %s'%(P,F))
if len(P) != 3:
raise TypeError('%s is not a projective point'%P)
x, y, z = R.gens()
# First case: if P = P2 then P is a flex
P2 = chord_and_tangent(F, P)
if are_projectively_equivalent(P, P2, base_ring=K):
# find the tangent to F in P
dx = K(F.derivative(x)(P))
dy = K(F.derivative(y)(P))
dz = K(F.derivative(z)(P))
# find a second point Q on the tangent line but not on the cubic
for tangent in [[dy, -dx, K.zero()], [dz, K.zero(), -dx], [K.zero(), -dz, dx]]:
tangent = projective_point(tangent)
Q = [tangent[0]+P[0], tangent[1]+P[1], tangent[2]+P[2]]
F_Q = F(Q)
if F_Q != 0: # At most one further point may accidentally be on the cubic
break
assert F_Q != 0
# pick linearly independent third point
开发者ID:Etn40ff,项目名称:sage,代码行数:67,代码来源:constructor.py
示例7: Sequence
#.........这里部分代码省略.........
You can make a sequence with a new universe from an old sequence.::
sage: w = Sequence(v, QQ)
sage: w
[0, 2, 2, 3, 4, 5, 6, 7, 8, 9]
sage: w.universe()
Rational Field
sage: w[1] = 2/3
sage: w
[0, 2/3, 2, 3, 4, 5, 6, 7, 8, 9]
Sequences themselves live in a category, the category of all sequences
in the given universe.::
sage: w.category()
Category of sequences in Rational Field
This is also the parent of any sequence::
sage: w.parent()
Category of sequences in Rational Field
The default universe for any sequence, if no compatible parent structure
can be found, is the universe of all Sage objects.
This example illustrates how every element of a list is taken into account
when constructing a sequence.::
sage: v = Sequence([1,7,6,GF(5)(3)]); v
[1, 2, 1, 3]
sage: v.universe()
Finite Field of size 5
sage: v.parent()
Category of sequences in Finite Field of size 5
sage: v.parent()([7,8,9])
[2, 3, 4]
"""
from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
if isinstance(x, Sequence_generic) and universe is None:
universe = x.universe()
x = list(x)
if isinstance(x, MPolynomialIdeal) and universe is None:
universe = x.ring()
x = x.gens()
if universe is None:
if not isinstance(x, (list, tuple)):
x = list(x)
#raise TypeError("x must be a list or tuple")
if len(x) == 0:
import sage.categories.all
universe = sage.categories.all.Objects()
else:
import sage.structure.element as coerce
y = x
x = list(x) # make a copy, or we'd change the type of the elements of x, which would be bad.
if use_sage_types:
# convert any Python built-in numerical types to Sage objects
from sage.rings.integer_ring import ZZ
from sage.rings.real_double import RDF
from sage.rings.complex_double import CDF
for i in range(len(x)):
if isinstance(x[i], int) or isinstance(x[i], long):
x[i] = ZZ(x[i])
elif isinstance(x[i], float):
x[i] = RDF(x[i])
elif isinstance(x[i], complex):
x[i] = CDF(x[i])
# start the pairwise coercion
for i in range(len(x)-1):
try:
x[i], x[i+1] = coerce.canonical_coercion(x[i],x[i+1])
except TypeError:
import sage.categories.all
universe = sage.categories.all.Objects()
x = list(y)
check = False # no point
break
if universe is None: # no type errors raised.
universe = coerce.parent(x[len(x)-1])
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.quotient_ring import is_QuotientRing
from sage.rings.polynomial.pbori import BooleanMonomialMonoid
if is_MPolynomialRing(universe) or \
(is_QuotientRing(universe) and is_MPolynomialRing(universe.cover_ring())) or \
isinstance(universe, BooleanMonomialMonoid):
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
try:
return PolynomialSequence(x, universe, immutable=immutable, cr=cr, cr_str=cr_str)
except (TypeError,AttributeError):
return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)
else:
return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)
开发者ID:CETHop,项目名称:sage,代码行数:101,代码来源:sequence.py
示例8: _coerce_map_from_
def _coerce_map_from_(self, P):
"""
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 this ring
- any ring that coerces into the foreground polynomial ring of this ring
EXAMPLES::
sage: A = GF(17)[['x','y']]
sage: A.has_coerce_map_from(ZZ)
True
sage: A.has_coerce_map_from(ZZ['x'])
True
sage: A.has_coerce_map_from(ZZ['y','x'])
True
sage: A.has_coerce_map_from(ZZ[['x']])
True
sage: A.has_coerce_map_from(ZZ[['y','x']])
True
sage: A.has_coerce_map_from(ZZ['x','z'])
False
sage: A.has_coerce_map_from(GF(3)['x','y'])
False
sage: A.has_coerce_map_from(Frac(ZZ['y','x']))
False
TESTS::
sage: M = PowerSeriesRing(ZZ,3,'x,y,z');
sage: M._coerce_map_from_(M)
True
sage: M._coerce_map_from_(M.remove_var(x))
True
sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x))
True
sage: M._coerce_map_from_(PolynomialRing(ZZ,'x,z'))
True
sage: M._coerce_map_from_(PolynomialRing(ZZ,0,''))
True
sage: M._coerce_map_from_(ZZ)
True
sage: M._coerce_map_from_(Zmod(13))
False
sage: M._coerce_map_from_(PolynomialRing(ZZ,2,'x,t'))
False
sage: M._coerce_map_from_(PolynomialRing(Zmod(11),2,'x,y'))
False
sage: P = PolynomialRing(ZZ,3,'z')
sage: H = PowerSeriesRing(P,4,'f'); H
Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring
sage: H._coerce_map_from_(P)
True
sage: H._coerce_map_from_(P.remove_var(P.gen(1)))
True
sage: H._coerce_map_from_(PolynomialRing(ZZ,'z2,f0'))
True
"""
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 True
return self._poly_ring().has_coerce_map_from(P)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:74,代码来源:multi_power_series_ring.py
示例9: Curve
#.........这里部分代码省略.........
sage: X = C.intersection(D); X
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^3 + y^3 + z^3,
x^4 + y^4 + z^4
Note that the intersection has dimension `0`.
::
sage: X.dimension()
0
sage: I = X.defining_ideal(); I
Ideal (x^3 + y^3 + z^3, x^4 + y^4 + z^4) of Multivariate Polynomial Ring in x, y, z over Rational Field
EXAMPLE: In three variables, the defining equation must be
homogeneous.
If the parent polynomial ring is in three variables, then the
defining ideal must be homogeneous.
::
sage: x,y,z = QQ['x,y,z'].gens()
sage: Curve(x^2+y^2)
Projective Conic Curve over Rational Field defined by x^2 + y^2
sage: Curve(x^2+y^2+z)
Traceback (most recent call last):
...
TypeError: x^2 + y^2 + z is not a homogeneous polynomial!
The defining polynomial must always be nonzero::
sage: P1.<x,y> = ProjectiveSpace(1,GF(5))
sage: Curve(0*x)
Traceback (most recent call last):
...
ValueError: defining polynomial of curve must be nonzero
"""
if is_AlgebraicScheme(F):
return Curve(F.defining_polynomials())
if isinstance(F, (list, tuple)):
if len(F) == 1:
return Curve(F[0])
F = Sequence(F)
P = F.universe()
if not is_MPolynomialRing(P):
raise TypeError("universe of F must be a multivariate polynomial ring")
for f in F:
if not f.is_homogeneous():
A = AffineSpace(P.ngens(), P.base_ring())
A._coordinate_ring = P
return AffineSpaceCurve_generic(A, F)
A = ProjectiveSpace(P.ngens()-1, P.base_ring())
A._coordinate_ring = P
return ProjectiveSpaceCurve_generic(A, F)
if not is_MPolynomial(F):
raise TypeError("F (=%s) must be a multivariate polynomial"%F)
P = F.parent()
k = F.base_ring()
if F.parent().ngens() == 2:
if F == 0:
raise ValueError("defining polynomial of curve must be nonzero")
A2 = AffineSpace(2, P.base_ring())
A2._coordinate_ring = P
if is_FiniteField(k):
if k.is_prime_field():
return AffineCurve_prime_finite_field(A2, F)
else:
return AffineCurve_finite_field(A2, F)
else:
return AffineCurve_generic(A2, F)
elif F.parent().ngens() == 3:
if F == 0:
raise ValueError("defining polynomial of curve must be nonzero")
P2 = ProjectiveSpace(2, P.base_ring())
P2._coordinate_ring = P
if F.total_degree() == 2 and k.is_field():
return Conic(F)
if is_FiniteField(k):
if k.is_prime_field():
return ProjectiveCurve_prime_finite_field(P2, F)
else:
return ProjectiveCurve_finite_field(P2, F)
else:
return ProjectiveCurve_generic(P2, F)
else:
raise TypeError("Number of variables of F (=%s) must be 2 or 3"%F)
开发者ID:amitjamadagni,项目名称:sage,代码行数:101,代码来源:constructor.py
示例10: Curve
#.........这里部分代码省略.........
True
"""
if not A is None:
if not isinstance(F, (list, tuple)):
return Curve([F], A)
if not is_AmbientSpace(A):
raise TypeError("A (=%s) must be either an affine or projective space"%A)
if not all([f.parent() == A.coordinate_ring() for f in F]):
raise TypeError("F (=%s) must be a list or tuple of polynomials of the coordinate ring of " \
"A (=%s)"%(F, A))
n = A.dimension_relative()
if n < 2:
raise TypeError("A (=%s) must be either an affine or projective space of dimension > 1"%A)
# there is no dimension check when initializing a plane curve, so check here that F consists
# of a single nonconstant polynomial
if n == 2:
if len(F) != 1 or F[0] == 0 or not is_MPolynomial(F[0]):
raise TypeError("F (=%s) must consist of a single nonconstant polynomial to define a plane curve"%(F,))
if is_AffineSpace(A):
if n > 2:
return AffineCurve(A, F)
k = A.base_ring()
if is_FiniteField(k):
if k.is_prime_field():
return AffinePlaneCurve_prime_finite_field(A, F[0])
return AffinePlaneCurve_finite_field(A, F[0])
return AffinePlaneCurve(A, F[0])
elif is_ProjectiveSpace(A):
if not all([f.is_homogeneous() for f in F]):
raise TypeError("polynomials defining a curve in a projective space must be homogeneous")
if n > 2:
return ProjectiveCurve(A, F)
k = A.base_ring()
if is_FiniteField(k):
if k.is_prime_field():
return ProjectivePlaneCurve_prime_finite_field(A, F[0])
return ProjectivePlaneCurve_finite_field(A, F[0])
return ProjectivePlaneCurve(A, F[0])
if is_AlgebraicScheme(F):
return Curve(F.defining_polynomials(), F.ambient_space())
if isinstance(F, (list, tuple)):
if len(F) == 1:
return Curve(F[0])
F = Sequence(F)
P = F.universe()
if not is_MPolynomialRing(P):
raise TypeError("universe of F must be a multivariate polynomial ring")
for f in F:
if not f.is_homogeneous():
A = AffineSpace(P.ngens(), P.base_ring())
A._coordinate_ring = P
return AffineCurve(A, F)
A = ProjectiveSpace(P.ngens()-1, P.base_ring())
A._coordinate_ring = P
return ProjectiveCurve(A, F)
if not is_MPolynomial(F):
raise TypeError("F (=%s) must be a multivariate polynomial"%F)
P = F.parent()
k = F.base_ring()
if F.parent().ngens() == 2:
if F == 0:
raise ValueError("defining polynomial of curve must be nonzero")
A2 = AffineSpace(2, P.base_ring())
A2._coordinate_ring = P
if is_FiniteField(k):
if k.is_prime_field():
return AffinePlaneCurve_prime_finite_field(A2, F)
else:
return AffinePlaneCurve_finite_field(A2, F)
else:
return AffinePlaneCurve(A2, F)
elif F.parent().ngens() == 3:
if F == 0:
raise ValueError("defining polynomial of curve must be nonzero")
P2 = ProjectiveSpace(2, P.base_ring())
P2._coordinate_ring = P
if F.total_degree() == 2 and k.is_field():
return Conic(F)
if is_FiniteField(k):
if k.is_prime_field():
return ProjectivePlaneCurve_prime_finite_field(P2, F)
else:
return ProjectivePlaneCurve_finite_field(P2, F)
else:
return ProjectivePlaneCurve(P2, F)
else:
raise TypeError("Number of variables of F (=%s) must be 2 or 3"%F)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:101,代码来源:constructor.py
示例11: ProjectiveSpace
def ProjectiveSpace(n, R=None, names='x'):
r"""
Return projective space of dimension `n` over the ring `R`.
EXAMPLES: The dimension and ring can be given in either order.
::
sage: ProjectiveSpace(3, QQ)
Projective Space of dimension 3 over Rational Field
sage: ProjectiveSpace(5, QQ)
Projective Space of dimension 5 over Rational Field
sage: P = ProjectiveSpace(2, QQ, names='XYZ'); P
Projective Space of dimension 2 over Rational Field
sage: P.coordinate_ring()
Multivariate Polynomial Ring in X, Y, Z over Rational Field
The divide operator does base extension.
::
sage: ProjectiveSpace(5)/GF(17)
Projective Space of dimension 5 over Finite Field of size 17
The default base ring is `\ZZ`.
::
sage: ProjectiveSpace(5)
Projective Space of dimension 5 over Integer Ring
There is also an projective space associated each polynomial ring.
::
sage: R = GF(7)['x,y,z']
sage: P = ProjectiveSpace(R); P
Projective Space of dimension 2 over Finite Field of size 7
sage: P.coordinate_ring()
Multivariate Polynomial Ring in x, y, z over Finite Field of size 7
sage: P.coordinate_ring() is R
True
::
sage: ProjectiveSpace(3, Zp(5), 'y')
Projective Space of dimension 3 over 5-adic Ring with capped relative precision 20
::
sage: ProjectiveSpace(2,QQ,'x,y,z')
Projective Space of dimension 2 over Rational Field
::
sage: PS.<x,y>=ProjectiveSpace(1,CC)
sage: PS
Projective Space of dimension 1 over Complex Field with 53 bits of precision
Projective spaces are not cached, i.e., there can be several with
the same base ring and dimension (to facilitate gluing
constructions).
"""
if is_MPolynomialRing(n) and R is None:
A = ProjectiveSpace(n.ngens()-1, n.base_ring())
A._coordinate_ring = n
return A
if isinstance(R, (int, long, Integer)):
n, R = R, n
if R is None:
R = ZZ # default is the integers
if R in _Fields:
if is_FiniteField(R):
return ProjectiveSpace_finite_field(n, R, names)
if is_RationalField(R):
return ProjectiveSpace_rational_field(n, R, names)
else:
return ProjectiveSpace_field(n, R, names)
elif is_CommutativeRing(R):
return ProjectiveSpace_ring(n, R, names)
else:
raise TypeError("R (=%s) must be a commutative ring"%R)
开发者ID:aaditya-thakkar,项目名称:sage,代码行数:82,代码来源:projective_space.py
示例12: __classcall_private__
def __classcall_private__(cls, morphism_or_polys, domain=None):
r"""
Return the appropriate dynamical system on an affine scheme.
TESTS::
sage: A.<x> = AffineSpace(ZZ,1)
sage: A1.<z> = AffineSpace(CC,1)
sage: H = End(A1)
sage: f2 = H([z^2+1])
sage: f = DynamicalSystem_affine(f2, A)
sage: f.domain() is A
False
::
sage: P1.<x,y> = ProjectiveSpace(QQ,1)
sage: DynamicalSystem_affine([y, 2*x], domain=P1)
Traceback (most recent call last):
...
ValueError: "domain" must be an affine scheme
sage: H = End(P1)
sage: DynamicalSystem_affine(H([y, 2*x]))
Traceback (most recent call last):
...
ValueError: "domain" must be an affine scheme
"""
if isinstance(morphism_or_polys, SchemeMorphism_polynomial):
morphism = morphism_or_polys
R = morphism.base_ring()
polys = list(morphism)
domain = morphism.domain()
if not is_AffineSpace(domain) and not isinstance(domain, AlgebraicScheme_subscheme_affine):
raise ValueError('"domain" must be an affine scheme')
if domain != morphism_or_polys.codomain():
raise ValueError('domain and codomain do not agree')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)
elif isinstance(morphism_or_polys,(list, tuple)):
polys = list(morphism_or_polys)
else:
polys = [morphism_or_polys]
# We now arrange for all of our list entries to lie in the same ring
# Fraction field case first
fraction_field = False
for poly in polys:
P = poly.parent()
if is_FractionField(P):
fraction_field = True
break
if fraction_field:
K = P.base_ring().fraction_field()
# Replace base ring with its fraction field
P = P.ring().change_ring(K).fraction_field()
polys = [P(poly) for poly in polys]
else:
# If any of the list entries lies in a quotient ring, we try
# to lift all entries to a common polynomial ring.
quotient_ring = False
for poly in polys:
P = poly.parent()
if is_QuotientRing(P):
quotient_ring = True
break
if quotient_ring:
polys = [P(poly).lift() for poly in polys]
else:
poly_ring = False
for poly in polys:
P = poly.parent()
if is_PolynomialRing(P) or is_MPolynomialRing(P):
poly_ring = True
break
if poly_ring:
polys = [P(poly) for poly in polys]
if domain is None:
f = polys[0]
CR = f.parent()
if CR is SR:
raise TypeError("Symbolic Ring cannot be the base ring")
if fraction_field:
CR = CR.ring()
domain = AffineSpace(CR)
R = domain.base_ring()
if R is SR:
raise TypeError("Symbolic Ring cannot be the base ring")
if not is_AffineSpace(domain) and not isinstance(domain, AlgebraicScheme_subscheme_affine):
raise ValueError('"domain" must be an affine scheme')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)
开发者ID:saraedum,项目名称:sage-renamed,代码行数:100,代码来源:affine_ds.py
注:本文中的sage.rings.polynomial.multi_polynomial_ring.is_MPolynomialRing函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论