Bill Allombert on Mon, 27 Sep 2004 16:39:06 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

storing primes found by factor.


Hello PARI-dev,

Here a patch that add a new default, factor_add_primes 
(turned on by default) that make factorint to automatically call
addprimes on primes factor found larger than 2^24.  

In particular if you stop a factorisation you can get the factors
already found using addprimes(), and they will be automatically
reused if you restart it.

As for the code, some one more familiar with the ifac machinery should
check that it is working properly, namely it should never addprimes()
factors that are not (BSW pseudo-)primes. I hope the '!(hint & 8)'
achieve that goal.

Cheers,
Bill


Index: src/basemath/ifactor1.c
===================================================================
RCS file: /home/cvs/pari/src/basemath/ifactor1.c,v
retrieving revision 1.67
diff -u -r1.67 ifactor1.c
--- src/basemath/ifactor1.c	26 Sep 2004 16:02:18 -0000	1.67
+++ src/basemath/ifactor1.c	27 Sep 2004 13:57:01 -0000
@@ -27,6 +27,8 @@
 extern ulong ucarrecomplet(ulong A);
 extern GEN mpqs(GEN N);/* returns a factor, a vector of factors, or NULL */
 
+int factor_add_primes = 1;
+
 /*C++ on ia64 do not like (long)NULL*/
 #define LNULL ((long)(GEN)NULL)
 /*********************************************************************/
@@ -3496,6 +3498,14 @@
     {
       if (DEBUGLEVEL >= 3) fprintferr("IFAC: (Partial fact.)Stop requested.\n");
       break;
+    }
+    /* When factor_add_primes is set, ifac automatically add primes >2^24
+     * to the addprimes DB. BA2004Jun22*/
+    if (factor_add_primes && !(hint & 8))
+    {
+      GEN p=(GEN)here[0];
+      if (lgefint(p)>3 || expi(p)>24)
+        addprimes(p);
     }
     here[2] = here[1] = *here = LNULL;
     here = ifac_main(&part);
Index: src/gp/gp.c
===================================================================
RCS file: /home/cvs/pari/src/gp/gp.c,v
retrieving revision 1.230
diff -u -r1.230 gp.c
--- src/gp/gp.c	26 Sep 2004 16:02:18 -0000	1.230
+++ src/gp/gp.c	27 Sep 2004 13:12:48 -0000
@@ -892,6 +892,10 @@
 }
 
 static GEN
+sd_factor_add_primes(char *v, int flag)
+{ return sd_toggle(v,flag,"factor_add_primes", &factor_add_primes); }
+
+static GEN
 sd_new_galois_format(char *v, int flag)
 { return sd_toggle(v,flag,"new_galois_format", &new_galois_format); }
 
@@ -1031,6 +1035,7 @@
   {"debugfiles",(void*)sd_debugfiles},
   {"debugmem",(void*)sd_debugmem},
   {"echo",(void*)sd_echo},
+  {"factor_add_primes",(void*)sd_factor_add_primes},
   {"format",(void*)sd_format},
   {"help",(void*)sd_help},
   {"histsize",(void*)sd_histsize},
Index: src/headers/paricom.h
===================================================================
RCS file: /home/cvs/pari/src/headers/paricom.h,v
retrieving revision 1.62
diff -u -r1.62 paricom.h
--- src/headers/paricom.h	23 Sep 2004 14:49:14 -0000	1.62
+++ src/headers/paricom.h	27 Sep 2004 13:12:48 -0000
@@ -151,6 +151,7 @@
 extern void* global_err_data;
 
 extern int new_galois_format;
+extern int factor_add_primes;
 
 enum manage_var_t {
     manage_var_create,			/* 0 */