def test_prime_function():
    # run the "checks" below using the following list of (delta,q) pairs
    half = QQ(1)/2
    delta_q_pairs = [
        # ([0], [half]),
        ([half], [half/4]),
        ([-half, half], [half/2, half/2]),
    ]
    product_threshold = 10

    for delta, q in delta_q_pairs:
        genus = len(delta)
        omega = build_prime_function(delta, q, product_threshold)
        phi_j = [
            delta[j] + q[j]**2*z/(1-z*delta[j].conjugate())
            for j in range(genus)
        ]
        yield check_vanishing_gamma, omega
        yield check_vanishing_phij_gamma, omega, phi_j
        yield check_pole_fixed_points, omega, delta, q, phi_j, genus
        # yield check_equation_5_17, omega
        yield check_symmetric, omega
示例#2
0
def test_prime_function():
    # run the "checks" below using the following list of (delta,q) pairs
    half = QQ(1) / 2
    delta_q_pairs = [
        # ([0], [half]),
        ([half], [half / 4]),
        ([-half, half], [half / 2, half / 2]),
    ]
    product_threshold = 10

    for delta, q in delta_q_pairs:
        genus = len(delta)
        omega = build_prime_function(delta, q, product_threshold)
        phi_j = [
            delta[j] + q[j]**2 * z / (1 - z * delta[j].conjugate())
            for j in range(genus)
        ]
        yield check_vanishing_gamma, omega
        yield check_vanishing_phij_gamma, omega, phi_j
        yield check_pole_fixed_points, omega, delta, q, phi_j, genus
        # yield check_equation_5_17, omega
        yield check_symmetric, omega
def backward_problem(branch_pts, prime_function_tests=False,
slitmap_tests=False, slitmap_full=False, plot_circles=False, plot_F=False,
plot_branch_pts=False, prec='double', product_threshold=5, max_time=200):
    # input:	
    # 	branch_pts = list of branch points
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	slitmap_full = Plot each component of the slitmap, for diagnostic
    # 					reasons
    # 	plot_circles = circle plot, unit circle and the Cj excised
    # 	plot_F = Plots the whole fundamental domain, F, with shading
    # 	plot_branch_pts = Plots the branch points with red xs
    #   prec = precision of group data. Double or infinite. Double is faster.
    # 	product_threshold = determines the max number of terms in the prime \
    # 	max_time = max time for prime function computation before timeout
    # 							function product
    #
    # output:
    #   delta = list of centers of circles
    #   q = list of radii of circles

    z = var('z') # complex variable not specified by x,y
    gamma = var('gamma') #base point for 'abelmap' or prime function
    
    # Make sure we are in the hyperbollic case.
    if len(branch_pts)%2 != 0: 
        raise ValueError("Right now this module only works for "
		"hyperelliptic curves with an even number of branch points. Try again "
        "with len(branch_pts)%2=0")

    # Force the list to be monotonically increasing. 
    branch_pts = sorted(branch_pts) # the lists are short enough rn 
                                   # this probably isn't too slow. 

    # Make sure no two branch points coincide
    if duplicates_in_list(branch_pts):
        raise ValueError("The list branch_pts cannot have duplicaties. This "
        "program does not yet support branch_pts of multiplicity greater than "
        " 1")
        
    genus = len(branch_pts)/2 # There are 2g branch_pts

    # Change branch point data to double or infinite precision
    if prec == 'double':
        branch_pts = map(CDF, branch_pts) # Complex double field
    elif (prec == 'infinity' or prec == 'inf'):
        branch_pts = map(CC, branch_pts) # infinite precision
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be "
                        "entered for 'prec'")

    # Plot the branch points if you want, not really necessary here.
    if plot_branch_pts:
        branch_point_plot(branch_pts) ## This can and should be fixed to just
                                      ## use the plot_points function

    # Define the Cj algebraically
    [delta,q] = define_group_data(genus) # We have delta[0] = delta_1, delta[1]
    							# = delta_2 etc. Kind of messy but it works out.
    							# There are g of each delta_j, q_j
    
    # Define the location of the intersection of the C_j with the real axis. We
    # have C_j = delta_j + q_j e^(it) centered on the real-axis. Therefore, for
    # the hyperelliptic case we just take one pre-branch point (i.e. the
    # preimage of the branchpoint under the slitmap) to be delta_j + q_j and the
    # other to be delta_j - q_j.
    # -------!!!!----!!!-- Question for non hyperelliptic case: What is
    # important about taking the intersectin of C_j with the real-axis? Are we
    # guaranteed that  -- These are defined algebraically.
    pre_branch_pts = [None]*2*len(xrange(genus))
    pre_branch_pts[::2] = [ delta[j]-q[j] for j in xrange(genus) ]
    pre_branch_pts[1::2] = [ delta[j]+q[j] for j in xrange(genus) ]
    # There are 2g pre_branch_pts. We interlace them in this way to help with
    # the algebraic problem below.
    
    # Define the prime function algebraically, make sure it doesn't take too
    # long!
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time) #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc: #stop if it takes too long
        print exc
