def rational_points(self, F=None):
"""
Return the list of `F`-rational points on the affine space self,
where `F` is a given finite field, or the base ring of self.
EXAMPLES::
sage: A = AffineSpace(1, GF(3))
sage: A.rational_points()
[(0), (1), (2)]
sage: A.rational_points(GF(3^2, 'b'))
[(0), (b), (b + 1), (2*b + 1), (2), (2*b), (2*b + 2), (b + 2), (1)]
sage: AffineSpace(2, ZZ).rational_points(GF(2))
[(0, 0), (1, 0), (0, 1), (1, 1)]
TESTS::
sage: AffineSpace(2, QQ).rational_points()
Traceback (most recent call last):
...
TypeError: Base ring (= Rational Field) must be a finite field.
sage: AffineSpace(1, GF(3)).rational_points(ZZ)
Traceback (most recent call last):
...
TypeError: Second argument (= Integer Ring) must be a finite field.
"""
if F is None:
if not is_FiniteField(self.base_ring()):
raise TypeError("Base ring (= %s) must be a finite field."%self.base_ring())
return [ P for P in self ]
elif not is_FiniteField(F):
raise TypeError("Second argument (= %s) must be a finite field."%F)
return [ P for P in self.base_extend(F) ]
def points(self, B=0):
"""
Return some or all rational points of a projective scheme.
INPUT:
- `B` -- integer (optional, default=0). The bound for the
coordinates.
OUTPUT:
A list of points. Over a finite field, all points are
returned. Over an infinite field, all points satisfying the
bound are returned.
EXAMPLES::
sage: P1 = ProjectiveSpace(GF(2),1)
sage: F.<a> = GF(4,'a')
sage: P1(F).points()
[(0 : 1), (1 : 0), (1 : 1), (a : 1), (a + 1 : 1)]
"""
from sage.schemes.projective.projective_rational_point import enum_projective_rational_field
from sage.schemes.projective.projective_rational_point import enum_projective_finite_field
R = self.value_ring()
if is_RationalField(R):
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
return enum_projective_rational_field(self,B)
elif is_FiniteField(R):
return enum_projective_finite_field(self.extended_codomain())
else:
raise TypeError("Unable to enumerate points over %s."%R)
def __init__(self, degree, base_ring, category=None):
"""
Base class for matrix groups over generic base rings
You should not use this class directly. Instead, use one of
the more specialized derived classes.
INPUT:
- ``degree`` -- integer. The degree (matrix size) of the
matrix group.
- ``base_ring`` -- ring. The base ring of the matrices.
TESTS::
sage: G = GL(2, QQ)
sage: from sage.groups.matrix_gps.matrix_group import MatrixGroup_generic
sage: isinstance(G, MatrixGroup_generic)
True
"""
assert is_Ring(base_ring)
assert is_Integer(degree)
self._deg = degree
if self._deg <= 0:
raise ValueError('the degree must be at least 1')
if (category is None) and is_FiniteField(base_ring):
from sage.categories.finite_groups import FiniteGroups
category = FiniteGroups()
super(MatrixGroup_generic, self).__init__(base=base_ring, category=category)
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) 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, (int, long, 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)
def points(self, B=0):
r"""
Return some or all rational points of an affine scheme.
INPUT:
- ``B`` -- integer (optional, default: 0). The bound for the
height of the coordinates.
OUTPUT:
- If the base ring is a finite field: all points of the scheme,
given by coordinate tuples.
- If the base ring is `\QQ` or `\ZZ`: the subset of points whose
coordinates have height ``B`` or less.
EXAMPLES: The bug reported at #11526 is fixed::
sage: A2 = AffineSpace(ZZ,2)
sage: F = GF(3)
sage: A2(F).points()
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
sage: R = ZZ
sage: A.<x,y> = R[]
sage: I = A.ideal(x^2-y^2-1)
sage: V = AffineSpace(R,2)
sage: X = V.subscheme(I)
sage: M = X(R)
sage: M.points(1)
[(-1, 0), (1, 0)]
::
sage: u = QQ['u'].0
sage: K.<v> = NumberField(u^2 + 3)
sage: A.<x,y> = AffineSpace(K,2)
sage: len(A(K).points(9))
361
"""
R = self.value_ring()
if is_RationalField(R) or R == ZZ:
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
from sage.schemes.affine.affine_rational_point import enum_affine_rational_field
return enum_affine_rational_field(self,B)
if R in NumberFields():
from sage.schemes.affine.affine_rational_point import enum_affine_number_field
return enum_affine_number_field(self,B)
elif is_FiniteField(R):
from sage.schemes.affine.affine_rational_point import enum_affine_finite_field
return enum_affine_finite_field(self)
else:
raise TypeError("Unable to enumerate points over %s."%R)
def _single_variate(base_ring, name, sparse, implementation):
import sage.rings.polynomial.polynomial_ring as m
name = normalize_names(1, name)
key = (base_ring, name, sparse, implementation if not sparse else None)
R = _get_from_cache(key)
if not R is None:
return R
if isinstance(base_ring, ring.CommutativeRing):
if is_IntegerModRing(base_ring) and not sparse:
n = base_ring.order()
if n.is_prime():
R = m.PolynomialRing_dense_mod_p(base_ring, name, implementation=implementation)
elif n > 1:
R = m.PolynomialRing_dense_mod_n(base_ring, name, implementation=implementation)
else: # n == 1!
R = m.PolynomialRing_integral_domain(base_ring, name) # specialized code breaks in this case.
elif is_FiniteField(base_ring) and not sparse:
R = m.PolynomialRing_dense_finite_field(base_ring, name, implementation=implementation)
elif isinstance(base_ring, padic_base_leaves.pAdicFieldCappedRelative):
R = m.PolynomialRing_dense_padic_field_capped_relative(base_ring, name)
elif isinstance(base_ring, padic_base_leaves.pAdicRingCappedRelative):
R = m.PolynomialRing_dense_padic_ring_capped_relative(base_ring, name)
elif isinstance(base_ring, padic_base_leaves.pAdicRingCappedAbsolute):
R = m.PolynomialRing_dense_padic_ring_capped_absolute(base_ring, name)
elif isinstance(base_ring, padic_base_leaves.pAdicRingFixedMod):
R = m.PolynomialRing_dense_padic_ring_fixed_mod(base_ring, name)
elif base_ring.is_field(proof=False):
R = m.PolynomialRing_field(base_ring, name, sparse)
elif base_ring.is_integral_domain(proof=False):
R = m.PolynomialRing_integral_domain(base_ring, name, sparse, implementation)
else:
R = m.PolynomialRing_commutative(base_ring, name, sparse)
else:
R = m.PolynomialRing_general(base_ring, name, sparse)
if hasattr(R, "_implementation_names"):
for name in R._implementation_names:
real_key = key[0:3] + (name,)
_save_in_cache(real_key, R)
else:
_save_in_cache(key, R)
return R
def rational_points(self, F=None):
"""
Return the list of `F`-rational points on the affine space self,
where `F` is a given finite field, or the base ring of self.
EXAMPLES::
sage: P = ProjectiveSpace(1, GF(3))
sage: P.rational_points()
[(0 : 1), (1 : 1), (2 : 1), (1 : 0)]
sage: P.rational_points(GF(3^2, 'b'))
[(0 : 1), (b : 1), (b + 1 : 1), (2*b + 1 : 1), (2 : 1), (2*b : 1), (2*b + 2 : 1), (b + 2 : 1), (1 : 1), (1 : 0)]
"""
if F is None:
return [ P for P in self ]
elif not is_FiniteField(F):
raise TypeError("Second argument (= %s) must be a finite field."%F)
return [ P for P in self.base_extend(F) ]
def create_object(self, version, key, **kwds):
"""
Create an object from a ``UniqueFactory`` key.
EXAMPLES::
sage: E = EllipticCurve.create_object(0, (GF(3), (1, 2, 0, 1, 2)))
sage: type(E)
<class 'sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category'>
.. NOTE::
Keyword arguments are currently only passed to the
constructor for elliptic curves over `\\QQ`; elliptic
curves over other fields do not support them.
"""
R, x = key
if R is rings.QQ:
from ell_rational_field import EllipticCurve_rational_field
return EllipticCurve_rational_field(x, **kwds)
elif is_NumberField(R):
from ell_number_field import EllipticCurve_number_field
return EllipticCurve_number_field(R, x)
elif rings.is_pAdicField(R):
from ell_padic_field import EllipticCurve_padic_field
return EllipticCurve_padic_field(R, x)
elif is_FiniteField(R) or (is_IntegerModRing(R) and R.characteristic().is_prime()):
from ell_finite_field import EllipticCurve_finite_field
return EllipticCurve_finite_field(R, x)
elif R in _Fields:
from ell_field import EllipticCurve_field
return EllipticCurve_field(R, x)
from ell_generic import EllipticCurve_generic
return EllipticCurve_generic(R, x)
def points(self, B=0):
r"""
Return some or all rational points of an affine scheme.
INPUT:
- ``B`` -- integer (optional, default: 0). The bound for the
height of the coordinates.
OUTPUT:
- If the base ring is a finite field: all points of the scheme,
given by coordinate tuples.
- If the base ring is `\QQ` or `\ZZ`: the subset of points whose
coordinates have height ``B`` or less.
EXAMPLES: The bug reported at #11526 is fixed::
sage: A2 = AffineSpace(ZZ,2)
sage: F = GF(3)
sage: A2(F).points()
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
sage: R = ZZ
sage: A.<x,y> = R[]
sage: I = A.ideal(x^2-y^2-1)
sage: V = AffineSpace(R,2)
sage: X = V.subscheme(I)
sage: M = X(R)
sage: M.points(1)
[(-1, 0), (1, 0)]
::
sage: u = QQ['u'].0
sage: K.<v> = NumberField(u^2 + 3)
sage: A.<x,y> = AffineSpace(K,2)
sage: len(A(K).points(9))
361
::
sage: A.<x,y> = AffineSpace(QQ,2)
sage: E = A.subscheme([x^2 + y^2 - 1, y^2 - x^3 + x^2 + x - 1])
sage: E(A.base_ring()).points()
[(-1, 0), (0, -1), (0, 1), (1, 0)]
"""
X = self.codomain()
from sage.schemes.affine.affine_space import is_AffineSpace
if not is_AffineSpace(X) and X.base_ring() in Fields():
# Then X must be a subscheme
dim_ideal = X.defining_ideal().dimension()
if dim_ideal < 0: # no points
return []
if dim_ideal == 0: # if X zero-dimensional
N = len(X.ambient_space().gens())
S = X.defining_polynomials()[0].parent()
R = PolynomialRing(S.base_ring(),'s',N,order='lex')
phi = S.hom(R.gens(),R)
J = R.ideal([phi(t) for t in X.defining_polynomials()])
D = J.variety()
points = []
for d in D:
P = [d[t] for t in R.gens()]
points.append(X(P))
points.sort()
return points
R = self.value_ring()
if is_RationalField(R) or R == ZZ:
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
from sage.schemes.affine.affine_rational_point import enum_affine_rational_field
return enum_affine_rational_field(self,B)
if R in NumberFields():
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
from sage.schemes.affine.affine_rational_point import enum_affine_number_field
return enum_affine_number_field(self,B)
elif is_FiniteField(R):
from sage.schemes.affine.affine_rational_point import enum_affine_finite_field
return enum_affine_finite_field(self)
else:
raise TypeError("Unable to enumerate points over %s."%R)
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)
def points(self, B=0, prec=53):
"""
Return some or all rational points of a projective scheme.
INPUT:
- `B` - integer (optional, default=0). The bound for the
coordinates.
- ``prec`` - he precision to use to compute the elements of bounded height for number fields
OUTPUT:
A list of points. Over a finite field, all points are
returned. Over an infinite field, all points satisfying the
bound are returned.
.. WARNING::
In the current implementation, the output of the [Doyle-Krumm] algorithm
cannot be guaranteed to be correct due to the necessity of floating point
computations. In some cases, the default 53-bit precision is
considerably lower than would be required for the algorithm to
generate correct output.
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: P(QQ).points(4)
[(-4 : 1), (-3 : 1), (-2 : 1), (-3/2 : 1), (-4/3 : 1), (-1 : 1),
(-3/4 : 1), (-2/3 : 1), (-1/2 : 1), (-1/3 : 1), (-1/4 : 1), (0 : 1),
(1/4 : 1), (1/3 : 1), (1/2 : 1), (2/3 : 1), (3/4 : 1), (1 : 0), (1 : 1),
(4/3 : 1), (3/2 : 1), (2 : 1), (3 : 1), (4 : 1)]
::
sage: u = QQ['u'].0
sage: K.<v> = NumberField(u^2 + 3)
sage: P.<x,y,z> = ProjectiveSpace(K,2)
sage: len(P(K).points(1.8))
381
::
sage: P1 = ProjectiveSpace(GF(2),1)
sage: F.<a> = GF(4,'a')
sage: P1(F).points()
[(0 : 1), (1 : 0), (1 : 1), (a : 1), (a + 1 : 1)]
::
sage: P.<x,y,z> = ProjectiveSpace(QQ,2)
sage: E = P.subscheme([(y^3-y*z^2) - (x^3-x*z^2),(y^3-y*z^2) + (x^3-x*z^2)])
sage: E(P.base_ring()).points()
[(-1 : -1 : 1), (-1 : 0 : 1), (-1 : 1 : 1), (0 : -1 : 1), (0 : 0 : 1), (0 : 1 : 1),
(1 : -1 : 1), (1 : 0 : 1), (1 : 1 : 1)]
"""
X = self.codomain()
from sage.schemes.projective.projective_space import is_ProjectiveSpace
if not is_ProjectiveSpace(X) and X.base_ring() in Fields():
#Then it must be a subscheme
dim_ideal = X.defining_ideal().dimension()
if dim_ideal < 1: # no points
return []
if dim_ideal == 1: # if X zero-dimensional
points = set()
for i in range(X.ambient_space().dimension_relative() + 1):
Y = X.affine_patch(i)
phi = Y.projective_embedding()
aff_points = Y.rational_points()
for PP in aff_points:
points.add(X.ambient_space()(list(phi(PP))))
points = sorted(points)
return points
R = self.value_ring()
if is_RationalField(R):
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
from sage.schemes.projective.projective_rational_point import enum_projective_rational_field
return enum_projective_rational_field(self,B)
elif R in NumberFields():
if not B > 0:
raise TypeError("A positive bound B (= %s) must be specified."%B)
from sage.schemes.projective.projective_rational_point import enum_projective_number_field
return enum_projective_number_field(self,B, prec=prec)
elif is_FiniteField(R):
from sage.schemes.projective.projective_rational_point import enum_projective_finite_field
return enum_projective_finite_field(self.extended_codomain())
else:
raise TypeError("Unable to enumerate points over %s."%R)
#.........这里部分代码省略.........
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)
#.........这里部分代码省略.........
sage: SR in Fields()
True
sage: F = FractionField(PolynomialRing(QQ,'t'))
sage: t = F.gen()
sage: E = EllipticCurve([t,0]); E
Elliptic Curve defined by y^2 = x^3 + t*x over Fraction Field of Univariate Polynomial Ring in t over Rational Field
sage: type(E)
<class 'sage.schemes.elliptic_curves.ell_field.EllipticCurve_field_with_category'>
sage: E.category()
Category of schemes over Fraction Field of Univariate Polynomial Ring in t over Rational Field
See :trac:`12517`::
sage: E = EllipticCurve([1..5])
sage: EllipticCurve(E.a_invariants())
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field
See :trac:`11773`::
sage: E = EllipticCurve()
Traceback (most recent call last):
...
TypeError: invalid input to EllipticCurve constructor
"""
import ell_generic, ell_field, ell_finite_field, ell_number_field, ell_rational_field, ell_padic_field # here to avoid circular includes
if j is not None:
if not x is None:
if is_Ring(x):
try:
j = x(j)
except (ZeroDivisionError, ValueError, TypeError):
raise ValueError, "First parameter must be a ring containing %s"%j
else:
raise ValueError, "First parameter (if present) must be a ring when j is specified"
return EllipticCurve_from_j(j, minimal_twist)
if x is None:
raise TypeError, "invalid input to EllipticCurve constructor"
if is_SymbolicEquation(x):
x = x.lhs() - x.rhs()
if parent(x) is SR:
x = x._polynomial_(rings.QQ['x', 'y'])
if is_MPolynomial(x):
if y is None:
return EllipticCurve_from_Weierstrass_polynomial(x)
else:
return EllipticCurve_from_cubic(x, y, morphism=False)
if is_Ring(x):
if is_RationalField(x):
return ell_rational_field.EllipticCurve_rational_field(x, y)
elif is_FiniteField(x) or (is_IntegerModRing(x) and x.characteristic().is_prime()):
return ell_finite_field.EllipticCurve_finite_field(x, y)
elif rings.is_pAdicField(x):
return ell_padic_field.EllipticCurve_padic_field(x, y)
elif is_NumberField(x):
return ell_number_field.EllipticCurve_number_field(x, y)
elif x in _Fields:
return ell_field.EllipticCurve_field(x, y)
return ell_generic.EllipticCurve_generic(x, y)
if isinstance(x, unicode):
x = str(x)
if isinstance(x, basestring):
return ell_rational_field.EllipticCurve_rational_field(x)
if is_RingElement(x) and y is None:
raise TypeError, "invalid input to EllipticCurve constructor"
if not isinstance(x, (list, tuple)):
raise TypeError, "invalid input to EllipticCurve constructor"
x = Sequence(x)
if not (len(x) in [2,5]):
raise ValueError, "sequence of coefficients must have length 2 or 5"
R = x.universe()
if isinstance(x[0], (rings.Rational, rings.Integer, int, long)):
return ell_rational_field.EllipticCurve_rational_field(x, y)
elif is_NumberField(R):
return ell_number_field.EllipticCurve_number_field(x, y)
elif rings.is_pAdicField(R):
return ell_padic_field.EllipticCurve_padic_field(x, y)
elif is_FiniteField(R) or (is_IntegerModRing(R) and R.characteristic().is_prime()):
return ell_finite_field.EllipticCurve_finite_field(x, y)
elif R in _Fields:
return ell_field.EllipticCurve_field(x, y)
return ell_generic.EllipticCurve_generic(x, y)
#.........这里部分代码省略.........
Traceback (most recent call last):
...
ValueError: Not a hyperelliptic curve: highly singular at infinity.
sage: HyperellipticCurve(F)
Hyperelliptic Curve over Rational Field defined by y^2 = x^6 + 1
An example with a singularity over an inseparable extension of the
base field::
sage: F.<t> = GF(5)[]
sage: P.<x> = F[]
sage: HyperellipticCurve(x^5+t)
Traceback (most recent call last):
...
ValueError: Not a hyperelliptic curve: singularity in the provided affine patch.
Input with integer coefficients creates objects with the integers
as base ring, but only checks smoothness over `\QQ`, not over Spec(`\ZZ`).
In other words, it is checked that the discriminant is non-zero, but it is
not checked whether the discriminant is a unit in `\ZZ^*`.::
sage: P.<x> = ZZ[]
sage: HyperellipticCurve(3*x^7+6*x+6)
Hyperelliptic Curve over Integer Ring defined by y^2 = 3*x^7 + 6*x + 6
"""
if (not is_Polynomial(f)) or f == 0:
raise TypeError, "Arguments f (=%s) and h (= %s) must be polynomials " \
"and f must be non-zero" % (f,h)
P = f.parent()
if h is None:
h = P(0)
try:
h = P(h)
except TypeError:
raise TypeError, \
"Arguments f (=%s) and h (= %s) must be polynomials in the same ring"%(f,h)
df = f.degree()
dh_2 = 2*h.degree()
if dh_2 < df:
g = (df-1)//2
else:
g = (dh_2-1)//2
if check_squarefree:
# Assuming we are working over a field, this checks that after
# resolving the singularity at infinity, we get a smooth double cover
# of P^1.
if P(2) == 0:
# characteristic 2
if h == 0:
raise ValueError, \
"In characteristic 2, argument h (= %s) must be non-zero."%h
if h[g+1] == 0 and f[2*g+1]**2 == f[2*g+2]*h[g]**2:
raise ValueError, "Not a hyperelliptic curve: " \
"highly singular at infinity."
should_be_coprime = [h, f*h.derivative()**2+f.derivative()**2]
else:
# characteristic not 2
F = f + h**2/4
if not F.degree() in [2*g+1, 2*g+2]:
raise ValueError, "Not a hyperelliptic curve: " \
"highly singular at infinity."
should_be_coprime = [F, F.derivative()]
try:
smooth = should_be_coprime[0].gcd(should_be_coprime[1]).degree()==0
except (AttributeError, NotImplementedError, TypeError):
try:
smooth = should_be_coprime[0].resultant(should_be_coprime[1])!=0
except (AttributeError, NotImplementedError, TypeError):
raise NotImplementedError, "Cannot determine whether " \
"polynomials %s have a common root. Use " \
"check_squarefree=False to skip this check." % \
should_be_coprime
if not smooth:
raise ValueError, "Not a hyperelliptic curve: " \
"singularity in the provided affine patch."
R = P.base_ring()
PP = ProjectiveSpace(2, R)
if names is None:
names = ["x","y"]
if is_FiniteField(R):
if g == 2:
return HyperellipticCurve_g2_finite_field(PP, f, h, names=names, genus=g)
else:
return HyperellipticCurve_finite_field(PP, f, h, names=names, genus=g)
elif is_RationalField(R):
if g == 2:
return HyperellipticCurve_g2_rational_field(PP, f, h, names=names, genus=g)
else:
return HyperellipticCurve_rational_field(PP, f, h, names=names, genus=g)
elif is_pAdicField(R):
if g == 2:
return HyperellipticCurve_g2_padic_field(PP, f, h, names=names, genus=g)
else:
return HyperellipticCurve_padic_field(PP, f, h, names=names, genus=g)
else:
if g == 2:
return HyperellipticCurve_g2_generic(PP, f, h, names=names, genus=g)
else:
return HyperellipticCurve_generic(PP, f, h, names=names, genus=g)
def MatrixGroup(gens):
r"""
Return the matrix group with given generators.
INPUT:
- ``gens`` - list of matrices in a matrix space or
matrix group
EXAMPLES::
sage: F = GF(5)
sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])]
sage: G = MatrixGroup(gens); G
Matrix group over Finite Field of size 5 with 2 generators:
[[[1, 2], [4, 1]], [[1, 1], [0, 1]]]
In the second example, the generators are a matrix over
`\ZZ`, a matrix over a finite field, and the integer
`2`. Sage determines that they both canonically map to
matrices over the finite field, so creates that matrix group
there.
::
sage: gens = [matrix(2,[1,2, -1, 1]), matrix(GF(7), 2, [1,1, 0,1]), 2]
sage: G = MatrixGroup(gens); G
Matrix group over Finite Field of size 7 with 3 generators:
[[[1, 2], [6, 1]], [[1, 1], [0, 1]], [[2, 0], [0, 2]]]
Each generator must be invertible::
sage: G = MatrixGroup([matrix(ZZ,2,[1,2,3,4])])
Traceback (most recent call last):
...
ValueError: each generator must be an invertible matrix but one is not:
[1 2]
[3 4]
Some groups aren't supported::
sage: SL(2, CC).gens()
Traceback (most recent call last):
...
NotImplementedError: Matrix group over Complex Field with 53 bits of precision not implemented.
sage: G = SL(0, QQ)
Traceback (most recent call last):
...
ValueError: The degree must be at least 1
"""
if len(gens) == 0:
raise ValueError, "gens must have positive length"
try:
R = gens[0].base_ring()
except AttributeError:
raise TypeError, "gens must be a list of matrices"
for i in range(len(gens)):
if not is_Matrix(gens[i]):
try:
gens[i] = gens[i].matrix()
except AttributeError:
pass
if is_FiniteField(R):
return MatrixGroup_gens_finite_field(gens)
else:
return MatrixGroup_gens(gens)
请发表评论