[Ecm-commits] r2373 - trunk

cvs commits ecm-commits at lists.gforge.inria.fr
Tue Feb 5 12:01:59 CET 2013


Author: morain
Date: 2013-02-05 12:01:58 +0100 (Tue, 05 Feb 2013)
New Revision: 2373

Log:
Preparing for fast CM step2 for more D's.


Modified:
   trunk/cmecm.c
   trunk/cmecm.h
   trunk/manyecm.c
   trunk/stage2.c
Modified: trunk/cmecm.c
===================================================================
--- trunk/cmecm.c	2013-02-04 20:54:03 UTC (rev 2372)
+++ trunk/cmecm.c	2013-02-05 11:01:58 UTC (rev 2373)
@@ -461,12 +461,20 @@
     mpz_t tmp;
     unsigned long umax, vmax, dF = 0, k = 0;
 
-    if(disc == -4){
+    mpz_init(tmp);
+    if(disc == -3){
+	/* U^2+3*V^2 <= 4*B2 */
+	/* tmp <- floor(sqrt(4*B2-3)) */
+	mpz_mul_2exp(tmp, B2, 2);
+	mpz_sub_si(tmp, tmp, 3);
+	mpz_sqrt(tmp, tmp);
+    }
+    else if(disc == -4){
 	/* tmp <- floor(sqrt(B2-1)) */
-	mpz_init_set(tmp, B2);
+	mpz_set(tmp, B2);
 	mpz_sub_si(tmp, tmp, 1);
 	mpz_sqrt(tmp, tmp);
-#if CMECM_D_4 == 0 /* standard version */
+#if CMECM_FAST == 0 /* standard version */
 	/* u^2 + v^2 <= B2, u odd, v even */
 	vmax = mpz_get_ui(tmp);
 	/* largest v must be even */
@@ -486,16 +494,16 @@
 	for(k = 1; k*dF < umax; k++);
 #else /* faster */
 	/* u^2 + v^2 <= B2, u > v > 0 */
-	umax = mpz_get_ui(tmp);
-	/* find smallest power of 2 >= umax */
-	for(dF = 1; dF < umax; dF <<= 1);
-	k = 1;
 #endif
-	mpz_clear(tmp);
     }
+    umax = mpz_get_ui(tmp);
+    /* find smallest power of 2 >= umax */
+    for(dF = 1; dF < umax; dF <<= 1);
+    k = 1;
+    mpz_clear(tmp);
     *pdF = dF;
     *pk = k;
-    printf("# Overridden params: dF=%ld, k=%ld\n", dF, k);
+    printf("# Overridden params for D=%d: dF=%ld, k=%ld\n", disc, dF, k);
 }
 
 /* F[i] <- ([kmin+i*dk]P)_x for 0 <= i < dF. */
@@ -576,17 +584,12 @@
     mpres_set(P->x, C->x, modulus);
     mpres_set(P->y, C->y, modulus);
     ec_point_init(omegaP, E, modulus);
-    if(C->disc == -4){
-	apply_CM(omegaP, C->disc, C->sq, P, modulus);
-#if CMECM_D_4 == 0
-	ret = all_multiples(f, F, dF, E, omegaP, modulus, 2, 2);
-#else /* TODO: replace omegaP with P... 
-	 in the pedestrian version, one evaluates [v][zeta4]P in F
-	 and [u]P in G, whereas we can share everything...!
-       */
-	ret = all_multiples(f, F, dF, E, omegaP, modulus, 1, 1);
+#if CMECM_FAST == 0
+    apply_CM(omegaP, C->disc, C->sq, P, modulus);
+    ret = all_multiples(f, F, dF, E, omegaP, modulus, 2, 2);
+#else /* we don't need another hero! */
+    ret = all_multiples(f, F, dF, E, P, modulus, 1, 1);
 #endif
-    }
     ec_point_clear(omegaP, E, modulus);
     ec_point_clear(P, E, modulus);
     ec_curve_clear(E, modulus);
@@ -630,21 +633,15 @@
 	mpres_init (state->fd[k].y, modulus);
     }
     
+#if CMECM_FAST == 0
     if(X->disc == -4){
-#if CMECM_D_4 == 0
 	umin = 1;
 	du = 2;
+    }
 #else
-# if 0
-	printf("# Case D=-4 suboptimal, man!\n");
-	umin = 1;
-	du = 1;
-# else
-	printf("# Skipping stuff in rootsG_init_CM\n");
-	return state;
-# endif
+    printf("# Skipping stuff in rootsG_init_CM for disc=%d\n", X->disc);
+    return state;
 #endif
-    }
     
     /* conversions */
     ec_curve_init(E, ECM_EC_TYPE_WEIERSTRASS_AFF, modulus);
