# 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
|
|
1 | 1 | |
2 | 2 | include '../ext/cdefs.pxi' |
3 | 3 | include '../ext/stdsage.pxi' |
| 4 | include '../ext/interrupt.pxi' |
4 | 5 | from sage.rings.integer cimport Integer |
5 | 6 | |
6 | 7 | cdef extern from "ratpoints.h": |
… |
… |
|
69 | 70 | ctypedef struct info_struct_exists_only: |
70 | 71 | int verbose |
71 | 72 | |
72 | | cdef bint ratpoints_mpz_exists_only(mpz_t *, long, int, bint) |
| 73 | cdef int ratpoints_mpz_exists_only(mpz_t *, long, int, bint) except -1 |
73 | 74 | |
74 | 75 | |
75 | 76 | |
diff -r 2ac50a2aae31 -r 1c570ad744e0 sage/libs/ratpoints.pyx
a
|
b
|
|
128 | 128 | sage_int = <Integer> coeffs[i] |
129 | 129 | mpz_set(args.cof[i], sage_int.value) |
130 | 130 | |
| 131 | _sig_on |
131 | 132 | total = find_points(&args, process, <void *>plist) |
| 133 | _sig_off |
132 | 134 | if total == RATPOINTS_NON_SQUAREFREE: |
133 | 135 | raise RuntimeError('Polynomial must be square-free') |
134 | 136 | if total == RATPOINTS_BAD_ARGS: |
… |
… |
|
168 | 170 | quit[0] = -1 |
169 | 171 | return 1 |
170 | 172 | |
171 | | cdef bint ratpoints_mpz_exists_only(mpz_t *coeffs, long H, int degree, bint verbose): |
| 173 | cdef int ratpoints_mpz_exists_only(mpz_t *coeffs, long H, int degree, bint verbose) except -1: |
172 | 174 | """ |
173 | 175 | Direct call to ratpoints to search for existence only. |
174 | 176 | |
… |
… |
|
193 | 195 | args.num_primes = RATPOINTS_DEFAULT_NUM_PRIMES |
194 | 196 | args.max_forbidden = RATPOINTS_DEFAULT_MAX_FORBIDDEN |
195 | 197 | args.flags = (RATPOINTS_VERBOSE & verby) |
| 198 | _sig_on |
196 | 199 | total = find_points(&args, process_exists_only, <void *>(&info_s)) |
| 200 | _sig_off |
197 | 201 | sage_free(args.domain) |
198 | 202 | if total == RATPOINTS_NON_SQUAREFREE: |
199 | 203 | raise RuntimeError('Polynomial must be square-free') |
200 | 204 | if total == RATPOINTS_BAD_ARGS: |
201 | 205 | raise RuntimeError('Bad arguments to ratpoints') |
202 | | return (total > 0) |
| 206 | return 1 if (total > 0) else 0 |
203 | 207 | |
204 | 208 | |
205 | 209 | |
diff -r 2ac50a2aae31 -r 1c570ad744e0 sage/schemes/elliptic_curves/descent_two_isogeny.pyx
a
|
b
|
|
21 | 21 | from sage.rings.integer cimport Integer |
22 | 22 | |
23 | 23 | include "../../ext/cdefs.pxi" |
| 24 | include "../../ext/interrupt.pxi" |
24 | 25 | include "../../libs/flint/fmpz_poly.pxi" |
25 | 26 | |
26 | 27 | from sage.libs.flint.zmod_poly cimport *, zmod_poly_t |
… |
… |
|
937 | 938 | |
938 | 939 | cdef int count(mpz_t c_mpz, mpz_t d_mpz, mpz_t *p_list, unsigned long p_list_len, |
939 | 940 | 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: |
941 | 942 | """ |
942 | 943 | Count the number of els/gls quartic 2-covers of E. |
943 | 944 | """ |
… |
… |
|
1013 | 1014 | print "\nCalling ratpoints for small point search" |
1014 | 1015 | for i from 0 <= i <= 4: |
1015 | 1016 | 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: |
1017 | 1021 | if verbosity > 2: |
1018 | 1022 | a_Int = Integer(0); mpz_set(a_Int.value, coeffs[4]) |
1019 | 1023 | c_Int = Integer(0); mpz_set(c_Int.value, coeffs[2]) |
1020 | 1024 | e_Int = Integer(0); mpz_set(e_Int.value, coeffs[0]) |
1021 | 1025 | print 'Found small global point, quartic (%d,%d,%d,%d,%d)'%(a_Int,0,c_Int,0,e_Int) |
1022 | | found_global_points = 1 |
1023 | 1026 | mpz_add_ui(n1, n1, ui1) |
1024 | 1027 | mpz_add_ui(n2, n2, ui1) |
1025 | 1028 | if verbose: |
… |
… |
|
1043 | 1046 | print "\nCalling ratpoints for large point search" |
1044 | 1047 | for i from 0 <= i <= 4: |
1045 | 1048 | 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: |
1047 | 1053 | if verbosity > 2: |
1048 | 1054 | print ' -- Found large global point.' |
1049 | 1055 | mpz_add_ui(n1, n1, ui1) |
… |
… |
|
1126 | 1132 | sage: log(n1,2) + log(n1_prime,2) - 2 # the rank |
1127 | 1133 | 0 |
1128 | 1134 | |
| 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 | |
1129 | 1157 | """ |
1130 | 1158 | cdef Integer a1, a2, a3, a4, a6, s2, s4, s6 |
1131 | 1159 | cdef Integer c, d, x0 |