csage.server.notebook.notebook Notebook q)q}q(U_Notebook__ulimitqUUsecureqU_Notebook__log_serverqU_Notebook__filenameqU:/home/was/talks/20071016-convergence/sage_notebook/nb.sobjqU_Notebook__confq (csage.server.notebook.server_conf ServerConfiguration q oq }q Uconfsq }q(Unumber_of_backupsqKUword_wrap_colsqKHU idle_timeoutqKU save_intervalqKUidle_check_intervalqKusbU_Notebook__server_logq]qU_Notebook__systemqNUportqMAU_Notebook__worksheetsq}q(Uadmin/4q(csage.server.notebook.worksheet Worksheet qoq}q(U_Worksheet__filenameqhU_Worksheet__ownerqUadminq U_Worksheet__cellsq!]q"(csage.server.notebook.cell Cell q#oq$}q%(U _Cell__inq&UU_Cell__worksheetq'hU_Cell__completionsq(U_Cell__out_htmlq)UU _Cell__idq*KU _Cell__outq+UUhas_new_outputq,U_Cell__versionq-KU _Cell__typeq.Uwrapq/U_Cell__interruptedq0ubaU_Worksheet__comp_is_runningq1U_Worksheet__saved_by_infoq2}q3U 1191414989q4h sU_Worksheet__attachedq5}q6U_Worksheet__dirq7U8/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/4q8U_Worksheet__queueq9]q:U_Worksheet__user_viewq;}qKU_Worksheet__viewersq?]q@U_Worksheet__nameqAUUntitledqBU_Worksheet__next_block_idqCKU!_Worksheet__last_compute_walltimeqDGA3χHU_Worksheet__collaboratorsqE]qFU_Worksheet__systemqGUsageqHU_Worksheet__last_editedqIGA3a/h qJubUadmin/3qK(hoqL}qM(hhKhh h!]qN((h#oqO}qP(h&U#var('x,y,z') show(x**2+y**2==z**2) qQU_Cell__introspect_htmlqRU!
qSh'hLh(U_Cell__introspectqTh)Uh*KU_Cell__is_htmlqUU_before_preparseqVUoos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/3/cells/0")
var('x,y,z')
show(x**2+y**2==z**2)qWh+UG
{y}^{2} + {x}^{2} = {z}^{2}
qXh,h-KU _Cell__sageqYcsage.interfaces.sage0 reduce_load_Sage qZ)Rq[U_Cell__url_to_selfq\U/home/admin/3/cells/0q]h.h/U _Cell__timeq^h0ub(h#oq_}q`(h&U"%latex $$\sage{x**2+y**2==z**2}$$qahRU!
qbh'hLh(hTh)U/qch*KhUhVUoos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/3/cells/1")
%latex

$$\sage{x**2+y**2==z**2}$$qdh+U

qeh,h-KhYh[h\U/home/admin/3/cells/1qfh.Uwrapqgh^h0ub(h#oqh}qi(h&Uh*Kh(hTh)Uh'hLh+Uh,h-Kh.h/h^h0ub(h#oqj}qk(h&Uh'hLh(h)Uh*Kh+Uh,h-Kh.h/h0ubeU_Worksheet__synchroqlKh1h2}qm(U
1191391957qnh U
1191392186qoh U
1191392168qph uh7U8/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/3qqh5}qrU_Worksheet__last_autosaveqsGAշh;}qth Ksh=h>Kh?]quhAhBhCKhDGAg&hE]qvh9]qwhGhHhIGA՝h qxubUadmin/2qy(hoqz}q{(hh hsGAQIh;}q|h KsU_Worksheet__confq}(csage.server.notebook.worksheet_conf
WorksheetConfiguration
q~oq}qUconfsq}qsbh2}q(U
1191378344qh U
1191378005qh U
1191393789qh U
1191352032qh U
1191365390qh U
1191391421qh U
1191384677qh U
1191351791qh U
1191377338qh U
1191351096qh U
1191378775qh U
1191387440qh U
1191376949qh U
1191352237qh U
1191416040qh U
1191376687qh U
1191377840qh U
1191366346qh U
1191415736qh U
1191352579qh U
1191419483qh U
1191378565qh U
1191377766qh U
1191417290qh U
1191415117qh U
1191416222qh U
1191376319qh U
1191366578qh U
1191365859qh U
1191379425qh U
1191416586qh U
1192576631qUadminqU
1191419287qh U
1191351326qh U
1191450192qUadminqU
1191450372qhU
1191366163qh U
1191449849qhU
1191385790qh U
1191393432qh U
1191417085qh U
1191450575qhU
1191384491qh U
1191421005qh U
1191384273qh U
1191416766qh U
1191392829qh U
1191377831qh U
1191352785qh U
1191377547qh uhE]qh5}qh?]qhAUdata!qU_Worksheet__sageqhZ)RqhIGAQhqhhyh7U8/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2qh>KihDGAn\h=h!]q((h#oq}q(h&TC#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0), \
                     (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()qhRU!
qh'hzh(hTh)Uh*Kh^hUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/1")
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0),                      (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()qh+U
h,h-KhYhh.Uwrapqh0ub(h#oq}q(h&T#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax=None, **kwds):
        if Cmax is None: Cmax = self._n
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return line(v2, rgbcolor=(0,0,1)) + line(voo, rgbcolor=(0.8,0,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds):
        if Cmax is None: Cmax = self._n
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) \
                 + line(v,rgbcolor=clr) + redline(0, Cmax) # + point(v,rgbcolor=(0,0,0), pointsize=3) 

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])qhRU!
qh'hzh(hTh)Uh*Kh^hUhVTZos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/2")
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax=None, **kwds):
        if Cmax is None: Cmax = self._n
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return line(v2, rgbcolor=(0,0,1)) + line(voo, rgbcolor=(0.8,0,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds):
        if Cmax is None: Cmax = self._n
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)                  + line(v,rgbcolor=clr) + redline(0, Cmax) # + point(v,rgbcolor=(0,0,0), pointsize=3) 

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])qh+U
h,h-K8hYhh.Uwrapqh0ub(h#oq}q(h&U=# make curve
time e37a = SatoTate(EllipticCurve('37a'), 10^6)qhRU!
qh'hzh(hTh)Uh*K,hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/44")
# make curve
time e37a = SatoTate(EllipticCurve('37a'), 10^6)qh+UW
computed aplist  4.928308
time to normalize  0.084005
Time: CPU 6.77 s, Wall: 15.99 s
qh,h-KhYhh.hh^h0ub(h#oq}q(h&U^show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qhRU!
qh'hzh(hTh)U.qh*K/hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/47")
show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qh+U
h,h-KhYhh\U/home/admin/2/cells/47qh.hh^h0ub(h#oq}q(h&U^show(e37a.plot_Delta(10^4, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qhRU!
qh'hzh(hTh)U.qh*K-hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/45")
show(e37a.plot_Delta(10^4, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qh+U
h,h-KhYhh\U/home/admin/2/cells/45qh.hh^h0ub(h#oq}q(h&U^show(e37a.plot_Delta(10^6, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qhRU!
qh'hzh(hTh)U.qh*K.hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/46")
show(e37a.plot_Delta(10^6, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qh+U
h,h-KhYh[h\U/home/admin/2/cells/46qh.h/h^h0ub(h#oq}q(h&U=# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)qhRU!
qh'hzh(hTh)Uh*K)hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/41")
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)qh+UV
computed aplist  5.356334
time to normalize  0.072004
Time: CPU 6.06 s, Wall: 8.39 s
qh,h-KhYh[h.h/h^h0ub(h#oq}q(h&U\show(S0.plot_Delta(10^6, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qhRU!
qh'hzh(hTh)U/qhUh*K*U_word_being_completedqU
S0.plot_DeqhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/42")
show(S0.plot_Delta(10^6, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])qh+U
h,h-K
hYh[h0h.h/h^h\U/home/admin/2/cells/42qub(h#oq}q(h&Ugshow(S0.plot_Delta(10^5, plot_points=100, max_points=100, L_norm=oo), ymax=0.1, ymin=0, figsize=[10,3])qhRU!
qh'hzh(hTh)U.qh*K+hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/43")
show(S0.plot_Delta(10^5, plot_points=100, max_points=100, L_norm=oo), ymax=0.1, ymin=0, figsize=[10,3])qh+U
h,h-KhYh[h\U/home/admin/2/cells/43qh.Uwrapqh^h0ub(h#oq}r(h&U;# make curve
time S0 = SatoTate(EllipticCurve('37a'), 10^6)rhRU!
rh'hzh(hTh)Uh*K1hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/49")
# make curve
time S0 = SatoTate(EllipticCurve('37a'), 10^6)rh+UV
computed aplist  5.452341
time to normalize  0.088005
Time: CPU 6.23 s, Wall: 7.71 s
rh,h-KhYh[h.Uwraprh^h0ub(h#or}r(h&Utime P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rhRU!
r	h'hzh(hTh)Uh*K2hUhVT2os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/50")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r
h+UE
Time: CPU 3.36 s, Wall: 3.82 s
CPU time: 8.47 s,  Wall time: 9.97 s
rh,h-KhYh[h\U/home/admin/2/cells/50rh.Uwrapr
h^h0ub(h#or}r(h&UF#fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rhRU!
rh'hzh(hTh)Uh*K0hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/48")
#fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rh+U
h,h-KhYh[h.Uwraprh^h0ub(h#or}r(h&Ushowtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*K3hUhVU^os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/51")
showtheta(P0+P1)rh+U
h,h-KhYh[h\U/home/admin/2/cells/51rh.h/h^h0ub(h#or}r(h&U# make curve
time S0 = SatoTate(EllipticCurve('11a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rhRU!
rh'hzh(hTh)Uh*K6hUhVTHos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/54")
# make curve
time S0 = SatoTate(EllipticCurve('11a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rh+U
computed aplist  6.004376
time to normalize  0.084006
Time: CPU 6.75 s, Wall: 8.61 s
Time: CPU 10.05 s, Wall: 11.99 s
Time: CPU 6.80 s, Wall: 7.73 s
r h,h-KhYh[h.Uwrapr!h^h0ub(h#or"}r#(h&Ushowtheta(P0+P1)r$hRU!
r%h'hzh(hTh)U.r&h*K5hUhVU^os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/53")
showtheta(P0+P1)r'h+U
h,h-KhYh[h\U/home/admin/2/cells/53r(h.h/h^h0ub(h#or)}r*(h&U# make curve
time S0 = SatoTate(EllipticCurve('389a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r+hRU!
r,h'hzh(hTh)Uh*K:hUhVTIos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/58")
# make curve
time S0 = SatoTate(EllipticCurve('389a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r-h+U
computed aplist  5.812363
time to normalize  0.088006
Time: CPU 6.58 s, Wall: 8.91 s
Time: CPU 10.13 s, Wall: 14.74 s
Time: CPU 7.09 s, Wall: 9.34 s
r.h,h-KhYh[h.Uwrapr/h^h0ub(h#or0}r1(h&Ushowtheta(P0+P1)r2hRU!
r3h'hzh(hTh)U.r4h*K9hUhVU^os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/57")
showtheta(P0+P1)r5h+U
h,h-KhYh[h\U/home/admin/2/cells/57r6h.h/h^h0ub(h#or7}r8(h&U# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r9hRU!
r:h'hzh(hTh)Uh*K8hUhVTJos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/56")
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r;h+U
computed aplist  5.724357
time to normalize  0.084005
Time: CPU 6.44 s, Wall: 8.98 s
Time: CPU 10.18 s, Wall: 14.21 s
Time: CPU 6.98 s, Wall: 9.24 s
r<h,h-KhYh[h.Uwrapr=h^h0ub(h#or>}r?(h&Ushowtheta(P0+P1)r@hRU!
rAh'hzh(hTh)U.rBh*KrHh'hzh(hTh)Uh*KBhUhVTJos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/66")
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rIh+U
computed aplist  5.372336
time to normalize  0.076004
Time: CPU 6.09 s, Wall: 7.20 s
Time: CPU 9.86 s, Wall: 12.41 s
Time: CPU 7.06 s, Wall: 8.90 s
rJh,h-KhYh[h.UwraprKh^h0ub(h#orL}rM(h&UEfit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rNhRU!
rOh'hzh(hTh)Uh*KVhUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/86")
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rPh+U
h,h-KhYh[h.UwraprQh^h0ub(h#orR}rS(h&Ushowtheta(P0 + P1 + fit)rThRU!
rUh'hzh(hTh)U.rVh*KUhUhVUfos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/85")
showtheta(P0 + P1 + fit)rWh+U
h,h-KhYh[h\U/home/admin/2/cells/85rXh.h/h^h0ub(h#orY}rZ(h&U%time
time S0 = SatoTate(EllipticCurve([19,234]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r[hRU!
r\h'hzh(hTh)Uh*KThUhVTios.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/84")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
time S0 = SatoTate(EllipticCurve([19,234]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))r]h+U
computed aplist  5.416338
time to normalize  0.076005
Time: CPU 6.09 s, Wall: 7.23 s
Time: CPU 9.72 s, Wall: 11.44 s
Time: CPU 6.84 s, Wall: 8.45 s
CPU time: 22.64 s,  Wall time: 27.12 s
r^h,h-KhYh[h.h/h^h0ub(h#or_}r`(h&UEfit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rahRU!
rbh'hzh(hTh)Uh*KXhUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/88")
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rch+U
h,h-KhYh[h.h/h^h0ub(h#ord}re(h&Ushowtheta(P0 + P1 + fit)rfhRU!
rgh'hzh(hTh)U.rhh*KWhUhVUfos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/87")
showtheta(P0 + P1 + fit)rih+U
h,h-KhYh[h\U/home/admin/2/cells/87rjh.Uwraprkh^h0ub(h#orl}rm(h&Utime S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rnhRU!
roh'hzh(hTh)Uh*K[hUhVTlos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/91")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rph+U
computed aplist  5.704355
time to normalize  0.116007
Time: CPU 9.35 s, Wall: 9.74 s
Time: CPU 6.41 s, Wall: 6.47 s
CPU time: 22.27 s,  Wall time: 23.47 s
rqh,h-KhYh[h.Uwraprrh^h0ub(h#ors}rt(U	_Cell__inruUqlog=math.log
r = 4.0
fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5))rvU_Cell__introspect_htmlrwU!
rxU_Cell__worksheetryhzU_Cell__completionsrzU_Cell__introspectr{U_Cell__out_htmlr|UU	_Cell__idr}KdU_Cell__is_htmlr~U_before_preparserUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/100")
log=math.log
r = 4.0
fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5))rU
_Cell__outrU
Uhas_new_outputrU_Cell__versionrKU_Cell__sagerh[U_Cell__typerhU_Cell__timerU_Cell__interruptedrub(h#or}r(h&UIfit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rhRU!
rh'hzh(hTh)Uh*K\hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/92")
fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rh+U
h,h-KhYh[h.Uwraprh^h0ub(h#or}r(h&U&showtheta(P0 + P1 + fit + fit_watkins)rhRU!
rh'hzh(hTh)U/rh*KZhUhVUtos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/90")
showtheta(P0 + P1 + fit + fit_watkins)rh+U
h,h-KhYh[h\U/home/admin/2/cells/90rh.Uwraprh^h0ub(h#or}r(juUjyhzjzj|Uj}KhjUjjKjhjub(h#or}r(juUtime S3 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rjwU!
rjyhzjzj{j|Uj}Kgj~jThos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/103")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S3 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))rjU
computed aplist  5.212326
time to normalize  0.088006
Time: CPU 9.36 s, Wall: 9.63 s
Time: CPU 6.62 s, Wall: 6.74 s
CPU time: 21.85 s,  Wall time: 22.40 s
rjjKjh[U_Cell__url_to_selfrU/home/admin/2/cells/103rjhjjub(h#or}r(juUfr = 3.0
fit_watkins = plot(lambda x: 1/2 - (1/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5))rjwU!
rjyhzjzj{j|Uj}Kfj~jUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/102")
r = 3.0
fit_watkins = plot(lambda x: 1/2 - (1/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5))rjU
jjKjh[jhjjub(h#or}r(h&U$showtheta(P0_3 + P1_3 + fit_watkins)rjwU!
rh'hzh(j{h)U.rh*KYj~jUros.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/89")
showtheta(P0_3 + P1_3 + fit_watkins)rh+U
h,h-Kjh[jU/home/admin/2/cells/89rh.Uwraprjh0ub(h#or}r(h&Uh'hzh(h)Uh*KSh+Uh,h-Kh.h/h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KAhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/65")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.708357
time to normalize  0.084005
Time: CPU 9.96 s, Wall: 13.32 s
Time: CPU 6.73 s, Wall: 9.17 s
Time: CPU 0.21 s, Wall: 0.24 s
CPU time: 23.33 s,  Wall time: 31.74 s
rh,h-KhYh[h\U/home/admin/2/cells/65rh.h/h^h0ub(h#or}r(h&Uh'hzh(h)Uh*K;h+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KEh+Uh,h-Kh.h/h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KDhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/68")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.496343
time to normalize  0.080005
Time: CPU 10.03 s, Wall: 12.37 s
Time: CPU 6.89 s, Wall: 9.98 s
Time: CPU 0.22 s, Wall: 0.25 s
CPU time: 23.34 s,  Wall time: 31.16 s
rh,h-KhYh[h\U/home/admin/2/cells/68rh.h/h^h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KGhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/71")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.60835
time to normalize  0.084005
Time: CPU 9.56 s, Wall: 11.41 s
Time: CPU 6.55 s, Wall: 7.51 s
Time: CPU 0.22 s, Wall: 0.22 s
CPU time: 22.69 s,  Wall time: 26.81 s
rh,h-KhYh[h\U/home/admin/2/cells/71rh.h/h^h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KRhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/82")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.44034
time to normalize  0.068004
Time: CPU 9.69 s, Wall: 11.92 s
Time: CPU 6.94 s, Wall: 8.90 s
Time: CPU 0.19 s, Wall: 0.20 s
CPU time: 22.93 s,  Wall time: 28.44 s
rh,h-KhYh[h\U/home/admin/2/cells/82rh.h/h^h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KQhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/81")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.816364
time to normalize  0.084005
Time: CPU 9.72 s, Wall: 12.06 s
Time: CPU 6.70 s, Wall: 8.50 s
Time: CPU 0.21 s, Wall: 0.23 s
CPU time: 23.30 s,  Wall time: 29.06 s
rh,h-KhYh[h\U/home/admin/2/cells/81rh.Uwraprh^h0ub(h#or}r(h&Ucfit = plot(lambda x: 1/2 - (19/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
showtheta(P0 + P1 + fit)rhRU!
rh'hzh(hTh)U/rh*KchUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/99")
fit = plot(lambda x: 1/2 - (19/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
showtheta(P0 + P1 + fit)rh+U
h,h-K
hYh[h\U/home/admin/2/cells/99rh.Uwraprh^h0ub(h#or}r(h&Ttime S0 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KPhUhVT	os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/80")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S0 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  6.008374
time to normalize  0.084004
Time: CPU 9.82 s, Wall: 13.54 s
Time: CPU 6.54 s, Wall: 7.59 s
Time: CPU 0.20 s, Wall: 0.43 s
CPU time: 23.27 s,  Wall time: 29.89 s
rh,h-KhYh[h\U/home/admin/2/cells/80rh.Uwraprh^h0ub(h#or}r(h&Ucfit = plot(lambda x: 1/2 - (28/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
showtheta(P0 + P1 + fit)rhRU!
rh'hzh(hTh)U/rh*KOhUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/79")
fit = plot(lambda x: 1/2 - (28/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
showtheta(P0 + P1 + fit)rh+U
h,h-KhYh[h\U/home/admin/2/cells/79rh.Uwraprh^h0ub(h#or}r(h&Uh'hzh(h)Uh*KNh+Uh,h-Kh.h/h0ub(h#or}r(h&Ttime S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6)
time P0 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rhRU!
rh'hzh(hTh)U.rh*KbhUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/98")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6)
time P0 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
time showtheta(P0+P1)rh+U
computed aplist  5.632352
time to normalize  0.080005
Time: CPU 16.38 s, Wall: 45.97 s
Time: CPU 11.85 s, Wall: 18.06 s
Time: CPU 1.67 s, Wall: 3.15 s
CPU time: 36.25 s,  Wall time: 74.68 s
rh,h-KhYh[h\U/home/admin/2/cells/98rh.h/h^h0ub(h#or}r(h&UEfit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rhRU!
rh'hzh(hTh)Uh*KahUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/97")
fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0))rh+U
h,h-K	hYh[h.Uwraprh^h0ub(h#or}r(h&Ushowtheta(P0 + P1 + fit)rhRU!
rh'hzh(hTh)U.r	h*K`hUhVUfos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/96")
showtheta(P0 + P1 + fit)r
h+U
h,h-K	hYh[h\U/home/admin/2/cells/96rh.h/h^h0ub(h#or}r
(h&Uh'hzh(h)Uh*K_h+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*K^h+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*K]h+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KMh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KLh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KKh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KJh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KIh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KHh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'hzh(h)Uh*KCh+Uh,h-Kh.h/h0ub(h#or }r!(h&Uh'hzh(h)Uh*K7h+Uh,h-Kh.h/h0ub(h#or"}r#(h&Uh'hzh(h)Uh*K4h+Uh,h-Kh.h/h0ub(h#or$}r%(h&U?# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 5*10^6)r&hRU!
r'h'hzh(hTh)Uh*K#hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/35")
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 5*10^6)r(h+UX
computed aplist  50.23914
time to normalize  1.796112
Time: CPU 59.98 s, Wall: 72.94 s
r)h,h-K2hYh[h\U/home/admin/2/cells/35r*h.h/h^h0ub(h#or+}r,(h&Utime P0 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))r-hRU!
r.h'hzh(hTh)Uh*K&hUhVT8os.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/38")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P0 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))r/h+UI
Time: CPU 12.93 s, Wall: 14.71 s
CPU time: 29.03 s,  Wall time: 34.74 s
r0h,h-KhYh[h.Uwrapr1h^h0ub(h#or2}r3(h&UGfit = plot(lambda x: 1/2 - 1/math.log(x), 10, 5*10^6, rgbcolor=(0,0,0))r4hRU!
r5h'hzh(hTh)Uh*K(hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/40")
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 5*10^6, rgbcolor=(0,0,0))r6h+U
h,h-KhYh[h\U/home/admin/2/cells/40r7h.Uwrapr8h^h0ub(h#or9}r:(h&Ushowtheta(P0+P1+fit)r;hRU!
r<h'hzh(hTh)U/r=hUh*K$hUshowthr>hVUbos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/36")
showtheta(P0+P1+fit)r?h+U
h,h-K0hYh[h0h.h/h^h\U/home/admin/2/cells/36r@ub(h#orA}rB(h&Uh'hzh(h)Uh*K?h+Uh,h-Kh.h/h0ub(h#orC}rD(h&Uh'hzh(h)Uh*K>h+Uh,h-Kh.h/h0ub(h#orE}rF(h&Uh'hzh(h)Uh*K=h+Uh,h-Kh.h/h0ub(h#orG}rH(h&Uh'hzh(h)Uh*K'h+Uh,h-Kh.h/h0ub(h#orI}rJ(h&TXS0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))rKhRU!
rLh'hzh(hTh)Uh*Kh^hUhVTos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/3")
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,  -20067762415575526585033208209338542750930230312178956502,  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))rMh+U
h,h-K
hYh[h.h/h0ub(h#orN}rO(h&Ua%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)rPhRU!
rQh'hzh(hTh)U.rRh*Kh^hUhVUos.chdir("/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/cells/8")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)rSh+U&
CPU time: 0.18 s,  Wall time: 0.20 s
rTh,h-KhYh[h\U/home/admin/2/cells/8rUh.h/h0ub(h#orV}rW(h&UW%time
P1 = S1.plot_theta_interval(10^6,plot_points=15,max_points=50)
P1.show(dpi=200)rXh'hzh(h)Uh*Kh+Uh,h-Kh.h/hYNh0ub(h#orY}rZ(h&UW%time
P2 = S2.plot_theta_interval(10^6,plot_points=15,max_points=50)
P2.show(dpi=200)r[h'hzh(h)Uh*Kh+Uh,h-KhYNh.h/h0ub(h#or\}r](h&UW%time
P3 = S3.plot_theta_interval(10^6,plot_points=15,max_points=50)
P3.show(dpi=200)r^h'hzh(h)Uh*Kh+Uh,h-KhYNh.h/h0ub(h#or_}r`(h&UW%time
P8 = S8.plot_theta_interval(10^6,plot_points=15,max_points=50)
P8.show(dpi=200)rah'hzh(h)Uh*K"h+Uh,h-KhYNh.h/h0ub(h#orb}rc(h&Uf%time
P0oo = S0.plot_theta_interval(10^6,plot_points=15,max_points=50, L_norm=oo)
P0oo.show(dpi=200)rdh'hzh(h)Uh*Kh+Uh,h-KhYNh.h/h0ub(h#ore}rf(h&Uf%time
P1oo = S1.plot_theta_interval(10^6,plot_points=15,max_points=50, L_norm=oo)
P1oo.show(dpi=200)rgh'hzh(h)Uh*Kh+Uh,h-KhYNh.h/h0ub(h#orh}ri(h&Uf%time
P2oo = S2.plot_theta_interval(10^6,plot_points=15,max_points=50, L_norm=oo)
P2oo.show(dpi=200)rjh'hzh(h)Uh*K	h+Uh,h-KhYNh.h/h0ub(h#ork}rl(h&Uf%time
P3oo = S3.plot_theta_interval(10^6,plot_points=15,max_points=50, L_norm=oo)
P3oo.show(dpi=200)rmh'hzh(h)Uh*K
h+Uh,h-KhYNh.h/h0ub(h#orn}ro(h&Uf%time
P8oo = S8.plot_theta_interval(10^6,plot_points=15,max_points=50, L_norm=oo)
P8oo.show(dpi=200)rph'hzh(h)Uh*Kh+Uh,h-KhYNh.h/h0ubehlMh1hGUsagerqhCKh9]rrubUadmin/1rs(hort}ru(U_Worksheet__filenamervjsU_Worksheet__ownerrwUadminrxU_Worksheet__cellsry]rz((h#or{}r|(U	_Cell__inr}U%latex

\sqrt{\sin(\pi)}r~U_Cell__introspect_htmlrU!
rU_Cell__worksheetrjtU_Cell__completionsrU_Cell__introspectrU_Cell__out_htmlrU/rU	_Cell__idrKU_Cell__is_htmlrU_before_preparserUtos.chdir("/mnt/hgfs/osx/talks/20070930-sato_tate/sage_notebook/worksheets/admin/1/cells/0")
%latex

\sqrt{\sin(\pi)}rU
_Cell__outrU

rUhas_new_outputrU_Cell__versionrKU_Cell__sagerh[U_Cell__url_to_selfrU/home/admin/1/cells/0rU_Cell__typerUwraprU_Cell__timerU_Cell__interruptedrub(h#or}r(j}UjjtjjUjKjUjjKjUwraprjubeU_Worksheet__synchrorKU_Worksheet__comp_is_runningrU_Worksheet__dirrUG/mnt/hgfs/osx/talks/20070930-sato_tate/sage_notebook/worksheets/admin/1rU_Worksheet__attachedr}rU_Worksheet__last_autosaverGAѿ{4U_Worksheet__user_viewr}rjxKsU_Worksheet__docbrowserrU_Worksheet__next_idrKU_Worksheet__viewersr]rU!_Worksheet__last_compute_walltimerGAѿB0iU_Worksheet__namerUUntitledrU_Worksheet__next_block_idrKU_Worksheet__systemrhHU_Worksheet__collaboratorsr]rU_Worksheet__queuer]rU_Worksheet__saved_by_infor}rU
1191047006rjxsU_Worksheet__last_editedrGAѿ{'jxrubUadmin/0r(hor}r(U_Worksheet__filenamerjU_Worksheet__ownerrUadminrU_Worksheet__cellsr]r((h#or}r(U	_Cell__inrUVreset('sqrt,pi')
var('x,a,T')
assume(T-a>0)
show( (2/pi)*integral(sqrt(1-x^2),x,a,T) )rU_Cell__introspect_htmlrU!
rU_Cell__worksheetrjU_Cell__completionsrU_Cell__introspectrU_Cell__out_htmlrUU	_Cell__idrKU_Cell__timerU_Cell__is_htmlrU_before_preparserUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/0")
reset('sqrt,pi')
var('x,a,T')
assume(T-a>0)
show( (2/pi)*integral(sqrt(1-x^2),x,a,T) )rU
_Cell__outrU
\frac{{2 \cdot \left( \frac{\sin^{-1} \left( T \right) + {T \cdot \left( \sqrt{ 1 - {T}^{2} } \right)}}{2} - \frac{\sin^{-1} \left( a \right) + {a \cdot \left( \sqrt{ 1 - {a}^{2} } \right)}}{2} \right)}}{\pi}
rUhas_new_outputrU_Cell__versionrKU _Cell__sagerh[U_Cell__url_to_selfrU/home/admin/0/cells/0rU _Cell__typerUwraprU_Cell__interruptedrub(h#or}r(jTC#auto def dist(v, b, left=-1.0r, right=1.0r): """ We divide the interval between left (default: 0) and right (default: pi) up into b bins. For each number in v (which must left and right), we find which bin it lies in and add this to a counter. This function then returns the bins and the number of elements of v that lie in each one. ALGORITHM: To find the index of the bin that a given number x lies in, we multiply x by b/length and take the floor. """ length = right - left normalize = float(b/length) vals = {} d = dict([(i,0) for i in range(b)]) for x in v: n = int(normalize*(float(x)-left)) d[n] += 1 return d, len(v) def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r): s = Graphics() left = float(left); right = float(right) length = right - left w = length/b k = 0 for i, n in d.iteritems(): k += n # ith bin has n objects in it. s += polygon([(w*i+left,0), (w*(i+1)+left,0), \ (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ rgbcolor=(0,0,0.5)) return s def semicircle0(): alpha = 2.0r / float(pi) def f(x): return alpha * math.sqrt(1-x^2) return plot(f, -1,1,rgbcolor=(0.5,0,0)) semicircle = semicircle0()rjU!
rjjjjjUjKjjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/1")
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0),                      (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()rjU
jjKjh[jh/jub(h#or}r(jT#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]rjU!
rjjjjjUjKjjjTGos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/2")
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]rjU
jjKjh[jh/jub(h#or}r(h&U# make curve
time S0 = SatoTate(EllipticCurve('5077a'))
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)rhRU!
rh'jh(hTh)Uh*KahUhVUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/97")
# make curve
time S0 = SatoTate(EllipticCurve('5077a'))
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)rh+U
Time: CPU 0.02 s, Wall: 0.01 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field
Time: CPU 1.48 s, Wall: 2.23 s
rh,h-KhYh[h\U/home/admin/0/cells/97rh.Uwraprh^h0ub(h#or}r(h&US0.Delta(10^4, -1, 1)rhRU!
rh'jh(hTh)Uh*KehUhVUoos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/101")
S0.Delta(10^4, -1, 1)rh+U/
(0.024699554129187312, 0.0049363701843274316)
rh,h-KhYh[h.Uwraprh^h0ub(h#or}r(h&U	P0.show()rhRU!
rh'jh(hTh)U.rh*KbhUhVUbos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/98")
P0.show()rh+U
h,h-KhYh[h\U/home/admin/0/cells/98rh.h/h^h0ub(h#or}r(h&Uh'jh(h)Uh*Kdh+Uh,h-Kh.h/h0ub(h#or}r(h&Uh'jh(h)Uh*Kch+Uh,h-Kh.h/h0ub(h#or}r(jTa#auto
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))

S = [S0,S1,S2,S3,S4,S5,S6,S7,S8]
CM = SatoTate(EllipticCurve('32a'))
Equest = SatoTate(EllipticCurve('72a1'))   # non-CM but doesn't satisfy hypo of Taylor's theorem
# Our curves S satisfy Taylor's theorem
#[min([e for p,e in X._E.conductor().factor()]) for X in S]rjU!
rjjjjjUjKjjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/3")
#auto
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))

S = [S0,S1,S2,S3,S4,S5,S6,S7,S8]
CM = SatoTate(EllipticCurve('32a'))
Equest = SatoTate(EllipticCurve('72a1'))   # non-CM but doesn't satisfy hypo of Taylor's theorem
# Our curves S satisfy Taylor's theorem
#[min([e for p,e in X._E.conductor().factor()]) for X in S]rjU
jjKjNjUwraprjub(h#or}r(jUcv = [S28.histogram(10^n,10*n) for n in range(1,7)]
G = graphics_array(v,3,2)
G.show(xmin=-1,ymin=0)rjU!
rjjjjjU-rjKjjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/4")
v = [S28.histogram(10^n,10*n) for n in range(1,7)]
G = graphics_array(v,3,2)
G.show(xmin=-1,ymin=0)rjU
jjKjh[jU/home/admin/0/cells/4rjUwraprjub(h#or}r(jUZv = [S28.qqplot(10^n) for n in range(2,7)]
G = graphics_array(v,2,3)
G.show(xmin=0,ymin=0)rjU!
r	jjjjjU-r
jKjjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/5")
v = [S28.qqplot(10^n) for n in range(2,7)]
G = graphics_array(v,2,3)
G.show(xmin=0,ymin=0)rjU
jjKjh[jU/home/admin/0/cells/5rjUwrapr
jub(h#or}r(jUv = [S28.plot_theta_interval(n,plot_points=15,max_points=50) for n in [10^3,10^4,10^5,10^6,2*10^6,3*10^6]]
show(graphics_array(v,2,3),ymin=0)rjKjjjUjjjjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/6")
v = [S28.plot_theta_interval(n,plot_points=15,max_points=50) for n in [10^3,10^4,10^5,10^6,2*10^6,3*10^6]]
show(graphics_array(v,2,3),ymin=0)rjU
jjKjNjjjub(h#or}r(jUJS28.plot_theta_interval(3*10^6,plot_points=15,max_points=50).show(dpi=200)rjKjjjUjjjjUjjKjNjUwraprjub(h#or}r(jUKS[0].plot_theta_interval(3*10^6,plot_points=15,max_points=50).show(dpi=200)rjKjjjUjjjjUjjKjNjUwraprjub(h#or}r(jU# 72a1 is the first curve to not satisfy Taylor's theorem
for E in cremona_optimal_curves(range(1,100)):
    if not E.has_cm() and min([e for p,e in E.conductor().factor()]) > 1:
        print E.cremona_label()
        breakrjK	jjjUjjjjU72a1rjjKjNjUwraprjub(h#or}r (jU`v = [S[i].histogram(10^3,20) for i in range(9)]
G = graphics_array(v,3,3)
G.show(xmin=-1,ymin=0)r!jK
jjjUjjjjUjjKjNjjjub(h#or"}r#(jU`v = [S[i].histogram(10^4,30) for i in range(9)]
G = graphics_array(v,3,3)
G.show(xmin=-1,ymin=0)r$jKjjjUjjjjUjjKjNjUwrapr%jub(h#or&}r'(jU`v = [S[i].histogram(10^5,50) for i in range(9)]
G = graphics_array(v,3,3)
G.show(xmin=-1,ymin=0)r(jKjjjUjjjjUjjKjNjUwrapr)jub(h#or*}r+(jU`v = [S[i].histogram(10^6,50) for i in range(9)]
G = graphics_array(v,3,3)
G.show(xmin=-1,ymin=0)r,jK
jjjUjjjjUjjKjNjjjub(h#or-}r.(jUiv = [S[i].xyplot(10^4) for i in range(9)]
G = graphics_array(v,3,3)
G.show(figsize=[5,10],xmin=-1,ymin=0)r/jKjjjUjjjjUjjKjNjjjub(h#or0}r1(jUCM.qqplot(1000000).show()r2jKjjjUjjjjUjjKjNjUwrapr3jub(h#or4}r5(jUSv = [S[i].qqplot(10^2) for i in range(9)]
show(graphics_array(v,3,3),xmin=0,ymin=0)r6jKjjjUjjjjUjjKjNjUwrapr7jub(h#or8}r9(jUSv = [S[i].qqplot(10^3) for i in range(9)]
show(graphics_array(v,3,3),xmin=0,ymin=0)r:jKjjjUjjjjUjjKjNjUwrapr;jub(h#or<}r=(jUSv = [S[i].qqplot(10^4) for i in range(9)]
show(graphics_array(v,3,3),xmin=0,ymin=0)r>jKjjjUjjjjUjjKjNjjjub(h#or?}r@(jUSv = [S[i].qqplot(10^5) for i in range(9)]
show(graphics_array(v,3,3),xmin=0,ymin=0)rAjKjjjUjjjjUjjKjNjUwraprBjub(h#orC}rD(jUwv = [S[i].plot_theta_interval(10^3,plot_points=40,max_points=100) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rEjKjjjUjjjjUjjKjNjjjub(h#orF}rG(jUwv = [S[i].plot_theta_interval(10^4,plot_points=20,max_points=100) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rHjKjjjUjjjjUjjKjNjUwraprIjub(h#orJ}rK(jUwv = [S[i].plot_theta_interval(10^5,plot_points=20,max_points=100) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rLjKjjjUjjjjUjjKjNjjjub(h#orM}rN(jUwv = [S[i].plot_theta_interval(10^6,plot_points=20,max_points=100) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rOjKjjjUjjjjUjjKjNjjjub(h#orP}rQ(jUwv = [S[i].plot_theta_interval(10^6,plot_points=50,max_points=100) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rRjKjjjUjjjjUjjKjNjjjub(h#orS}rT(jUv = [S[i].plot_theta_interval(10^5,plot_points=20,max_points=100, a=-0.5, b=0.5) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rUjKjjjUjjjjUjjKjNjjjub(h#orV}rW(jUv = [S[i].plot_theta_interval(10^5,plot_points=20,max_points=100, a=-0.5, b=0) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)rXjKjjjUjjjjUjjKjNjjjub(h#orY}rZ(jUv = [S[i].plot_theta_interval(10^5,plot_points=20,max_points=100, a=0, b=0.5) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)r[jKjjjUjjjjUjjKjNjjjub(h#or\}r](jUv = [S[i].plot_theta_interval(10^5,plot_points=20,max_points=100, a=-0.2, b=0.2) for i in range(9)]
show(graphics_array(v,3,3),ymin=0)r^jKjjjUjjjjUjjKjNjUwrapr_jub(h#or`}ra(jU_P = S11a.plot_theta_interval(20000, plot_points=20, max_points=50,verbose=False)
P.show(ymin=0)rbjKjjjUjjjjUjjKjNjUwraprcjub(h#ord}re(jU#E2 = SatoTate(EllipticCurve('37b'))rfjU!
rgjKjjjUjjjjjU|os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/30")
E2 = SatoTate(EllipticCurve('37b'))rhjU
jjKjh[jUwraprijub(h#orj}rk(jUOtime E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rljU!
rmjKjjjU.rnjjjjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/31")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rojU&
CPU time: 0.15 s,  Wall time: 0.17 s
rpjjKjh[jU/home/admin/0/cells/31rqjjjub(h#orr}rs(j}UPtime E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()rtjU!
rujjjjjU.rvjK&jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/38")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()rwjU&
CPU time: 3.05 s,  Wall time: 3.10 s
rxjjKjh[jU/home/admin/0/cells/38ryjjjjub(h#orz}r{(j}UPtime E2.plot_theta_interval(10^6,plot_points=10,max_points=50, L_norm=oo).show()r|jU!
r}jjjjjU.r~jK'jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/39")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
E2.plot_theta_interval(10^6,plot_points=10,max_points=50, L_norm=oo).show()rjU(
CPU time: 45.13 s,  Wall time: 46.76 s
rjjKjh[jU/home/admin/0/cells/39rjjjjub(h#or}r(j}UOtime E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rjU!
rjjjjjU.rjK(jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/40")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
E2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rjU&
CPU time: 0.16 s,  Wall time: 0.17 s
rjjKjh[jU/home/admin/0/cells/40rjjjjub(h#or}r(j}UjjjjUjK)jUjjKjjjub(h#or}r(jU9Erank2 = SatoTate(EllipticCurve('433a'))
Erank2._E.rank()rjK jjjUjjjjU2jjKjNjUwraprjub(h#or}r(jUDErank2.plot_theta_interval(10^6,plot_points=10,max_points=50).show()rjK!jjjUjjjjUjjKjNjjjub(h#or}r(jUBS[8].plot_theta_interval(10^6,plot_points=10,max_points=50).show()rjK"jjjUjjjjUjjKjNjjjub(h#or}r(jUY = S[4].YCab(2*10^6,-1,1)rjK#jjjUjjjjUjjKjNjUwraprjub(h#or}r(jUG# We next investigate relation between L_oo and L_2 conjecture and rankrjU!
rjjjjjUjK$jjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/36")
# We next investigate relation between L_oo and L_2 conjecture and rankrjU
jjKjh[jjjub(h#or}r(j}UOtime S2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rjU!
rjjjjjU.rjK0jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/48")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=2).show()rjU&
CPU time: 2.82 s,  Wall time: 2.91 s
rjjKjh[jU/home/admin/0/cells/48rjUwraprjjub(h#or}r(j}UQtime S3.plot_theta_interval(2*10^5,plot_points=10,max_points=50, L_norm=2).show()rjU!
rjjjjjU.rjK1jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/49")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S3.plot_theta_interval(2*10^5,plot_points=10,max_points=50, L_norm=2).show()rjU&
CPU time: 4.37 s,  Wall time: 4.58 s
rjjKjh[jU/home/admin/0/cells/49rjjjjub(h#or}r(j}UMtime P3 = S3.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)rjU!
rjjjjjUjK2jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/50")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P3 = S3.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)rjU(
CPU time: 10.17 s,  Wall time: 10.68 s
rjjKjh[jUwraprjjub(h#or}r(j}Utime P = S0.plot_theta_interval(2*10^4,plot_points=400,max_points=50, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjK7jjT8os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/55")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S0.plot_theta_interval(2*10^4,plot_points=400,max_points=50, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU(
CPU time: 22.29 s,  Wall time: 27.03 s
rjjK	jh[jU/home/admin/0/cells/55rjjjjub(h#or}r(U	_Cell__inrTS0b = SatoTate(EllipticCurve([1,0,0,-1070,7812])) # rank 0 curve with 16 rational torsion points
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rU_Cell__introspect_htmlrU!
rU_Cell__worksheetrjU_Cell__completionsrU_Cell__introspectrU_Cell__out_htmlrU.rU	_Cell__idrKIU_Cell__is_htmlrU_before_preparserTtos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/73")
S0b = SatoTate(EllipticCurve([1,0,0,-1070,7812])) # rank 0 curve with 16 rational torsion points
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rU
_Cell__outrU 
Time: CPU 7.05 s, Wall: 8.08 s
rUhas_new_outputrU_Cell__versionrKU_Cell__sagerh[U_Cell__url_to_selfrU/home/admin/0/cells/73rU_Cell__typerjU_Cell__timerU_Cell__interruptedrub(h#or}r(jT+S0b = SatoTate(EllipticCurve([1,0,0,-2276760100,41806588162832])) # rank 0 curve with 16 rational torsion points
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKJjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/74")
S0b = SatoTate(EllipticCurve([1,0,0,-2276760100,41806588162832])) # rank 0 curve with 16 rational torsion points
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU 
Time: CPU 7.40 s, Wall: 8.84 s
rjjKjh[jU/home/admin/0/cells/74rjjjjub(h#or}r(jTS0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKLjjTvos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/76")
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU 
Time: CPU 6.62 s, Wall: 7.56 s
rjjKjh[jU/home/admin/0/cells/76rjjjjub(h#or}r(jTS0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2+1)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKVjjTwos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/86")
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2+1)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
Time: CPU 9.46 s, Wall: 10.55 s
rjjKjh[jU/home/admin/0/cells/86rjUwraprjjub(h#or}r(jUEEllipticCurve([1,1,0,-6382494330,-196446593263212]).Lseries_zeros(10)rjU!
rjjjjjUjKQjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/81")
EllipticCurve([1,1,0,-6382494330,-196446593263212]).Lseries_zeros(10)rjU{
[0.381937496, 1.10669327, 1.78306573, 2.67003217, 3.31400622, 3.69721591, 4.47711843, 5.40906461, 5.74298574, 6.05685775]
rjjKjh[jjjjub(h#or}r(jU0EllipticCurve([0,1,0,83,-541]).Lseries_zeros(10)rjU!
rjjjjjUjKRjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/82")
EllipticCurve([0,1,0,83,-541]).Lseries_zeros(10)rjU{
[0.425771568, 1.35747206, 1.93087578, 2.86700601, 3.19382656, 3.95669880, 4.46037859, 4.92495501, 5.44063183, 6.22234529]
rjjKjh[jjjjub(h#or}r(jTS0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2 )/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKSjjTkos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/83")
S0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2 )/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU 
Time: CPU 5.88 s, Wall: 6.48 s
rjjKjh[jU/home/admin/0/cells/83rjjjjub(h#or}r(jT(e = EllipticCurve([0,0,0,-3,-137])
print e.Lseries_zeros(10)
S0b = SatoTate(e) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.r	jKUjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/85")
e = EllipticCurve([0,0,0,-3,-137])
print e.Lseries_zeros(10)
S0b = SatoTate(e) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)r
jU
[0.520023601, 1.46390028, 1.95614909, 2.92061029, 3.50869960, 4.27684884, 4.61381633, 5.27326559, 5.97248683, 6.67728376]
Time: CPU 5.85 s, Wall: 8.82 s
rjjKjh[jU/home/admin/0/cells/85rjjjjub(h#or
}r(jUodef conj(x):
    return 1 - (1.33 + 1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKTjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/84")
def conj(x):
    return 1 - (1.33 + 1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU
jjKjh[jU/home/admin/0/cells/84rjjjjub(h#or}r(jTS0b = SatoTate(EllipticCurve([0,0,0,20,-160])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKMjjTaos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/77")
S0b = SatoTate(EllipticCurve([0,0,0,20,-160])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU 
Time: CPU 6.56 s, Wall: 7.25 s
rjjKjh[jU/home/admin/0/cells/77rjjjjub(h#or}r(jU6e = EllipticCurve([0,0,0,20,-160])
e.Lseries_zeros(10)rjU!
rjjjjjUjjKNU_word_being_completedr U
e.Lseries_zerr!jUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/78")
e = EllipticCurve([0,0,0,20,-160])
e.Lseries_zeros(10)r"jU{
[0.608539063, 1.37691916, 2.36681367, 2.59157600, 3.46044322, 3.63239235, 4.00439962, 5.31911644, 5.42716982, 6.31741139]
r#jjKjh[jUwrapr$jjub(h#or%}r&(jU&EllipticCurve('11a').Lseries_zeros(10)r'jU!
r(jjjjjUjKOjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/79")
EllipticCurve('11a').Lseries_zeros(10)r)jUz
[6.36261389, 8.60353962, 10.0355091, 11.4512586, 13.5686391, 15.9140726, 17.0336103, 17.9414336, 19.1857250, 20.3792605]
r*jjKjh[jU/home/admin/0/cells/79r+jUwrapr,jjub(h#or-}r.(jUjjjjUjKPjUjjKjjjub(h#or/}r0(jT)S1b = SatoTate(EllipticCurve([1,0,0,-49423080,130545230400])) # rank 1 curve with 16 rational torsion points
time P = S1b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1+1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)r1jU!
r2jjjjjU.r3jKKjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/75")
S1b = SatoTate(EllipticCurve([1,0,0,-49423080,130545230400])) # rank 1 curve with 16 rational torsion points
time P = S1b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1+1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)r4jU 
Time: CPU 7.33 s, Wall: 8.68 s
r5jjKjh[jU/home/admin/0/cells/75r6jjjjub(h#or7}r8(jTS1b = SatoTate(EllipticCurve([0,-1,1,-2605193533,16913745257718])) # rank 1 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1 - (1/2+2)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)r9jU!
r:jjjjjU.r;jKWjjTvos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/87")
S1b = SatoTate(EllipticCurve([0,-1,1,-2605193533,16913745257718])) # rank 1 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1 - (1/2+2)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)r<jU 
Time: CPU 5.67 s, Wall: 6.17 s
r=jjKjh[jU/home/admin/0/cells/87r>jjjjub(h#or?}r@(jUDEllipticCurve([0,-1,1,-2605193533,16913745257718]).Lseries_zeros(10)rAjU!
rBjjjjjUjKXjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/88")
EllipticCurve([0,-1,1,-2605193533,16913745257718]).Lseries_zeros(10)rCjU|
[0.000000000, 0.918917736, 1.50311262, 2.48062026, 3.28311814, 3.90648923, 4.73267355, 5.07671794, 5.38960462, 6.01241899]
rDjjKjh[jjjjub(h#orE}rF(j}Utime P = S1.plot_theta_interval(10^5,plot_points=80,max_points=40, L_norm=2)

def conj(x):
    return 1 - 1/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rGjU!
rHjjjjjUjK3jjT/os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/51")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S1.plot_theta_interval(10^5,plot_points=80,max_points=40, L_norm=2)

def conj(x):
    return 1 - 1/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rIjU
jjKjNjU/home/admin/0/cells/51rJjUwraprKjjub(h#orL}rM(j}Utime P = S2.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rNjU!
rOjjjjjU.rPjK8jjT<os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/56")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S2.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rQjU(
CPU time: 14.17 s,  Wall time: 27.09 s
rRjjKjh[jU/home/admin/0/cells/56rSjUwraprTjjub(h#orU}rV(jT'S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(10^5,plot_points=100,max_points=40, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rWjU!
rXjjjjjU.rYjKDjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/68")
S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(10^5,plot_points=100,max_points=40, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rZjU"
Time: CPU 40.51 s, Wall: 48.38 s
r[jjKjh[jU/home/admin/0/cells/68r\jjjjub(h#or]}r^(jT%S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(10^6,plot_points=5,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)r_jU!
r`jjjjjU.rajK]jjT~os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/93")
S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(10^6,plot_points=5,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)rbjU"
Time: CPU 29.57 s, Wall: 33.27 s
rcjjKjh[jU/home/admin/0/cells/93rdjUwraprejjub(h#orf}rg(jT-S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(4*10^4,plot_points=200,max_points=30, L_norm=2)

s = float(2.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^4)
show(C + P, figsize=[10,7],ymin=0)rhjU!
rijjjjjU.rjjKEjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/69")
S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(4*10^4,plot_points=200,max_points=30, L_norm=2)

s = float(2.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^4)
show(C + P, figsize=[10,7],ymin=0)rkjU"
Time: CPU 30.44 s, Wall: 41.40 s
rljjKjh[jU/home/admin/0/cells/69rmjjjjub(h#orn}ro(jT%time
S2b = SatoTate(EllipticCurve([0,1,0,-125,-424]))  # last rank 2 in Cremona (to 120K)
P = S2b.plot_theta_interval(10^5,plot_points=40,max_points=20, L_norm=2)

s = float(2.2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rpjU!
rqjjjjjU/rrjKGjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/71")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S2b = SatoTate(EllipticCurve([0,1,0,-125,-424]))  # last rank 2 in Cremona (to 120K)
P = S2b.plot_theta_interval(10^5,plot_points=40,max_points=20, L_norm=2)

s = float(2.2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rsjU(
CPU time: 42.33 s,  Wall time: 57.30 s
rtjjKjh[jU/home/admin/0/cells/71rujUwraprvjjub(h#orw}rx(jUos = float(1)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)ryU_Cell__introspect_htmlrzU!
r{jjjU_Cell__introspectr|jU.r}jK\U_Cell__is_htmlr~U_before_preparserUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/92")
s = float(1)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU
jjKU_Cell__sagerh[U_Cell__url_to_selfrU/home/admin/0/cells/92rjUwraprU_Cell__timerjub(h#or}r(jUr
s = float(2.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKHjjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/72")
s = float(2.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^4)
show(C + P, figsize=[10,7],ymin=0)rjU
jjKjh[jU/home/admin/0/cells/72rjjjjub(h#or}r(U	_Cell__inrUtime P = S3.plot_theta_interval(2*10^4,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1/2 - 1/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjzU!
rU_Cell__worksheetrjU_Cell__completionsrj|U_Cell__out_htmlrU.rU	_Cell__idrK`j~jT5os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/96")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S3.plot_theta_interval(2*10^4,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1/2 - 1/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rU
_Cell__outrU&
CPU time: 1.95 s,  Wall time: 2.33 s
rUhas_new_outputrU_Cell__versionrKjh[jU/home/admin/0/cells/96rU_Cell__typerUwraprjU_Cell__interruptedrub(h#or}r(j}Utime P = S3.plot_theta_interval(5*10^5,plot_points=15,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU/rjK4jjT@os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/52")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S3.plot_theta_interval(5*10^5,plot_points=15,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)rjU(
CPU time: 69.98 s,  Wall time: 92.30 s
rjjK,jh[jU/home/admin/0/cells/52rjUwraprjjub(h#or}r(jUtime P = S3.plot_theta_interval(10^6,plot_points=50,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)rjzU!
rjjjj|jU.rjK_j~jT<os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/95")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S3.plot_theta_interval(10^6,plot_points=50,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)rjU+
CPU time: 661.63 s,  Wall time: 1365.69 s
rjjKjh[jU/home/admin/0/cells/95rjUwraprjjub(h#or}r(jUqs = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^5)
show(C + P, figsize=[10,7],ymin=0)rjzU!
rjjjj|jU.rjK^j~jUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/94")
s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^5)
show(C + P, figsize=[10,7],ymin=0)rjU
jjKjh[jU/home/admin/0/cells/94rjjjjub(h#or}r(jT
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=2,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKYjjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/89")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=2,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)rjUI
Time: CPU 34.64 s, Wall: 57.08 s
CPU time: 36.54 s,  Wall time: 60.31 s
rjjKjh[jU/home/admin/0/cells/89rjjjjub(h#or}r(jT%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=8,max_points=10, L_norm=oo)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjK[jjTos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/91")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=8,max_points=10, L_norm=oo)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)rjTE
0.34
0.00454126481363
0.00310350333117
0.00401606255675
0.00374246662969
0.00282335819277
0.00277784636981
0.00269948551726
0.34
0.00454126481363
0.00310350333117
0.00401606255675
0.00374246662969
0.00282335819277
0.00277784636981
0.00269948551726
Time: CPU 113.93 s, Wall: 130.53 s
CPU time: 114.30 s,  Wall time: 130.95 s
rjjKjh[jU/home/admin/0/cells/91rjjjjub(h#or}r(jTS3b = SatoTate(EllipticCurve([1,-1,1,-6,0]))  # second rank-3 curve
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjK@jjT[os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/64")
S3b = SatoTate(EllipticCurve([1,-1,1,-6,0]))  # second rank-3 curve
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU"
Time: CPU 12.00 s, Wall: 13.14 s
rjjKjh[jU/home/admin/0/cells/64rjjjjub(h#or}r(jTS3b = SatoTate(EllipticCurve([0,0,0,-8699,252426]))  # cremona rank-3 curve with biggest cond
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjKAjjTuos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/65")
S3b = SatoTate(EllipticCurve([0,0,0,-8699,252426]))  # cremona rank-3 curve with biggest cond
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU"
Time: CPU 12.08 s, Wall: 14.11 s
rjjKjh[jU/home/admin/0/cells/65rjjjjub(h#or}r(jTS3b = SatoTate(EllipticCurve([1,0,1,-131,558]))  # cremona rank-3 curve with 2-torsion
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjUjKCjjTnos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/67")
S3b = SatoTate(EllipticCurve([1,0,1,-131,558]))  # cremona rank-3 curve with 2-torsion
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjTg
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/2.py", line 4, in 
    S3b = SatoTate(EllipticCurve([Integer(1),Integer(0),Integer(1),-Integer(131),Integer(558)]))  # cremona rank-3 curve with 2-torsion
NameError: name 'SatoTate' is not definedrjjKjh[jU/home/admin/0/cells/67rjUwraprjjub(h#or}r(jUjjjjUjKBjUjjKjjjub(h#or}r(j}U%time 
P = S4.plot_theta_interval(10^4,plot_points=200,max_points=20, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU/rjK9jjT?os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/57")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S4.plot_theta_interval(10^4,plot_points=200,max_points=20, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^4)
show(C + P, figsize=[10,7],ymin=0)rjU&
CPU time: 2.64 s,  Wall time: 2.88 s
rjjKjh[jU/home/admin/0/cells/57rjUwraprjjub(h#or}r(jU%time 
P = S4.plot_theta_interval(2*10^4,plot_points=500,max_points=20, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjK?jjTCos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/63")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S4.plot_theta_interval(2*10^4,plot_points=500,max_points=20, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)rjU(
CPU time: 26.71 s,  Wall time: 31.46 s
rjjKjh[jU/home/admin/0/cells/63rjjjjub(h#or}r(j}Utime P = S5.plot_theta_interval(10^5,plot_points=80,max_points=40, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU!
rjjjjjU.rjK:jjT>os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/58")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S5.plot_theta_interval(10^5,plot_points=80,max_points=40, L_norm=2)

s = float(3.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)rjU&
CPU time: 0.33 s,  Wall time: 0.34 s
rjjKjh[jU/home/admin/0/cells/58rjUwraprjjub(h#or}r(j}Utime P6 = S6.plot_theta_interval(10^5,plot_points=60,max_points=40, L_norm=2)
def conj(x):
    return 1 - 4/log(x)
C6 = plot(conj, 100, 10^5)
show(C6 + P6, figsize=[20,10])rjU!
rjjjjjU/rjK5jjT+os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/53")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P6 = S6.plot_theta_interval(10^5,plot_points=60,max_points=40, L_norm=2)
def conj(x):
    return 1 - 4/log(x)
C6 = plot(conj, 100, 10^5)
show(C6 + P6, figsize=[20,10])rjU&
CPU time: 1.19 s,  Wall time: 1.26 s
rjjKjh[jU/home/admin/0/cells/53rjUwraprjjub(h#or}r(j}Utime P = S7.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(4.25)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7], ymin=0)rjU!
r	jjjjjU.r
jK;jjT@os.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/59")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S7.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(4.25)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7], ymin=0)rjU&
CPU time: 0.34 s,  Wall time: 0.40 s
rjjKjh[jU/home/admin/0/cells/59r
jUwraprjjub(h#or}r(j}Utime P = S8.plot_theta_interval(10^5,plot_points=30,max_points=40, L_norm=2)

s = float(4.25)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7], ymin=0)rjU!
rjjjjjU.rjKrjjjjjU.rjK=jjTAos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/61")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
P = S28.plot_theta_interval(10^5,plot_points=20,max_points=40, L_norm=2)

s = float(6.25)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7], ymin=0)rjU&
CPU time: 0.37 s,  Wall time: 0.37 s
rjjKjh[jU/home/admin/0/cells/61rjjjjub(h#or }r!(j}UPtime S2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r"jU!
r#jjjjjU.r$jK*jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/42")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S2.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r%jU
0.467684212266
0.0352938479114
0.0166787427859
0.0176996046889
0.0156258913368
0.0132107756123
0.0170905493296
0.0145727448193
0.0116221377156
0.00953200941205
CPU time: 2.94 s,  Wall time: 3.00 s
r&jjKjh[jU/home/admin/0/cells/42r'jjjjub(h#or(}r)(j}UPtime S4.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r*jU!
r+jjjjjU.r,jK+jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/43")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S4.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r-jU&
CPU time: 2.90 s,  Wall time: 3.61 s
r.jjKjh[jU/home/admin/0/cells/43r/jjjjub(h#or0}r1(j}UPtime S6.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r2jU!
r3jjjjjU.r4jK,jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/44")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S6.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r5jU&
CPU time: 2.80 s,  Wall time: 2.85 s
r6jjKjh[jU/home/admin/0/cells/44r7jjjjub(h#or8}r9(j}UPtime S8.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r:jU!
r;jjjjjU.r<jK-jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/45")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S8.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()r=jU&
CPU time: 2.79 s,  Wall time: 2.88 s
r>jjKjh[jU/home/admin/0/cells/45r?jjjjub(h#or@}rA(j}UQtime S28.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()rBjU!
rCjjjjjU.rDjK.jjUos.chdir("/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/cells/46")
__SAGE_t__=cputime()
__SAGE_w__=walltime()
S28.plot_theta_interval(10^5,plot_points=10,max_points=50, L_norm=oo).show()rEjU&
CPU time: 3.12 s,  Wall time: 3.16 s
rFjjKjh[jU/home/admin/0/cells/46rGjUwraprHjjub(h#orI}rJ(j}UjjjjUjK/jUjjKjjjubeU_Worksheet__synchrorKMPU_Worksheet__comp_is_runningrLU_Worksheet__saved_by_inforM}rN(U
1191080455rOUadminrPU
1191055540rQjxU
1191376694rRh U
1191351292rSh U
1191073618rTUadminrUU
1191054003rVjxU
1191054400rWjxU
1191073858rXjUU
1191055725rYjxU
1191053627rZjxU
1191074770r[jUU
1191057688r\Uadminr]U
1191057124r^j]U
1191106219r_jPU
1191054588r`jxU
1191376968rah U
1191048941rbjxU
1191068588rcjUU
1191056652rdjxU
1191053446rejxU
1191073066rfjUU
1191074974rgjUU
1191057501rhj]U
1191080645rijPU
1191069274rjjUU
1190935780rkjU
1191068012rljUU
1191048721rmjxU
1191047358rnjxU
1191068219rojUU
1191072756rpjUU
1191071031rqjUU
1191053812rrjxU
1191071849rsjUU
1191070340rtjUU
1190935800rujU
1191071393rvjUU
1191049456rwjxU
1191070029rxjUU
1191069743ryjUU
1191047173rzjxU
1191048054r{jxU
1190935793r|jU
1191080209r}jPU
1191071668r~jUU
1191074332rjUU
1191053003rjxU
1191057307rj]U
1191072570rjUU
1191075510rjUU
1191053241rjxU
1191070770rjUU
1191070589rjUU
1191069031rjUU
1191048281rjxU
1191074051rjUU
1191049192rjxU
1191054217rjxU
1191073431rjUU
1191057762rj]uU_Worksheet__dirrUC/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0rU_Worksheet__attachedr}rU_Worksheet__collaboratorsr]rU_Worksheet__last_autosaverGA-zU_Worksheet__user_viewr}rjKsU_Worksheet__next_idrKfU_Worksheet__viewersr]rU_Worksheet__namerU	Sato TaterU_Worksheet__next_block_idrKU!_Worksheet__last_compute_walltimerGA3#", line 1, in 
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/66.py", line 4, in 
    exec compile(ur'EllipticCurve(\u002711a\u0027).Lseries_zero(Integer(10))' + '\n', '', 'single')
  File "/home/was/s/data/extcode/sage/", line 1, in 
    
AttributeError: 'EllipticCurve_rational_field' object has no attribute 'Lseries_zero'
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:31)
{{{id=79|
EllipticCurve('11a').Lseries_zeros(10)
///
[6.36261389, 8.60353962, 10.0355091, 11.4512586, 13.5686391, 15.9140726, 17.0336103, 17.9414336, 19.1857250, 20.3792605]
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:32)
{{{id=81|
EllipticCurve([1,1,0,-6382494330,-196446593263212]).Lseries_zeros(10)
///
[0.381937496, 1.10669327, 1.78306573, 2.67003217, 3.31400622, 3.69721591, 4.47711843, 5.40906461, 5.74298574, 6.05685775]
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:32)
{{{id=82|
EllipticCurve([0,1,0,83,-541]).Lseries_zeros(10)
///
[0.425771568, 1.35747206, 1.93087578, 2.86700601, 3.19382656, 3.95669880, 4.46037859, 4.92495501, 5.44063183, 6.22234529]
}}}rTnWorksheet 'Sato Tate' (2007-09-29 at 06:37)
{{{id=83|
S0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 6.46 s, Wall: 7.45 s
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:39)
{{{id=84|
def conj(x):
    return 1 - (1 + 1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:39)
{{{id=84|
def conj(x):
    return 1 - (2 + 1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:39)
{{{id=84|
def conj(x):
    return 1 - (1.33 + 1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
}}}rT2Worksheet 'Sato Tate' (2007-09-29 at 06:43)
{{{id=85|
e = EllipticCurve([0,0,0,-3,-137])
print e.Lseries_zeros(10)
S0b = SatoTate(e) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):    S0b = SatoTate(e) # rank 0 curve with big height
  File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/ell_rational_field.py", line 1830, in Lseries_zeros
    return lcalc.zeros(n, L=self)
  File "/home/was/s/local/lib/python2.5/site-packages/sage/lfunctions/lcalc.py", line 108, in zeros
    X = self('-z %s %s'%(int(n), L))
  File "/home/was/s/local/lib/python2.5/site-packages/sage/lfun...
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 06:44)
{{{id=85|
e = EllipticCurve([0,0,0,-3,-137])
print e.Lseries_zeros(10)
S0b = SatoTate(e) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
[0.520023601, 1.46390028, 1.95614909, 2.92061029, 3.50869960, 4.27684884, 4.61381633, 5.27326559, 5.97248683, 6.67728376]
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/2.py", line 6, in 
    S0b = SatoTate(e) # rank 0 curve with big height
NameError: name 'SatoTate' is not defined
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 06:44)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 06:45)
{{{id=85|
e = EllipticCurve([0,0,0,-3,-137])
print e.Lseries_zeros(10)
S0b = SatoTate(e) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
[0.520023601, 1.46390028, 1.95614909, 2.92061029, 3.50869960, 4.27684884, 4.61381633, 5.27326559, 5.97248683, 6.67728376]
Time: CPU 5.85 s, Wall: 8.82 s
}}}rTwWorksheet 'Sato Tate' (2007-09-29 at 06:46)
{{{id=83|
S0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2 + 1/1.33)/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 5.93 s, Wall: 6.59 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 06:46)
{{{id=83|
S0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2 + )/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
Syntax Error:
        return 1 - (1/2 + )/log(x)
}}}rToWorksheet 'Sato Tate' (2007-09-29 at 06:47)
{{{id=83|
S0b = SatoTate(EllipticCurve([1,0,0,114606,-22471344])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^4,plot_points=100,max_points=30, L_norm=2)

def conj(x):
    return 1 - (1/2 )/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 5.88 s, Wall: 6.48 s
}}}rTuWorksheet 'Sato Tate' (2007-09-29 at 06:48)
{{{id=86|
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2)/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 4.51 s, Wall: 4.97 s
}}}rTwWorksheet 'Sato Tate' (2007-09-29 at 06:48)
{{{id=86|
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2+1)/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 4.28 s, Wall: 4.79 s
}}}rTzWorksheet 'Sato Tate' (2007-09-29 at 06:49)
{{{id=86|
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2+1)/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 9.13 s, Wall: 10.16 s
}}}rT|Worksheet 'Sato Tate' (2007-09-29 at 06:49)
{{{id=86|
S0b = SatoTate(EllipticCurve([1,1,0,-6382494330,-196446593263212])) # rank 0 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=15,max_points=20, L_norm=2)

def conj(x):
    return 1 - (1/2+1)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 9.46 s, Wall: 10.55 s
}}}rTzWorksheet 'Sato Tate' (2007-09-29 at 06:51)
{{{id=87|
S1b = SatoTate(EllipticCurve([0,-1,1,-2605193533,16913745257718])) # rank 1 curve with big height
time P = S0b.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1 - (1/2+2)/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 5.67 s, Wall: 6.17 s
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 06:51)
{{{id=88|
EllipticCurve([0,-1,1,-2605193533,16913745257718]).Lseries_zeros(10)
///
[0.000000000, 0.918917736, 1.50311262, 2.48062026, 3.28311814, 3.90648923, 4.73267355, 5.07671794, 5.38960462, 6.01241899]
}}}r	TJWorksheet 'Sato Tate' (2007-09-29 at 06:52)
{{{id=89|
time P = S3.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):    
NameError: name 'S3' is not defined
}}}r
TJWorksheet 'Sato Tate' (2007-09-29 at 06:52)
{{{id=89|
time P = S3.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):    
NameError: name 'S3' is not defined
}}}rTeWorksheet 'Sato Tate' (2007-09-29 at 06:53)
{{{id=89|
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^5,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 5.74 s, Wall: 6.27 s
}}}rTgWorksheet 'Sato Tate' (2007-09-29 at 06:53)
{{{id=89|
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(5*10^5,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 15.92 s, Wall: 17.84 s
}}}r
TcWorksheet 'Sato Tate' (2007-09-29 at 06:54)
{{{id=89|
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(10^6,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 34.30 s, Wall: 42.15 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 06:59)
{{{id=89|
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=5,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 43.62 s, Wall: 55.11 s
CPU time: 44.33 s,  Wall time: 56.09 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:04)
{{{id=89|
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=10,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):    
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/4.py", line 144, in plot_theta_interval
    vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/4.py", line 137, in compute_theta_interval
    zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
  File "/home/was/talks...
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:06)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:06)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))

S = [S0,S1,S2,S3,S4,S5,S6,S7,S8]
CM = SatoTate(EllipticCurve('32a'))
Equest = SatoTate(EllipticCurve('72a1'))   # non-CM but doesn't satisfy hypo of Taylor's theorem
# Our curves S satisfy Taylor's theorem
[min([e for p,e in X._E.conductor().factor()]) for X in S]
///
[1, 1, 1, 1, 1, 1, 1, 1, 1]
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:08)
{{{id=89|
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=2,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 34.64 s, Wall: 57.08 s
CPU time: 36.54 s,  Wall time: 60.31 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:09)
{{{id=91|
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=2,max_points=10, L_norm=oo)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)
///
0.34
0.00374246662969
0.34
0.00374246662969
Time: CPU 17.13 s, Wall: 21.06 s
CPU time: 17.52 s,  Wall time: 21.51 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:11)
{{{id=91|
%time
S3b = SatoTate(EllipticCurve([0,1,1,-30,60]))  # second rank-3 curve

time P = S3b.plot_theta_interval(2*10^6,plot_points=8,max_points=10, L_norm=oo)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 2*10^6)
show(C + P, figsize=[10,7],ymin=0)
///
0.34
0.00454126481363
0.00310350333117
0.00401606255675
0.00374246662969
0.00282335819277
0.00277784636981
0.00269948551726
0.34
0.00454126481363
0.00310350333117
0.00401606255675
0.00374246662969
0.00282335819277
0.00277784636981
0.00269948551726
Time: CPU 113.93 s, Wall: 130.53 s
CPU time: 114.30 s,  Wall time: 130.95 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:18)
{{{id=93|
S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(5*10^5,plot_points=5,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 14.75 s, Wall: 16.49 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 07:19)
{{{id=93|
S2b = SatoTate(EllipticCurve([0,0,0,-1215,42822]))  # a rank 2 curve with large conductor and 3-torsion
time P = S2b.plot_theta_interval(10^6,plot_points=5,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)
///
Time: CPU 29.57 s, Wall: 33.27 s
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 08:37)
{{{id=67|
S3b = SatoTate(EllipticCurve([1,0,1,-131,558]))  # cremona rank-3 curve with 2-torsion
time P = S3b.plot_theta_interval(10^5,plot_points=40,max_points=40, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/talks/20070930-sato_tate/sage_notebook/worksheets/admin/0/code/2.py", line 4, in 
    S3b = SatoTate(EllipticCurve([Integer(1),Integer(0),Integer(1),-Integer(131),Integer(558)]))  # cremona rank-3 curve with 2-torsion
NameError: name 'SatoTate' is not defined
}}}rT|Worksheet 'Sato Tate' (2007-09-29 at 08:37)
{{{id=1|
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0), \
                     (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 08:37)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rT|Worksheet 'Sato Tate' (2007-09-29 at 08:38)
{{{id=71|
%time
S2b = SatoTate(EllipticCurve([0,1,0,-125,-424]))  # last rank 2 in Cremona (to 120K)
P = S2b.plot_theta_interval(10^4,plot_points=100,max_points=20, L_norm=2)

s = float(2.2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^4)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 12.37 s,  Wall time: 20.77 s
}}}rT{Worksheet 'Sato Tate' (2007-09-29 at 08:40)
{{{id=71|
%time
S2b = SatoTate(EllipticCurve([0,1,0,-125,-424]))  # last rank 2 in Cremona (to 120K)
P = S2b.plot_theta_interval(10^5,plot_points=40,max_points=20, L_norm=2)

s = float(2.2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 42.33 s,  Wall time: 57.30 s
}}}rUWorksheet 'Sato Tate' (2007-09-29 at 08:40)
{{{id=92|
s = float(1)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}rTFWorksheet 'Sato Tate' (2007-09-29 at 08:41)
{{{id=52|
time P = S3.plot_theta_interval(10^5,plot_points=30,max_points=20, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
Traceback (most recent call last):    
NameError: name 'S3' is not defined
}}}rTWorksheet 'Sato Tate' (2007-09-29 at 08:42)
{{{id=3|
#auto
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))

S = [S0,S1,S2,S3,S4,S5,S6,S7,S8]
CM = SatoTate(EllipticCurve('32a'))
Equest = SatoTate(EllipticCurve('72a1'))   # non-CM but doesn't satisfy hypo of Taylor's theorem
# Our curves S satisfy Taylor's theorem
#[min([e for p,e in X._E.conductor().factor()]) for X in S]
}}}rT"Worksheet 'Sato Tate' (2007-09-29 at 08:43)
{{{id=52|
time P = S3.plot_theta_interval(10^5,plot_points=30,max_points=20, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 35.45 s,  Wall time: 50.36 s
}}}r UWorksheet 'Sato Tate' (2007-09-29 at 08:43)
{{{id=94|
s = float(2.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r!UWorksheet 'Sato Tate' (2007-09-29 at 08:43)
{{{id=94|
s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r"UWorksheet 'Sato Tate' (2007-09-29 at 08:44)
{{{id=94|
s = float(1.8)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r#UWorksheet 'Sato Tate' (2007-09-29 at 08:44)
{{{id=94|
s = float(1.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r$T#Worksheet 'Sato Tate' (2007-09-29 at 08:45)
{{{id=52|
time P = S3.plot_theta_interval(4*10^5,plot_points=5,max_points=20, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^5)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 23.36 s,  Wall time: 34.55 s
}}}r%UWorksheet 'Sato Tate' (2007-09-29 at 08:45)
{{{id=94|
s = float(1.5)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r&UWorksheet 'Sato Tate' (2007-09-29 at 08:45)
{{{id=94|
s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 4*10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r'UWorksheet 'Sato Tate' (2007-09-29 at 08:46)
{{{id=52|
time P = S3.plot_theta_interval(5*10^5,plot_points=15,max_points=10, L_norm=2)

s = float(3)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)
}}}r(T&Worksheet 'Sato Tate' (2007-09-29 at 08:48)
{{{id=52|
time P = S3.plot_theta_interval(5*10^5,plot_points=15,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 5*10^5)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 69.98 s,  Wall time: 92.30 s
}}}r)T(Worksheet 'Sato Tate' (2007-09-29 at 15:50)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r*TWorksheet 'Sato Tate' (2007-09-29 at 15:50)
{{{id=3|
#auto
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))

S = [S0,S1,S2,S3,S4,S5,S6,S7,S8]
CM = SatoTate(EllipticCurve('32a'))
Equest = SatoTate(EllipticCurve('72a1'))   # non-CM but doesn't satisfy hypo of Taylor's theorem
# Our curves S satisfy Taylor's theorem
#[min([e for p,e in X._E.conductor().factor()]) for X in S]
}}}r+TWorksheet 'Sato Tate' (2007-09-29 at 15:51)
{{{id=96|
time P = S3.plot_theta_interval(2*10^4,plot_points=10,max_points=10, L_norm=2)

def conj(x):
    return 1/2 - 1/log(x)

C = plot(conj, 100, 2*10^4)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 1.95 s,  Wall time: 2.33 s
}}}r,T%Worksheet 'Sato Tate' (2007-09-29 at 16:15)
{{{id=95|
time P = S3.plot_theta_interval(10^6,plot_points=50,max_points=10, L_norm=2)

s = float(2)
def conj(x):
    return 1 - s/log(x)

C = plot(conj, 100, 10^6)
show(C + P, figsize=[10,7],ymin=0)
///
CPU time: 661.63 s,  Wall time: 1365.69 s
}}}r-T|Worksheet 'Sato Tate' (2007-10-02 at 11:54)
{{{id=1|
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0), \
                     (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()
}}}r.T(Worksheet 'Sato Tate' (2007-10-02 at 11:54)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r/TxWorksheet 'data!' (2007-10-02 at 12:03)
{{{id=1|
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0), \
                     (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()
}}}r0T]Worksheet 'data!' (2007-10-02 at 12:03)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r1TWorksheet 'data!' (2007-10-02 at 12:03)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}r2UWorksheet 'data!' (2007-10-02 at 12:07)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^6,plot_points=15,max_points=50)
P0.show(dpi=200)
}}}r3UWorksheet 'data!' (2007-10-02 at 12:07)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^4,plot_points=5,max_points=20)
P0.show(dpi=100)
///
CPU time: 0.49 s,  Wall time: 0.67 s
}}}r4UWorksheet 'data!' (2007-10-02 at 12:07)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5,plot_points=5,max_points=20)
P0.show(dpi=100)
///
CPU time: 2.72 s,  Wall time: 3.04 s
}}}r5UWorksheet 'data!' (2007-10-02 at 12:07)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5,plot_points=10,max_points=20)
P0.show(dpi=100)
///
CPU time: 5.73 s,  Wall time: 6.76 s
}}}r6UWorksheet 'data!' (2007-10-02 at 12:08)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10)
P0.show(dpi=100)
///
CPU time: 5.79 s,  Wall time: 6.82 s
}}}r7TWorksheet 'data!' (2007-10-02 at 12:08)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=oo)
P0.show(dpi=100)
///
0.1
0.010847316519
0.0102780936315
0.00685298286442
0.00681343770093
0.00654483692742
0.00487101358334
0.00379166966379
0.00250706546962
0.00374828830735
0.1
0.010847316519
0.0102780936315
0.00685298286442
0.00681343770093
0.00654483692742
0.00487101358334
0.00379166966379
0.00250706546962
0.00374828830735
CPU time: 6.22 s,  Wall time: 7.53 s
}}}r8T\Worksheet 'data!' (2007-10-02 at 12:10)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r9TFWorksheet 'data!' (2007-10-02 at 12:12)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r:TWorksheet 'data!' (2007-10-02 at 12:12)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}r;UWorksheet 'data!' (2007-10-02 at 12:12)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 4.22 s,  Wall time: 7.19 s
}}}r<TYWorksheet 'data!' (2007-10-02 at 12:12)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r=TWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        #X = Xab(a,b)
        #Y = self.YCab(C,a,b)
        X = lambda T: float(0)
        Y = lambda T: float(0)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r>TWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}r?TfWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
Traceback (most recent call last):    P0.show(dpi=100)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/16.py", line 150, in plot_theta_interval
    vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/16.py", line 143, in compute_theta_interval
    zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
  File "/home/was/sd5/sato-...
}}}r@TWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        #X = Xab(a,b)
        #Y = self.YCab(C,a,b)
        X = lambda T: float(1)
        Y = lambda T: float(1)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rATWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rBTWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rCTfWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
Traceback (most recent call last):    P0.show(dpi=100)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/19.py", line 150, in plot_theta_interval
    vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/19.py", line 143, in compute_theta_interval
    zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
  File "/home/was/sd5/sato-...
}}}rDTWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        #X = Xab(a,b)
        #Y = self.YCab(C,a,b)
        X = lambda T: float(1)
        Y = lambda T: float(0.5)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rETWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rFUWorksheet 'data!' (2007-10-02 at 12:16)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 0.18 s,  Wall time: 0.18 s
}}}rGTWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        #X = Xab(a,b)
        Y = self.YCab(C,a,b)
        X = lambda T: float(1)
        #Y = lambda T: float(0.5)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rHTWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rIUWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 3.91 s,  Wall time: 4.90 s
}}}rJUWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 3.91 s,  Wall time: 4.90 s
}}}rKTWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rLUWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 4.25 s,  Wall time: 5.30 s
}}}rMTWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        #Y = self.YCab(C,a,b)
        #X = lambda T: float(1)
        Y = lambda T: float(0.5)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rNTWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rOUWorksheet 'data!' (2007-10-02 at 12:17)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 0.28 s,  Wall time: 0.34 s
}}}rPTWorksheet 'data!' (2007-10-02 at 12:19)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        return lambda T: float(1)
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rQTWorksheet 'data!' (2007-10-02 at 12:19)
{{{id=3|
S0 = SatoTate(EllipticCurve('11a'))
S1 = SatoTate(EllipticCurve('37a'))
S2 = SatoTate(EllipticCurve('389a'))
S3 = SatoTate(EllipticCurve('5077a'))
S4 = SatoTate(EllipticCurve([1,-1,0,-79,289]))
S5 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]))
S6 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]))
S7 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]))
S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]))
S28 = SatoTate(EllipticCurve([1,-1,1,\
  -20067762415575526585033208209338542750930230312178956502,\
  34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]))
}}}rRUWorksheet 'data!' (2007-10-02 at 12:19)
{{{id=8|
%time
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
P0.show(dpi=100)
///
CPU time: 0.18 s,  Wall time: 0.20 s
}}}rSTWorksheet 'data!' (2007-10-02 at 12:20)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTUWorksheet 'data!' (2007-10-02 at 12:20)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'))
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 3.04 s, Wall: 3.74 s
}}}rUTWorksheet 'data!' (2007-10-02 at 15:49)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        return [float(0)]*n
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rVUWorksheet 'data!' (2007-10-02 at 15:49)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'))
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.19 s, Wall: 0.56 s
}}}rWTWorksheet 'data!' (2007-10-02 at 15:50)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        return [float(0)]*n
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rXUWorksheet 'data!' (2007-10-02 at 15:50)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'))
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 3.32 s, Wall: 4.27 s
}}}rYTWorksheet 'data!' (2007-10-02 at 15:50)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        t = cputime()
        anlist = self.anlist(n)
        print cputime(t)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rZT9Worksheet 'data!' (2007-10-02 at 15:57)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n

    def init_aplist(self):
        n = self._n
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i]) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
///
Syntax Error:
            self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i]) for i in range(len(v))]
}}}r[TWorksheet 'data!' (2007-10-02 at 15:58)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n

    def init_aplist(self):
        n = self._n
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r\TWorksheet 'data!' (2007-10-02 at 15:58)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n

    def init_aplist(self):
        n = self._n
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r]T]Worksheet 'data!' (2007-10-02 at 15:58)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'))
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
TypeError: __init__() takes exactly 3 arguments (2 given)
}}}r^TWorksheet 'data!' (2007-10-02 at 15:58)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/48.py", line 5, in 
    exec compile(ur'__time__=misc.cputime(); __wall__=misc.walltime();  P0 = S0.plot_theta_interval(Integer(10)**Integer(5), plot_points=Integer(10), max_points=Integer(10), L_norm=Integer(2)); print         "Time: CPU %.2f s, Wall: %.2f s"%(misc.cputime(__time__), misc.walltime(__wal...
}}}r_TWorksheet 'data!' (2007-10-02 at 15:59)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}r`THWorksheet 'data!' (2007-10-02 at 15:59)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/49.py", line 23, in __init__
    self.init_aplist(n)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/49.py", line 26, in init_aplist
    v = E.aplist(n)
NameError: global name 'E' is not defined
}}}raTWorksheet 'data!' (2007-10-02 at 15:59)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rbUWorksheet 'data!' (2007-10-02 at 15:59)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.04 s, Wall: 0.08 s
}}}rcUWorksheet 'data!' (2007-10-02 at 15:59)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.03 s
}}}rdTuWorksheet 'data!' (2007-10-02 at 16:02)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self):
        n = self._n
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}reTWorksheet 'data!' (2007-10-02 at 16:02)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/54.py", line 23, in __init__
    self.init_aplist(n)
TypeError: init_aplist() takes exactly 1 argument (2 given)
}}}rfTdWorksheet 'data!' (2007-10-02 at 16:02)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rgTHWorksheet 'data!' (2007-10-02 at 16:02)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/56.py", line 23, in __init__
    self.init_aplist(n)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/56.py", line 26, in init_aplist
    v = E.aplist(n)
NameError: global name 'E' is not defined
}}}rhTjWorksheet 'data!' (2007-10-02 at 16:03)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}riUWorksheet 'data!' (2007-10-02 at 16:03)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.02 s
}}}rjU>Worksheet 'data!' (2007-10-02 at 16:03)
{{{id=36|
show(P0)
}}}rkTrWorksheet 'data!' (2007-10-02 at 16:04)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rlUWorksheet 'data!' (2007-10-02 at 16:04)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.01 s, Wall: 0.01 s
}}}rmU>Worksheet 'data!' (2007-10-02 at 16:04)
{{{id=36|
show(P0)
}}}rnU>Worksheet 'data!' (2007-10-02 at 16:04)
{{{id=36|
show(P0)
}}}roTWorksheet 'data!' (2007-10-02 at 16:05)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
        return lambda T: float(1)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rpUWorksheet 'data!' (2007-10-02 at 16:05)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.02 s
}}}rqU>Worksheet 'data!' (2007-10-02 at 16:05)
{{{id=36|
show(P0)
}}}rrTlWorksheet 'data!' (2007-10-02 at 16:05)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rsUWorksheet 'data!' (2007-10-02 at 16:05)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.02 s
}}}rtU>Worksheet 'data!' (2007-10-02 at 16:05)
{{{id=36|
show(P0)
}}}ruTlWorksheet 'data!' (2007-10-02 at 16:07)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rvUWorksheet 'data!' (2007-10-02 at 16:07)
{{{id=35|
S0 = SatoTate(EllipticCurve('11a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.02 s
}}}rwU>Worksheet 'data!' (2007-10-02 at 16:07)
{{{id=36|
show(P0)
}}}rxUWorksheet 'data!' (2007-10-02 at 16:08)
{{{id=35|
%time
S0 = SatoTate(EllipticCurve('11a'), 10^5)
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
CPU time: 0.59 s,  Wall time: 0.60 s
}}}ryU>Worksheet 'data!' (2007-10-02 at 16:08)
{{{id=36|
show(P0)
}}}rzUWorksheet 'data!' (2007-10-02 at 16:08)
{{{id=35|
%time
S0 = SatoTate(EllipticCurve('5077a'), 10^5)
P0 = S0.plot_theta_interval(10^5, plot_points=10, max_points=10, L_norm=2)
///
CPU time: 0.54 s,  Wall time: 0.56 s
}}}r{U>Worksheet 'data!' (2007-10-02 at 16:08)
{{{id=36|
show(P0)
}}}r|U>Worksheet 'data!' (2007-10-02 at 16:08)
{{{id=36|
show(P0)
}}}r}UWorksheet 'data!' (2007-10-02 at 16:08)
{{{id=35|
%time
S0 = SatoTate(EllipticCurve('5077a'), 10^5)
P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.55 s,  Wall time: 0.56 s
}}}r~U>Worksheet 'data!' (2007-10-02 at 16:08)
{{{id=36|
show(P0)
}}}rTmWorksheet 'data!' (2007-10-02 at 16:09)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        #self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rUWorksheet 'data!' (2007-10-02 at 16:09)
{{{id=35|
%time
S0 = SatoTate(EllipticCurve('5077a'), 10^5)
P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.54 s,  Wall time: 0.58 s
}}}rU>Worksheet 'data!' (2007-10-02 at 16:09)
{{{id=36|
show(P0)
}}}rU>Worksheet 'data!' (2007-10-02 at 16:09)
{{{id=36|
show(P0)
}}}rTWWorksheet 'data!' (2007-10-02 at 16:10)
{{{id=35|
%time
S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
CPU time: 0.57 s,  Wall time: 0.67 s
}}}rTzWorksheet 'data!' (2007-10-02 at 16:10)
{{{id=35|
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.03 s, Wall: 0.03 s
CPU time: 0.56 s,  Wall time: 0.59 s
}}}rTWorksheet 'data!' (2007-10-02 at 16:11)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
Time: CPU 0.52 s, Wall: 0.59 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.04 s, Wall: 0.04 s
}}}rTlWorksheet 'data!' (2007-10-02 at 16:12)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 16:12)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
Time: CPU 0.54 s, Wall: 0.57 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.04 s, Wall: 0.04 s
}}}rTWorksheet 'data!' (2007-10-02 at 16:12)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        print "init %s"%n
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 16:12)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
init 100000
Time: CPU 0.52 s, Wall: 0.55 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.04 s, Wall: 0.03 s
}}}rTWorksheet 'data!' (2007-10-02 at 16:12)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
init 100000
Time: CPU 0.52 s, Wall: 0.55 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.04 s, Wall: 0.03 s
}}}rTWorksheet 'data!' (2007-10-02 at 18:51)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        print "init %s"%n
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 18:52)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
print S0
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
init 100000
Time: CPU 1.02 s, Wall: 1.20 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 100000
Time: CPU 0.12 s, Wall: 0.12 s
}}}rTWorksheet 'data!' (2007-10-02 at 18:52)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=20, max_points=10, L_norm=2)
///
init 10000
Time: CPU 0.08 s, Wall: 0.09 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.05 s, Wall: 0.05 s
}}}rU>Worksheet 'data!' (2007-10-02 at 18:52)
{{{id=36|
show(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 18:58)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        print "init %s"%n
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 18:58)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
init 10000
Time: CPU 0.07 s, Wall: 0.06 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.02 s, Wall: 0.02 s
}}}rT|Worksheet 'Sato Tate' (2007-10-02 at 18:58)
{{{id=1|
#auto
def dist(v, b, left=-1.0r, right=1.0r):
    """
    We divide the interval between left (default: 0) and 
    right (default: pi) up into b bins.
   
    For each number in v (which must left and right), 
    we find which bin it lies in and add this to a counter.
    This function then returns the bins and the number of
    elements of v that lie in each one. 

    ALGORITHM: To find the index of the bin that a given 
    number x lies in, we multiply x by b/length and take the 
    floor. 
    """
    length = right - left
    normalize = float(b/length)
    vals = {}
    d = dict([(i,0) for i in range(b)])
    for x in v:
        n = int(normalize*(float(x)-left))
        d[n] += 1
    return d, len(v)

def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r):
    s = Graphics()
    left = float(left); right = float(right)
    length = right - left
    w = length/b
    k = 0
    for i, n in d.iteritems():
        k += n
        # ith bin has n objects in it. 
        s += polygon([(w*i+left,0), (w*(i+1)+left,0), \
                     (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ 
                     rgbcolor=(0,0,0.5))
    return s

def semicircle0():
    alpha = 2.0r / float(pi)
    def f(x):
        return alpha * math.sqrt(1-x^2)
    return plot(f, -1,1,rgbcolor=(0.5,0,0))
semicircle = semicircle0()
}}}rT(Worksheet 'Sato Tate' (2007-10-02 at 18:58)
{{{id=2|
#auto
from math import asin, log, sqrt

def line1(xmin,xmax):
    return line([(xmin,1),(xmax,1)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E):
        self._E = E    
    
    def __repr__(self): 
        return "Sato-Tate data for %s"%self._E

    def anlist(self, n):
        return self._E.anlist(n)
 
    def normalized_aplist(self, n):
        anlist = self.anlist(n)
        two = float(2)
        v = [float(anlist[p])/(two*sqrt(p)) for p in prime_range(n)]
        return v

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            print val
            err = 0
        else:
            n = int(L_norm)
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_2 norm.
            err = float(err^(1.0/n))
    
        #self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey)            + point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + line1(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rT=Worksheet 'Sato Tate' (2007-10-02 at 18:58)
{{{id=97|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Traceback (most recent call last):    print S0
TypeError: __init__() takes exactly 2 arguments (3 given)
}}}rTeWorksheet 'Sato Tate' (2007-10-02 at 18:59)
{{{id=97|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'))
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.02 s, Wall: 0.01 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field
Time: CPU 1.48 s, Wall: 2.23 s
}}}rUCWorksheet 'Sato Tate' (2007-10-02 at 18:59)
{{{id=98|
P0.show()
}}}rTWorksheet 'data!' (2007-10-02 at 18:59)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
init 10000
Time: CPU 0.05 s, Wall: 0.06 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.02 s, Wall: 0.02 s
}}}rU>Worksheet 'data!' (2007-10-02 at 18:59)
{{{id=36|
show(P0)
}}}rU9Worksheet 'data!' (2007-10-02 at 19:02)
{{{id=37|
S0.
}}}rU>Worksheet 'data!' (2007-10-02 at 19:02)
{{{id=37|
S0.Delta
}}}rU>Worksheet 'data!' (2007-10-02 at 19:02)
{{{id=37|
S0.Delta
}}}rU}Worksheet 'data!' (2007-10-02 at 19:02)
{{{id=37|
S0.Delta(1000, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rUWorksheet 'Sato Tate' (2007-10-02 at 19:02)
{{{id=101|
S0.Delta(1000, -1, 1)
///
(0.11653786581910371, 0.011000750818943632)
}}}rU}Worksheet 'data!' (2007-10-02 at 19:03)
{{{id=37|
S0.Delta(10^4, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rUWorksheet 'Sato Tate' (2007-10-02 at 19:03)
{{{id=101|
S0.Delta(10^4, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rU}Worksheet 'data!' (2007-10-02 at 19:03)
{{{id=37|
S0.Delta(10^3, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rU}Worksheet 'data!' (2007-10-02 at 19:03)
{{{id=37|
S0.Delta(10^4, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rTWorksheet 'data!' (2007-10-02 at 19:04)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        print "init %s"%n
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        self._sorted_aplist = list(self._normalized_aplist)
        self._sorted_aplist.sort()
  
    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):
        self.init_aplist(n)
        return self._normalized_aplist

    def sorted_aplist(self, n):
        self.init_aplist(n)
        return self._sorted_aplist

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 19:04)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
init 10000
Time: CPU 0.05 s, Wall: 0.05 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
init 100
init 1100
init 2100
init 3100
init 4100
init 5100
init 6100
init 7100
init 8100
init 9100
Time: CPU 0.23 s, Wall: 0.32 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:04)
{{{id=37|
S0.Delta(10^4, -1, 1)
///
init 10000
(0.024699554129187312, 0.0049363701843274316)
}}}rU>Worksheet 'data!' (2007-10-02 at 19:04)
{{{id=36|
show(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:08)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]
}}}rTWorksheet 'data!' (2007-10-02 at 19:08)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.07 s, Wall: 0.07 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.03 s, Wall: 0.03 s
}}}rU}Worksheet 'data!' (2007-10-02 at 19:09)
{{{id=37|
S0.Delta(10^4, -1, 1)
///
(0.024699554129187312, 0.0049363701843274316)
}}}rU{Worksheet 'data!' (2007-10-02 at 19:09)
{{{id=37|
S0.Delta(10^3, -1, 1)
///
(0.11653786581910371, 0.011000750818943632)
}}}rU>Worksheet 'data!' (2007-10-02 at 19:09)
{{{id=36|
show(P0)
}}}rUFWorksheet 'data!' (2007-10-02 at 19:09)
{{{id=36|
show(P0, ymin=0)
}}}rUPWorksheet 'data!' (2007-10-02 at 19:09)
{{{id=36|
show(P0, ymin=0, ymax=0.6)
}}}rTWorksheet 'data!' (2007-10-02 at 19:10)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6)
}}}rTWorksheet 'data!' (2007-10-02 at 19:10)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[7,3])
}}}rTWorksheet 'data!' (2007-10-02 at 19:10)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.05 s, Wall: 0.05 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.02 s, Wall: 0.02 s
}}}rU?Worksheet 'data!' (2007-10-02 at 19:10)
{{{id=36|
showtheta
}}}rUCWorksheet 'data!' (2007-10-02 at 19:10)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        v = self._E.aplist(n)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rTWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.05 s, Wall: 0.05 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.02 s, Wall: 0.02 s
}}}rTWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=10, max_points=10, L_norm=2)
///
Time: CPU 0.05 s, Wall: 0.05 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.02 s, Wall: 0.02 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^4)
print S0
time P0 = S0.plot_theta_interval(10^4, plot_points=100, max_points=10, L_norm=2)
///
Time: CPU 0.05 s, Wall: 0.05 s
Sato-Tate data for Elliptic Curve defined by y^2 + y = x^3 - 7*x + 6 over Rational Field using primes up to 10000
Time: CPU 0.20 s, Wall: 0.21 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:11)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:12)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
time P0 = S0.plot_theta_interval(10^5, plot_points=100, max_points=10, L_norm=2)
///
Time: CPU 0.54 s, Wall: 0.55 s
Time: CPU 0.35 s, Wall: 0.40 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:12)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:12)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
///
Time: CPU 6.90 s, Wall: 7.91 s
Time: CPU 2.46 s, Wall: 2.82 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:12)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:15)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print cputime('computed aplist ', cputime(t))
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print cputime('time to normalize ', cputime(t))

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rTWorksheet 'data!' (2007-10-02 at 19:15)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/131.py", line 23, in __init__
    self.init_aplist(n)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/131.py", line 28, in init_aplist
    print cputime('computed aplist ', cputime(t))
TypeError: cputime() takes at most 1 argument (2 given)
}}}rT{Worksheet 'data!' (2007-10-02 at 19:16)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print cputime('computed aplist ', cputime(t))
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rTWorksheet 'data!' (2007-10-02 at 19:16)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
///
Traceback (most recent call last):    time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/133.py", line 23, in __init__
    self.init_aplist(n)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/133.py", line 28, in init_aplist
    print cputime('computed aplist ', cputime(t))
TypeError: cputime() takes at most 1 argument (2 given)
}}}rTrWorksheet 'data!' (2007-10-02 at 19:16)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rT<Worksheet 'data!' (2007-10-02 at 19:16)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=10, L_norm=2)
///
computed aplist  5.408338
time to normalize  0.084006
Time: CPU 6.14 s, Wall: 6.93 s
Time: CPU 2.38 s, Wall: 2.71 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:16)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:17)
{{{id=38|
time P0 = S0.plot_theta_interval(10^6, plot_points=200, max_points=10, L_norm=2)
///
CPU time: 2.47 s,  Wall time: 2.69 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:17)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr, pointsize=5) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.424026
time to normalize  0.012001
Time: CPU 0.52 s, Wall: 0.56 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=10, L_norm=2)
///
CPU time: 0.74 s,  Wall time: 0.80 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr, pointsize=2) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.408025
time to normalize  0.012
Time: CPU 0.49 s, Wall: 0.53 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=10, L_norm=2)
///
CPU time: 0.78 s,  Wall time: 0.84 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=36|
showtheta(P0)
}}}rUCWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.00 s,  Wall time: 0.00 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=clr, pointsize=2) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.412025
time to normalize  0.00799999999998
Time: CPU 0.50 s, Wall: 0.50 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.07 s,  Wall time: 0.07 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.07 s,  Wall time: 0.07 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:20)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,0), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,1), pointsize=2) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.424026
time to normalize  0.0119999999999
Time: CPU 0.52 s, Wall: 0.55 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.08 s,  Wall time: 0.19 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=36|
showtheta(P0)
}}}rTWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.448028
time to normalize  0.012001
Time: CPU 0.54 s, Wall: 0.59 s
}}}rUWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=20, max_points=10, L_norm=2)
///
CPU time: 0.07 s,  Wall time: 0.13 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=10, L_norm=2)
///
CPU time: 0.70 s,  Wall time: 0.73 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:21)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=40, L_norm=2)
///
CPU time: 1.48 s,  Wall time: 1.55 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2)
///
CPU time: 3.23 s,  Wall time: 3.55 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo)
///
CPU time: 0.57 s,  Wall time: 0.59 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=36|
showtheta(P0)
}}}rUWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2)
///
CPU time: 0.00 s,  Wall time: 0.00 s
}}}rUCWorksheet 'data!' (2007-10-02 at 19:22)
{{{id=36|
showtheta(P0)
}}}rT"Worksheet 'data!' (2007-10-02 at 19:25)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2)
time P1 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo)
///
Time: CPU 0.01 s, Wall: 0.01 s
CPU time: 0.03 s,  Wall time: 0.02 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:25)
{{{id=36|
showtheta(P0+P1)
}}}rT>Worksheet 'data!' (2007-10-02 at 19:26)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo, clr=(0,0,0.5))
///
Time: CPU 0.01 s, Wall: 0.01 s
CPU time: 0.02 s,  Wall time: 0.02 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:26)
{{{id=36|
showtheta(P0+P1)
}}}rT>Worksheet 'data!' (2007-10-02 at 19:26)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 0.01 s, Wall: 0.01 s
CPU time: 0.02 s,  Wall time: 0.02 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:26)
{{{id=36|
showtheta(P0+P1)
}}}rT>Worksheet 'data!' (2007-10-02 at 19:28)
{{{id=38|
time P0 = S0.plot_theta_interval(10^4, plot_points=200, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^4, plot_points=200, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 0.14 s, Wall: 0.15 s
CPU time: 2.25 s,  Wall time: 2.58 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:28)
{{{id=36|
showtheta(P0+P1)
}}}rT>Worksheet 'data!' (2007-10-02 at 19:29)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 0.01 s, Wall: 0.01 s
CPU time: 0.02 s,  Wall time: 0.02 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:29)
{{{id=36|
showtheta(P0+P1)
}}}rUWorksheet 'data!' (2007-10-02 at 19:29)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 2*10^6)
///
computed aplist  12.908807
time to normalize  0.15201
Time: CPU 14.53 s, Wall: 17.10 s
}}}rT>Worksheet 'data!' (2007-10-02 at 19:29)
{{{id=38|
time P0 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^5, plot_points=200, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 0.54 s, Wall: 0.56 s
CPU time: 3.36 s,  Wall time: 3.67 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:29)
{{{id=36|
showtheta(P0+P1)
}}}rT<Worksheet 'data!' (2007-10-02 at 19:30)
{{{id=38|
time P0 = S0.plot_theta_interval(10^6, plot_points=20, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=20, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 0.42 s, Wall: 0.44 s
CPU time: 1.10 s,  Wall time: 1.15 s
}}}rUPWorksheet 'data!' (2007-10-02 at 19:30)
{{{id=36|
showtheta(P0+P1)
///
e185
}}}rT>Worksheet 'data!' (2007-10-02 at 19:30)
{{{id=38|
time P0 = S0.plot_theta_interval(10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 1.86 s, Wall: 2.47 s
CPU time: 4.74 s,  Wall time: 5.66 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:30)
{{{id=36|
showtheta(P0+P1)
}}}rTBWorksheet 'data!' (2007-10-02 at 19:30)
{{{id=38|
time P0 = S0.plot_theta_interval(2*10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(2*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 3.71 s, Wall: 4.59 s
CPU time: 8.06 s,  Wall time: 9.65 s
}}}rUFWorksheet 'data!' (2007-10-02 at 19:30)
{{{id=36|
showtheta(P0+P1)
}}}rTWorksheet 'data!' (2007-10-02 at 19:31)
{{{id=40|
fit = plot(1/2 - 1/log(x), 10, 2*10^6)
///
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/192.py", line 4, in 
    exec compile(ur'fit = plot(Integer(1)/Integer(2) - Integer(1)/log(x), Integer(10), Integer(2)*Integer(10)**Integer(6))' + '\n', '', 'single')
  File "/home/was/s/data/extcode/sage/", line 1, in 
    
TypeError: a float is required
}}}rUkWorksheet 'data!' (2007-10-02 at 19:31)
{{{id=40|
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 2*10^6)
}}}rUFWorksheet 'data!' (2007-10-02 at 19:31)
{{{id=36|
showtheta(P0+P1)
}}}rUJWorksheet 'data!' (2007-10-02 at 19:32)
{{{id=36|
showtheta(P0+P1+fit)
}}}rU}Worksheet 'data!' (2007-10-02 at 19:32)
{{{id=40|
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 2*10^6, rgbcolor=(0,0,0))
}}}rUJWorksheet 'data!' (2007-10-02 at 19:32)
{{{id=36|
showtheta(P0+P1+fit)
}}}rUWorksheet 'data!' (2007-10-02 at 19:35)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^7)
///
computed aplist  82.149134
Killed
}}}rT>Worksheet 'data!' (2007-10-02 at 19:36)
{{{id=38|
time P0 = S0.plot_theta_interval(10^7, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^7, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 3.71 s, Wall: 4.59 s
CPU time: 8.06 s,  Wall time: 9.65 s
}}}rTEWorksheet 'data!' (2007-10-02 at 19:43)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 5*10^6)
///
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/203.py", line 5, in 
    exec compile(ur'__time__=misc.cputime(); __wall__=misc.walltime();  S0 = SatoTate(EllipticCurve(\u00275077a\u0027), Integer(5)*Integer(10)**Integer(6)); print         "Time: CPU %.2f s, Wall: %.2f s"%(misc.cputime(__time__), misc.walltime(__wall__))' + '\n', '', 'single')
  File ...
}}}rTWorksheet 'data!' (2007-10-02 at 19:43)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 19:45)
{{{id=35|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 5*10^6)
///
computed aplist  50.23914
time to normalize  1.796112
Time: CPU 59.98 s, Wall: 72.94 s
}}}rTFWorksheet 'data!' (2007-10-02 at 19:45)
{{{id=38|
time P0 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 12.93 s, Wall: 14.71 s
CPU time: 29.03 s,  Wall time: 34.74 s
}}}rU}Worksheet 'data!' (2007-10-02 at 19:45)
{{{id=40|
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 5*10^6, rgbcolor=(0,0,0))
}}}rUJWorksheet 'data!' (2007-10-02 at 19:45)
{{{id=36|
showtheta(P0+P1+fit)
}}}rTWorksheet 'data!' (2007-10-02 at 21:04)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_Delta(Cmax, *args, **kwds)
        return point(v, rgbcolor=(0,0,0), pointsize=3) + line(v, rgbcolor=clr)

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 21:04)
{{{id=41|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.508032
time to normalize  0.00800000000001
Time: CPU 0.72 s, Wall: 0.76 s
}}}r	UCWorksheet 'data!' (2007-10-02 at 21:04)
{{{id=42|
show(S0.plot_
}}}r
UHWorksheet 'data!' (2007-10-02 at 21:04)
{{{id=42|
show(S0.plot_Delta
}}}rUHWorksheet 'data!' (2007-10-02 at 21:04)
{{{id=42|
show(S0.plot_Delta
}}}rU`Worksheet 'data!' (2007-10-02 at 21:05)
{{{id=42|
show(S0.plot_Delta(10^5), plot_points=100)
}}}r
U`Worksheet 'data!' (2007-10-02 at 21:05)
{{{id=42|
show(S0.plot_Delta(10^5), plot_points=200)
}}}rU`Worksheet 'data!' (2007-10-02 at 21:05)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100))
}}}rU|Worksheet 'data!' (2007-10-02 at 21:05)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100), ymax=0.1, ymin=0)
///
e215
}}}rUWorksheet 'data!' (2007-10-02 at 21:05)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}rUWorksheet 'data!' (2007-10-02 at 21:06)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}rUWorksheet 'data!' (2007-10-02 at 21:06)
{{{id=43|
show(S0.plot_Delta(10^5, plot_points=100, max_points=100, L_norm=oo), ymax=0.1, ymin=0, figsize=[10,3])
}}}rTNWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax, **kwds):
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return point(v2, rgbcolor=(0,0,0), pointsize=3) + line(v2, rgbcolor=(0,0,1)) + \
               point(voo, rgbcolor=(0,0,0), pointsize=3) + line(voo, rgbcolor=(0,0.5,1))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rTNWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax, **kwds):
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return point(v2, rgbcolor=(0,0,0), pointsize=3) + line(v2, rgbcolor=(0,0,1)) + \
               point(voo, rgbcolor=(0,0,0), pointsize=3) + line(voo, rgbcolor=(0,0.5,1))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=41|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.432027
time to normalize  0.008
Time: CPU 0.52 s, Wall: 0.55 s
}}}rUWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=41|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.432027
time to normalize  0.008
Time: CPU 0.52 s, Wall: 0.55 s
}}}rUWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}rTNWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax, **kwds):
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return point(v2, rgbcolor=(0,0,0), pointsize=3) + line(v2, rgbcolor=(0,0,1)) + \
               point(voo, rgbcolor=(0,0,0), pointsize=3) + line(voo, rgbcolor=(0,0.5,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=41|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^5)
///
computed aplist  0.424027
time to normalize  0.00800099999998
Time: CPU 0.50 s, Wall: 0.54 s
}}}rUWorksheet 'data!' (2007-10-02 at 21:08)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}rTNWorksheet 'data!' (2007-10-02 at 21:09)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax, **kwds):
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return point(v2, rgbcolor=(0,0,0), pointsize=3) + line(v2, rgbcolor=(0,0,1)) + \
               point(voo, rgbcolor=(0,0,0), pointsize=3) + line(voo, rgbcolor=(0.8,0,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax, clr=(0,0,1), *args, **kwds):
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 21:09)
{{{id=41|
# make curve
time S0 = SatoTate(EllipticCurve('5077a'), 10^6)
///
computed aplist  5.356334
time to normalize  0.072004
Time: CPU 6.06 s, Wall: 8.39 s
}}}rTWorksheet 'data!' (2007-10-02 at 21:09)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax=None, **kwds):
        if Cmax is None: Cmax = self._n
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return point(v2, rgbcolor=(0,0,0), pointsize=3) + line(v2, rgbcolor=(0,0,1)) + \
               point(voo, rgbcolor=(0,0,0), pointsize=3) + line(voo, rgbcolor=(0.8,0,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds):
        if Cmax is None: Cmax = self._n
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) + \
                point(v,rgbcolor=(0,0,0), pointsize=3) + line(v,rgbcolor=clr) + redline(0, Cmax)

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}rUWorksheet 'data!' (2007-10-02 at 21:09)
{{{id=42|
show(S0.plot_Delta(10^5, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}rUWorksheet 'data!' (2007-10-02 at 21:09)
{{{id=42|
show(S0.plot_Delta(10^6, plot_points=100, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r UWorksheet 'data!' (2007-10-02 at 21:11)
{{{id=44|
# make curve
time e37a = SatoTate(EllipticCurve('37a'), 10^6)
///
computed aplist  5.324333
time to normalize  0.076005
Time: CPU 6.02 s, Wall: 7.14 s
}}}r!UWorksheet 'data!' (2007-10-02 at 21:11)
{{{id=45|
show(e37a.plot_Delta(10^5, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r"UWorksheet 'data!' (2007-10-02 at 21:11)
{{{id=46|
show(e37a.plot_Delta(10^6, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r#TDWorksheet 'data!' (2007-10-02 at 21:12)
{{{id=2|
#auto
from math import asin, log, sqrt

def redline(xmin,xmax):
    return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0))

def Xab(a,b):
    bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r)
    aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r)
    def X(T):
        return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa)
    return X

import bisect

class SatoTate:
    def __init__(self, E, n):
        self._E = E    
        self._n = n
        self.init_aplist(n)

    def init_aplist(self, n):
        t = cputime()
        v = self._E.aplist(n, python_ints=True)
        print 'computed aplist ', cputime(t)
        P = prime_range(n)
        self._aplist = v
        two = float(2)
        t = cputime()
        self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))]
        print 'time to normalize ', cputime(t)

    def __repr__(self): 
        return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n)
 
    def normalized_aplist(self, n):  # returns a copy
        k = prime_pi(n)
        v = self._normalized_aplist
        if k > len(v):
             raise ValueError, "call init_aplist"
        return v[:prime_pi(n)]

    def sorted_aplist(self, n):
        v = self.normalized_aplist(n)
        v.sort()
        return v

    def YCab(self, Cmax, a=-1, b=1):
        v = self.sorted_aplist(Cmax)
    
        denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a))
        try:
           normalize = float(1)/denom
        except:
           def Y(T):
               return 1.0r
           return Y
        start_pos = bisect.bisect_left(v, float(a))

        def Y(T):
            # find position that T would go in if it were inserted
            # in the sorted list v.
            n = bisect.bisect_right(v, float(T)) - start_pos
            return n * normalize
        return Y


    def xyplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pX = plot(X, a, b, rgbcolor=(1,0,0))
        pY = plot(Y, a, b, rgbcolor=(0,0,1))
        return pX + pY

    def qqplot(self, C, a=-1, b=1):
        """
        Return the quantile-quantile plot for given a,b, up to C.
        """
        Y = self.YCab(C,a=a,b=b)
        X = Xab(a=a,b=b)
        pl = parametric_plot((X, Y), a,b)
        ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0))
        return pl+ll
 
    def Delta(self, C, a, b, max_points=300, L_norm=2):
        """
        Delta_{a}^{b} function:

        INPUT: C - cutoff
             a,b - evaluate over the interval (a,b)
             max_points - number of points used in numerical integral         
             L_norm --the integer n=2 or n=oo. 
                      Compute the L_n norm.   For n finite this
                      is the integral of the difference to the power n.
                      For n = +oo, this is the L_oo norm, which is the max
                      of the absolute value of the difference (where the max
                      is evaluated at max_points equidistributed points).
        """
        key = (C,a,b,max_points, L_norm)
        try:
           return self._delta[key]
        except AttributeError:
           self._delta = {}
        except KeyError:
           pass
        X = Xab(a,b)
        Y = self.YCab(C,a,b)     # This takes all the time.

        if L_norm == oo:
            val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)])
            err = 0
        else:
            n = int(L_norm)   # usually n = 2.
            def h(T):
                return (X(T) - Y(T))^n
            val, err = integral_numerical(h, a, b, max_points=max_points, 
              algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10)
            val = float(val^(1.0/n)) # compute L_n norm.
            err = float(err^(1.0/n))
    
        self._delta[key] = (val, err)
        return val, err

    def plot_Delta(self, Cmax=None, **kwds):
        if Cmax is None: Cmax = self._n
        v2 = self.compute_Delta(Cmax, L_norm=2,  **kwds)
        voo = self.compute_Delta(Cmax, L_norm=oo, **kwds)
        return line(v2, rgbcolor=(0,0,1)) + line(voo, rgbcolor=(0.8,0,0))

    def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, 
                            max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
           return val
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def theta(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val)/log(C), val, err

    def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2):
        val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm)
        return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C)

    def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, 
                 max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        def f(C):
           z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm)
           if verbose: print C, z
           return z[0]
        return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))]

    def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, 
                max_points=300, L_norm=2, verbose=False):
        a,b = (float(a), float(b))
        vmin = []; vmax = []
        for C in range(100, Cmax, int(Cmax/plot_points)):
            zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm)
            vmin.append((C, zmin))
            vmax.append((C, zmax))
            if verbose: print C, zmin, zmax
        return vmin, vmax

    def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds):
        if Cmax is None: Cmax = self._n
        vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
        v = self.compute_theta(Cmax, *args, **kwds)
        grey = (0.7,0.7,0.7)
        return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) \
                 + line(v,rgbcolor=clr) + redline(0, Cmax) # + point(v,rgbcolor=(0,0,0), pointsize=3) 

    def histogram(self, Cmax, num_bins):
        v = self.normalized_aplist(Cmax)
        d, total_number_of_points = dist(v, num_bins)
        return frequency_histogram(d, num_bins, total_number_of_points) + semicircle

    def x_times_Delta(self, x):
        return x*self.Delta(x, -1,1, max_points=500)[0]

def showtheta(P):
    P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4])
}}}r$UWorksheet 'data!' (2007-10-02 at 21:12)
{{{id=44|
# make curve
time e37a = SatoTate(EllipticCurve('37a'), 10^6)
///
computed aplist  5.120321
time to normalize  0.080005
Time: CPU 5.85 s, Wall: 7.80 s
}}}r%UWorksheet 'data!' (2007-10-02 at 21:13)
{{{id=45|
show(e37a.plot_Delta(10^5, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r&UWorksheet 'data!' (2007-10-02 at 21:13)
{{{id=46|
show(e37a.plot_Delta(10^6, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r'UWorksheet 'data!' (2007-10-02 at 21:29)
{{{id=45|
show(e37a.plot_Delta(10^4, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r(UWorksheet 'data!' (2007-10-02 at 21:57)
{{{id=47|
show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r)UWorksheet 'data!' (2007-10-02 at 21:57)
{{{id=47|
show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.3, ymin=0, figsize=[10,3])
}}}r*UWorksheet 'data!' (2007-10-02 at 21:57)
{{{id=47|
show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.1, ymin=0, figsize=[10,3])
}}}r+UWorksheet 'data!' (2007-10-02 at 23:03)
{{{id=49|
# make curve
time S0 = SatoTate(EllipticCurve('37a'), 10^6)
///
computed aplist  5.452341
time to normalize  0.088005
Time: CPU 6.23 s, Wall: 7.71 s
}}}r,TWorksheet 'data!' (2007-10-02 at 23:03)
{{{id=50|
time P0 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
///
Traceback (most recent call last):    time P1 = S0.plot_theta_interval(5*10^6, plot_points=100, max_points=100, L_norm=oo, clr=(0,0.5,0))
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/236.py", line 174, in plot_theta_interval
    vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds)
  File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/236.py", line 166, in compute_theta_interval
    zmin,zmax = self.thet...
}}}r-T=Worksheet 'data!' (2007-10-02 at 23:04)
{{{id=50|
time P0 = S0.plot_theta_interval(10^6, plot_points=150, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=150, max_points=80, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 3.47 s, Wall: 4.18 s
CPU time: 8.47 s,  Wall time: 10.26 s
}}}r.U}Worksheet 'data!' (2007-10-02 at 23:04)
{{{id=48|
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 5*10^6, rgbcolor=(0,0,0))
}}}r/U{Worksheet 'data!' (2007-10-02 at 23:04)
{{{id=48|
fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
}}}r0UJWorksheet 'data!' (2007-10-02 at 23:04)
{{{id=51|
showtheta(P0+P1+fit)
}}}r1U|Worksheet 'data!' (2007-10-02 at 23:05)
{{{id=48|
#fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0))
}}}r2UFWorksheet 'data!' (2007-10-02 at 23:05)
{{{id=51|
showtheta(P0+P1)
}}}r3T<Worksheet 'data!' (2007-10-02 at 23:05)
{{{id=50|
time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1))
time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0))
///
Time: CPU 3.36 s, Wall: 3.82 s
CPU time: 8.47 s,  Wall time: 9.97 s
}}}r4UFWorksheet 'data!' (2007-10-02 at 23:05)
{{{id=51|
showtheta(P0+P1)
}}}r5T+Worksheet 'Untitled' (2007-10-02 at 23:15)
{{{id=0|
var('x,y,z')
show(x**2+y**2==z**2) 
///
Timeout exceeded in read_nonblocking().

version: 2.0 ($Revision: 1.151 $)
command: /home/was/s/local/bin/maxima
args: ['/home/was/s/local/bin/maxima', '-p', '/home/was/s/local/bin/sage-maxima.lisp']
patterns:
    \(\%i[0-9]+\)
buffer (last 100 chars): 
before (last 100 chars): 
after: 
match: None
match_index: None
exitstatus: None
flag_eof: 0
pid: 23404
child_fd: 3
timeout: 30
delimiter: <...
}}}r6UWorksheet 'Untitled' (2007-10-02 at 23:16)
{{{id=0|
var('x,y,z')
show(x**2+y**2==z**2) 
///
{y}^{2} + {x}^{2} = {z}^{2}
}}}r7UWorksheet 'Untitled' (2007-10-02 at 23:16) {{{id=0| var('x,y,z') show(x**2+y**2==z**2) ///
{y}^{2} + {x}^{2} = {z}^{2}
}}}r8UZWorksheet 'Untitled' (2007-10-02 at 23:16) {{{id=1| %latex $$\sage{x**2+y**2==z**2}$$ }}}r9TWorksheet 'data!' (2007-10-02 at 23:27) {{{id=54| # make curve time S0 = SatoTate(EllipticCurve('11a'), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 6.004376 time to normalize 0.084006 Time: CPU 6.75 s, Wall: 8.61 s Time: CPU 10.05 s, Wall: 11.99 s Time: CPU 6.80 s, Wall: 7.73 s }}}r:UFWorksheet 'data!' (2007-10-02 at 23:27) {{{id=53| showtheta(P0+P1) }}}r;TWorksheet 'data!' (2007-10-02 at 23:29) {{{id=58| # make curve time S0 = SatoTate(EllipticCurve('389a'), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.812363 time to normalize 0.088006 Time: CPU 6.58 s, Wall: 8.91 s Time: CPU 10.13 s, Wall: 14.74 s Time: CPU 7.09 s, Wall: 9.34 s }}}r<UFWorksheet 'data!' (2007-10-02 at 23:29) {{{id=57| showtheta(P0+P1) }}}r=TWorksheet 'data!' (2007-10-02 at 23:37) {{{id=56| # make curve time S0 = SatoTate(EllipticCurve('5077a'), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.724357 time to normalize 0.084005 Time: CPU 6.44 s, Wall: 8.98 s Time: CPU 10.18 s, Wall: 14.21 s Time: CPU 6.98 s, Wall: 9.24 s }}}r>UFWorksheet 'data!' (2007-10-02 at 23:37) {{{id=60| showtheta(P0+P1) }}}r?TWorksheet 'data!' (2007-10-02 at 23:38) {{{id=65| time S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.708357 time to normalize 0.084005 Time: CPU 9.96 s, Wall: 13.32 s Time: CPU 6.73 s, Wall: 9.17 s Time: CPU 0.21 s, Wall: 0.24 s CPU time: 23.33 s, Wall time: 31.74 s }}}r@TWorksheet 'data!' (2007-10-02 at 23:43) {{{id=68| time S0 = SatoTate(EllipticCurve([0, 0, 1, -79, 342]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.496343 time to normalize 0.080005 Time: CPU 10.03 s, Wall: 12.37 s Time: CPU 6.89 s, Wall: 9.98 s Time: CPU 0.22 s, Wall: 0.25 s CPU time: 23.34 s, Wall time: 31.16 s }}}rAU6Worksheet 'data!' (2007-10-03 at 05:38) {{{id=70| }}}rBT Worksheet 'data!' (2007-10-03 at 05:39) {{{id=71| time S0 = SatoTate(EllipticCurve([1, 1, 0, -2582, 48720]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.60835 time to normalize 0.084005 Time: CPU 9.56 s, Wall: 11.41 s Time: CPU 6.55 s, Wall: 7.51 s Time: CPU 0.22 s, Wall: 0.22 s CPU time: 22.69 s, Wall time: 26.81 s }}}rCT Worksheet 'data!' (2007-10-03 at 05:39) {{{id=82| time S0 = SatoTate(EllipticCurve([0, 0, 0, -10012, 346900]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.44034 time to normalize 0.068004 Time: CPU 9.69 s, Wall: 11.92 s Time: CPU 6.94 s, Wall: 8.90 s Time: CPU 0.19 s, Wall: 0.20 s CPU time: 22.93 s, Wall time: 28.44 s }}}rDT Worksheet 'data!' (2007-10-03 at 05:40) {{{id=81| time S0 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.468342 time to normalize 0.072004 Time: CPU 9.86 s, Wall: 13.49 s Time: CPU 6.53 s, Wall: 8.20 s Time: CPU 0.20 s, Wall: 0.36 s CPU time: 22.71 s, Wall time: 30.85 s }}}rETWorksheet 'data!' (2007-10-03 at 05:40) {{{id=80| time S0 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.724358 time to normalize 0.072004 Time: CPU 9.62 s, Wall: 11.71 s Time: CPU 6.50 s, Wall: 8.02 s Time: CPU 0.20 s, Wall: 0.21 s CPU time: 22.67 s, Wall time: 29.42 s }}}rFTWorksheet 'data!' (2007-10-03 at 05:49) {{{id=66| # make curve time S0 = SatoTate(EllipticCurve('5077a'), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.372336 time to normalize 0.076004 Time: CPU 6.09 s, Wall: 7.20 s Time: CPU 9.86 s, Wall: 12.41 s Time: CPU 7.06 s, Wall: 8.90 s }}}rGU{Worksheet 'data!' (2007-10-03 at 05:49) {{{id=86| fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rHUNWorksheet 'data!' (2007-10-03 at 05:49) {{{id=85| showtheta(P0 + P1 + fit) }}}rITWorksheet 'data!' (2007-10-03 at 05:54) {{{id=84| # make curve time S0 = SatoTate(EllipticCurve('11a'), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 6.148385 time to normalize 0.212012 Time: CPU 6.99 s, Wall: 9.07 s Time: CPU 9.85 s, Wall: 12.97 s Time: CPU 6.80 s, Wall: 8.37 s }}}rJTUWorksheet 'data!' (2007-10-03 at 05:55) {{{id=84| # make curve %time time S0 = SatoTate(EllipticCurve([19,234]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// Syntax Error: %time }}}rKTWorksheet 'data!' (2007-10-03 at 05:56) {{{id=84| %time time S0 = SatoTate(EllipticCurve([19,234]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.416338 time to normalize 0.076005 Time: CPU 6.09 s, Wall: 7.23 s Time: CPU 9.72 s, Wall: 11.44 s Time: CPU 6.84 s, Wall: 8.45 s CPU time: 22.64 s, Wall time: 27.12 s }}}rLU{Worksheet 'data!' (2007-10-03 at 05:56) {{{id=88| fit = plot(lambda x: 1/2 - 1/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rMUNWorksheet 'data!' (2007-10-03 at 05:57) {{{id=87| showtheta(P0 + P1 + fit) }}}rNTWorksheet 'data!' (2007-10-03 at 06:03) {{{id=91| time S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.768361 time to normalize 0.076005 Time: CPU 9.90 s, Wall: 12.42 s Time: CPU 6.94 s, Wall: 8.04 s CPU time: 23.31 s, Wall time: 28.67 s }}}rOUNWorksheet 'data!' (2007-10-03 at 06:03) {{{id=90| showtheta(P0 + P1 + fit) }}}rPU{Worksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rQUNWorksheet 'data!' (2007-10-03 at 06:06) {{{id=90| showtheta(P0 + P1 + fit) }}}rRU}Worksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - 1.5/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rSUNWorksheet 'data!' (2007-10-03 at 06:06) {{{id=90| showtheta(P0 + P1 + fit) }}}rTU}Worksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - 1.2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUUNWorksheet 'data!' (2007-10-03 at 06:06) {{{id=90| showtheta(P0 + P1 + fit) }}}rVU~Worksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - 1.25/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rWUNWorksheet 'data!' (2007-10-03 at 06:06) {{{id=90| showtheta(P0 + P1 + fit) }}}rXU}Worksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - 1.3/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rYUNWorksheet 'data!' (2007-10-03 at 06:06) {{{id=90| showtheta(P0 + P1 + fit) }}}rZUWorksheet 'data!' (2007-10-03 at 06:06) {{{id=92| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}r[UNWorksheet 'data!' (2007-10-03 at 06:07) {{{id=90| showtheta(P0 + P1 + fit) }}}r\TWorksheet 'data!' (2007-10-03 at 06:13) {{{id=98| time S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6) time P0 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// Traceback (most recent call last): time P0 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) NameError: name 'SatoTate' is not defined }}}r]TxWorksheet 'data!' (2007-10-03 at 06:13) {{{id=1| #auto def dist(v, b, left=-1.0r, right=1.0r): """ We divide the interval between left (default: 0) and right (default: pi) up into b bins. For each number in v (which must left and right), we find which bin it lies in and add this to a counter. This function then returns the bins and the number of elements of v that lie in each one. ALGORITHM: To find the index of the bin that a given number x lies in, we multiply x by b/length and take the floor. """ length = right - left normalize = float(b/length) vals = {} d = dict([(i,0) for i in range(b)]) for x in v: n = int(normalize*(float(x)-left)) d[n] += 1 return d, len(v) def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r): s = Graphics() left = float(left); right = float(right) length = right - left w = length/b k = 0 for i, n in d.iteritems(): k += n # ith bin has n objects in it. s += polygon([(w*i+left,0), (w*(i+1)+left,0), \ (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ rgbcolor=(0,0,0.5)) return s def semicircle0(): alpha = 2.0r / float(pi) def f(x): return alpha * math.sqrt(1-x^2) return plot(f, -1,1,rgbcolor=(0.5,0,0)) semicircle = semicircle0() }}}r^TDWorksheet 'data!' (2007-10-03 at 06:13) {{{id=2| #auto from math import asin, log, sqrt def redline(xmin,xmax): return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0)) def Xab(a,b): bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r) aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r) def X(T): return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa) return X import bisect class SatoTate: def __init__(self, E, n): self._E = E self._n = n self.init_aplist(n) def init_aplist(self, n): t = cputime() v = self._E.aplist(n, python_ints=True) print 'computed aplist ', cputime(t) P = prime_range(n) self._aplist = v two = float(2) t = cputime() self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))] print 'time to normalize ', cputime(t) def __repr__(self): return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n) def normalized_aplist(self, n): # returns a copy k = prime_pi(n) v = self._normalized_aplist if k > len(v): raise ValueError, "call init_aplist" return v[:prime_pi(n)] def sorted_aplist(self, n): v = self.normalized_aplist(n) v.sort() return v def YCab(self, Cmax, a=-1, b=1): v = self.sorted_aplist(Cmax) denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a)) try: normalize = float(1)/denom except: def Y(T): return 1.0r return Y start_pos = bisect.bisect_left(v, float(a)) def Y(T): # find position that T would go in if it were inserted # in the sorted list v. n = bisect.bisect_right(v, float(T)) - start_pos return n * normalize return Y def xyplot(self, C, a=-1, b=1): """ Return the quantile-quantile plot for given a,b, up to C. """ Y = self.YCab(C,a=a,b=b) X = Xab(a=a,b=b) pX = plot(X, a, b, rgbcolor=(1,0,0)) pY = plot(Y, a, b, rgbcolor=(0,0,1)) return pX + pY def qqplot(self, C, a=-1, b=1): """ Return the quantile-quantile plot for given a,b, up to C. """ Y = self.YCab(C,a=a,b=b) X = Xab(a=a,b=b) pl = parametric_plot((X, Y), a,b) ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0)) return pl+ll def Delta(self, C, a, b, max_points=300, L_norm=2): """ Delta_{a}^{b} function: INPUT: C - cutoff a,b - evaluate over the interval (a,b) max_points - number of points used in numerical integral L_norm --the integer n=2 or n=oo. Compute the L_n norm. For n finite this is the integral of the difference to the power n. For n = +oo, this is the L_oo norm, which is the max of the absolute value of the difference (where the max is evaluated at max_points equidistributed points). """ key = (C,a,b,max_points, L_norm) try: return self._delta[key] except AttributeError: self._delta = {} except KeyError: pass X = Xab(a,b) Y = self.YCab(C,a,b) # This takes all the time. if L_norm == oo: val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)]) err = 0 else: n = int(L_norm) # usually n = 2. def h(T): return (X(T) - Y(T))^n val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10) val = float(val^(1.0/n)) # compute L_n norm. err = float(err^(1.0/n)) self._delta[key] = (val, err) return val, err def plot_Delta(self, Cmax=None, **kwds): if Cmax is None: Cmax = self._n v2 = self.compute_Delta(Cmax, L_norm=2, **kwds) voo = self.compute_Delta(Cmax, L_norm=oo, **kwds) return line(v2, rgbcolor=(0,0,1)) + line(voo, rgbcolor=(0.8,0,0)) def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) def f(C): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return val return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))] def theta(self, C, a=-1, b=1, max_points=300, L_norm=2): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return -log(val)/log(C), val, err def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C) def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) def f(C): z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm) if verbose: print C, z return z[0] return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))] def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) vmin = []; vmax = [] for C in range(100, Cmax, int(Cmax/plot_points)): zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm) vmin.append((C, zmin)) vmax.append((C, zmax)) if verbose: print C, zmin, zmax return vmin, vmax def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds): if Cmax is None: Cmax = self._n vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds) v = self.compute_theta(Cmax, *args, **kwds) grey = (0.7,0.7,0.7) return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) \ + line(v,rgbcolor=clr) + redline(0, Cmax) # + point(v,rgbcolor=(0,0,0), pointsize=3) def histogram(self, Cmax, num_bins): v = self.normalized_aplist(Cmax) d, total_number_of_points = dist(v, num_bins) return frequency_histogram(d, num_bins, total_number_of_points) + semicircle def x_times_Delta(self, x): return x*self.Delta(x, -1,1, max_points=500)[0] def showtheta(P): P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4]) }}}r_TWorksheet 'data!' (2007-10-03 at 06:15) {{{id=98| time S8 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6) time P0 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S8.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.632352 time to normalize 0.080005 Time: CPU 16.38 s, Wall: 45.97 s Time: CPU 11.85 s, Wall: 18.06 s Time: CPU 1.67 s, Wall: 3.15 s CPU time: 36.25 s, Wall time: 74.68 s }}}r`TWorksheet 'data!' (2007-10-03 at 06:15) {{{id=96| showtheta(P0 + P1 + fit) /// Traceback (most recent call last): File "", line 1, in File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/294.py", line 4, in exec compile(ur'showtheta(P0 + P1 + fit)' + '\n', '', 'single') File "/home/was/s/data/extcode/sage/", line 1, in NameError: name 'fit' is not defined }}}raUWorksheet 'data!' (2007-10-03 at 06:15) {{{id=97| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rbUNWorksheet 'data!' (2007-10-03 at 06:15) {{{id=96| showtheta(P0 + P1 + fit) }}}rcUWorksheet 'data!' (2007-10-03 at 06:15) {{{id=97| fit = plot(lambda x: 1/2 - (5/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rdUNWorksheet 'data!' (2007-10-03 at 06:15) {{{id=96| showtheta(P0 + P1 + fit) }}}reUWorksheet 'data!' (2007-10-03 at 06:15) {{{id=97| fit = plot(lambda x: 1/2 - (6/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rfUNWorksheet 'data!' (2007-10-03 at 06:15) {{{id=96| showtheta(P0 + P1 + fit) }}}rgUWorksheet 'data!' (2007-10-03 at 06:48) {{{id=97| fit = plot(lambda x: 1/2 - (8/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rhUNWorksheet 'data!' (2007-10-03 at 06:48) {{{id=96| showtheta(P0 + P1 + fit) }}}riUWorksheet 'data!' (2007-10-03 at 06:48) {{{id=97| fit = plot(lambda x: 1/2 - ((8-2)/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rjUNWorksheet 'data!' (2007-10-03 at 06:48) {{{id=96| showtheta(P0 + P1 + fit) }}}rkUWorksheet 'data!' (2007-10-03 at 06:48) {{{id=97| fit = plot(lambda x: 1/2 - (2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) /// Syntax Error: fit = plot(lambda x: 1/2 - (2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rlU{Worksheet 'data!' (2007-10-03 at 06:48) {{{id=97| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rmUNWorksheet 'data!' (2007-10-03 at 06:48) {{{id=96| showtheta(P0 + P1 + fit) }}}rnUWorksheet 'data!' (2007-10-03 at 06:50) {{{id=97| fit = plot(lambda x: 1/2 - (8/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}roUNWorksheet 'data!' (2007-10-03 at 06:50) {{{id=96| showtheta(P0 + P1 + fit) }}}rpU{Worksheet 'data!' (2007-10-03 at 06:50) {{{id=97| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rqUNWorksheet 'data!' (2007-10-03 at 06:50) {{{id=96| showtheta(P0 + P1 + fit) }}}rrTWorksheet 'data!' (2007-10-03 at 06:51) {{{id=80| time S0 = SatoTate(EllipticCurve([1,-1,1,-20067762415575526585033208209338542750930230312178956502,34481611795030556467032985690390720374855944359319180361266008296291939448732243429 ]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 6.008374 time to normalize 0.084004 Time: CPU 9.82 s, Wall: 13.54 s Time: CPU 6.54 s, Wall: 7.59 s Time: CPU 0.20 s, Wall: 0.43 s CPU time: 23.27 s, Wall time: 29.89 s }}}rsUWorksheet 'data!' (2007-10-03 at 06:51) {{{id=79| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rtUWorksheet 'data!' (2007-10-03 at 06:51) {{{id=79| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}ruUWorksheet 'data!' (2007-10-03 at 06:52) {{{id=79| fit = plot(lambda x: 1/2 - 3/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rvUWorksheet 'data!' (2007-10-03 at 06:52) {{{id=79| fit = plot(lambda x: 1/2 - (10/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rwUWorksheet 'data!' (2007-10-03 at 06:52) {{{id=79| fit = plot(lambda x: 1/2 - 3/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rxUWorksheet 'data!' (2007-10-03 at 06:52) {{{id=79| fit = plot(lambda x: 1/2 - (28/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}ryUWorksheet 'data!' (2007-10-03 at 06:53) {{{id=79| fit = plot(lambda x: 1/2 - (10/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rzUWorksheet 'data!' (2007-10-03 at 06:53) {{{id=79| fit = plot(lambda x: 1/2 - (9/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}r{UWorksheet 'data!' (2007-10-03 at 06:53) {{{id=79| fit = plot(lambda x: 1/2 - (28/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}r|UWorksheet 'data!' (2007-10-03 at 06:53) {{{id=79| fit = plot(lambda x: 1/2 - (28/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}r}UWorksheet 'data!' (2007-10-03 at 06:53) {{{id=79| fit = plot(lambda x: 1/2 - (29/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}r~UWorksheet 'data!' (2007-10-03 at 06:54) {{{id=79| fit = plot(lambda x: 1/2 - (28/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rT Worksheet 'data!' (2007-10-03 at 07:17) {{{id=81| time S0 = SatoTate(EllipticCurve([0, 0, 1, -23737, 960366]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) time showtheta(P0+P1) /// computed aplist 5.816364 time to normalize 0.084005 Time: CPU 9.72 s, Wall: 12.06 s Time: CPU 6.70 s, Wall: 8.50 s Time: CPU 0.21 s, Wall: 0.23 s CPU time: 23.30 s, Wall time: 29.06 s }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - (8/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - (24/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - (21/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - (18/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - (19/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:17) {{{id=99| fit = plot(lambda x: 1/2 - 2/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:18) {{{id=99| fit = plot(lambda x: 1/2 - (19/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:18) {{{id=99| fit = plot(lambda x: 1/2 - (18/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:18) {{{id=99| fit = plot(lambda x: 1/2 - (20/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 07:18) {{{id=99| fit = plot(lambda x: 1/2 - (19/9)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) showtheta(P0 + P1 + fit) }}}rTDWorksheet 'data!' (2007-10-03 at 15:17) {{{id=2| #auto from math import asin, log, sqrt def redline(xmin,xmax): return line([(xmin,1/2),(xmax,1/2)], rgbcolor=(1,0,0)) def Xab(a,b): bb = (asin(b)/2r + b*sqrt(1r-b^2r)/2r) aa = (asin(a)/2r + a*sqrt(1r-a^2r)/2r) def X(T): return (asin(T)/2r + T*sqrt(1r-T^2r)/2r - aa)/(bb - aa) return X import bisect class SatoTate: def __init__(self, E, n): self._E = E self._n = n self.init_aplist(n) def init_aplist(self, n): t = cputime() v = self._E.aplist(n, python_ints=True) print 'computed aplist ', cputime(t) P = prime_range(n) self._aplist = v two = float(2) t = cputime() self._normalized_aplist = [float(v[i])/(two*math.sqrt(P[i])) for i in range(len(v))] print 'time to normalize ', cputime(t) def __repr__(self): return "Sato-Tate data for %s using primes up to %s"%(self._E, self._n) def normalized_aplist(self, n): # returns a copy k = prime_pi(n) v = self._normalized_aplist if k > len(v): raise ValueError, "call init_aplist" return v[:prime_pi(n)] def sorted_aplist(self, n): v = self.normalized_aplist(n) v.sort() return v def YCab(self, Cmax, a=-1, b=1): v = self.sorted_aplist(Cmax) denom = bisect.bisect_right(v, float(b)) - bisect.bisect_left(v, float(a)) try: normalize = float(1)/denom except: def Y(T): return 1.0r return Y start_pos = bisect.bisect_left(v, float(a)) def Y(T): # find position that T would go in if it were inserted # in the sorted list v. n = bisect.bisect_right(v, float(T)) - start_pos return n * normalize return Y def xyplot(self, C, a=-1, b=1): """ Return the quantile-quantile plot for given a,b, up to C. """ Y = self.YCab(C,a=a,b=b) X = Xab(a=a,b=b) pX = plot(X, a, b, rgbcolor=(1,0,0)) pY = plot(Y, a, b, rgbcolor=(0,0,1)) return pX + pY def qqplot(self, C, a=-1, b=1): """ Return the quantile-quantile plot for given a,b, up to C. """ Y = self.YCab(C,a=a,b=b) X = Xab(a=a,b=b) pl = parametric_plot((X, Y), a,b) ll = line([(0,0), (1.1,1.1)], rgbcolor=(1,0,0)) return pl+ll def Delta(self, C, a, b, max_points=300, L_norm=2): """ Delta_{a}^{b} function: INPUT: C - cutoff a,b - evaluate over the interval (a,b) max_points - number of points used in numerical integral L_norm --the integer n=2 or n=oo. Compute the L_n norm. For n finite this is the integral of the difference to the power n. For n = +oo, this is the L_oo norm, which is the max of the absolute value of the difference (where the max is evaluated at max_points equidistributed points). """ key = (C,a,b,max_points, L_norm) try: return self._delta[key] except AttributeError: self._delta = {} except KeyError: pass X = Xab(a,b) Y = self.YCab(C,a,b) # This takes all the time. if L_norm == oo: val = max([abs(X(T)-Y(T)) for T in srange(a,b,float(b-a)/max_points)]) err = 0 else: n = int(L_norm) # usually n = 2. def h(T): return (X(T) - Y(T))^n val, err = integral_numerical(h, a, b, max_points=max_points, algorithm='qag', rule=1,eps_abs=1e-10, eps_rel=1e-10) val = float(val^(1.0/n)) # compute L_n norm. err = float(err^(1.0/n)) self._delta[key] = (val, err) return val, err def plot_Delta(self, Cmax=None, **kwds): if Cmax is None: Cmax = self._n v2 = self.compute_Delta(Cmax, L_norm=2, **kwds) voo = self.compute_Delta(Cmax, L_norm=oo, **kwds) return line(v2, rgbcolor=(0,0,1)) + line(voo, rgbcolor=(0.8,0,0)) def compute_Delta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) def f(C): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return val return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))] def theta(self, C, a=-1, b=1, max_points=300, L_norm=2): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return -log(val)/log(C), val, err def theta_interval(self, C, a=-1, b=1, max_points=300, L_norm=2): val, err = self.Delta(C, a, b, max_points=max_points, L_norm=L_norm) return -log(val-abs(err))/log(C), -log(val+abs(err))/log(C) def compute_theta(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) def f(C): z = self.theta(C, a, b, max_points=max_points, L_norm=L_norm) if verbose: print C, z return z[0] return [(x,f(x)) for x in range(100, Cmax, int(Cmax/plot_points))] def compute_theta_interval(self, Cmax, plot_points=30, a=-1, b=1, max_points=300, L_norm=2, verbose=False): a,b = (float(a), float(b)) vmin = []; vmax = [] for C in range(100, Cmax, int(Cmax/plot_points)): zmin,zmax = self.theta_interval(C, a, b, max_points=max_points, L_norm=L_norm) vmin.append((C, zmin)) vmax.append((C, zmax)) if verbose: print C, zmin, zmax return vmin, vmax def plot_theta_interval(self, Cmax=None, clr=(0,0,1), *args, **kwds): if Cmax is None: Cmax = self._n vmin, vmax = self.compute_theta_interval(Cmax, *args, **kwds) v = self.compute_theta(Cmax, *args, **kwds) grey = (0.7,0.7,0.7) return line(vmin,rgbcolor=grey)+line(vmax,rgbcolor=grey) \ + line(v,rgbcolor=clr) + redline(0, Cmax) # + point(v,rgbcolor=(0,0,0), pointsize=3) def histogram(self, Cmax, num_bins): v = self.normalized_aplist(Cmax) d, total_number_of_points = dist(v, num_bins) return frequency_histogram(d, num_bins, total_number_of_points) + semicircle def x_times_Delta(self, x): return x*self.Delta(x, -1,1, max_points=500)[0] def showtheta(P): P.show(xmin=0, ymin=0, ymax=0.6, figsize=[9,4]) }}}rTWorksheet 'data!' (2007-10-03 at 15:18) {{{id=91| time S0 = SatoTate(EllipticCurve([1,-1,0,-79,289]), 10^6) time P0 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.704355 time to normalize 0.116007 Time: CPU 9.35 s, Wall: 9.74 s Time: CPU 6.41 s, Wall: 6.47 s CPU time: 22.27 s, Wall time: 23.47 s }}}rUWorksheet 'data!' (2007-10-03 at 15:23) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1+r/2)*(1+log(log(x)))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUWorksheet 'data!' (2007-10-03 at 15:23) {{{id=92| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUWorksheet 'data!' (2007-10-03 at 15:23) {{{id=92| #fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUWorksheet 'data!' (2007-10-03 at 15:23) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1+r/2)*(1+log(log(x)))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUNWorksheet 'data!' (2007-10-03 at 15:23) {{{id=90| showtheta(P0 + P1 + fit) }}}rU@Worksheet 'data!' (2007-10-03 at 15:23) {{{id=101| show(fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:24) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1+r/2)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rU@Worksheet 'data!' (2007-10-03 at 15:24) {{{id=101| show(fit) }}}rU@Worksheet 'data!' (2007-10-03 at 15:24) {{{id=101| show(fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:24) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rU@Worksheet 'data!' (2007-10-03 at 15:24) {{{id=101| show(fit) }}}rUNWorksheet 'data!' (2007-10-03 at 15:24) {{{id=90| showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:24) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1+r/4)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUNWorksheet 'data!' (2007-10-03 at 15:25) {{{id=90| showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:25) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (1-r/4)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUNWorksheet 'data!' (2007-10-03 at 15:25) {{{id=90| showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:25) {{{id=100| log=math.log r = 4.0 fit = plot(lambda x: 1/2 - (4/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rUNWorksheet 'data!' (2007-10-03 at 15:25) {{{id=90| showtheta(P0 + P1 + fit) }}}rUWorksheet 'data!' (2007-10-03 at 15:25) {{{id=100| log=math.log r = 4.0 fit_watkins = plot(lambda x: 1/2 - (4/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rUWorksheet 'data!' (2007-10-03 at 15:25) {{{id=92| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rU\Worksheet 'data!' (2007-10-03 at 15:25) {{{id=90| showtheta(P0 + P1 + fit + fit_watkins) }}}rUWorksheet 'data!' (2007-10-03 at 15:26) {{{id=100| log=math.log r = 4.0 fit_watkins = plot(lambda x: 1/2 - (2/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rUWorksheet 'data!' (2007-10-03 at 15:26) {{{id=92| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rU\Worksheet 'data!' (2007-10-03 at 15:26) {{{id=90| showtheta(P0 + P1 + fit + fit_watkins) }}}rUWorksheet 'data!' (2007-10-03 at 15:26) {{{id=100| log=math.log r = 4.0 fit_watkins = plot(lambda x: 1/2 - (1/2)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rUfWorksheet 'data!' (2007-10-03 at 15:26) {{{id=90| showtheta(P0 + P1 + fit + fit_watkins) /// e359 }}}rUWorksheet 'data!' (2007-10-03 at 15:26) {{{id=100| log=math.log r = 4.0 fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rUWorksheet 'data!' (2007-10-03 at 15:26) {{{id=92| fit = plot(lambda x: 1/2 - (4/3)/math.log(x), 10, 10^6, rgbcolor=(0,0,0)) }}}rU\Worksheet 'data!' (2007-10-03 at 15:26) {{{id=90| showtheta(P0 + P1 + fit + fit_watkins) }}}rTWorksheet 'data!' (2007-10-03 at 15:28) {{{id=103| time S3 = SatoTate(EllipticCurve('5077a'), 10^6) time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// Traceback (most recent call last): time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/constructor.py", line 115, in EllipticCurve return ell_rational_field.EllipticCurve_rational_field(x) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/ell_rational_field.py", line 105, in __init__ ... }}}rTWorksheet 'data!' (2007-10-03 at 15:28) {{{id=103| time S3 = SatoTate(EllipticCurve('5077a'), 10^6) time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// Traceback (most recent call last): time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/constructor.py", line 115, in EllipticCurve return ell_rational_field.EllipticCurve_rational_field(x) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/ell_rational_field.py", line 105, in __init__ ... }}}rTWorksheet 'data!' (2007-10-03 at 15:28) {{{id=103| time S3 = SatoTate(EllipticCurve('5077a'), 10^6) time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// Traceback (most recent call last): time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/constructor.py", line 115, in EllipticCurve return ell_rational_field.EllipticCurve_rational_field(x) File "/home/was/s/local/lib/python2.5/site-packages/sage/schemes/elliptic_curves/ell_rational_field.py", line 105, in __init__ ... }}}rTWorksheet 'data!' (2007-10-03 at 15:28) {{{id=103| time S3 = SatoTate(EllipticCurve('5077a'), 10^6) time P0_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.480343 time to normalize 0.092006 Traceback (most recent call last): time P1_3 = S0.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) NameError: name 'S0' is not defined }}}rUWorksheet 'data!' (2007-10-03 at 15:28) {{{id=102| r = 4.0 fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rTWorksheet 'data!' (2007-10-03 at 15:28) {{{id=89| showtheta(P0_3 + P1_3 + fit_watkins) /// Traceback (most recent call last): File "", line 1, in File "/home/was/sd5/sato-tate/sage_notebook/worksheets/admin/2/code/41.py", line 4, in exec compile(ur'showtheta(P0_3 + P1_3 + fit_watkins)' + '\n', '', 'single') File "/home/was/s/data/extcode/sage/", line 1, in NameError: name 'P0_3' is not defined }}}rTWorksheet 'data!' (2007-10-03 at 15:29) {{{id=103| time S3 = SatoTate(EllipticCurve('5077a'), 10^6) time P0_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=2, clr=(0,0,1)) time P1_3 = S3.plot_theta_interval(10^6, plot_points=300, max_points=80, L_norm=oo, clr=(0,0.5,0)) /// computed aplist 5.212326 time to normalize 0.088006 Time: CPU 9.36 s, Wall: 9.63 s Time: CPU 6.62 s, Wall: 6.74 s CPU time: 21.85 s, Wall time: 22.40 s }}}rUWorksheet 'data!' (2007-10-03 at 15:29) {{{id=102| r = 4.0 fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0,0.5,0.5)) }}}rUZWorksheet 'data!' (2007-10-03 at 15:29) {{{id=89| showtheta(P0_3 + P1_3 + fit_watkins) }}}rUWorksheet 'data!' (2007-10-03 at 15:29) {{{id=102| r = 4.0 fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5)) }}}rUWorksheet 'data!' (2007-10-03 at 15:29) {{{id=102| r = 3.0 fit_watkins = plot(lambda x: 1/2 - (2/r)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5)) }}}rUZWorksheet 'data!' (2007-10-03 at 15:29) {{{id=89| showtheta(P0_3 + P1_3 + fit_watkins) }}}rUWorksheet 'data!' (2007-10-03 at 15:30) {{{id=102| r = 3.0 fit_watkins = plot(lambda x: 1/2 - 1*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5)) }}}rUZWorksheet 'data!' (2007-10-03 at 15:30) {{{id=89| showtheta(P0_3 + P1_3 + fit_watkins) }}}rUWorksheet 'data!' (2007-10-03 at 15:30) {{{id=102| r = 3.0 fit_watkins = plot(lambda x: 1/2 - (1/3)*log(log(x))/log(x), 10, 10^6, rgbcolor=(0.2,0.1,0.5)) }}}rUZWorksheet 'data!' (2007-10-03 at 15:30) {{{id=89| showtheta(P0_3 + P1_3 + fit_watkins) }}}rTxWorksheet 'data!' (2007-10-16 at 16:17) {{{id=1| #auto def dist(v, b, left=-1.0r, right=1.0r): """ We divide the interval between left (default: 0) and right (default: pi) up into b bins. For each number in v (which must left and right), we find which bin it lies in and add this to a counter. This function then returns the bins and the number of elements of v that lie in each one. ALGORITHM: To find the index of the bin that a given number x lies in, we multiply x by b/length and take the floor. """ length = right - left normalize = float(b/length) vals = {} d = dict([(i,0) for i in range(b)]) for x in v: n = int(normalize*(float(x)-left)) d[n] += 1 return d, len(v) def frequency_histogram(d, b, num=5000, left=-1.0r, right=1.0r): s = Graphics() left = float(left); right = float(right) length = right - left w = length/b k = 0 for i, n in d.iteritems(): k += n # ith bin has n objects in it. s += polygon([(w*i+left,0), (w*(i+1)+left,0), \ (w*(i+1)+left, n/(num*w)), (w*i+left, n/(num*w))],\ rgbcolor=(0,0,0.5)) return s def semicircle0(): alpha = 2.0r / float(pi) def f(x): return alpha * math.sqrt(1-x^2) return plot(f, -1,1,rgbcolor=(0.5,0,0)) semicircle = semicircle0() }}}rUWorksheet 'data!' (2007-10-16 at 16:17) {{{id=44| # make curve time e37a = SatoTate(EllipticCurve('37a'), 10^6) /// computed aplist 4.928308 time to normalize 0.084005 Time: CPU 6.77 s, Wall: 15.99 s }}}rUWorksheet 'data!' (2007-10-16 at 16:17) {{{id=47| show(e37a.plot_Delta(10^3, plot_points=400, max_points=100), ymax=0.1, ymin=0, figsize=[10,3]) }}}rUWorksheet 'data!' (2007-10-16 at 16:18) {{{id=45| show(e37a.plot_Delta(10^4, plot_points=200, max_points=100), ymax=0.1, ymin=0, figsize=[10,3]) }}}reubsUaddressrU localhostrU_Notebook__dirrU2/home/was/talks/20071016-convergence/sage_notebookrU_Notebook__historyr]rub.