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
def __init__(self, X, coordinates, check=True): r""" See :class:`SchemeMorphism_point_toric_field` for documentation. TESTS:: sage: fan = FaceFan(lattice_polytope.octahedron(2)) sage: P1xP1 = ToricVariety(fan) sage: P1xP1(1,2,3,4) [1 : 2 : 3 : 4] """ # Convert scheme to its set of points over the base ring if is_Scheme(X): X = X(X.base_ring()) super(SchemeMorphism_point_toric_field, self).__init__(X) if check: # Verify that there are the right number of coords # Why is it not done in the parent? if is_SchemeMorphism(coordinates): coordinates = list(coordinates) if not isinstance(coordinates, (list, tuple)): raise TypeError("coordinates must be a scheme point, list, " "or tuple. Got %s" % coordinates) d = X.codomain().ambient_space().ngens() if len(coordinates) != d: raise ValueError("there must be %d coordinates! Got only %d: " "%s" % (d, len(coordinates), coordinates)) # Make sure the coordinates all lie in the appropriate ring coordinates = Sequence(coordinates, X.value_ring()) # Verify that the point satisfies the equations of X. X.codomain()._check_satisfies_equations(coordinates) self._coords = coordinates
def enum_affine_number_field(X, B): """ Enumerates affine points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height up to ``B`` and adds those that are on the scheme to the list. INPUT: - ``X`` - a scheme defined over a number field. - ``B`` - a real number. OUTPUT: - a list containing the affine points of ``X`` of absolute height up to ``B``, sorted. EXAMPLES:: sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 2, 'v') sage: A.<x,y,z> = AffineSpace(K, 3) sage: X = A.subscheme([y^2 - x]) sage: enum_affine_number_field(X(K), 4) [(0, 0, -1), (0, 0, -v), (0, 0, -1/2*v), (0, 0, 0), (0, 0, 1/2*v), (0, 0, v), (0, 0, 1), (1, -1, -1), (1, -1, -v), (1, -1, -1/2*v), (1, -1, 0), (1, -1, 1/2*v), (1, -1, v), (1, -1, 1), (1, 1, -1), (1, 1, -v), (1, 1, -1/2*v), (1, 1, 0), (1, 1, 1/2*v), (1, 1, v), (1, 1, 1)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = AffineSpace(K, 2) sage: X=A.subscheme(x-y) sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: enum_affine_number_field(X, 3) [(-1, -1), (-1/2*v - 1/2, -1/2*v - 1/2), (1/2*v - 1/2, 1/2*v - 1/2), (0, 0), (-1/2*v + 1/2, -1/2*v + 1/2), (1/2*v + 1/2, 1/2*v + 1/2), (1, 1)] """ from sage.schemes.affine.affine_space import is_AffineSpace if (is_Scheme(X)): if (not is_AffineSpace(X.ambient_space())): raise TypeError( "ambient space must be affine space over a number field") X = X(X.base_ring()) else: if (not is_AffineSpace(X.codomain().ambient_space())): raise TypeError( "codomain must be affine space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(B): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def Jacobian(X, **kwds): """ Return the Jacobian. INPUT: - ``X`` -- polynomial, algebraic variety, or anything else that has a Jacobian elliptic curve. - ``kwds`` -- optional keyword arguments. The input ``X`` can be one of the following: * A polynomial, see :func:`Jacobian_of_equation` for details. * A curve, see :func:`Jacobian_of_curve` for details. EXAMPLES:: sage: R.<u,v,w> = QQ[] sage: Jacobian(u^3+v^3+w^3) Elliptic Curve defined by y^2 = x^3 - 27/4 over Rational Field sage: C = Curve(u^3+v^3+w^3) sage: Jacobian(C) Elliptic Curve defined by y^2 = x^3 - 27/4 over Rational Field sage: P2.<u,v,w> = ProjectiveSpace(2, QQ) sage: C = P2.subscheme(u^3+v^3+w^3) sage: Jacobian(C) Elliptic Curve defined by y^2 = x^3 - 27/4 over Rational Field sage: Jacobian(C, morphism=True) Scheme morphism: From: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by: u^3 + v^3 + w^3 To: Elliptic Curve defined by y^2 = x^3 - 27/4 over Rational Field Defn: Defined on coordinates by sending (u : v : w) to (-u^4*v^4*w - u^4*v*w^4 - u*v^4*w^4 : 1/2*u^6*v^3 - 1/2*u^3*v^6 - 1/2*u^6*w^3 + 1/2*v^6*w^3 + 1/2*u^3*w^6 - 1/2*v^3*w^6 : u^3*v^3*w^3) """ try: return X.jacobian(**kwds) except AttributeError: pass morphism = kwds.pop('morphism', False) from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial if is_MPolynomial(X): if morphism: from sage.schemes.curves.constructor import Curve return Jacobian_of_equation(X, curve=Curve(X), **kwds) else: return Jacobian_of_equation(X, **kwds) from sage.schemes.generic.scheme import is_Scheme if is_Scheme(X) and X.dimension() == 1: return Jacobian_of_curve(X, morphism=morphism, **kwds)
def enum_product_projective_finite_field(X): r""" Enumerates projective points on scheme ``X`` defined over a finite field. INPUT: - ``X`` - a scheme defined over a finite field or a set of abstract rational points of such a scheme. OUTPUT: - a list containing the projective points of ``X`` over the finite field, sorted. EXAMPLES:: sage: PP.<x,y,z,w> = ProductProjectiveSpaces([1, 1], GF(3)) sage: from sage.schemes.product_projective.rational_point import \ enum_product_projective_finite_field sage: enum_product_projective_finite_field(PP) [(0 : 1 , 0 : 1), (0 : 1 , 1 : 0), (0 : 1 , 1 : 1), (0 : 1 , 2 : 1), (1 : 0 , 0 : 1), (1 : 0 , 1 : 0), (1 : 0 , 1 : 1), (1 : 0 , 2 : 1), (1 : 1 , 0 : 1), (1 : 1 , 1 : 0), (1 : 1 , 1 : 1), (1 : 1 , 2 : 1), (2 : 1 , 0 : 1), (2 : 1 , 1 : 0), (2 : 1 , 1 : 1), (2 : 1 , 2 : 1)] :: sage: PP.<x0,x1,x2,x3> = ProductProjectiveSpaces([1, 1], GF(17)) sage: X = PP.subscheme([x0^2 + 2*x1^2]) sage: from sage.schemes.product_projective.rational_point import \ enum_product_projective_finite_field sage: len(enum_product_projective_finite_field(X)) 36 """ if (is_Scheme(X)): if (not is_ProductProjectiveSpaces(X.ambient_space())): raise TypeError( "ambient space must be product of projective space over the rational field" ) X = X(X.base_ring()) else: if (not is_ProductProjectiveSpaces(X.codomain().ambient_space())): raise TypeError( "codomain must be product of projective space over the rational field" ) R = X.codomain().ambient_space() pts = [] for P in R.rational_points(): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def enum_affine_number_field(X, B): """ Enumerates affine points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height up to ``B`` and adds those that are on the scheme to the list. INPUT: - ``X`` - a scheme defined over a number field. - ``B`` - a real number. OUTPUT: - a list containing the affine points of ``X`` of absolute height up to ``B``, sorted. EXAMPLES:: sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 2, 'v') sage: A.<x,y,z> = AffineSpace(K, 3) sage: X = A.subscheme([y^2 - x]) sage: enum_affine_number_field(X(K), 4) [(0, 0, -1), (0, 0, -v), (0, 0, -1/2*v), (0, 0, 0), (0, 0, 1/2*v), (0, 0, v), (0, 0, 1), (1, -1, -1), (1, -1, -v), (1, -1, -1/2*v), (1, -1, 0), (1, -1, 1/2*v), (1, -1, v), (1, -1, 1), (1, 1, -1), (1, 1, -v), (1, 1, -1/2*v), (1, 1, 0), (1, 1, 1/2*v), (1, 1, v), (1, 1, 1)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = AffineSpace(K, 2) sage: X=A.subscheme(x-y) sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: enum_affine_number_field(X, 3) [(-1, -1), (-1/2*v - 1/2, -1/2*v - 1/2), (1/2*v - 1/2, 1/2*v - 1/2), (0, 0), (-1/2*v + 1/2, -1/2*v + 1/2), (1/2*v + 1/2, 1/2*v + 1/2), (1, 1)] """ from sage.schemes.affine.affine_space import is_AffineSpace if(is_Scheme(X)): if (not is_AffineSpace(X.ambient_space())): raise TypeError("ambient space must be affine space over a number field") X = X(X.base_ring()) else: if (not is_AffineSpace(X.codomain().ambient_space())): raise TypeError("codomain must be affine space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(B): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def enum_projective_number_field(X,B): """ Enumerates projective points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height of at most ``B`` and adds those that are on the scheme to the list. INPUT: - ``X`` - a scheme defined over a number field - ``B`` - a real number OUTPUT: - a list containing the projective points of ``X`` of absolute height up to ``B``, sorted. EXAMPLES:: sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^3 - 5,'v') sage: P.<x,y,z> = ProjectiveSpace(K, 2) sage: X = P.subscheme([x - y]) sage: enum_projective_number_field(X(K),125) [(0 : 0 : 1), (-1 : -1 : 1), (1 : 1 : 1), (-1/5*v^2 : -1/5*v^2 : 1), (-v : -v : 1), (1/5*v^2 : 1/5*v^2 : 1), (v : v : 1), (1 : 1 : 0)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3,'v') sage: A.<x,y> = ProjectiveSpace(K,1) sage: X=A.subscheme(x-y) sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: enum_projective_number_field(X,3) [(1 : 1)] """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if(is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError("Ambient space must be projective space over a number field") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError("Codomain must be projective space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(B): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def __init__(self, C): """ Initialize. TESTS:: sage: from sage.schemes.jacobians.abstract_jacobian import Jacobian_generic sage: P2.<x, y, z> = ProjectiveSpace(QQ, 2) sage: C = Curve(x^3 + y^3 + z^3) sage: J = Jacobian_generic(C); J Jacobian of Projective Plane Curve over Rational Field defined by x^3 + y^3 + z^3 sage: type(J) <class 'sage.schemes.jacobians.abstract_jacobian.Jacobian_generic_with_category'> Note: this is an abstract parent, so we skip element tests:: sage: TestSuite(J).run(skip =["_test_an_element",\ "_test_elements",\ "_test_elements_eq_reflexive",\ "_test_elements_eq_symmetric",\ "_test_elements_eq_transitive",\ "_test_elements_neq",\ "_test_some_elements"]) :: sage: Jacobian_generic(ZZ) Traceback (most recent call last): ... TypeError: Argument (=Integer Ring) must be a scheme. sage: Jacobian_generic(P2) Traceback (most recent call last): ... ValueError: C (=Projective Space of dimension 2 over Rational Field) must have dimension 1. :: sage: P2.<x, y, z> = ProjectiveSpace(Zmod(6), 2) sage: C = Curve(x + y + z, P2) sage: Jacobian_generic(C) Traceback (most recent call last): ... TypeError: C (=Projective Plane Curve over Ring of integers modulo 6 defined by x + y + z) must be defined over a field. """ if not is_Scheme(C): raise TypeError("Argument (=%s) must be a scheme." % C) if C.base_ring() not in _Fields: raise TypeError("C (=%s) must be defined over a field." % C) if C.dimension() != 1: raise ValueError("C (=%s) must have dimension 1." % C) self.__curve = C Scheme.__init__(self, C.base_scheme())
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.generic.scheme import is_Scheme if is_Scheme(x): return x.Hom(self) return SchemeTopologicalPoint_prime_ideal(self, x)
def __init__(self, C): """ TESTS:: sage: from sage.schemes.jacobians.abstract_jacobian import Jacobian_generic sage: P2.<x, y, z> = ProjectiveSpace(QQ, 2) sage: C = Curve(x^3 + y^3 + z^3) sage: J = Jacobian_generic(C); J Jacobian of Projective Plane Curve over Rational Field defined by x^3 + y^3 + z^3 sage: type(J) <class 'sage.schemes.jacobians.abstract_jacobian.Jacobian_generic_with_category'> Note: this is an abstract parent, so we skip element tests:: sage: TestSuite(J).run(skip =["_test_an_element",\ "_test_elements",\ "_test_elements_eq_reflexive",\ "_test_elements_eq_symmetric",\ "_test_elements_eq_transitive",\ "_test_elements_neq",\ "_test_some_elements"]) :: sage: Jacobian_generic(ZZ) Traceback (most recent call last): ... TypeError: Argument (=Integer Ring) must be a scheme. sage: Jacobian_generic(P2) Traceback (most recent call last): ... ValueError: C (=Projective Space of dimension 2 over Rational Field) must have dimension 1. sage: P2.<x, y, z> = ProjectiveSpace(Zmod(6), 2) sage: C = Curve(x + y + z) sage: Jacobian_generic(C) Traceback (most recent call last): ... TypeError: C (=Projective Plane Curve over Ring of integers modulo 6 defined by x + y + z) must be defined over a field. """ if not is_Scheme(C): raise TypeError("Argument (=%s) must be a scheme."%C) if C.base_ring() not in _Fields: raise TypeError("C (=%s) must be defined over a field."%C) if C.dimension() != 1: raise ValueError("C (=%s) must have dimension 1."%C) self.__curve = C Scheme.__init__(self, C.base_scheme())
def Schemes(X=None): """ Construct a category of schemes. EXAMPLES:: sage: Schemes() Category of Schemes sage: Schemes(Spec(ZZ)) Category of schemes over Integer Ring sage: Schemes(ZZ) Category of schemes over Integer Ring """ if X is None: return Schemes_abstract() from sage.schemes.generic.scheme import is_Scheme if not is_Scheme(X): X = Schemes()(X) return Schemes_over_base(X)
def __classcall_private__(cls, X = None): """ Implement the dispatching ``Schemes(ZZ)`` -> ``Schemes_over_base``. EXAMPLES:: sage: Schemes() Category of schemes sage: Schemes(Spec(ZZ)) Category of schemes over Integer Ring sage: Schemes(ZZ) Category of schemes over Integer Ring """ if X is not None: from sage.schemes.generic.scheme import is_Scheme if not is_Scheme(X): X = Schemes()(X) return Schemes_over_base(X) else: return super(Schemes, cls).__classcall__(cls)
def __classcall_private__(cls, X=None): """ Implement the dispatching ``Schemes(ZZ)`` -> ``Schemes_over_base``. EXAMPLES:: sage: Schemes() Category of schemes sage: Schemes(Spec(ZZ)) Category of schemes over Integer Ring sage: Schemes(ZZ) Category of schemes over Integer Ring """ if X is not None: from sage.schemes.generic.scheme import is_Scheme if not is_Scheme(X): X = Schemes()(X) return Schemes_over_base(X) else: return super(Schemes, cls).__classcall__(cls)
def enum_affine_rational_field(X, B): """ Enumerates affine rational points on scheme ``X`` (defined over `\QQ`) up to bound ``B``. INPUT: - ``X`` - a scheme or set of abstract rational points of a scheme; - ``B`` - a positive integer bound. OUTPUT: - a list containing the affine points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: A.<x,y,z> = AffineSpace(3,QQ) sage: from sage.schemes.affine.affine_rational_point import enum_affine_rational_field sage: enum_affine_rational_field(A(QQ),1) [(-1, -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), (0, -1, -1), (0, -1, 0), (0, -1, 1), (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 1, -1), (0, 1, 0), (0, 1, 1), (1, -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)] :: sage: A.<w,x,y,z> = AffineSpace(4,QQ) sage: S = A.subscheme([x^2-y*z+3,w^3+z+y^2]) sage: enum_affine_rational_field(S(QQ),2) [] sage: enum_affine_rational_field(S(QQ),3) [(-2, 0, -3, -1)] :: sage: A.<x,y> = AffineSpace(2,QQ) sage: C = Curve(x^2+y-x) sage: enum_affine_rational_field(C,10) [(-2, -6), (-1, -2), (0, 0), (1, 0), (2, -2), (3, -6)] AUTHORS: - David R. Kohel <*****@*****.**>: original version. - Charlie Turner (06-2010): small adjustments. """ if is_Scheme(X): X = X(X.base_ring()) n = X.codomain().ambient_space().ngens() if X.value_ring() is ZZ: Q = [1] else: # rational field Q = range(1, B + 1) R = [0] + [s * k for k in range(1, B + 1) for s in [1, -1]] pts = [] P = [0] * n m = ZZ(0) try: pts.append(X(P)) except TypeError: pass iters = [iter(R) for _ in range(n)] for it in iters: it.next() i = 0 while i < n: try: a = ZZ(iters[i].next()) except StopIteration: iters[i] = iter(R) # reset P[i] = iters[i].next() # reset P[i] to 0 and increment i += 1 continue m = m.gcd(a) P[i] = a for b in Q: if m.gcd(b) == 1: try: pts.append(X([num / b for num in P])) except TypeError: pass i = 0 m = ZZ(0) pts.sort() return pts
def enum_projective_rational_field(X, B): r""" Enumerates projective, rational points on scheme ``X`` of height up to bound ``B``. INPUT: - ``X`` - a scheme or set of abstract rational points of a scheme. - ``B`` - a positive integer bound. OUTPUT: - a list containing the projective points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: P.<X,Y,Z> = ProjectiveSpace(2, QQ) sage: C = P.subscheme([X+Y-Z]) sage: from sage.schemes.projective.projective_rational_point import enum_projective_rational_field sage: enum_projective_rational_field(C(QQ), 6) [(-5 : 6 : 1), (-4 : 5 : 1), (-3 : 4 : 1), (-2 : 3 : 1), (-3/2 : 5/2 : 1), (-1 : 1 : 0), (-1 : 2 : 1), (-2/3 : 5/3 : 1), (-1/2 : 3/2 : 1), (-1/3 : 4/3 : 1), (-1/4 : 5/4 : 1), (-1/5 : 6/5 : 1), (0 : 1 : 1), (1/6 : 5/6 : 1), (1/5 : 4/5 : 1), (1/4 : 3/4 : 1), (1/3 : 2/3 : 1), (2/5 : 3/5 : 1), (1/2 : 1/2 : 1), (3/5 : 2/5 : 1), (2/3 : 1/3 : 1), (3/4 : 1/4 : 1), (4/5 : 1/5 : 1), (5/6 : 1/6 : 1), (1 : 0 : 1), (6/5 : -1/5 : 1), (5/4 : -1/4 : 1), (4/3 : -1/3 : 1), (3/2 : -1/2 : 1), (5/3 : -2/3 : 1), (2 : -1 : 1), (5/2 : -3/2 : 1), (3 : -2 : 1), (4 : -3 : 1), (5 : -4 : 1), (6 : -5 : 1)] sage: enum_projective_rational_field(C,6) == enum_projective_rational_field(C(QQ),6) True :: sage: P3.<W,X,Y,Z> = ProjectiveSpace(3, QQ) sage: enum_projective_rational_field(P3, 1) [(-1 : -1 : -1 : 1), (-1 : -1 : 0 : 1), (-1 : -1 : 1 : 0), (-1 : -1 : 1 : 1), (-1 : 0 : -1 : 1), (-1 : 0 : 0 : 1), (-1 : 0 : 1 : 0), (-1 : 0 : 1 : 1), (-1 : 1 : -1 : 1), (-1 : 1 : 0 : 0), (-1 : 1 : 0 : 1), (-1 : 1 : 1 : 0), (-1 : 1 : 1 : 1), (0 : -1 : -1 : 1), (0 : -1 : 0 : 1), (0 : -1 : 1 : 0), (0 : -1 : 1 : 1), (0 : 0 : -1 : 1), (0 : 0 : 0 : 1), (0 : 0 : 1 : 0), (0 : 0 : 1 : 1), (0 : 1 : -1 : 1), (0 : 1 : 0 : 0), (0 : 1 : 0 : 1), (0 : 1 : 1 : 0), (0 : 1 : 1 : 1), (1 : -1 : -1 : 1), (1 : -1 : 0 : 1), (1 : -1 : 1 : 0), (1 : -1 : 1 : 1), (1 : 0 : -1 : 1), (1 : 0 : 0 : 0), (1 : 0 : 0 : 1), (1 : 0 : 1 : 0), (1 : 0 : 1 : 1), (1 : 1 : -1 : 1), (1 : 1 : 0 : 0), (1 : 1 : 0 : 1), (1 : 1 : 1 : 0), (1 : 1 : 1 : 1)] ALGORITHM: We just check all possible projective points in correct dimension of projective space to see if they lie on ``X``. AUTHORS: - John Cremona and Charlie Turner (06-2010) """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if (is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError( "ambient space must be projective space over the rational field" ) X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError( "codomain must be projective space over the rational field") n = X.codomain().ambient_space().ngens() zero = (0, ) * n pts = [] for c in cartesian_product_iterator([srange(-B, B + 1) for _ in range(n)]): if gcd(c) == 1 and c > zero: try: pts.append(X(c)) except TypeError: pass pts.sort() return pts
def enum_projective_finite_field(X): """ Enumerates projective points on scheme ``X`` defined over a finite field. INPUT: - ``X`` - a scheme defined over a finite field or a set of abstract rational points of such a scheme. OUTPUT: - a list containing the projective points of ``X`` over the finite field, sorted. EXAMPLES:: sage: F = GF(53) sage: P.<X,Y,Z> = ProjectiveSpace(2,F) sage: from sage.schemes.projective.projective_rational_point import enum_projective_finite_field sage: len(enum_projective_finite_field(P(F))) 2863 sage: 53^2+53+1 2863 :: sage: F = GF(9,'a') sage: P.<X,Y,Z> = ProjectiveSpace(2,F) sage: C = Curve(X^3-Y^3+Z^2*Y) sage: enum_projective_finite_field(C(F)) [(0 : 0 : 1), (0 : 1 : 1), (0 : 2 : 1), (1 : 1 : 0), (a + 1 : 2*a : 1), (a + 1 : 2*a + 1 : 1), (a + 1 : 2*a + 2 : 1), (2*a + 2 : a : 1), (2*a + 2 : a + 1 : 1), (2*a + 2 : a + 2 : 1)] :: sage: F = GF(5) sage: P2F.<X,Y,Z> = ProjectiveSpace(2,F) sage: enum_projective_finite_field(P2F) [(0 : 0 : 1), (0 : 1 : 0), (0 : 1 : 1), (0 : 2 : 1), (0 : 3 : 1), (0 : 4 : 1), (1 : 0 : 0), (1 : 0 : 1), (1 : 1 : 0), (1 : 1 : 1), (1 : 2 : 1), (1 : 3 : 1), (1 : 4 : 1), (2 : 0 : 1), (2 : 1 : 0), (2 : 1 : 1), (2 : 2 : 1), (2 : 3 : 1), (2 : 4 : 1), (3 : 0 : 1), (3 : 1 : 0), (3 : 1 : 1), (3 : 2 : 1), (3 : 3 : 1), (3 : 4 : 1), (4 : 0 : 1), (4 : 1 : 0), (4 : 1 : 1), (4 : 2 : 1), (4 : 3 : 1), (4 : 4 : 1)] ALGORITHM: Checks all points in projective space to see if they lie on ``X``. .. WARNING:: If ``X`` is defined over an infinite field, this code will not finish! AUTHORS: - John Cremona and Charlie Turner (06-2010). """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if (is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError( "ambient space must be projective space over a finite") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError( "codomain must be projective space over a finite field") n = X.codomain().ambient_space().ngens() - 1 F = X.value_ring() pts = [] for k in range(n + 1): for c in cartesian_product_iterator([F for _ in range(k)]): try: pts.append(X(list(c) + [1] + [0] * (n - k))) except TypeError: pass pts.sort() return pts
def enum_projective_number_field(X, B, prec=53): """ Enumerates projective points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height of at most ``B`` and adds those that are on the scheme to the list. INPUT: - ``X`` - a scheme defined over a number field. - ``B`` - a real number. - ``prec`` - the precision to use for computing the elements of bounded height of number fields. OUTPUT: - a list containing the projective points of ``X`` of absolute height up to ``B``, sorted. .. WARNING:: In the current implementation, the output of the [Doyle-Krumm] algorithm for elements of bounded height 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: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^3 - 5,'v') sage: P.<x,y,z> = ProjectiveSpace(K, 2) sage: X = P.subscheme([x - y]) sage: enum_projective_number_field(X(K), 5^(1/3), prec=2^10) [(0 : 0 : 1), (-1 : -1 : 1), (1 : 1 : 1), (-1/5*v^2 : -1/5*v^2 : 1), (-v : -v : 1), (1/5*v^2 : 1/5*v^2 : 1), (v : v : 1), (1 : 1 : 0)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = ProjectiveSpace(K,1) sage: X = A.subscheme(x-y) sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: enum_projective_number_field(X, 2) [(1 : 1)] """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if (is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError( "ambient space must be projective space over a number field") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError( "codomain must be projective space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(B, prec): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def _call_(self, x): """ Construct a scheme from the data in ``x`` EXAMPLES: Let us first construct the category of schemes:: sage: S = Schemes(); S Category of schemes We create a scheme from a ring:: sage: X = S(ZZ); X # indirect doctest Spectrum of Integer Ring We create a scheme from a scheme (do nothing):: sage: S(X) Spectrum of Integer Ring We create a scheme morphism from a ring homomorphism.x:: sage: phi = ZZ.hom(QQ); phi Natural morphism: From: Integer Ring To: Rational Field sage: f = S(phi); f # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Natural morphism: From: Integer Ring To: Rational Field sage: f.domain() Spectrum of Rational Field sage: f.codomain() Spectrum of Integer Ring sage: S(f) # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Natural morphism: From: Integer Ring To: Rational Field """ from sage.schemes.generic.scheme import is_Scheme if is_Scheme(x): return x from sage.schemes.generic.morphism import is_SchemeMorphism if is_SchemeMorphism(x): return x from sage.rings.ring import CommutativeRing from sage.schemes.generic.spec import Spec from sage.categories.map import Map from sage.categories.all import Rings if isinstance(x, CommutativeRing): return Spec(x) elif isinstance(x, Map) and x.category_for().is_subcategory(Rings()): # x is a morphism of Rings A = Spec(x.codomain()) return A.hom(x) else: raise TypeError("No way to create an object or morphism in %s from %s"%(self, x))
def enum_projective_number_field(X, **kwds): """ Enumerates projective points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height of at most ``B`` and adds those that are on the scheme to the list. This algorithm computes 2 lists: L containing elements x in `K` such that H_k(x) <= B, and a list L' containing elements x in `K` that, due to floating point issues, may be slightly larger then the bound. This can be controlled by lowering the tolerance. ALGORITHM: This is an implementation of the revised algorithm (Algorithm 4) in [DK2013]_. Algorithm 5 is used for imaginary quadratic fields. INPUT: kwds: - ``bound`` - a real number - ``tolerance`` - a rational number in (0,1] used in doyle-krumm algorithm-4 - ``precision`` - the precision to use for computing the elements of bounded height of number fields. OUTPUT: - a list containing the projective points of ``X`` of absolute height up to ``B``, sorted. EXAMPLES:: sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^3 - 5,'v') sage: P.<x,y,z> = ProjectiveSpace(K, 2) sage: X = P.subscheme([x - y]) sage: enum_projective_number_field(X(K), bound=RR(5^(1/3)), prec=2^10) [(0 : 0 : 1), (-1 : -1 : 1), (1 : 1 : 1), (-1/5*v^2 : -1/5*v^2 : 1), (-v : -v : 1), (1/5*v^2 : 1/5*v^2 : 1), (v : v : 1), (1 : 1 : 0)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = ProjectiveSpace(K,1) sage: X = A.subscheme(x-y) sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: enum_projective_number_field(X, bound=2) [(1 : 1)] """ B = kwds.pop('bound') tol = kwds.pop('tolerance', 1e-2) prec = kwds.pop('precision', 53) from sage.schemes.projective.projective_space import is_ProjectiveSpace if is_Scheme(X): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError( "ambient space must be projective space over a number field") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError( "codomain must be projective space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(bound=B, tolerance=tol, precision=prec): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def enum_affine_number_field(X, **kwds): """ Enumerates affine points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height up to ``B`` and adds those that are on the scheme to the list. This algorithm computes 2 lists: L containing elements x in `K` such that H_k(x) <= B, and a list L' containing elements x in `K` that, due to floating point issues, may be slightly larger then the bound. This can be controlled by lowering the tolerance. ALGORITHM: This is an implementation of the revised algorithm (Algorithm 4) in [Doyle-Krumm]_. Algorithm 5 is used for imaginary quadratic fields. INPUT: kwds: - ``bound`` - a real number - ``tolerance`` - a rational number in (0,1] used in doyle-krumm algorithm-4 - ``precision`` - the precision to use for computing the elements of bounded height of number fields. OUTPUT: - a list containing the affine points of ``X`` of absolute height up to ``B``, sorted. EXAMPLES:: sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 2, 'v') sage: A.<x,y,z> = AffineSpace(K, 3) sage: X = A.subscheme([y^2 - x]) sage: enum_affine_number_field(X(K), bound=2**0.5) [(0, 0, -1), (0, 0, -v), (0, 0, -1/2*v), (0, 0, 0), (0, 0, 1/2*v), (0, 0, v), (0, 0, 1), (1, -1, -1), (1, -1, -v), (1, -1, -1/2*v), (1, -1, 0), (1, -1, 1/2*v), (1, -1, v), (1, -1, 1), (1, 1, -1), (1, 1, -v), (1, 1, -1/2*v), (1, 1, 0), (1, 1, 1/2*v), (1, 1, v), (1, 1, 1)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = AffineSpace(K, 2) sage: X=A.subscheme(x-y) sage: from sage.schemes.affine.affine_rational_point import enum_affine_number_field sage: enum_affine_number_field(X, bound=3**0.25) [(-1, -1), (-1/2*v - 1/2, -1/2*v - 1/2), (1/2*v - 1/2, 1/2*v - 1/2), (0, 0), (-1/2*v + 1/2, -1/2*v + 1/2), (1/2*v + 1/2, 1/2*v + 1/2), (1, 1)] """ B = kwds.pop('bound') tol = kwds.pop('tolerance', 1e-2) prec = kwds.pop('precision', 53) from sage.schemes.affine.affine_space import is_AffineSpace if is_Scheme(X): if not is_AffineSpace(X.ambient_space()): raise TypeError( "ambient space must be affine space over a number field") X = X(X.base_ring()) elif not is_AffineSpace(X.codomain().ambient_space()): raise TypeError("codomain must be affine space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(bound=B, tolerance=tol, precision=prec): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def _call_(self, x): """ Construct a scheme from the data in ``x`` EXAMPLES: Let us first construct the category of schemes:: sage: S = Schemes(); S Category of schemes We create a scheme from a ring:: sage: X = S(ZZ); X # indirect doctest Spectrum of Integer Ring We create a scheme from a scheme (do nothing):: sage: S(X) Spectrum of Integer Ring We create a scheme morphism from a ring homomorphism.x:: sage: phi = ZZ.hom(QQ); phi Ring Coercion morphism: From: Integer Ring To: Rational Field sage: f = S(phi); f # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Ring Coercion morphism: From: Integer Ring To: Rational Field sage: f.domain() Spectrum of Rational Field sage: f.codomain() Spectrum of Integer Ring sage: S(f) # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Ring Coercion morphism: From: Integer Ring To: Rational Field """ from sage.schemes.generic.scheme import is_Scheme if is_Scheme(x): return x from sage.schemes.generic.morphism import is_SchemeMorphism if is_SchemeMorphism(x): return x from sage.rings.morphism import is_RingHomomorphism from sage.rings.ring import CommutativeRing from sage.schemes.generic.spec import Spec if isinstance(x, CommutativeRing): return Spec(x) elif is_RingHomomorphism(x): A = Spec(x.codomain()) return A.hom(x) else: raise TypeError("No way to create an object or morphism in %s from %s"%(self, x))
def enum_product_projective_rational_field(X, B): r""" Enumerate projective, rational points on scheme ``X`` of height up to bound ``B``. INPUT: - ``X`` -- a scheme or set of abstract rational points of a scheme - ``B`` -- a positive integer bound OUTPUT: - a list containing the product projective points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: PP.<x0,x1,x2,x3,x4> = ProductProjectiveSpaces([1, 2], QQ) sage: from sage.schemes.product_projective.rational_point import \ enum_product_projective_rational_field sage: enum_product_projective_rational_field(PP,1) [(-1 : 1 , -1 : -1 : 1), (-1 : 1 , -1 : 0 : 1), (-1 : 1 , -1 : 1 : 0), (-1 : 1 , -1 : 1 : 1), (-1 : 1 , 0 : -1 : 1), (-1 : 1 , 0 : 0 : 1), (-1 : 1 , 0 : 1 : 0), (-1 : 1 , 0 : 1 : 1), (-1 : 1 , 1 : -1 : 1), (-1 : 1 , 1 : 0 : 0), (-1 : 1 , 1 : 0 : 1), (-1 : 1 , 1 : 1 : 0), (-1 : 1 , 1 : 1 : 1), (0 : 1 , -1 : -1 : 1), (0 : 1 , -1 : 0 : 1), (0 : 1 , -1 : 1 : 0), (0 : 1 , -1 : 1 : 1), (0 : 1 , 0 : -1 : 1), (0 : 1 , 0 : 0 : 1), (0 : 1 , 0 : 1 : 0), (0 : 1 , 0 : 1 : 1), (0 : 1 , 1 : -1 : 1), (0 : 1 , 1 : 0 : 0), (0 : 1 , 1 : 0 : 1), (0 : 1 , 1 : 1 : 0), (0 : 1 , 1 : 1 : 1), (1 : 0 , -1 : -1 : 1), (1 : 0 , -1 : 0 : 1), (1 : 0 , -1 : 1 : 0), (1 : 0 , -1 : 1 : 1), (1 : 0 , 0 : -1 : 1), (1 : 0 , 0 : 0 : 1), (1 : 0 , 0 : 1 : 0), (1 : 0 , 0 : 1 : 1), (1 : 0 , 1 : -1 : 1), (1 : 0 , 1 : 0 : 0), (1 : 0 , 1 : 0 : 1), (1 : 0 , 1 : 1 : 0), (1 : 0 , 1 : 1 : 1), (1 : 1 , -1 : -1 : 1), (1 : 1 , -1 : 0 : 1), (1 : 1 , -1 : 1 : 0), (1 : 1 , -1 : 1 : 1), (1 : 1 , 0 : -1 : 1), (1 : 1 , 0 : 0 : 1), (1 : 1 , 0 : 1 : 0), (1 : 1 , 0 : 1 : 1), (1 : 1 , 1 : -1 : 1), (1 : 1 , 1 : 0 : 0), (1 : 1 , 1 : 0 : 1), (1 : 1 , 1 : 1 : 0), (1 : 1 , 1 : 1 : 1)] :: sage: PP.<x,y,z,u,v> = ProductProjectiveSpaces([2,1], QQ) sage: X = PP.subscheme([x^2 + x*y + y*z, u*u-v*u]) sage: from sage.schemes.product_projective.rational_point import \ enum_product_projective_rational_field sage: enum_product_projective_rational_field(X,4) [(-2 : 4 : 1 , 0 : 1), (-2 : 4 : 1 , 1 : 1), (-1 : 1 : 0 , 0 : 1), (-1 : 1 : 0 , 1 : 1), (-2/3 : -4/3 : 1 , 0 : 1), (-2/3 : -4/3 : 1 , 1 : 1), (-1/2 : -1/2 : 1 , 0 : 1), (-1/2 : -1/2 : 1 , 1 : 1), (0 : 0 : 1 , 0 : 1), (0 : 0 : 1 , 1 : 1), (0 : 1 : 0 , 0 : 1), (0 : 1 : 0 , 1 : 1), (1 : -1/2 : 1 , 0 : 1), (1 : -1/2 : 1 , 1 : 1)] """ if(is_Scheme(X)): if (not is_ProductProjectiveSpaces(X.ambient_space())): raise TypeError("ambient space must be product of projective space over the rational field") X = X(X.base_ring()) else: if (not is_ProductProjectiveSpaces(X.codomain().ambient_space())): raise TypeError("codomain must be product of projective space over the rational field") R = X.codomain().ambient_space() m = R.num_components() iters = [ R[i].points_of_bounded_height(bound=B) for i in range(m) ] dim = [R[i].dimension_relative() + 1 for i in range(m)] dim_prefix = [0, dim[0]] # prefixes dim list for i in range(1, len(dim)): dim_prefix.append(dim_prefix[i] + dim[i]) pts = [] P = [] for i in range(m): pt = next(iters[i]) for j in range(dim[i]): P.append(pt[j]) # initial value of P try: # add the initial point pts.append(X(P)) except TypeError: pass i = 0 while i < m: try: pt = next(iters[i]) for j in range(dim[i]): P[dim_prefix[i] + j] = pt[j] try: pts.append(X(P)) except TypeError: pass i = 0 except StopIteration: iters[i] = R[i].points_of_bounded_height(bound=B) pt = next(iters[i]) # reset for j in range(dim[i]): P[dim_prefix[i] + j] = pt[j] i += 1 pts.sort() return pts
def enum_affine_finite_field(X): r""" Enumerates affine points on scheme ``X`` defined over a finite field. INPUT: - ``X`` - a scheme defined over a finite field or a set of abstract rational points of such a scheme. OUTPUT: - a list containing the affine points of ``X`` over the finite field, sorted. EXAMPLES:: sage: F = GF(7) sage: A.<w,x,y,z> = AffineSpace(4, F) sage: C = A.subscheme([w^2+x+4, y*z*x-6, z*y+w*x]) sage: from sage.schemes.affine.affine_rational_point import enum_affine_finite_field sage: enum_affine_finite_field(C(F)) [] sage: C = A.subscheme([w^2+x+4, y*z*x-6]) sage: enum_affine_finite_field(C(F)) [(0, 3, 1, 2), (0, 3, 2, 1), (0, 3, 3, 3), (0, 3, 4, 4), (0, 3, 5, 6), (0, 3, 6, 5), (1, 2, 1, 3), (1, 2, 2, 5), (1, 2, 3, 1), (1, 2, 4, 6), (1, 2, 5, 2), (1, 2, 6, 4), (2, 6, 1, 1), (2, 6, 2, 4), (2, 6, 3, 5), (2, 6, 4, 2), (2, 6, 5, 3), (2, 6, 6, 6), (3, 1, 1, 6), (3, 1, 2, 3), (3, 1, 3, 2), (3, 1, 4, 5), (3, 1, 5, 4), (3, 1, 6, 1), (4, 1, 1, 6), (4, 1, 2, 3), (4, 1, 3, 2), (4, 1, 4, 5), (4, 1, 5, 4), (4, 1, 6, 1), (5, 6, 1, 1), (5, 6, 2, 4), (5, 6, 3, 5), (5, 6, 4, 2), (5, 6, 5, 3), (5, 6, 6, 6), (6, 2, 1, 3), (6, 2, 2, 5), (6, 2, 3, 1), (6, 2, 4, 6), (6, 2, 5, 2), (6, 2, 6, 4)] :: sage: A.<x,y,z> = AffineSpace(3, GF(3)) sage: S = A.subscheme(x+y) sage: enum_affine_finite_field(S) [(0, 0, 0), (0, 0, 1), (0, 0, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2), (2, 1, 0), (2, 1, 1), (2, 1, 2)] ALGORITHM: Checks all points in affine space to see if they lie on X. .. WARNING:: If ``X`` is defined over an infinite field, this code will not finish! AUTHORS: - John Cremona and Charlie Turner (06-2010) """ from sage.schemes.affine.affine_space import is_AffineSpace if is_Scheme(X): if not is_AffineSpace(X.ambient_space()): raise TypeError( "ambient space must be affine space over a finite field") X = X(X.base_ring()) elif not is_AffineSpace(X.codomain().ambient_space()): raise TypeError("codomain must be affine space over a finite field") n = X.codomain().ambient_space().ngens() F = X.value_ring() pts = [] for c in cartesian_product_iterator([F] * n): try: pts.append(X(c)) except Exception: pass pts.sort() return pts
def enum_affine_finite_field(X): r""" Enumerates affine points on scheme ``X`` defined over a finite field. INPUT: - ``X`` - a scheme defined over a finite field or a set of abstract rational points of such a scheme. OUTPUT: - a list containing the affine points of ``X`` over the finite field, sorted. EXAMPLES:: sage: F = GF(7) sage: A.<w,x,y,z> = AffineSpace(4,F) sage: C = A.subscheme([w^2+x+4,y*z*x-6,z*y+w*x]) sage: from sage.schemes.affine.affine_rational_point import enum_affine_finite_field sage: enum_affine_finite_field(C(F)) [] sage: C = A.subscheme([w^2+x+4,y*z*x-6]) sage: enum_affine_finite_field(C(F)) [(0, 3, 1, 2), (0, 3, 2, 1), (0, 3, 3, 3), (0, 3, 4, 4), (0, 3, 5, 6), (0, 3, 6, 5), (1, 2, 1, 3), (1, 2, 2, 5), (1, 2, 3, 1), (1, 2, 4, 6), (1, 2, 5, 2), (1, 2, 6, 4), (2, 6, 1, 1), (2, 6, 2, 4), (2, 6, 3, 5), (2, 6, 4, 2), (2, 6, 5, 3), (2, 6, 6, 6), (3, 1, 1, 6), (3, 1, 2, 3), (3, 1, 3, 2), (3, 1, 4, 5), (3, 1, 5, 4), (3, 1, 6, 1), (4, 1, 1, 6), (4, 1, 2, 3), (4, 1, 3, 2), (4, 1, 4, 5), (4, 1, 5, 4), (4, 1, 6, 1), (5, 6, 1, 1), (5, 6, 2, 4), (5, 6, 3, 5), (5, 6, 4, 2), (5, 6, 5, 3), (5, 6, 6, 6), (6, 2, 1, 3), (6, 2, 2, 5), (6, 2, 3, 1), (6, 2, 4, 6), (6, 2, 5, 2), (6, 2, 6, 4)] :: sage: A.<x,y,z> = AffineSpace(3,GF(3)) sage: S = A.subscheme(x+y) sage: enum_affine_finite_field(S) [(0, 0, 0), (0, 0, 1), (0, 0, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2), (2, 1, 0), (2, 1, 1), (2, 1, 2)] ALGORITHM: Checks all points in affine space to see if they lie on X. .. WARNING:: If ``X`` is defined over an infinite field, this code will not finish! AUTHORS: - John Cremona and Charlie Turner (06-2010) """ if is_Scheme(X): X = X(X.base_ring()) n = X.codomain().ambient_space().ngens() F = X.value_ring() pts = [] for c in cartesian_product_iterator([F]*n): try: pts.append(X(c)) except Exception: pass pts.sort() return pts
def enum_affine_rational_field(X,B): """ Enumerates affine rational points on scheme ``X`` (defined over `\QQ`) up to bound ``B``. INPUT: - ``X`` - a scheme or set of abstract rational points of a scheme; - ``B`` - a positive integer bound. OUTPUT: - a list containing the affine points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: A.<x,y,z> = AffineSpace(3,QQ) sage: from sage.schemes.affine.affine_rational_point import enum_affine_rational_field sage: enum_affine_rational_field(A(QQ),1) [(-1, -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), (0, -1, -1), (0, -1, 0), (0, -1, 1), (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 1, -1), (0, 1, 0), (0, 1, 1), (1, -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)] :: sage: A.<w,x,y,z> = AffineSpace(4,QQ) sage: S = A.subscheme([x^2-y*z+3,w^3+z+y^2]) sage: enum_affine_rational_field(S(QQ),2) [] sage: enum_affine_rational_field(S(QQ),3) [(-2, 0, -3, -1)] :: sage: A.<x,y> = AffineSpace(2,QQ) sage: C = Curve(x^2+y-x) sage: enum_affine_rational_field(C,10) [(-2, -6), (-1, -2), (0, 0), (1, 0), (2, -2), (3, -6)] AUTHORS: - David R. Kohel <*****@*****.**>: original version. - Charlie Turner (06-2010): small adjustments. """ if is_Scheme(X): X = X(X.base_ring()) n = X.codomain().ambient_space().ngens() if X.value_ring() is ZZ: Q = [ 1 ] else: # rational field Q = range(1, B + 1) R = [ 0 ] + [ s*k for k in range(1, B+1) for s in [1, -1] ] pts = [] P = [0] * n m = ZZ(0) try: pts.append(X(P)) except TypeError: pass iters = [ iter(R) for _ in range(n) ] for it in iters: it.next() i = 0 while i < n: try: a = ZZ(iters[i].next()) except StopIteration: iters[i] = iter(R) # reset P[i] = iters[i].next() # reset P[i] to 0 and increment i += 1 continue m = m.gcd(a) P[i] = a for b in Q: if m.gcd(b) == 1: try: pts.append(X([ num/b for num in P ])) except TypeError: pass i = 0 m = ZZ(0) pts.sort() return pts
def enum_affine_rational_field(X, B): """ Enumerates affine rational points on scheme ``X`` up to bound ``B``. INPUT: - ``X`` - a scheme or set of abstract rational points of a scheme. - ``B`` - a positive integer bound. OUTPUT: - a list containing the affine points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: A.<x,y,z> = AffineSpace(3, QQ) sage: from sage.schemes.affine.affine_rational_point import enum_affine_rational_field sage: enum_affine_rational_field(A(QQ), 1) [(-1, -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), (0, -1, -1), (0, -1, 0), (0, -1, 1), (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 1, -1), (0, 1, 0), (0, 1, 1), (1, -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)] :: sage: A.<w,x,y,z> = AffineSpace(4, QQ) sage: S = A.subscheme([x^2-y*z+1, w^3+z+y^2]) sage: enum_affine_rational_field(S(QQ), 1) [(0, 0, -1, -1)] sage: enum_affine_rational_field(S(QQ), 2) [(0, 0, -1, -1), (1, -1, -1, -2), (1, 1, -1, -2)] :: sage: A.<x,y> = AffineSpace(2, QQ) sage: C = Curve(x^2+y-x) sage: enum_affine_rational_field(C, 10) # long time (3 s) [(-2, -6), (-1, -2), (-2/3, -10/9), (-1/2, -3/4), (-1/3, -4/9), (0, 0), (1/3, 2/9), (1/2, 1/4), (2/3, 2/9), (1, 0), (4/3, -4/9), (3/2, -3/4), (5/3, -10/9), (2, -2), (3, -6)] AUTHORS: - David R. Kohel <*****@*****.**>: original version. - Charlie Turner (06-2010): small adjustments. - Raman Raghukul 2018: updated. """ from sage.schemes.affine.affine_space import is_AffineSpace if is_Scheme(X): if not is_AffineSpace(X.ambient_space()): raise TypeError( "ambient space must be affine space over the rational field") X = X(X.base_ring()) elif not is_AffineSpace(X.codomain().ambient_space()): raise TypeError( "codomain must be affine space over the rational field") n = X.codomain().ambient_space().ngens() VR = X.value_ring() if VR is ZZ: R = [0] + [s * k for k in range(1, B + 1) for s in [1, -1]] iters = [iter(R) for _ in range(n)] else: # rational field iters = [QQ.range_by_height(B + 1) for _ in range(n)] pts = [] P = [0] * n try: pts.append(X(P)) except TypeError: pass for it in iters: next(it) i = 0 while i < n: try: a = VR(next(iters[i])) except StopIteration: if VR is ZZ: iters[i] = iter(R) else: # rational field iters[i] = QQ.range_by_height(B + 1) P[i] = next(iters[i]) # reset P[i] to 0 and increment i += 1 continue P[i] = a try: pts.append(X(P)) except TypeError: pass i = 0 pts.sort() return pts
def enum_projective_number_field(X,B, prec=53): """ Enumerates projective points on scheme ``X`` defined over a number field. Simply checks all of the points of absolute height of at most ``B`` and adds those that are on the scheme to the list. INPUT: - ``X`` - a scheme defined over a number field - ``B`` - a real number - ``prec`` - the precision to use for computing the elements of bounded height of number fields OUTPUT: - a list containing the projective points of ``X`` of absolute height up to ``B``, sorted. .. WARNING:: In the current implementation, the output of the [Doyle-Krumm] algorithm for elements of bounded height 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: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: u = QQ['u'].0 sage: K = NumberField(u^3 - 5,'v') sage: P.<x,y,z> = ProjectiveSpace(K, 2) sage: X = P.subscheme([x - y]) sage: enum_projective_number_field(X(K), 5^(1/3), prec=2^10) [(0 : 0 : 1), (-1 : -1 : 1), (1 : 1 : 1), (-1/5*v^2 : -1/5*v^2 : 1), (-v : -v : 1), (1/5*v^2 : 1/5*v^2 : 1), (v : v : 1), (1 : 1 : 0)] :: sage: u = QQ['u'].0 sage: K = NumberField(u^2 + 3, 'v') sage: A.<x,y> = ProjectiveSpace(K,1) sage: X=A.subscheme(x-y) sage: from sage.schemes.projective.projective_rational_point import enum_projective_number_field sage: enum_projective_number_field(X, 2) [(1 : 1)] """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if(is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError("Ambient space must be projective space over a number field") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError("Codomain must be projective space over a number field") R = X.codomain().ambient_space() pts = [] for P in R.points_of_bounded_height(B, prec): try: pts.append(X(P)) except TypeError: pass pts.sort() return pts
def enum_projective_finite_field(X): """ Enumerates projective points on scheme ``X`` defined over a finite field. INPUT: - ``X`` - a scheme defined over a finite field or a set of abstract rational points of such a scheme. OUTPUT: - a list containing the projective points of ``X`` over the finite field, sorted. EXAMPLES:: sage: F = GF(53) sage: P.<X,Y,Z> = ProjectiveSpace(2,F) sage: from sage.schemes.projective.projective_rational_point import enum_projective_finite_field sage: len(enum_projective_finite_field(P(F))) 2863 sage: 53^2+53+1 2863 :: sage: F = GF(9,'a') sage: P.<X,Y,Z> = ProjectiveSpace(2,F) sage: C = Curve(X^3-Y^3+Z^2*Y) sage: enum_projective_finite_field(C(F)) [(0 : 0 : 1), (0 : 1 : 1), (0 : 2 : 1), (1 : 1 : 0), (a + 1 : 2*a : 1), (a + 1 : 2*a + 1 : 1), (a + 1 : 2*a + 2 : 1), (2*a + 2 : a : 1), (2*a + 2 : a + 1 : 1), (2*a + 2 : a + 2 : 1)] :: sage: F = GF(5) sage: P2F.<X,Y,Z> = ProjectiveSpace(2,F) sage: enum_projective_finite_field(P2F) [(0 : 0 : 1), (0 : 1 : 0), (0 : 1 : 1), (0 : 2 : 1), (0 : 3 : 1), (0 : 4 : 1), (1 : 0 : 0), (1 : 0 : 1), (1 : 1 : 0), (1 : 1 : 1), (1 : 2 : 1), (1 : 3 : 1), (1 : 4 : 1), (2 : 0 : 1), (2 : 1 : 0), (2 : 1 : 1), (2 : 2 : 1), (2 : 3 : 1), (2 : 4 : 1), (3 : 0 : 1), (3 : 1 : 0), (3 : 1 : 1), (3 : 2 : 1), (3 : 3 : 1), (3 : 4 : 1), (4 : 0 : 1), (4 : 1 : 0), (4 : 1 : 1), (4 : 2 : 1), (4 : 3 : 1), (4 : 4 : 1)] ALGORITHM: Checks all points in projective space to see if they lie on X. .. WARNING:: If ``X`` is defined over an infinite field, this code will not finish! AUTHORS: - John Cremona and Charlie Turner (06-2010). """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if(is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError("Ambient space must be projective space over a finite") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError("Codomain must be projective space over a finite field") n = X.codomain().ambient_space().ngens()-1 F = X.value_ring() pts = [] for k in range(n+1): for c in cartesian_product_iterator([F for _ in range(k)]): try: pts.append(X(list(c)+[1]+[0]*(n-k))) except TypeError: pass pts.sort() return pts
def _call_(self, x): """ Construct a scheme from the data in ``x`` EXAMPLES: Let us first construct the category of schemes:: sage: S = Schemes(); S Category of schemes We create a scheme from a ring:: sage: X = S(ZZ); X # indirect doctest Spectrum of Integer Ring We create a scheme from a scheme (do nothing):: sage: S(X) Spectrum of Integer Ring We create a scheme morphism from a ring homomorphism.x:: sage: phi = ZZ.hom(QQ); phi Ring Coercion morphism: From: Integer Ring To: Rational Field sage: f = S(phi); f # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Ring Coercion morphism: From: Integer Ring To: Rational Field sage: f.domain() Spectrum of Rational Field sage: f.codomain() Spectrum of Integer Ring sage: S(f) # indirect doctest Affine Scheme morphism: From: Spectrum of Rational Field To: Spectrum of Integer Ring Defn: Ring Coercion morphism: From: Integer Ring To: Rational Field """ from sage.schemes.generic.scheme import is_Scheme if is_Scheme(x): return x from sage.schemes.generic.morphism import is_SchemeMorphism if is_SchemeMorphism(x): return x from sage.rings.morphism import is_RingHomomorphism from sage.rings.commutative_ring import is_CommutativeRing from sage.schemes.generic.spec import Spec if is_CommutativeRing(x): return Spec(x) elif is_RingHomomorphism(x): A = Spec(x.codomain()) return A.hom(x) else: raise TypeError( "No way to create an object or morphism in %s from %s" % (self, x))
def enum_projective_rational_field(X,B): r""" Enumerates projective, rational points on scheme ``X`` of height up to bound ``B``. INPUT: - ``X`` - a scheme or set of abstract rational points of a scheme; - ``B`` - a positive integer bound. OUTPUT: - a list containing the projective points of ``X`` of height up to ``B``, sorted. EXAMPLES:: sage: P.<X,Y,Z> = ProjectiveSpace(2,QQ) sage: C = P.subscheme([X+Y-Z]) sage: from sage.schemes.projective.projective_rational_point import enum_projective_rational_field sage: enum_projective_rational_field(C(QQ),6) [(-5 : 6 : 1), (-4 : 5 : 1), (-3 : 4 : 1), (-2 : 3 : 1), (-3/2 : 5/2 : 1), (-1 : 1 : 0), (-1 : 2 : 1), (-2/3 : 5/3 : 1), (-1/2 : 3/2 : 1), (-1/3 : 4/3 : 1), (-1/4 : 5/4 : 1), (-1/5 : 6/5 : 1), (0 : 1 : 1), (1/6 : 5/6 : 1), (1/5 : 4/5 : 1), (1/4 : 3/4 : 1), (1/3 : 2/3 : 1), (2/5 : 3/5 : 1), (1/2 : 1/2 : 1), (3/5 : 2/5 : 1), (2/3 : 1/3 : 1), (3/4 : 1/4 : 1), (4/5 : 1/5 : 1), (5/6 : 1/6 : 1), (1 : 0 : 1), (6/5 : -1/5 : 1), (5/4 : -1/4 : 1), (4/3 : -1/3 : 1), (3/2 : -1/2 : 1), (5/3 : -2/3 : 1), (2 : -1 : 1), (5/2 : -3/2 : 1), (3 : -2 : 1), (4 : -3 : 1), (5 : -4 : 1), (6 : -5 : 1)] sage: enum_projective_rational_field(C,6) == enum_projective_rational_field(C(QQ),6) True :: sage: P3.<W,X,Y,Z> = ProjectiveSpace(3,QQ) sage: enum_projective_rational_field(P3,1) [(-1 : -1 : -1 : 1), (-1 : -1 : 0 : 1), (-1 : -1 : 1 : 0), (-1 : -1 : 1 : 1), (-1 : 0 : -1 : 1), (-1 : 0 : 0 : 1), (-1 : 0 : 1 : 0), (-1 : 0 : 1 : 1), (-1 : 1 : -1 : 1), (-1 : 1 : 0 : 0), (-1 : 1 : 0 : 1), (-1 : 1 : 1 : 0), (-1 : 1 : 1 : 1), (0 : -1 : -1 : 1), (0 : -1 : 0 : 1), (0 : -1 : 1 : 0), (0 : -1 : 1 : 1), (0 : 0 : -1 : 1), (0 : 0 : 0 : 1), (0 : 0 : 1 : 0), (0 : 0 : 1 : 1), (0 : 1 : -1 : 1), (0 : 1 : 0 : 0), (0 : 1 : 0 : 1), (0 : 1 : 1 : 0), (0 : 1 : 1 : 1), (1 : -1 : -1 : 1), (1 : -1 : 0 : 1), (1 : -1 : 1 : 0), (1 : -1 : 1 : 1), (1 : 0 : -1 : 1), (1 : 0 : 0 : 0), (1 : 0 : 0 : 1), (1 : 0 : 1 : 0), (1 : 0 : 1 : 1), (1 : 1 : -1 : 1), (1 : 1 : 0 : 0), (1 : 1 : 0 : 1), (1 : 1 : 1 : 0), (1 : 1 : 1 : 1)] ALGORITHM: We just check all possible projective points in correct dimension of projective space to see if they lie on ``X``. AUTHORS: - John Cremona and Charlie Turner (06-2010) """ from sage.schemes.projective.projective_space import is_ProjectiveSpace if(is_Scheme(X)): if (not is_ProjectiveSpace(X.ambient_space())): raise TypeError("Ambient space must be projective space over the rational field") X = X(X.base_ring()) else: if (not is_ProjectiveSpace(X.codomain().ambient_space())): raise TypeError("Codomain must be projective space over the rational field") n = X.codomain().ambient_space().ngens() zero = (0,) * n pts = [] for c in cartesian_product_iterator([srange(-B,B+1) for _ in range(n)]): if gcd(c) == 1 and c > zero: try: pts.append(X(c)) except TypeError: pass pts.sort() return pts