Bill Allombert on Wed, 21 Jun 2023 13:42:21 +0200


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

Re: How to compute "Mod(2^(n+1), n)" for very big n?


On Wed, Jun 21, 2023 at 01:02:48PM +0200, hermann@stamm-wilbrandt.de wrote:
> Pari userguide states that integers must be in absolute value less than
> 2^536870815 on 64bit systems.
> 
> My n has only 79 decimal digits, but I assume the following error is because
> of said integer size restriction:
> 
> ? #digits(n)
> %152 = 79
> ? Mod(2^(n+1),n)
>   ***   at top-level: Mod(2^(n+1),n)
>   ***                      ^---------
>   *** _^_: overflow in lg().
>   ***   Break loop: type 'break' to go back to GP prompt
> break>
> 
> So it seems "Mod()" computes LHS value first before applying RHS modulo.
> Is that true?

Mod is not a modulo operation, it is a constructor for the ring Z/nZ.
(hence the capital M).
So if you want to compute in Z/nZ, map 2 to Z/nZ with Mod(2,n) and then 
apply ^(n+1)

Mod(2,n)^(n+1)

Cheers,
Bill