Bill Allombert on Wed, 29 Nov 2017 19:00:05 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Segmentation Fault in PARI library related to factoru_pow()


On Wed, Nov 29, 2017 at 12:22:57PM -0500, Max Alekseyev wrote:
> Bill, thank you for clarification!
> I wonder though about the general idea behind using vectors vs small
> vectors. Say, why factoru_pow() returns 3-component vector while its
> components are small vectors? Why not using just small vectors (or just
> vectors) here?

t_VECs are vectors of arbitrary GENs.
t_VECSMALLs are much more compact and efficient than t_VEC but they can
only handle small integers, and not arbitrary GENs.

So it is not possible for a t_VECSMALL to have other t_VECSMALL as
components, but a t_VEC can.

Since factoru_pow deals with small integers, all the part of the
factorisation will be small integers, so we can store them in
t_VECSMALLs. However to return the result as a single object,
we create a single t_VEC with 3 components whose components are
t_VECSMALL.

Of course we could have made factoru_pow to look like this:

void factoru_pow(ulong n, GEN *P, GEN *E, GEN *PE)
and set each of *P, *E, *PE to a t_VECSMALL instead

but then it would have been harder to pass the result to other
functions.

Cheers,
Bill.