Ticket #8155: trac_8155.patch

File trac_8155.patch, 5.8 KB (added by rlm, 13 years ago)
  • sage/libs/ratpoints.pxd

    # HG changeset patch
    # User Robert L. Miller <rlm@rlmiller.org>
    # Date 1265167063 28800
    # Node ID 1c570ad744e044691bacdbd9a64ca65aca2cc273
    # Parent  2ac50a2aae3184d64bb5a0d815884ed10ee0703c
    trac #8155: sig_on/sig_off in native two-isogeny descent
    
    diff -r 2ac50a2aae31 -r 1c570ad744e0 sage/libs/ratpoints.pxd
    a b  
    11
    22include '../ext/cdefs.pxi'
    33include '../ext/stdsage.pxi'
     4include '../ext/interrupt.pxi'
    45from sage.rings.integer cimport Integer
    56
    67cdef extern from "ratpoints.h":
     
    6970ctypedef struct info_struct_exists_only:
    7071    int verbose
    7172
    72 cdef bint ratpoints_mpz_exists_only(mpz_t *, long, int, bint)
     73cdef int ratpoints_mpz_exists_only(mpz_t *, long, int, bint) except -1
    7374
    7475
    7576
  • sage/libs/ratpoints.pyx

    diff -r 2ac50a2aae31 -r 1c570ad744e0 sage/libs/ratpoints.pyx
    a b  
    128128        sage_int = <Integer> coeffs[i]
    129129        mpz_set(args.cof[i], sage_int.value)
    130130   
     131    _sig_on
    131132    total = find_points(&args, process, <void *>plist)
     133    _sig_off
    132134    if total == RATPOINTS_NON_SQUAREFREE:
    133135        raise RuntimeError('Polynomial must be square-free')
    134136    if total == RATPOINTS_BAD_ARGS:
     
    168170    quit[0] = -1
    169171    return 1
    170172
    171 cdef bint ratpoints_mpz_exists_only(mpz_t *coeffs, long H, int degree, bint verbose):
     173cdef int ratpoints_mpz_exists_only(mpz_t *coeffs, long H, int degree, bint verbose) except -1:
    172174    """
    173175    Direct call to ratpoints to search for existence only.
    174176   
     
    193195    args.num_primes = RATPOINTS_DEFAULT_NUM_PRIMES
    194196    args.max_forbidden = RATPOINTS_DEFAULT_MAX_FORBIDDEN
    195197    args.flags = (RATPOINTS_VERBOSE & verby)
     198    _sig_on
    196199    total = find_points(&args, process_exists_only, <void *>(&info_s))
     200    _sig_off
    197201    sage_free(args.domain)
    198202    if total == RATPOINTS_NON_SQUAREFREE:
    199203        raise RuntimeError('Polynomial must be square-free')
    200204    if total == RATPOINTS_BAD_ARGS:
    201205        raise RuntimeError('Bad arguments to ratpoints')
    202     return (total > 0)
     206    return 1 if (total > 0) else 0
    203207
    204208
    205209
  • sage/schemes/elliptic_curves/descent_two_isogeny.pyx

    diff -r 2ac50a2aae31 -r 1c570ad744e0 sage/schemes/elliptic_curves/descent_two_isogeny.pyx
    a b  
    2121from sage.rings.integer cimport Integer
    2222
    2323include "../../ext/cdefs.pxi"
     24include "../../ext/interrupt.pxi"
    2425include "../../libs/flint/fmpz_poly.pxi"
    2526
    2627from sage.libs.flint.zmod_poly cimport *, zmod_poly_t
     
    937938
    938939cdef int count(mpz_t c_mpz, mpz_t d_mpz, mpz_t *p_list, unsigned long p_list_len,
    939940               int global_limit_small, int global_limit_large,
    940                int verbosity, bint selmer_only, mpz_t n1, mpz_t n2):
     941               int verbosity, bint selmer_only, mpz_t n1, mpz_t n2) except -1:
    941942    """
    942943    Count the number of els/gls quartic 2-covers of E.
    943944    """
     
    10131014                print "\nCalling ratpoints for small point search"
    10141015            for i from 0 <= i <= 4:
    10151016                mpz_set(coeffs_ratp[i], coeffs[i])
    1016             if ratpoints_mpz_exists_only(coeffs_ratp, global_limit_small, 4, verbose):
     1017            _sig_on
     1018            found_global_points = ratpoints_mpz_exists_only(coeffs_ratp, global_limit_small, 4, verbose)
     1019            _sig_off
     1020            if found_global_points:
    10171021                if verbosity > 2:
    10181022                    a_Int = Integer(0); mpz_set(a_Int.value, coeffs[4])
    10191023                    c_Int = Integer(0); mpz_set(c_Int.value, coeffs[2])
    10201024                    e_Int = Integer(0); mpz_set(e_Int.value, coeffs[0])
    10211025                    print 'Found small global point, quartic (%d,%d,%d,%d,%d)'%(a_Int,0,c_Int,0,e_Int)
    1022                 found_global_points = 1
    10231026                mpz_add_ui(n1, n1, ui1)
    10241027                mpz_add_ui(n2, n2, ui1)
    10251028            if verbose:
     
    10431046                        print "\nCalling ratpoints for large point search"
    10441047                    for i from 0 <= i <= 4:
    10451048                        mpz_set(coeffs_ratp[i], coeffs[i])
    1046                     if ratpoints_mpz_exists_only(coeffs_ratp, global_limit_large, 4, verbose):
     1049                    _sig_on
     1050                    found_global_points = ratpoints_mpz_exists_only(coeffs_ratp, global_limit_large, 4, verbose)
     1051                    _sig_off
     1052                    if found_global_points:
    10471053                        if verbosity > 2:
    10481054                            print '  -- Found large global point.'
    10491055                        mpz_add_ui(n1, n1, ui1)
     
    11261132        sage: log(n1,2) + log(n1_prime,2) - 2 # the rank
    11271133        0
    11281134
     1135    TESTS:
     1136   
     1137    Here we contrive an example to demonstrate that a keyboard interrupt
     1138    is caught. Here we let `E` be the smallest optimal curve with two-torsion
     1139    and nontrivial Sha[2]. This ensures that the two-descent will be looking
     1140    for rational points which do not exist, and by setting global_limit_large
     1141    to a very high bound, it will still be working when we simulate a ctrl-c::
     1142   
     1143        sage: from sage.schemes.elliptic_curves.descent_two_isogeny import two_descent_by_two_isogeny
     1144        sage: import signal
     1145        sage: E = EllipticCurve('960d'); E
     1146        Elliptic Curve defined by y^2 = x^3 - x^2 - 900*x - 10098 over Rational Field
     1147        sage: E.sha().an()
     1148        4
     1149        sage: try:
     1150        ...     signal.alarm(2)
     1151        ...     two_descent_by_two_isogeny(E, global_limit_large=10^8)
     1152        ... except KeyboardInterrupt:
     1153        ...     print "Caught!"
     1154        0
     1155        ... Caught!
     1156
    11291157    """
    11301158    cdef Integer a1, a2, a3, a4, a6, s2, s4, s6
    11311159    cdef Integer c, d, x0