Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Copy source code?

by pvfki (Novice)
on Jul 19, 2019 at 04:29 UTC ( #11103001=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am relatively novice to Perl and had installed Math::Prime::Util::GMP modules. I am trying to adjust some of the subroutines in Math::Prime::Util by finding the .pl files for each of them in the directory libraries. For instance, I want to add / change the parameters to sieve_range() function by simply finding a .pl file for the subroutine and changing the code inside the file. Unfortunately, I did not find any such file. The closest thing I found was a file called 'sieve.c'. Is there still a simple way to change the subroutine's parameters and variable meanings manually or is the subroutine hard-coded (not easily to manipulate)?

Replies are listed 'Best First'.
Re: Copy source code?
by Laurent_R (Canon) on Jul 19, 2019 at 07:49 UTC
    GMP (GNU Multi-Precision) is a collection of libraries written in the c language for high performance (not specific to Perl). Math::Prime::Util::GMP is a kind of Perl interface to it. So, it is quite normal that you'll find something like sieve.c in there. I probably wouldn't advise you to try to change anything to it.

    On the other hand, if high performance is not your primary goal, you will probably find pure Perl implementation of what you're looking for by going up in the directory hierarchy (in Math::Prime::util or Math::Prime).

Re: Copy source code?
by hippo (Bishop) on Jul 19, 2019 at 08:07 UTC
    For instance, I want to add / change the parameters to sieve_range() function by simply finding a .pl file for the subroutine and changing the code inside the file.

    This has a bit of an XY Problem sound to it. Why do you want to change the parameters to sieve_range()?

Re: Copy source code?
by syphilis (Archbishop) on Jul 19, 2019 at 13:09 UTC
    I want to add / change the parameters to sieve_range() function by simply finding a .pl file for the subroutine and changing the code inside the file

    If you want to make changes to the number or types of arguments that sieve_range() accepts, you'll have to make those changes in XS.xs and rebuild Math::Prime::Util.

    The file 'sieve.c' contains a function named _sieve_range() which, AFAICS, is a separate function to sieve_range().
    The _sieve_range() function seems to be a function that is private to 'sieve.c'.

    I suggest contacting the Math::Prime::Util author regarding any changes you would like to see.

      I was hoping to manipulate it mostly because I am after the high performance of this particular function, as Laurent_R pointed out. I did write (with some help) my own sieving script to my liking, but it is really crude and slow performing. Dana Jacobsen (the author of most of these libraries) seems to be the person to contact, but if he isn't reachable, are there other people on this forum that are capable of making additions/changes to the libraries?
        I haven't heard form Dana for a while and, according to his homenode, he was last here 3 months ago.
        Have you tried emailing him at the address shown at ?

        Other than that, if you tell us exactly what you wish to change about Math::Prime::Util::sieve_range(), someone here might be able to provide you with the required changes to XS.xs (and any other affected files).

        Update: According to the Math::Prime::Util github repo Dana's latest commit was made less than a month ago, so I think there's a good chance that he's still active and contactable.

Re: Copy source code?
by Don Coyote (Hermit) on Jul 19, 2019 at 08:08 UTC

    Hello pvfki Welcome to the Monastery.

    Perl is in principle a Text and Languague manipulation tool. Math tends to be handed over to C code. Essentially you need to know how Perl relates to C, which is usually a more advanced level approach.

    Having had a quick look on for the Math::Prime::Util::GMP module, the top result being Math::Prime::Util::GMP.

    A secondary result was this module Math::Prime::Util::PP. You may find this to be of more use as it is a pure perl Module. This means you would not need to get involved with the under the hood implementations. Unless of course you are proficient already with that level of hacking.

    Essentially you can mess around with the subroutines to your liking. This is of interest to me, and that Perl primarily manipulates text appeals to the arithmetically minded out there. I think a main concern is how to determine what all these internal optimisations these programs do, are.

    There is also Perl 6. Which is investigating user created operations and inlining low level languages right into the script.

    Naturally, do update this thread with any algorithms that crack the primes you find. Good Luck.

Re: Copy source code?
by soonix (Canon) on Jul 19, 2019 at 13:59 UTC
    You want to change the parameters of a function without changing the inner workings of same function? E.g. have some default values?

    Then simply define a new function with uses the parameters as you want them, have it juggle the parameters as you need and have it call the original function …

Re: Copy source code?
by davido (Cardinal) on Jul 22, 2019 at 04:15 UTC

    Dana's a great guy, and easy to work with if you've got some good ideas. Have you considered forking and creating a pull request? Or making a request by emailing his PAUSE account or by raising a Github issue?

    To work on code in Math::Prime::Util you're going to need to learn some C, and Perl XS. My experience working with Dana on some pet projects a few years ago, as well as attending a Perl conference talk or two of his, is that he's thought Math::Prime::Util through very well. But he's never struck me as someone who would be unwilling to make further improvements if they're sensible.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11103001]
Approved by marto
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2023-05-31 03:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found