Thanks,
I had to apt install pari-gp2c first.
Yes, "-G" option outputs rewritten GP, but unlikely useful as a code
formatter.
I tried the last GP script I worked with from this new repo:
https://github.com/Hermann-SW/Colbert_numbers/tree/main#readme
I executed gp2c with "-G":
hermann@7600x:~/Colbert_numbers$ gp2c -G validate.gp -o out
hermann@7600x:~/Colbert_numbers$
This is original 9 line GP script:
hermann@7600x:~/Colbert_numbers$ cat validate.gp
\r Colbert.py
assert(b) = { if(!(b), error("assertion failed")); }
print("6 entries of the form [k,n,s,x,y], with p=k*2^n+1, s^2%p==p-1 and
p==x^2+y^2");
foreach(C,v,p=v[1]*2^v[2]+1;\
printf("%18s (%d-digit
prime)\n",Str(v[1],"*2^",v[2],"+1"),#digits(p));\
assert(v[3]^2%p==p-1);\
assert(v[4]^2+v[5]^2==p);\
);
print("done, all asserts OK");
hermann@7600x:~/Colbert_numbers$
gp2c reads in the full 35MB(!) file Colbert.py with t_VEC of t-VEC C and
makes it 1st line of output. I will skip that line here for obvious
reasons:
hermann@7600x:~/Colbert_numbers$ tail -n+2 out ; echo
assert(b)=
{
if(!b,error("assertion failed"))
}
print("6 entries of the form [k,n,s,x,y], with p=k*2^n+1, s^2%p==p-1 and
p==x^2+y^2"); \
foreach(C,v,p=(v[1]*(2^v[2]))+1; \
printf("%18s (%d-digit
prime)\n",Str(v[1],"*2^",v[2],"+1"),length(digits(p))); \
assert(((v[3]^2)%p)==(p-1)); \
assert(((v[4]^2)+(v[5]^2))==p)); \
print("done, all asserts OK")
hermann@7600x:~/Colbert_numbers$
So gp2c -G expands assert 1-line function to 4 lines.
But also removes all indentation that should help to understand.
It adds a space between ";\", so a bit of formatting.
But gp2c -G has a small bug as well:
It removes final semicolon in assert implementation, which results in
showing function definition where it should not when executed. But the
remainder of the output is OK:
hermann@7600x:~/Colbert_numbers$ gp -q < out
(b)->if(!b,error("assertion failed"))
6 entries of the form [k,n,s,x,y], with p=k*2^n+1, s^2%p==p-1 and
p==x^2+y^2
5359*2^5054502+1 (1521561-digit prime)
33661*2^7031232+1 (2116617-digit prime)
28433*2^7830457+1 (2357207-digit prime)
27653*2^9167433+1 (2759677-digit prime)
19249*2^13018586+1 (3918990-digit prime)
10223*2^31172165+1 (9383761-digit prime)
done, all asserts OK
hermann@7600x:~/Colbert_numbers$
Regards,
Hermann.
On 2023-08-19 22:18, Charles Greathouse wrote:
> I think gp2c has an option -G to output GP, which would presumably
> handle formatting. I’m not aware of a GP linter.
>
> On Sat, Aug 19, 2023 at 1:05 PM <[email protected]> wrote:
>
>> I am working with PARI/GP scripts a lot, sometimes because they are
>> even
>> faster than C++ with libgmpxx ("halfgcd()" vs. "halfgcdii()"),
>> mostly
>> because everything can be done very compact and fast, and because
>> PariDroid is with me on sartphone on hikes with dog.
>>
>> For C++ I use cpplint and cppcheck for linting, and they provide
>> warnings about missing spaces, ... which I modify source manually
>> until
>> clean.
>>
>> For Python I use "pylint", and "black" for formatting (cool
>> software).
>>
>> I really would like to lint or format PARI/GP scripts, but
>> understand if
>> those are not available.
>>
>> Regards,
>>
>> Hermann.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.