Commit 31be314f authored by Peter Bruin's avatar Peter Bruin

clean up jacobian.c

parent 03200890
#include <math.h> /* log */
#include <pari/pari.h>
#include "algsmall.h"
#include "finite-fields.h"
#include "matsmall.h"
#include "addflip-chain.h"
#include "curve.h"
......@@ -25,60 +22,29 @@
and we need to know \Gamma(X,{\cal L}_0^i) for i <= 9.
*/
static GEN
jacobian_V (GEN X) {
switch (jacobian_type (X)) {
static long
jacobian_power(GEN J) {
switch (jacobian_type(J)) {
case JACOBIAN_TYPE_MEDIUM:
/* For the medium model, V = \Gamma(X,{\cal L}_0^2). */
return jacobian_V_0_2 (X);
return 2;
case JACOBIAN_TYPE_LARGE:
/* For the large model, V = \Gamma(X,{\cal L}_0^3). */
return jacobian_V_0_3 (X);
return 3;
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return NULL;
pari_err(e_MISC, "invalid type for the Jacobian");
return 0;
}
}
static GEN
jacobian_IGS_V (GEN X) {
switch (jacobian_type (X)) {
case JACOBIAN_TYPE_MEDIUM:
return curve_IGS_V (X, 2);
case JACOBIAN_TYPE_LARGE:
return curve_IGS_V (X, 3);
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return NULL;
}
jacobian_V(GEN J) {
return curve_V(J, jacobian_power(J));
}
static int
jacobian_deg_L (GEN X) {
switch (jacobian_type (X)) {
case JACOBIAN_TYPE_MEDIUM:
/* For the medium model, {\cal L} = {\cal L}_0^2. */
return 2 * jacobian_deg_L_0 (X);
case JACOBIAN_TYPE_LARGE:
/* For the large model, {\cal L} = {\cal L}_0^3. */
return 3 * jacobian_deg_L_0 (X);
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return 0;
}
}
static int
jacobian_dim_V_2 (GEN X) {
switch (jacobian_type (X)) {
case JACOBIAN_TYPE_MEDIUM:
return lg (curve_V (X, 4)) - 1;
case JACOBIAN_TYPE_LARGE:
return lg (curve_V (X, 6)) - 1;
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return 0;
}
static GEN
jacobian_IGS_V(GEN J) {
return curve_IGS_V(J, jacobian_power(J));
}
/*
......@@ -89,25 +55,7 @@ jacobian_dim_V_2 (GEN X) {
*/
GEN
jacobian_deflate (GEN X, GEN W_D) {
unsigned long p = curve_base_field_characteristic (X);
GEN T = curve_base_field_polynomial (X);
GEN V = jacobian_V (X);
int degree_D = jacobian_divisor_deg (X, W_D);
int dim_W_2_D = jacobian_dim_V_2 (X) - degree_D;
const float alpha = 0.9;
int h = 1 + ceil (log ((jacobian_deg_L (X) - degree_D) / alpha)
/ log_ffsize (p, T));
GEN IGS, IGS_V;
pari_sp av = avma;
if (lg(W_D) < 4)
return gcopy(W_D);
do {
avma = av;
IGS = matsmall_random_subspace(W_D, h, 0, p, T);
IGS_V = curve_multiply_subspaces(X, IGS, V);
} while (lg (IGS_V) - 1 < dim_W_2_D);
return gerepileupto(av, IGS);
return curve_divisor_IGS(X, W_D, jacobian_power(X));
}
/*
......@@ -118,18 +66,7 @@ GEN
jacobian_inflate (GEN X, GEN IGS_D) {
GEN V = jacobian_V (X);
pari_sp av = avma;
int i;
switch (jacobian_type(X)) {
case JACOBIAN_TYPE_MEDIUM:
i = 2;
break;
case JACOBIAN_TYPE_LARGE:
i = 3;
break;
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return NULL;
}
long i = jacobian_power(X);
return gerepileupto(av, curve_divide_subspaces
(X, curve_multiply_subspaces(X, IGS_D, V), 2 * i,
jacobian_IGS_V(X), i));
......@@ -146,18 +83,7 @@ GEN
jacobian_flip (GEN X, GEN W_D, GEN s) {
GEN V = jacobian_V (X);
pari_sp av = avma;
int i;
switch (jacobian_type (X)) {
case JACOBIAN_TYPE_MEDIUM:
i = 2;
break;
case JACOBIAN_TYPE_LARGE:
i = 3;
break;
default:
pari_err (e_MISC, "invalid type for the Jacobian");
return NULL;
}
long i = jacobian_power(X);
return gerepileupto (av, curve_divide_subspaces
(X, curve_multiply_section_subspace(X, s, V), 2*i,
jacobian_deflate (X, W_D), i));
......@@ -603,18 +529,9 @@ jacobian_count_points (GEN J) {
GEN
jacobian_random_point (GEN J) {
/*
We need to find a random divisor of degree d.
In the case of the large model, the choice below means that
we pick a small divisor.
*/
long d = curve_degree (J);
if (jacobian_type (J) == JACOBIAN_TYPE_MEDIUM)
return curve_random_divisor (J, d, 2);
if (jacobian_type (J) == JACOBIAN_TYPE_LARGE)
return curve_random_divisor (J, d, 3);
pari_err (e_MISC, "invalid type for the Jacobian");
return NULL;
/* In the case of the large model, we pick a small divisor. */
return curve_random_divisor(J, curve_degree(J),
jacobian_power(J));
}
GEN
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment