def _make_ToricVariety(self, name, coordinate_names): """ Construct a toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. OUTPUT: A :class:`toric variety <sage.schemes.toric.variety.ToricVariety_field>`. EXAMPLES:: sage: toric_varieties.A1() # indirect doctest 1-d affine toric variety """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = '_cached_'+name else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = '_cached_'+name+'_'+'_'.join(coordinate_names) if dict_key not in self.__dict__: fan = Fan(cones, rays, check=self._check) self.__dict__[dict_key] = \ ToricVariety(fan, coordinate_names=coordinate_names) return self.__dict__[dict_key]
def _make_ToricVariety(self, name, coordinate_names): """ Construct a toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. OUTPUT: A :class:`toric variety <sage.schemes.toric.variety.ToricVariety_field>`. EXAMPLES:: sage: toric_varieties.A1() # indirect doctest 1-d affine toric variety """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = "_cached_" + name else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = "_cached_" + name + "_" + "_".join(coordinate_names) if dict_key not in self.__dict__: fan = Fan(cones, rays, check=self._check) self.__dict__[dict_key] = ToricVariety(fan, coordinate_names=coordinate_names) return self.__dict__[dict_key]
def _make_CPRFanoToricVariety(self, name, coordinate_names, base_ring): r""" Construct a (crepant partially resolved) Fano toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. - ``base_ring`` -- a ring (default: `\QQ`). The base ring for the toric variety. OUTPUT: A :class:`CPR-Fano toric variety <sage.schemes.toric.fano_variety.CPRFanoToricVariety_field>`. EXAMPLES:: sage: toric_varieties.P2() # indirect doctest 2-d CPR-Fano toric variety covered by 3 affine patches """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = (name, base_ring) else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = (name, base_ring) + tuple(coordinate_names) if dict_key not in self.__dict__: polytope = LatticePolytope(rays, lattice=ToricLattice(len(rays[0]))) points = [tuple(_) for _ in polytope.points()] ray2point = [points.index(r) for r in rays] charts = [[ray2point[i] for i in c] for c in cones] self.__dict__[dict_key] = \ CPRFanoToricVariety(Delta_polar=polytope, coordinate_points=ray2point, charts=charts, coordinate_names=coordinate_names, base_ring=base_ring, check=self._check) return self.__dict__[dict_key]
def _make_CPRFanoToricVariety(self, name, coordinate_names, base_ring): """ Construct a (crepant partially resolved) Fano toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. - ``base_ring`` -- a ring (default: `\QQ`). The base ring for the toric variety. OUTPUT: A :class:`CPR-Fano toric variety <sage.schemes.toric.fano_variety.CPRFanoToricVariety_field>`. EXAMPLES:: sage: toric_varieties.P2() # indirect doctest 2-d CPR-Fano toric variety covered by 3 affine patches """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = (name, base_ring) else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = (name, base_ring) + tuple(coordinate_names) if dict_key not in self.__dict__: polytope = LatticePolytope(rays, lattice=ToricLattice(len(rays[0]))) points = [tuple(_) for _ in polytope.points()] ray2point = [points.index(r) for r in rays] charts = [ [ray2point[i] for i in c] for c in cones ] self.__dict__[dict_key] = \ CPRFanoToricVariety(Delta_polar=polytope, coordinate_points=ray2point, charts=charts, coordinate_names=coordinate_names, base_ring=base_ring, check=self._check) return self.__dict__[dict_key]
def _make_CPRFanoToricVariety(self, name, coordinate_names): """ Construct a (crepant partially resolved) Fano toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. OUTPUT: A :class:`CPR-Fano toric variety <sage.schemes.toric.fano_variety.CPRFanoToricVariety_field>`. EXAMPLES:: sage: toric_varieties.P2() # indirect doctest 2-d CPR-Fano toric variety covered by 3 affine patches """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = "_cached_" + name else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = "_cached_" + name + "_" + "_".join(coordinate_names) if dict_key not in self.__dict__: polytope = LatticePolytope(matrix(rays).transpose()) points = map(tuple, polytope.points().columns()) ray2point = [points.index(r) for r in rays] charts = [[ray2point[i] for i in c] for c in cones] self.__dict__[dict_key] = CPRFanoToricVariety( Delta_polar=polytope, coordinate_points=ray2point, charts=charts, coordinate_names=coordinate_names, check=self._check, ) return self.__dict__[dict_key]
def _make_CPRFanoToricVariety(self, name, coordinate_names): """ Construct a (crepant partially resolved) Fano toric variety and cache the result. INPUT: - ``name`` -- string. One of the pre-defined names in the ``toric_varieties_rays_cones`` data structure. - ``coordinate_names`` -- A string describing the names of the homogeneous coordinates of the toric variety. OUTPUT: A :class:`CPR-Fano toric variety <sage.schemes.toric.fano_variety.CPRFanoToricVariety_field>`. EXAMPLES:: sage: toric_varieties.P2() # indirect doctest 2-d CPR-Fano toric variety covered by 3 affine patches """ rays, cones = toric_varieties_rays_cones[name] if coordinate_names is None: dict_key = '_cached_'+name else: coordinate_names = normalize_names(coordinate_names, len(rays), DEFAULT_PREFIX) dict_key = '_cached_'+name+'_'+'_'.join(coordinate_names) if dict_key not in self.__dict__: polytope = LatticePolytope( matrix(rays).transpose() ) points = map(tuple, polytope.points().columns()) ray2point = [points.index(r) for r in rays] charts = [ [ray2point[i] for i in c] for c in cones ] self.__dict__[dict_key] = \ CPRFanoToricVariety(Delta_polar=polytope, coordinate_points=ray2point, charts=charts, coordinate_names=coordinate_names, check=self._check) return self.__dict__[dict_key]
def WP(self, *q, **kw): # Specific keyword arguments instead of **kw would be preferable, # later versions of Python might support specific (optional) keyword # arguments after *q. r""" Construct weighted projective `n`-space over a field. INPUT: - ``q`` -- a sequence of positive integers relatively prime to one another. The weights ``q`` can be given either as a list or tuple, or as positional arguments. Two keyword arguments: - ``K`` -- a field (default: `\QQ`). - ``names`` -- string or list (tuple) of strings (default 'z+'). See :func:`~sage.schemes.toric.variety.normalize_names` for acceptable formats. OUTPUT: - A :class:`toric variety <sage.schemes.toric.variety.ToricVariety_field>`. If `q=(q_0,\dots,q_n)`, then the output is the weighted projective space `\mathbb{P}(q_0,\dots,q_n)` over `K`. ``names`` are the names of the generators of the homogeneous coordinate ring. EXAMPLES: A hyperelliptic curve `C` of genus 2 as a subscheme of the weighted projective plane `\mathbb{P}(1,3,1)`:: sage: X = toric_varieties.WP([1,3,1], names='x y z') sage: X.inject_variables() Defining x, y, z sage: g = y^2-(x^6-z^6) sage: C = X.subscheme([g]); C Closed subscheme of 2-d toric variety covered by 3 affine patches defined by: -x^6 + z^6 + y^2 """ if len(q) == 1: # tuples and lists of weights are acceptable input if isinstance(q[0], (list, tuple)): q = q[0] q = list(q) m = len(q) # allow case q=[1]? (not allowed presently) if m < 2: raise ValueError("more than one weight must be provided (got %s)" % q) for i in range(m): try: q[i] = ZZ(q[i]) except (TypeError): raise TypeError("the weights (=%s) must be integers" % q) if q[i] <= 0: raise ValueError("the weights (=%s) must be positive integers" % q) if not gcd(q) == 1: raise ValueError("the weights (=%s) must be relatively prime" % q) # set default values for K and names K = QQ names = "z+" for key in kw: if key == "K": K = kw["K"] if K not in _Fields: raise TypeError("K (=%r) must be a field" % K) elif key == "names": names = kw["names"] names = normalize_names(names, m, DEFAULT_PREFIX) else: raise TypeError("got an unexpected keyword argument %r" % key) L = ToricLattice(m) L_sub = L.submodule([L(q)]) Q = L / L_sub rays = [] cones = [] w = range(m) L_basis = L.basis() for i in w: b = L_basis[i] v = Q.coordinate_vector(Q(b)) rays = rays + [v] w_c = w[:i] + w[i + 1 :] cones = cones + [tuple(w_c)] fan = Fan(cones, rays) return ToricVariety(fan, coordinate_names=names, base_field=K)
def WP(self, *q, **kw): # Specific keyword arguments instead of **kw would be preferable, # later versions of Python might support specific (optional) keyword # arguments after *q. r""" Construct weighted projective `n`-space over a field. INPUT: - ``q`` -- a sequence of positive integers relatively prime to one another. The weights ``q`` can be given either as a list or tuple, or as positional arguments. Two keyword arguments: - ``K`` -- a field (default: `\QQ`). - ``names`` -- string or list (tuple) of strings (default 'z+'). See :func:`~sage.schemes.toric.variety.normalize_names` for acceptable formats. OUTPUT: - A :class:`toric variety <sage.schemes.toric.variety.ToricVariety_field>`. If `q=(q_0,\dots,q_n)`, then the output is the weighted projective space `\mathbb{P}(q_0,\dots,q_n)` over `K`. ``names`` are the names of the generators of the homogeneous coordinate ring. EXAMPLES: A hyperelliptic curve `C` of genus 2 as a subscheme of the weighted projective plane `\mathbb{P}(1,3,1)`:: sage: X = toric_varieties.WP([1,3,1], names='x y z') sage: X.inject_variables() Defining x, y, z sage: g = y^2-(x^6-z^6) sage: C = X.subscheme([g]); C Closed subscheme of 2-d toric variety covered by 3 affine patches defined by: -x^6 + z^6 + y^2 """ if len(q)==1: # tuples and lists of weights are acceptable input if isinstance(q[0], (list, tuple)): q = q[0] q = list(q) m = len(q) # allow case q=[1]? (not allowed presently) if m < 2: raise ValueError("more than one weight must be provided (got %s)" % q) for i in range(m): try: q[i] = ZZ(q[i]) except(TypeError): raise TypeError("the weights (=%s) must be integers" % q) if q[i] <= 0: raise ValueError("the weights (=%s) must be positive integers" % q) if not gcd(q) == 1: raise ValueError("the weights (=%s) must be relatively prime" % q) # set default values for K and names K = QQ names = 'z+' for key in kw: if key == 'K': K = kw['K'] if K not in _Fields: raise TypeError("K (=%r) must be a field" % K) elif key == 'names': names = kw['names'] names = normalize_names(names, m, DEFAULT_PREFIX) else: raise TypeError("got an unexpected keyword argument %r" % key) L = ToricLattice(m) L_sub = L.submodule([L(q)]) Q = L/L_sub rays = [] cones = [] w = range(m) L_basis = L.basis() for i in w: b = L_basis[i] v = Q.coordinate_vector(Q(b)) rays = rays + [v] w_c = w[:i] + w[i+1:] cones = cones + [tuple(w_c)] fan = Fan(cones,rays) return ToricVariety(fan, coordinate_names=names, base_field=K)