3
$\begingroup$

I recently became aware that PARI/GP may be useful for high-precision calculations. Has anyone had experience with this software; if so, I would be grateful if you might provide me a couple of simple examples of its code so that I may get started. I have no colleages who can help me. I would like to practice at first some simple things like computing $log_{2}k$ (large $k$) accurate to many $k$ digits and then use this in further computation. Also, can PARI/GP convert the calculation to binary with the same accuracy as it computes, say $log_{2}n$? Any guidance is appreciated.

$\endgroup$
3
$\begingroup$

Real logarithm can calculate any CAS. But pari/gp can smallest discrete logarithm by modulo. Example:

? n=2^77+7
%1 = 151115727451828646838279
?
? m=Mod(2,n)
%2 = Mod(2, 151115727451828646838279)
?
? h=znorder(m)
%3 = 96869056058864517204
?
? z=znlog(89,m,h)
%4 = 52540840786720769887
?
? m^z
%5 = Mod(89, 151115727451828646838279)
?
? m^(z+h)
%6 = Mod(89, 151115727451828646838279)
?
? m^(z+2*h)
%7 = Mod(89, 151115727451828646838279)
?
? m^(z+3*h)
%8 = Mod(89, 151115727451828646838279)
?
? m^(z+33*h)
%9 = Mod(89, 151115727451828646838279)
?
? m^(z+100*h)
%10 = Mod(89, 151115727451828646838279)

Convert to binary:

? n=2^77+7
%11 = 151115727451828646838279
?
? binary(n)
%12 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]

Setup 4th bit (5th, if counting from zero-bit):

? n2=bitor(n,2^4)
%13 = 151115727451828646838295
?
? binary(n2)
%14 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1]

Setdown second bit:

? n3=bitnegimply(n2,2^2)
%15 = 151115727451828646838291
?
? binary(n3)
%16 = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1]

Count of bits:

? vecsum(binary(n3))
%17 = 4
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.