Ejemplo n.º 1
0
def animate_flat_plot(f, step=10, limit=None, figsize=None):
    db = DB()

    if type(f) != list:
        f = [f, ]

    # Figure out how many frames we will have
    # ...not very efficient
    max = 1
    for i in range(len(f)):
        n = len(db.load_roots(f[i], raw=False))
        if max < n:
            max = n

    if (limit and max < limit) or not limit:
        limit = max
    frames = ceil(limit / step)

    plots = list()
    for i in range(frames):
        j = (i + 1) * step
        plots.append(flat_plot(f, j, False))

    figsize = (15, len(f))

    return animate(plots, figsize=figsize)
Ejemplo n.º 2
0
def weyl_sum(f,l,stop=None):
    db = DB()
    roots = db.load_roots(f)[:stop]
    sum = 0

    for n in range(len(roots)):
        print sum
        print roots[n]
        sum += 1 / (n + 1) * exp(2*pi.n()*l*roots[n].n()).n()

    return sum
Ejemplo n.º 3
0
def distance_prime(f):
    db = DB()
    roots = db.load_roots(f, raw=True)
    p = int(roots[0][1])
    lst = list()
    for r in roots:
        p1 = int(r[1])
        if p != p1:
            lst.append((p, p1 - p))
            p = p1

    return lst
Ejemplo n.º 4
0
def density_interval(f, low, high, limit=None, convergence=False):
    """Return the density for the interval [low, high]."""
    db = DB()
    roots = db.load_roots(f, raw=False)[:limit]
    total = len(roots)
    count = 0
    if convergence:
        lst = list()

    for i in range(len(roots)):
        if low <= roots[i] <= high:
            count += 1
        if convergence:
            lst.append((i + 1, count / (i + 1)))

    if convergence:
        return lst
    else:
        return count / total
Ejemplo n.º 5
0
def flat_plot(f, limit=None, legend=False, save=False):
    """
    Produces a plot of normalized roots for given irreducible f

    INPUT:
      `f` -- Either a polynomial or a list of polynomials
      `limit` -- Limit the number of roots used in the plot
      `legend` -- Show lables for polynomials

    OUTPUT:
      Sage graphics object
    """
    db = DB()
    
    if type(f) != list:
        f = [f, ]

    plot = scatter_plot([])
    classes = list() # For color coordination

    for i in range(len(f)):
        # Identify a class of f by (degree, group id) tuple.
        degree = f[i].degree()
        gid = f[i].galois_group()._n
        cid = (degree, gid)
        if classes.count(cid) == 0:
            classes.append(cid)
        color = classes.index(cid)

        # Add plots
        roots = db.load_roots(f[i], raw=False)[:limit]
        points = [(j,i + 1) for j in roots]
        plot_opts = {'edgecolor': colors[0],
                     'facecolor': colors[color], 
                     'markersize': 10}
        plot += scatter_plot(points, **plot_opts)

        # Add labels
        count = len(roots)
        label = str(i + 1) + ": " + "D" + str(degree) + "G" + str(gid)
        # If the database contains more roots than given limit, do not add count
        # on the label, otherwise add count
        if not limit or count != limit:
            label += "(" + str(count) + ")" 

        label_opts = {'fontsize': 8, 
                      'rgbcolor': (20, 20, 20),
                      'horizontal_alignment': 'left'}
        plot += text(label, (1.02, i + 1), **label_opts)

        if legend:
            legend_opts ={'fontsize': 8, 
                          'rgbcolor': (20, 20, 20),
                          'horizontal_alignment': 'left'}
            legend_text = "(" + str(i + 1) + ") " + str(f[i])
            plot += text(legend_text, (0.01, -i-1), **legend_opts)

    if not limit:
        limit = ""

    plot += text(limit, (1,len(f)-0.2), horizontal_alignment='right')
    for i in range(11):
        plot += line([(i * 0.1, -100), (i * 0.1, 100)], alpha = 0.2, rgbcolor = (0, 0, 0))

    plot.axes(False)
    plot.axes_color((0.2, 0.2, 0.2))
    if not legend:
        axes_range = {'xmin': 0, 'xmax': 1.3, 'ymin': 0.5, 'ymax': len(f) + 0.5}
    else:
        axes_range = {'xmin': 0, 'xmax': 1.3, 'ymin': -len(f), 'ymax': len(f)}
      
    plot.set_axes_range(**axes_range)

    return plot