Advertisement
apexsquirt

[PHP-CLI] Riemann zeta function zeroes "test" in ℍ

Jul 30th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2. //not really efficient but it does the job relatively well enough lol
  3. function conj($q) { return [$q[0],-$q[1],-$q[2],-$q[3]]; }
  4. function mul($q1,$q2) { return [$q1[0]*$q2[0]-$q1[1]*$q2[1]-$q1[2]*$q2[2]-$q1[3]*$q2[3],
  5.                                 $q1[1]*$q2[0]+$q1[0]*$q2[1]-$q1[3]*$q2[2]+$q1[2]*$q2[3],
  6.                                 $q1[2]*$q2[0]+$q1[3]*$q2[1]+$q1[0]*$q2[2]-$q1[1]*$q2[3],
  7.                                 $q1[3]*$q2[0]-$q1[2]*$q2[1]+$q1[1]*$q2[2]+$q1[0]*$q2[3]]; }
  8. function add($q1,$q2) { return [$q1[0]+$q2[0],$q1[1]+$q2[1],$q1[2]+$q2[2],$q1[3]+$q2[3]]; }
  9. function opp($q) { return [-$q[0],-$q[1],-$q[2],-$q[3]]; }
  10. function norm($q) { return sqrt(pow($q[0],2)+pow($q[1],2)+pow($q[2],2)+pow($q[3],2)); }
  11. function a($q) { return mul([1/(norm($q)**2),0,0,0],conj($q)); }
  12. function b($q) { return [0,$q[1],$q[2],$q[3]]; }
  13. function c($q) { if (b($q) != [0,0,0,0]) {
  14.                         return mul(
  15.                             [exp($q[0]),0,0,0],
  16.                             add (
  17.                                 [cos(norm(b($q))),0,0,0],
  18.                                 opp (
  19.                                         mul([sin(norm(b($q)))/norm(b($q)),0,0,0],b($q))
  20.                                     )
  21.                                 )
  22.                         ); } else {
  23.                             return [exp($q[0]),0,0,0];
  24.                         }
  25.                 }
  26. function zeta($q,$up) {
  27.     $eta = 0;
  28.     for ($i = 1; $i <= $up; $i++) {
  29.         if ($i % 2 == 1) { $eta = add($eta,(c(mul($q,[-log($i),0,0,0])))); }
  30.         if ($i % 2 == 0) { $eta = add($eta,opp((c(mul($q,[-log($i),0,0,0]))))); }
  31.     }
  32.     return  mul(
  33.                 a(add(
  34.                       [1,0,0,0],
  35.                       opp(c(add(
  36.                                 [log(2),0,0,0],
  37.                                 opp(mul(
  38.                                         $q,
  39.                                         [log(2),0,0,0]
  40.                                 ))
  41.                       )))
  42.                  )),
  43.                 $eta
  44.             );
  45. }
  46. function show($q) { return $q[0]."+".$q[1]."i+".$q[2]."j+".$q[3]."k"; }
  47. print "This program computes random instances of Z(a+bi+cj+dk) and gives potential zeroes approximations\n";
  48. print "Please use a precision sufficiently larger than 0.0000000001 for best accuracy\n";
  49. $scal = readline("Precision (smallest decimal k s.t. a/k, b/k, c/k, d/k are integers) : ");
  50. $up = readline("Zeta sum upper bound (the larger the better) : ");
  51. $maxa = readline("0  < a <= ");
  52. $maxb = readline("0 <= b <= ");
  53. $maxc = readline("0 <= c <= ");
  54. $maxd = readline("0 <= d <= ");
  55. $bruh = [];
  56. while (0 < 1) {
  57.     $p = [rand(1,$maxa/$scal)*$scal,rand(0,$maxb/$scal)*$scal,rand(0,$maxc/$scal)*$scal,rand(0,$maxd/$scal)*$scal];
  58.     $q = norm(zeta($p,$up));
  59.     if ($q < $scal*ceil(0.0000000001/$scal) & !in_array($p,$bruh)) { print "Z(".show($p).") = $q                \n"; $bruh[count($bruh)] = $p; }
  60.     else { print "Z(".show($p).") = $q                \r"; }
  61. }
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement