AKS test for primes: Difference between revisions

Content deleted Content added
Walterpachl (talk | contribs)
m →‎{{header|REXX}}: fix 'accounting' problem (courtesy GS)
Added zkl
Line 1,102: Line 1,102:
primes under 35: 2,3,5,7,11,13,17,19,23,29,31
primes under 35: 2,3,5,7,11,13,17,19,23,29,31
primes under 50: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
primes under 50: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
</pre>

=={{header|zkl}}==
{{trans|Python}}
<lang zkl>var BN=Import("zklBigNum");
fcn expand_x_1(p){
ex := L(BN(1));
foreach i in (p){ ex.append(ex[-1] * -(p-i) / (i+1)) }
return(ex.reverse())
}
fcn aks_test(p){
if (p < 2) return(False);
ex := expand_x_1(p);
ex[0] = ex[0] + 1;
return(not ex[0,-1].filter('%.fp1(p)));
}
println("# p: (x-1)^p for small p");
foreach p in (12){
println("%3d: ".fmt(p),expand_x_1(p).enumerate()
.pump(String,fcn([(n,e)]){"%+d%s ".fmt(e,n and "x^%d".fmt(n) or "")}));
}
println("\n# small primes using the aks test");
println([0..110].filter(aks_test).toString(*));</lang>
{{out}}
<pre>
# p: (x-1)^p for small p
0: +1
1: -1 +1x^1
2: +1 -2x^1 +1x^2
3: -1 +3x^1 -3x^2 +1x^3
4: +1 -4x^1 +6x^2 -4x^3 +1x^4
5: -1 +5x^1 -10x^2 +10x^3 -5x^4 +1x^5
6: +1 -6x^1 +15x^2 -20x^3 +15x^4 -6x^5 +1x^6
7: -1 +7x^1 -21x^2 +35x^3 -35x^4 +21x^5 -7x^6 +1x^7
8: +1 -8x^1 +28x^2 -56x^3 +70x^4 -56x^5 +28x^6 -8x^7 +1x^8
9: -1 +9x^1 -36x^2 +84x^3 -126x^4 +126x^5 -84x^6 +36x^7 -9x^8 +1x^9
10: +1 -10x^1 +45x^2 -120x^3 +210x^4 -252x^5 +210x^6 -120x^7 +45x^8 -10x^9 +1x^10
11: -1 +11x^1 -55x^2 +165x^3 -330x^4 +462x^5 -462x^6 +330x^7 -165x^8 +55x^9 -11x^10 +1x^11

# small primes using the aks test
L(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109)
</pre>
</pre>