Skip Menu |

This queue is for tickets about the Math-Prime-Util-GMP CPAN distribution.

Report information
The Basics
Id: 110988
Status: open
Priority: 0/
Queue: Math-Prime-Util-GMP

People
Owner: DANAJ [...] cpan.org
Requestors: DANAJ [...] cpan.org
Cc: hv [...] crypt.org
sisyphus [...] cpan.org
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



CC: hv [...] crypt.org, sisyphus [...] cpan.org
Subject: Math::GMPz / Math::GMP / Math::BigInt output
Currently Math::Prime::Util:GMP does all I/O via strings. While this is easy and very portable, it is quite time consuming for large inputs, and can add significant overhead for some functions even with small inputs. For an example, this takes about 6 minutes currently: $perl -E 'use ntheory ":all"; my $n = primorial(230077)/2229464046810-3131794; @f = Math::Prime::Util::GMP::sieve_primes($n+1, $n+4680156-1, 1e9); say $_-$n for @f;' but the actual *work* is about 1 minute 45 seconds. Changing sieve_primes to return the offsets directly gives that fast time, as does a change to return the full numbers as Math::GMPz objects (assuming $n is a Math::GMPz object as well). I have code to do this, it needs to be turned on in all functions and tested. Principles (please add input): (1) If the input is a Math::GMPz or Math::GMP object, the mpz_t is immediately available and is used. Otherwise it is read as a UV/IV if it fits in both UV and long, or string otherwise. I briefly tried getting Math::BigInt::GMP input but it's complicated. (2) the return type is always identical to the input if they were Math::GMPz or Math::GMP (multi-argument functions will just pick one of the arguments to be the deciding one). Now we have debatable points: (a) if the input(s) were some other object (e.g. Math::Pari or Math::BigInt) should we insist that the inputs we that same object type? This seems nice for the user. Making Math::GMP and Math::GMPz objects for output is very simple and fast, but other types not so much (we are forced to call their new() methods for each return value). (b) since we obviously have GMP, I'm thinking I could add a dependency on Math::GMPz and make all input returned as that type if not a Math::GMP. This could cause havoc if someone was using Math::Pari or Math::BigInt though, as they don't always play well together. (c) I could add a config option 'class' that takes values 'string''Math::GMP','Math::GMPz', maybe others. Setting it would force all output to that type. 'string' can be useful if the caller is always doing string manipulation on the output (lots of OEIS sequences do this sort of thing).
CC: <hv [...] crypt.org>, <sisyphus [...] cpan.org>
Subject: Re: [rt.cpan.org #110988] Math::GMPz / Math::GMP / Math::BigInt output
Date: Sat, 9 Jan 2016 12:19:30 +1100
To: <bug-Math-Prime-Util-GMP [...] rt.cpan.org>
From: <sisyphus1 [...] optusnet.com.au>
Show quoted text
-----Original Message----- From: Dana Jacobsen via RT Sent: Friday, January 08, 2016 5:05 AM Cc: hv@crypt.org ; sisyphus@cpan.org Subject: [rt.cpan.org #110988] Math::GMPz / Math::GMP / Math::BigInt output
> Now we have debatable points: > (a) if the input(s) were some other object (e.g. Math::Pari or > Math::BigInt) should we insist that the inputs we that same object type? > This seems nice for the user. Making Math::GMP and Math::GMPz objects for > output is very simple and fast, but other types not so much (we are forced > to call their new() methods for each return value).
I don't think there's any hard and fast rule here. I would expect that the output would be the same type as the input, but you could set it up differently if you want - in which case the documentation should explain your reasons for doing so. (b) since we obviously have GMP, I'm thinking I could add a dependency on Math::GMPz and make all input returned as that type if not a Math::GMP. This could cause havoc if someone was using Math::Pari or Math::BigInt though, as they don't always play well together. It's years since I've used Math::Pari and I don't know anything about how it plays with Math::GMPz - but I would have thought that $z = Rmpz_init_set_str($math_pari_object, 0) would work reliably, though not particularly quickly. Or is there more to the problem than simply converting one to the other ? Are there other issues with Math::BigInt and Math::GMPz that will not be covered by #110986 ? (c) I could add a config option 'class' that takes values 'string''Math::GMP','Math::GMPz', maybe others. Setting it would force all output to that type. 'string' can be useful if the caller is always doing string manipulation on the output (lots of OEIS sequences do this sort of thing). That sounds like a good idea - obviously the user already chooses the input type and, with this config option, they also get to choose the output type. It's not going to impact upon performance, it should be easy to document clearly, and it will allow the user to do exactly what he wants (or, at least, to get exactly what he asked for ;-) I like (c). Cheers, Rob