示例#4
0
def backward_problem(branch_pts,
                     prime_function_tests=False,
                     slitmap_tests=False,
                     slitmap_full=False,
                     plot_circles=False,
                     plot_F=False,
                     plot_branch_pts=False,
                     prec='double',
                     product_threshold=5,
                     max_time=200):
    # input:
    # 	branch_pts = list of branch points
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	slitmap_full = Plot each component of the slitmap, for diagnostic
    # 					reasons
    # 	plot_circles = circle plot, unit circle and the Cj excised
    # 	plot_F = Plots the whole fundamental domain, F, with shading
    # 	plot_branch_pts = Plots the branch points with red xs
    #   prec = precision of group data. Double or infinite. Double is faster.
    # 	product_threshold = determines the max number of terms in the prime \
    # 	max_time = max time for prime function computation before timeout
    # 							function product
    #
    # output:
    #   delta = list of centers of circles
    #   q = list of radii of circles

    z = var('z')  # complex variable not specified by x,y
    gamma = var('gamma')  #base point for 'abelmap' or prime function

    # Make sure we are in the hyperbollic case.
    if len(branch_pts) % 2 != 0:
        raise ValueError(
            "Right now this module only works for "
            "hyperelliptic curves with an even number of branch points. Try again "
            "with len(branch_pts)%2=0")

    # Force the list to be monotonically increasing.
    branch_pts = sorted(branch_pts)  # the lists are short enough rn
    # this probably isn't too slow.

    # Make sure no two branch points coincide
    if duplicates_in_list(branch_pts):
        raise ValueError(
            "The list branch_pts cannot have duplicaties. This "
            "program does not yet support branch_pts of multiplicity greater than "
            " 1")

    genus = len(branch_pts) / 2  # There are 2g branch_pts

    # Change branch point data to double or infinite precision
    if prec == 'double':
        branch_pts = map(CDF, branch_pts)  # Complex double field
    elif (prec == 'infinity' or prec == 'inf'):
        branch_pts = map(CC, branch_pts)  # infinite precision
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be "
                        "entered for 'prec'")

    # Plot the branch points if you want, not really necessary here.
    if plot_branch_pts:
        branch_point_plot(branch_pts)  ## This can and should be fixed to just
        ## use the plot_points function

    # Define the Cj algebraically
    [delta,
     q] = define_group_data(genus)  # We have delta[0] = delta_1, delta[1]
    # = delta_2 etc. Kind of messy but it works out.
    # There are g of each delta_j, q_j

    # Define the location of the intersection of the C_j with the real axis. We
    # have C_j = delta_j + q_j e^(it) centered on the real-axis. Therefore, for
    # the hyperelliptic case we just take one pre-branch point (i.e. the
    # preimage of the branchpoint under the slitmap) to be delta_j + q_j and the
    # other to be delta_j - q_j.
    # -------!!!!----!!!-- Question for non hyperelliptic case: What is
    # important about taking the intersectin of C_j with the real-axis? Are we
    # guaranteed that  -- These are defined algebraically.
    pre_branch_pts = [None] * 2 * len(xrange(genus))
    pre_branch_pts[::2] = [delta[j] - q[j] for j in xrange(genus)]
    pre_branch_pts[1::2] = [delta[j] + q[j] for j in xrange(genus)]
    # There are 2g pre_branch_pts. We interlace them in this way to help with
    # the algebraic problem below.

    # Define the prime function algebraically, make sure it doesn't take too
    # long!
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time)  #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc:  #stop if it takes too long
        print exc
def forward_problem(delta,
                    q,
                    prime_function_tests=False,
                    slitmap_tests=False,
                    slitmap_full=False,
                    plot_circles=False,
                    plot_F=False,
                    plot_branch_pts=False,
                    prec='double',
                    product_threshold=5,
                    max_time=200):
    #
    # This module does the full forward problem. Starting with group data,
    # construct the SK prime function, the slitmap, and hence the branch points
    # of an algebraic curve.
    #
    # input:
    # 	delta = list of centers of circles
    # 	q = list of radii of circles
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	slitmap_full = Plot each component of the slitmap, for diagnostic
    # 					reasons
    # 	plot_circles = circle plot, unit circle and the Cj excised
    # 	plot_F = Plots the whole fundamental domain, F, with shading
    # 	plot_branch_pts = Plots the branch points with red xs
    #   prec = precision of group data. Double or infinite. Double is faster.
    # 	product_threshold = determines the max number of terms in the prime \
    # 							function product
    # 	max_time = max time for prime function computation before timeout
    #
    # output:
    # 	branch_pts = branch points obtained.

    z = var('z')  # complex variable
    gamma = var('gamma')  #base point for 'abelmap' or prime function

    genus = len(q)

    # Change group data to double or infinite precision
    if prec == 'double':
        delta, q = map(CDF, delta), map(CDF, q)  # Complex double
    elif (prec == 'infinite' or prec == 'inf'):
        delta, q = map(CC, delta), map(CC, q)  #infinite precision
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be "
                        "entered for 'prec'.")

    # Before plotting, define a uniform color scheme to be used throughout all
    # plots so we can keep track of which circle is which.
    circle_colors = [(0.6 * random(), random(), random())
                     for k in xrange(genus)]
    # Plot some stuff about the region if we want.
    if plot_circles:
        D_zeta = circle_plots(delta, q,
                              colors=circle_colors)  #returns plot data
        D_zeta.show(axes=True, title='$D_{\zeta}$', aspect_ratio=1)
        # show and put on an equal-axis plot

    if plot_F:
        D_zeta = F_plot(delta, q, colors=circle_colors)  #returns plot data
        D_zeta.show(axes=True, title='$D_{\zeta}$')
        # show, but maybe not on equal-axis plot.

    # Build the prime function, but make sure it doesn't take too long
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time)  #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc:  #stop if it takes too long.
        print exc
