Karim Belabas on Tue, 24 Feb 2026 14:46:10 +0100


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

Re: Why does factorint() take 128ms for 1853 decimal digit prime, while isprime() takes 16:45min/2min cpu/real time?


* hermann@stamm-wilbrandt.de [2026-02-24 13:55]:
> On 2026-02-24 00:24, Aurel Page wrote:
> > Dear Hermann,
> > 
> > That is because by default, factor does not prove that the factors are
> > prime. They are only guaranteed to be pseudoprimes.
> > ...
> > You can use default(factor_proven, 1) to change this behaviour.
> > 
> > Best,
> > Aurel
> > 
> Thanks Aurel,
> 
> while my previous questions were OK, my last question was not.
> 
> default(factor_proven, 1) is discussed in 3.8.1 of doc:
> https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.17.2/users.pdf#page=177
> 
> But I should have learned about it myself easily with "??factorint".

Maybe I'm missing something but this seems to be easy to find:

14:38) gp > ??factorint 
factorint(x,{flag = 0}):

   Factors  the  integer n into a product of pseudoprimes  (see ispseudoprime),
[...]
the  divisors  are  by  default not proven primes if they are larger than 2^64,
they only failed the BPSW compositeness test (see ispseudoprime).   Use isprime
on  the  result  if  you  want  to guarantee primality or set the factor_proven
default  to 1.
[...]


N.B. I don't recommend setting that default outside validating a specific
computation (then unsetting it again). It may slow down gp considerably
in ways which are hard to predict or mitigate for users.

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/