Bill Allombert on Fri, 06 Oct 2023 19:39:01 +0200


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

Re: "my(...)" scoping question


On Fri, Oct 06, 2023 at 07:14:33PM +0200, hermann@stamm-wilbrandt.de wrote:
> Running this GP script
> https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/pari/all_rsa.foursquare.gp
> 
> all is fine:
> 
> $ gp -q < all_rsa.foursquare.gp
> ...
> 2048 [28, 158197984288196117699097355897947500264458455190848222964138664214873348733353898043756194523483689509093385743402168573089458743256253901017830264069606012704497883085623209455523704906878923700142603965513457096959088734082854043425944788477935555382589380809038501009740812793032665236884977009980514922487, 13011773238477059231321994244187743729468594581843753487082884034603212622185946597112257777907861613001484624197063577339843512098442794834693496703933881475402708427339094714589624392731377779402228770755581888942318831433232790010161732825667949844267841944332119616646371761146340753071052451512068626398,
> 0]~
>   ***   last result computed in 3,373 ms.
> all asserts OK
> hermann@7600x:~/RSA_numbers_factored/pari$
> 
> 
> 
> I added "if(n%8!=7,assert(F[4]==0));" as last line into main "{ ... }"
> block (to prove that really sum of 3 squares got computed):
> 
> {
>   foreach(rsa,r,[l,n]=r;
>     my(F=foursquarep(n));
>     print(l," ",F);
>     assert(vecsum([x^2|x<-F])==n));
>     if(n%8!=7,assert(F[4]==0));
> }
> 
> Although output for RSA-2048 as well as vecsum assert are good, the
> following assert "thinks" F is a t_POL:

Your code is misindented, the 'if' should be at the level of the 'foreach'.

The scope of my() end with the innermost closure that contains the my().
What exactly is a closure in this definition is a bit more difficult to explain.
Here there are four closures:
- the whole block of code
- the third argument of "foreach "
- The [x^2| block
- the second argument of "if".

So the scope end with foreach.

Cheers,
Bill.