def forward_problem_on_Points_and_Lines(delta,
                                        q,
                                        Points,
                                        Lines,
                                        plot_circles=True,
                                        plot_F=False,
                                        slitmap_full=True,
                                        slitmap_direct=False,
                                        prec='double',
                                        product_threshold=5,
                                        max_time=200,
                                        prime_function_tests=False,
                                        slitmap_tests=False,
                                        point_size=80,
                                        save_plots=False):
    #
    # This module does the forward problem with test point(s) and line(s) in
    # place. I.e. it places a point somewhere in the fundamental domain, F,
    # then tracks it as we do the slitmap. Usually we do this using
    # slitmap_full which will be the default, however, there is a flag for
    # this.
    #
    # input:
    #   delta = centers of circles, list
    #   q = radii of circles, list
    #   Points = points to plot in the domain, list
    #   Lines = lines to plot in the domain, list
    #   plot_circles = plot the circles from the group data and the
    #       points and lines in the fundamental domain together.
    #   plot_F = plot the fundamental domain. Lines are filled in as well.
    #   slitmap_full = build the full slitmap, from zeta1, zeta2, z
    #   slitmap_direct = build the slitmap all in one step. Minimum output.
    #   prec = double or infinite precision of the group data?
    # 	product_threshold = determines the max number of terms in the prime \
    # 							function product
    # 	max_time = max time for prime function computation before timeout
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	point_size = marker size for point_plot
    #   save_plots = save the plots or just display them?
    #
    # output:
    #   only plots
    #
    z = var('z')  # complex variable
    gamma = var('gamma')  #base point for 'abelmap' or prime function

    genus = len(q)

    # Generate colors for plotting here since we want them to be uniform across
    # plot_circles and slitmap plots
    circle_colors = [(0.6 * random(), random(), random())
                     for k in xrange(genus)]
    point_colors = [(0.6 * random(), random(), random())
                    for k in xrange(len(Points))]
    line_colors = [(0.6 * random(), random(), random())
                   for k in xrange(len(Lines))]
    # We multiply the "R" by 0.6 so nothing is too red.

    # Change group data to double or infinite precision
    if prec == 'double':
        delta, q = map(CDF, delta), map(CDF, q)  # Complex double
        Points = map(CDF, Points)
        Lines = [map(CDF, line) for line in Lines]
    elif (prec == 'infinite' or prec == 'inf'):
        delta, q = map(CC, delta), map(CC, q)  #infinite precision
        Points = map(CC, Points)
        Lines = [map(CC, line) for line in Lines]
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be "
                        "entered for 'prec'.")

    # Plot some stuff about the region if we want.
    if plot_circles:
        D_zeta = circle_plots(delta, q, colors=circle_colors)
        D_zeta += plot_points(Points,
                              colors=point_colors,
                              mark_size=point_size)
        D_zeta += plot_lines(Lines, colors=line_colors, thickness=2)

        if save_plots == False:
            D_zeta.show(axes=True, title='$D_{\zeta}$', aspect_ratio=1)
            # show and put on an equal-axis plot
        else:
            D_zeta.save('circle_plot.eps')

    # Plot F, the fundamental domain
    if plot_F:
        D_zeta = F_plot(delta, q, colors=circle_colors)
        D_zeta += plot_points(Points,
                              colors=point_colors,
                              mark_size=point_size)
        D_zeta += plot_lines(Lines, colors=line_colors, thickness=2)
        if save_plots == False:
            D_zeta.show(axes=True, title='$F$, the Fundamental Domain')
        else:
            D_zeta.save('Fundamental_domain.eps')

    # Build the prime function, but make sure it doesn't take too long
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time)  #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc:  #stop if it takes too long.
        print exc
def forward_problem(delta, q, prime_function_tests=False,
slitmap_tests=False, slitmap_full=False, plot_circles=False, plot_F=False, 
plot_branch_pts=False, prec='double', product_threshold=5, max_time=200):
    #
    # This module does the full forward problem. Starting with group data,
    # construct the SK prime function, the slitmap, and hence the branch points
    # of an algebraic curve. 
    #
    # input:	
    # 	delta = list of centers of circles
    # 	q = list of radii of circles
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	slitmap_full = Plot each component of the slitmap, for diagnostic
    # 					reasons
    # 	plot_circles = circle plot, unit circle and the Cj excised
    # 	plot_F = Plots the whole fundamental domain, F, with shading
    # 	plot_branch_pts = Plots the branch points with red xs
    #   prec = precision of group data. Double or infinite. Double is faster.
    # 	product_threshold = determines the max number of terms in the prime \
    # 							function product
    # 	max_time = max time for prime function computation before timeout
    #
    # output:
    # 	branch_pts = branch points obtained.
    
    z = var('z') # complex variable
    gamma = var('gamma') #base point for 'abelmap' or prime function
    
    genus = len(q)

    # Change group data to double or infinite precision
    if prec == 'double':
        delta, q = map(CDF, delta), map(CDF, q) # Complex double
    elif (prec=='infinite' or prec=='inf'):
        delta, q = map(CC, delta), map(CC, q) #infinite precision
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be " 
                "entered for 'prec'.")
    

    # Before plotting, define a uniform color scheme to be used throughout all
    # plots so we can keep track of which circle is which.
    circle_colors = [ (0.6*random(), random(), random()) for k in xrange(genus)
                        ]
    # Plot some stuff about the region if we want.
    if plot_circles: 
        D_zeta=circle_plots(delta, q, colors=circle_colors) #returns plot data
        D_zeta.show(axes = True, title='$D_{\zeta}$', aspect_ratio = 1) 
        # show and put on an equal-axis plot

    if plot_F:
        D_zeta=F_plot(delta, q, colors=circle_colors) #returns plot data
        D_zeta.show(axes = True, title='$D_{\zeta}$')
        # show, but maybe not on equal-axis plot.
    
    # Build the prime function, but make sure it doesn't take too long
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time) #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc: #stop if it takes too long.
        print exc
