# 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


329  329  from sage.misc.all import latex, prod, uniq, cached_method 
330  330  from sage.structure.unique_representation import UniqueRepresentation 
331  331  from sage.modules.free_module_element import vector 
332   from sage.rings.all import PolynomialRing, ZZ, QQ 
 332  from sage.rings.all import Infinity, PolynomialRing, ZZ, QQ 
333  333  from sage.rings.quotient_ring_element import QuotientRingElement 
334  334  from sage.rings.quotient_ring import QuotientRing_generic 
335  335  from sage.schemes.affine.affine_space import AffineSpace 
… 
… 

2747  2747  from sage.geometry.fan import discard_faces 
2748  2748  return ToricVariety(Fan(discard_faces(cones), check=False)) 
2749  2749  
2750   def toricPointCount(self,q): 
 2750  def count_points(self): 
2751  2751  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  
2758  2756  OUTPUT: 
2759  2757  
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:: 
2773  2761  
2774  2762  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() 
2778  2765  27 
2779   sage: V.toricPointCount(8) 
 2766  sage: V.change_ring(GF(8, "a")).count_points() 
2780  2767  729 
2781   sage: V.toricPointCount(101) 
 2768  sage: V.change_ring(GF(101)).count_points() 
2782  2769  1061208 
2783  2770  
2784   This is an example of what happens for a nonsmooth 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() 
2791  2775  Traceback (most recent call last): 
2792  2776  ... 
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. 
2794  2793  
2795  2794  AUTHORS: 
2796  2795  
2797    Beth Malmskog (20130714): 0.1 
2798    Adriana Salerno (20130714): 0.1 
2799    Yiwei She (20130714): 0.1 
2800    Christelle Vincent (20130714): 0.1 
2801    Ursula Whitcher (20130714): 0.1 
2802   
 2796   Beth Malmskog (20130714) 
 2797  
 2798   Adriana Salerno (20130714) 
 2799  
 2800   Yiwei She (20130714) 
 2801  
 2802   Christelle Vincent (20130714) 
 2803  
 2804   Ursula Whitcher (20130714) 
2803  2805  """ 
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[nk]*(q1)**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 * (q1)**(nk) for k, dk in enumerate(d)) 
2818  2814  
2819  2815  
2820  2816  def normalize_names(names=None, ngens=None, prefix=None, indices=None, 