hermann on Sat, 30 Sep 2023 02:20:55 +0200


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

Re: Manually transpile Python code to GP: what about class / __name__ ?


On 2023-09-09 16:04, hermann@stamm-wilbrandt.de wrote:
...
I have this at end of RSA_numbers_factored.py:

if __name__ == "__main__":
    RSA().validate()

It executes member function validate only when called "python
RSA_numbers_factored.py".
It does not call validate() when being imported.

Is a similar mechanism and/or trick available for GP?

I found a way to simulate that Python mechanism.

At the very end of RSA_numbers_factored.gp:
...
{
    if (getenv("validate"),
        gettime();
        RSA.validate(getenv("doprint"));
        write("/dev/stderr",gettime(),"ms"));
}

Now if starting gp with "importing" the library for working with it,
$ gp -q RSA_numbers_factored.gp

or
? readvec("RSA_numbers_factored.gp");

no validation will be done.


The equivalent of "python RSA_numbers_factored.py" that executes
validation because of __name__ == "__main__" is this:

$ validate=1 gp -q < RSA_numbers_factored.gp
3598ms
$ validate=1 doprint=1 gp -q < RSA_numbers_factored.gp

with p-1 and q-1 factorizations (n=p*q): 25
59 digits, 79 digits,100 digits,110 digits,120 digits,129 digits,130 digits, 140 digits,150 digits,155 digits,160 digits,170 digits,576 bits ,180 digits, 190 digits,640 bits ,200 digits,210 digits,704 bits ,220 digits,230 digits,
232 digits,768 bits  ,240 digits,250 digits,

without (p-1) and (q-1) factorizations, but p and q: 0

have not been factored sofar: 31
260 digits,270 digits,896 bits ,280 digits,290 digits,300 digits,309 digits, 1024 bits ,310 digits,320 digits,330 digits,340 digits,350 digits,360 digits, 370 digits,380 digits,390 digits,400 digits,410 digits,420 digits,430 digits, 440 digits,450 digits,460 digits,1536 bits ,470 digits,480 digits,490 digits,
500 digits,617 digits,2048 bits  (=617 digits)

3566ms
$


Regards,

Hermann.