spx2 has asked for the wisdom of the Perl Monks concerning the following question:

Is there a module on CPAN for getting fast the prime factors of some number ? I looked at Math::Big::Factors and it's really slow(for 5-digit numbers on a quad-core it's dead slow compared to pari-gp(I know factoring is hard but not this hard...).

I also tried Math::Factor::XS that gets all factors not the prime ones, and this is not what I want. Is there such a module on CPAN that works out the prime factors in at a reasonable speed ?

Thanks

  • Comment on CPAN module for prime factors of a number

Replies are listed 'Best First'.
Re: CPAN module for prime factors of a number
by BrowserUk (Patriarch) on Dec 18, 2009 at 13:17 UTC

    Have you seen Math::Pari::factorint?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I would use that, but I want to use it as a dependency for a module that will go on CPAN. How does CPAN cope with external dependencies such as pari/gp because Math::Pari is only an interface to pari/gp which needs to be installed. Looking forward to your oppinion about this , thanks :)

        If you install Math::Pari using the cpan shell, it offers to fetch and build Pari/GP for you. That's no guarentee the build will succeed--it fails on my Win64 system--but should work most places I think.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        Twice in one day, still not getting the hang of reading the documentation I see :) It's a good habit that will save you time.

        Math::Pari is only an interface to pari/gp which needs to be installed

        All you need do is install the Math::Pari module. To do that, you will need to grab the pari source, but you don't have to build GP/PARI - see the instructions at http://cpansearch.perl.org/src/ILYAZ/Math-Pari-2.01080603/INSTALL.

        Last time I tried, Math::Pari wouldn't build with the pari-2.3.4 source, so (I think) I used the pari-2.1.7 source, which was fine. Perhaps that has changed with latest Math::Pari releases - last version I built was 2.010800.

        Cheers,
        Rob