tony . reix on Thu, 09 Mar 2023 16:28:45 +0100


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

Be able to use sqrt(2) as I (square root of -1)


‌Hi,

Pari/gp knows that I^2=-1 and thus each time I^2 appears in a computation, it is replaced by -1 .
I'd like to have the same behavior for sqrt(2): a name like R2 such that whenever a computation involves R2^2, it replaces it by 2.

I'm running a suite Vn that involves very big numbers which are a product of sqrt(2) when n is odd, and a true integer when n is even.
sqrt(2) is used as a symbolic value, which vanishes from time to time from Vn, and I do modulo computation, with Vn when n is even, or when Vn/sqrt(2) when n is odd.

For now, I'm using: lift(Mod(floor(v1/sqrt(2)),w))  . That's OK up to a big value of Vn (n < 101), till floor() says:
      floor: precision too low in truncr (precision loss in truncation).

Morever, I'm not sure that the results are correct after some dozens of iterations.

Example:
w=679;
v0=2; v1=2*sqrt(2);
for(i=1,n,
           v0=2*sqrt(2)*v1-v0;
           v1=2*sqrt(2)*v0-v1;
           printf("V%3d:  %3d   V%3d: %3d\n", 2*i,
                                              lift(Mod(floor(v0),w)),
                                              2*i+1,
                                              lift(Mod(floor(v1/sqrt(2)),w))
           )
)

.....

V100:   67   V101: 116
  ***   at top-level: ...%3d: %3d\n",2*i,lift(Mod(floor(v0),w)),2*i+1,l
  ***                                             ^---------------------
  *** floor: precision too low in truncr (precision loss in truncation).
  ***   Break loop: type 'break' to go back to GP prompt


I've tried to find a solution in the documentation of Pari/gp. I failed.

I tried to do something like the following, and I see that Mod() is able to do interesting stuff:
? B=5+3*A
%113 = 3*A + 5
? B2=B^2
%114 = 9*A^2 + 30*A + 25
? Mod(B2,7)
%115 = Mod(2, 7)*A^2 + Mod(2, 7)*A + Mod(4, 7)

But I don't know how to go further. Is there some function for parsing this polynome and translate A^2 in 2 when it appears ?

Do you have a solution ?

Thx

Tony