Ticket #14891: trac_14891_reviewer.patch

File trac_14891_reviewer.patch, 4.7 KB (added by Andrey Novoseltsev, 9 years ago)
  • sage/schemes/toric/variety.py

    # HG changeset patch
    # User Andrey Novoseltsev <novoselt@gmail.com>
    # Date 1373921426 21600
    # Node ID 5d6fc764fbff1f75c52c21d3474ec1cdde6d30f9
    # Parent  c20f1a097a61f23b69855e7f938f86f0926f4447
    Reviewer's adjustments to the count of points on toric varieties.
    
    diff --git a/sage/schemes/toric/variety.py b/sage/schemes/toric/variety.py
    a b  
    329329from sage.misc.all import latex, prod, uniq, cached_method
    330330from sage.structure.unique_representation import UniqueRepresentation
    331331from sage.modules.free_module_element import vector
    332 from sage.rings.all import PolynomialRing, ZZ, QQ
     332from sage.rings.all import Infinity, PolynomialRing, ZZ, QQ
    333333from sage.rings.quotient_ring_element import QuotientRingElement
    334334from sage.rings.quotient_ring import QuotientRing_generic
    335335from sage.schemes.affine.affine_space import AffineSpace
     
    27472747        from sage.geometry.fan import discard_faces
    27482748        return ToricVariety(Fan(discard_faces(cones), check=False))
    27492749
    2750     def toricPointCount(self,q):
     2750    def count_points(self):
    27512751        r"""
    2752         This function computes the number of points in the ambient toric variety over F_q using the formula in Fulton [F], section 4.5, as long as the variety is smooth.
    2753 
    2754         INPUT:
    2755 
    2756         - ``q`` -- a positive prime integer or prime power.
    2757 
     2752        Return the number of points of ``self``.
     2753       
     2754        Over a finite field only smooth varieties are supported.
     2755       
    27582756        OUTPUT:
    27592757
    2760         - The number of points on the toric variety over Fq.
    2761 
    2762 
    2763         REFERENCES:
    2764 
    2765         .. [F] Fulton, W., "Introduction to Toric Varieties", Princeton University Press, 1993.
    2766 
    2767 
    2768         EXAMPLES:
    2769 
    2770         This example illustrates the point count for a few primes and powers of primes.
    2771 
    2772             ::
     2758        - an integer.
     2759
     2760        EXAMPLES::
    27732761
    27742762            sage: o = lattice_polytope.octahedron(3)
    2775             sage: cube = o.polar()
    2776             sage: V=ToricVariety(NormalFan(cube))
    2777             sage: V.toricPointCount(2)
     2763            sage: V = ToricVariety(FaceFan(o))
     2764            sage: V.change_ring(GF(2)).count_points()
    27782765            27
    2779             sage: V.toricPointCount(8)
     2766            sage: V.change_ring(GF(8, "a")).count_points()
    27802767            729
    2781             sage: V.toricPointCount(101)
     2768            sage: V.change_ring(GF(101)).count_points()
    27822769            1061208
    27832770
    2784         This is an example of what happens for a non-smooth variety.
    2785 
    2786             ::
    2787 
    2788             sage: o = lattice_polytope.octahedron(3)
    2789             sage: V=ToricVariety(NormalFan(o))
    2790             sage: V.toricPointCount(31)
     2771        Only smooth varieties over finite fields are currently handled::
     2772
     2773            sage: V = ToricVariety(NormalFan(o))
     2774            sage: V.change_ring(GF(2)).count_points()
    27912775            Traceback (most recent call last):
    27922776            ...
    2793             TypeError: The variety is not smooth
     2777            NotImplementedError: the variety is not smooth
     2778           
     2779        Over infinite fields the number of points is not very tricky::
     2780
     2781            sage: V.count_points()
     2782            +Infinity
     2783           
     2784        ALGORITHM:
     2785       
     2786        Uses the formula in Fulton [F]_, section 4.5.
     2787
     2788        REFERENCES:
     2789
     2790        ..  [F]
     2791            Fulton, W., "Introduction to Toric Varieties",
     2792            Princeton University Press, 1993.
    27942793
    27952794        AUTHORS:
    27962795
    2797         - Beth Malmskog (2013-07-14): 0.1
    2798         - Adriana Salerno (2013-07-14): 0.1
    2799         - Yiwei She (2013-07-14): 0.1
    2800         - Christelle Vincent (2013-07-14): 0.1
    2801         - Ursula Whitcher (2013-07-14): 0.1
    2802 
     2796        - Beth Malmskog (2013-07-14)
     2797       
     2798        - Adriana Salerno (2013-07-14)
     2799       
     2800        - Yiwei She (2013-07-14)
     2801       
     2802        - Christelle Vincent (2013-07-14)
     2803       
     2804        - Ursula Whitcher (2013-07-14)
    28032805        """
    2804         if self.is_smooth():
    2805             fan = self.fan()
    2806             cones=fan.cones()
    2807             n = self.dimension()
    2808             d = []
    2809             for i in range(n+1):
    2810                 d.append(len(cones[i]))
    2811             card = 0
    2812             for k in range(n+1):
    2813                 card = card + d[n-k]*(q-1)**k
    2814             return card
    2815         else:
    2816             raise TypeError, "The variety is not smooth"
    2817 
     2806        if not self.base_ring().is_finite():
     2807            return Infinity
     2808        if not self.is_smooth():
     2809            raise NotImplementedError("the variety is not smooth")
     2810        q = self.base_ring().order()       
     2811        n = self.dimension()
     2812        d = map(len, self.fan().cones())
     2813        return sum(dk * (q-1)**(n-k) for k, dk in enumerate(d))
    28182814
    28192815
    28202816def normalize_names(names=None, ngens=None, prefix=None, indices=None,