Factorize denominator of rationale

Marc Glisse marc.glisse at inria.fr
Tue Nov 22 19:08:09 CET 2022


For (2^a)*(3^b), I think we can avoid writing to any mpz_t, if performance 
matters. I'd use mpz_scan1 to get a, then mpz_sizeinbase(x,2)-a multiplied 
by a constant should round to b.

But yes, mpz_remove is more general and readable. And its cost is likely 
negligible compared to the rational operations that come before.

On Tue, 22 Nov 2022, Paul Zimmermann wrote:

>       Hi,
>
> the function you want is probably mpz_remove().
> (A _ui version would be most welcome.)
>
> Best regards,
> Paul Zimmermann
>
>> From: Øystein Schønning-Johansen <oysteijo at gmail.com>
>> Date: Tue, 22 Nov 2022 11:00:50 +0100
>> 
>> Hi!
>> 
>> I'm working with probabilities of a sequence of dice rolls, and the
>> different probabilities to be exact with rationales. I've got it all
>> working fine.
>> 
>> However, I want to write out all probabilities to a file and since there's
>> a lot of them, I want to reduce the file size and need the output string to
>> be as short as possible. I hence use mpq_canonicalize() and write out with
>> base 36. Works, but can I even be better?
>> 
>> Since these are consecutive dice rolls, I can always represent the
>> denominator (after canonicalize) as (2^a)*(3^b) and I then only have to
>> store the a and the b. So, the question is: How can I find the a and the b
>> of such denominators?
>> 
>> Best regards,
>> -Øystein
>> _______________________________________________
>> gmp-discuss mailing list
>> gmp-discuss at gmplib.org
>> https://gmplib.org/mailman/listinfo/gmp-discuss
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss

-- 
Marc Glisse


More information about the gmp-discuss mailing list