@@ -721,3 +718,30 @@
     ec_curve_clear(E, modulus);
     return ret;
 }
+
+/* Given F(X) = prod(X-x_u), compute G(X) = F([omega]*X).
+ */
+int
+compute_G_from_F(listz_t G, listz_t F, unsigned long dF, curve *X,
+		 mpmod_t modulus)
+{
+    int ret = ECM_NO_FACTOR_FOUND;
+    unsigned long j;
+
+    if(X->disc == -3){
+	/* [omega](X, Y) = (zeta6*X, Y), hence G(X) = F(zeta6*X) */
+    }    
+    else if(X->disc == -4){
+	/* [omega](X, Y) = (-X, zeta4*Y), hence G(X) = F(-X) */
+	printf("# making G(X) = F(-X)\n");
+	for (j = 0; j < dF; j ++){
+	    mpz_set(G[j], F[j]);
+	    if(j & 1){
+		/* [X^j]G = -[X^j]F */
+		if(mpz_sgn(G[j]) != 0)
+		    mpz_sub(G[j], modulus->orig_modulus, G[j]);
+	    }
+	}
+    }
+    return ret;
+}

Modified: trunk/cmecm.h
===================================================================
--- trunk/cmecm.h	2013-02-04 20:54:03 UTC (rev 2372)
+++ trunk/cmecm.h	2013-02-05 11:01:58 UTC (rev 2373)
@@ -1,4 +1,4 @@
-#define CMECM_D_4 1 /* fast version */
+#define CMECM_FAST 1 /* fast version */
 
 int build_curves_with_CM(mpz_t f, int *nE, ec_curve_t *tE, ec_point_t *tP, int disc, mpmod_t n, mpz_t *sqroots);
 void
@@ -6,3 +6,4 @@
 int ecm_rootsF_CM(mpz_t f, listz_t F, unsigned long dF, curve *C, mpmod_t modulus);
 ecm_roots_state_t *ecm_rootsG_init_CM (mpz_t f, curve *X, root_params_t *root_params, unsigned long dF, unsigned long blocks, mpmod_t modulus);
 int ecm_rootsG_CM (mpz_t f, listz_t G, unsigned long dF, ecm_roots_state_t *state, mpmod_t modulus);
+int compute_G_from_F(listz_t G, listz_t F, unsigned long dF, curve *X, mpmod_t modulus);

Modified: trunk/manyecm.c
===================================================================
--- trunk/manyecm.c	2013-02-04 20:54:03 UTC (rev 2372)
+++ trunk/manyecm.c	2013-02-05 11:01:58 UTC (rev 2373)
@@ -1077,7 +1077,7 @@
     mpz_t N, tf[NFMAX], B2;
     int res = 0, smin = -1, smax = -1, ncurves = 0, method = ECM_ECM;
     int nf = 0, i, bb = 0;
-    double B1 = 0.0;
+    double B1 = 0.0, dB2 = 0.0;
     int disc = 0, b = 0, n = 0;
     char *infilename = NULL, *curvesname = NULL, *torsion = NULL;
     char buf[10000], c;
@@ -1103,7 +1103,8 @@
 	    argc -= 2;
 	}
 	else if ((argc > 2) && (strcmp (argv[1], "-B2") == 0)){
-	    mpz_set_str(B2, argv[2], 10);
+	    dB2 = atof(argv[2]);
+	    mpz_set_d(B2, dB2);
 	    argv += 2;
 	    argc -= 2;
 	}

Modified: trunk/stage2.c
===================================================================
--- trunk/stage2.c	2013-02-04 20:54:03 UTC (rev 2372)
+++ trunk/stage2.c	2013-02-05 11:01:58 UTC (rev 2373)
@@ -643,19 +643,9 @@
 	  youpi = ecm_rootsG (f, G, dF, (ecm_roots_state_t *) rootsG_state, 
 			      modulus);
       else
-#if CMECM_D_4 == 1
+#if CMECM_FAST == 1
 	  if(disc == -4){
-	      /* we are using G(X) = F(-X), so skip many things! */
-	      printf("# making G(X) = F(-X)\n");
-	      unsigned long j;
-	      for (j = 0; j < dF; j ++){
-		  mpz_set(G[j], F[j]);
-		  if(j & 1){
-		      /* [X^j]G = -[X^j]F */
-		      if(mpz_sgn(G[j]) != 0)
-			  mpz_sub(G[j], modulus->orig_modulus, G[j]);
-		  }
-	      }
+	      compute_G_from_F(G, F, dF, (curve *) X, modulus);
 	      goto got_G;
 	  }
 	  else




More information about the Ecm-commits mailing list