def forward_problem_on_Points_and_Lines(
        delta, q, Points, Lines, plot_circles=True, plot_F=False,
        slitmap_full=True, slitmap_direct=False, prec='double', 
        product_threshold=5, max_time=200, prime_function_tests=False, 
        slitmap_tests=False, point_size=80, save_plots=False
        ):
    #
    # This module does the forward problem with test point(s) and line(s) in
    # place. I.e. it places a point somewhere in the fundamental domain, F, 
    # then tracks it as we do the slitmap. Usually we do this using 
    # slitmap_full which will be the default, however, there is a flag for
    # this.
    #
    # input:
    #   delta = centers of circles, list
    #   q = radii of circles, list
    #   Points = points to plot in the domain, list
    #   Lines = lines to plot in the domain, list
    #   plot_circles = plot the circles from the group data and the
    #       points and lines in the fundamental domain together.
    #   plot_F = plot the fundamental domain. Lines are filled in as well.
    #   slitmap_full = build the full slitmap, from zeta1, zeta2, z
    #   slitmap_direct = build the slitmap all in one step. Minimum output.
    #   prec = double or infinite precision of the group data?
    # 	product_threshold = determines the max number of terms in the prime \
    # 							function product
    # 	max_time = max time for prime function computation before timeout
    # 	prime_function_tests = Check to see if the prime function passes some
    # 							tests
    # 	slitmap_tests = Check to see if the slitmap passes some tests
    # 	point_size = marker size for point_plot
    #   save_plots = save the plots or just display them?
    #
    # output:
    #   only plots
    #
    z = var('z') # complex variable
    gamma = var('gamma') #base point for 'abelmap' or prime function
    
    genus = len(q)

    # Generate colors for plotting here since we want them to be uniform across
    # plot_circles and slitmap plots
    circle_colors = [ (0.6*random(), random(), random()) for k in 
            xrange(genus) ]
    point_colors = [ (0.6*random(), random(), random()) for k in
            xrange(len(Points)) ]
    line_colors = [ (0.6*random(), random(), random()) for k in
            xrange(len(Lines)) ]
    # We multiply the "R" by 0.6 so nothing is too red.

    # Change group data to double or infinite precision
    if prec == 'double':
        delta, q = map(CDF, delta), map(CDF, q) # Complex double
        Points = map(CDF, Points)
        Lines = [ map(CDF, line) for line in Lines ]
    elif (prec=='infinite' or prec=='inf'):
        delta, q = map(CC, delta), map(CC, q) #infinite precision
        Points = map(CC, Points)
        Lines = [ map(CC, line) for line in Lines ]
    else:
        raise TypeError("Either 'double' or 'infinite' precision must be " 
                "entered for 'prec'.")
    
    # Plot some stuff about the region if we want.
    if plot_circles:
        D_zeta = circle_plots(delta, q, colors=circle_colors) 
        D_zeta += plot_points(Points, colors=point_colors, 
                            mark_size=point_size)
        D_zeta += plot_lines(Lines, colors=line_colors, thickness=2)

        if save_plots==False:
            D_zeta.show(axes=True, title='$D_{\zeta}$', aspect_ratio=1) 
            # show and put on an equal-axis plot
        else:
            D_zeta.save('circle_plot.eps')

    # Plot F, the fundamental domain
    if plot_F:
        D_zeta = F_plot(delta, q, colors=circle_colors)
        D_zeta += plot_points(Points, colors=point_colors, 
                     mark_size=point_size)
        D_zeta += plot_lines(Lines, colors=line_colors, thickness=2)
        if save_plots==False:
            D_zeta.show(axes = True, title = '$F$, the Fundamental Domain')
        else:
            D_zeta.save('Fundamental_domain.eps')
    
    # Build the prime function, but make sure it doesn't take too long
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(max_time) #Let it take max_time seconds at most!
    try:
        omega = build_prime_function(delta, q, product_threshold)
    except Exception, exc: #stop if it takes too long.
        print exc