Request: mpz_addmul_2exp
Marc Glisse
marc.glisse at inria.fr
Wed May 10 22:16:30 CEST 2023
On Wed, 10 May 2023, abbott at dima.unige.it wrote:
> I'd like to have mpz_addmul_2exp.
> The application is evaluating a univariate polynomial with "small integer"
> coefficients at x=2 (or x=2^k some k).
>
> Outline application code:
> vector<mpz_class> coeffs = ...
> int d = deg(...);
> mpz_class val = mpz_mul_2exp(coeffs[d], d);
> for (int i=d-1; i >= 0; --i)
> mpz_addmul_2exp(val, coeffs[i], i);
>
> [[I know I am mixing mpz_class and mpz_t]]
> If the coeffs are small, this should be nearly linear time, I hope.
On some platforms we have an internal mpn_addlsh_n (or a few variants like
mpn_addlsh*_n), used in particular for Toom multiplication. Wrapping that
in a mpz function, with a simple fallback code, sounds doable. Or maybe we
could add a generic version of mpn_addlsh_n.
It can also be useful if someone implements a bigfloat type as mpz_t * 2^e
(as opposed to mpz_t * 2^(64*e)).
Someone motivated and with the proper FSF assignment would need to write
the code+tests+doc...
--
Marc Glisse
More information about the gmp-discuss
mailing list