#!/usr/bin/php = 1); $res = $bicomplex; for ($p=2; $p<=$n; $p++) $res = bicomplex_mul($res, $bicomplex); return $res; } function bicomplex_is_immortal($bicomplex, $power) { $bicomplexpow = bicomplex_int_power($bicomplex, $power); for ($i=0; $i<4; $i++) { $x1 = bcabs($bicomplex[$i]); $x2 = bcabs($bicomplexpow[$i]); if (substr($x2, -strlen($x1)) != $x1) return false; } return $bicomplexpow; } function _go($a, $b, $c, $d, $power, $distance, &$progr, &$found) { $bicomplex = [$a, $b, $c, $d]; $bicomplexpower = bicomplex_is_immortal($bicomplex, $power); if ($bicomplexpower !== false) { $a_ = $bicomplexpower[0]; $b_ = $bicomplexpower[1]; $c_ = $bicomplexpower[2]; $d_ = $bicomplexpower[3]; // Z=z1+jz1 z1=a+bi z2=cj+dij=cj+dk (k=ij) if (($c!=0) || ($d!=0)) { // BICP z1 + jz2 with z2=...+...i and z1=...+...i $str = "BICP "; } else if ($b!=0) { // CPLX z1 + jz2 with z2=0+0i and z1=...+...i $str = "CPLX "; } else { // REAL z1 + jz2 with z2=0+0i and z1=...+0i $str = "REAL "; } $str .= "| Distance=$distance | "; $str .= "[$a + $b i + $c j + $d k] ^ $power = [$a_ + $b_ i + $c_ j + $d_ k]"; # if (!in_array($str,$found)) { # echo "$str\n"; # $found[] = $str; file_put_contents('/tmp/daniel_immortal_bicomplex', "$str\n", FILE_APPEND); $found++; # } } #if ($progr++ % 10000 == 0) { # echo "(Dist=$distance) Processing ($a, $b, $c, $d) with power $power \r"; #} } if (file_exists(__DIR__.'/savestate.txt')) { $start_distance = trim(file_get_contents(__DIR__.'/savestate.txt')); } else { $start_distance = 0; } for ($distance=$start_distance; $distance<=MAX_DISTANCE; $distance++) { $str = "--------- Distance: $distance ---------"; echo " \r"; echo "$str\n"; $found = 0; $progr = 0; if (file_exists("/tmp/daniel_immortal_bicomplex")) system("rm /tmp/daniel_immortal_bicomplex"); $a = $distance; for ($b=0; $b<=$distance; $b++) { for ($c=0; $c<=$distance; $c++) { for ($d=0; $d<=$distance; $d++) { if ($d == 0) echo "\r".round(memory_get_usage()/1024/1024, 2)." MiB ($found found); ($a), $b, $c, $d "; for ($power=2; $power<=MAX_POWER; $power++) { _go($a, $b, $c, $d, $power, $distance, $progr, $found); _go($b, $a, $c, $d, $power, $distance, $progr, $found); _go($b, $c, $a, $d, $power, $distance, $progr, $found); _go($b, $c, $d, $a, $power, $distance, $progr, $found); } } } } # file_put_contents(__DIR__.'/result.txt', "$str\n", FILE_APPEND); # chdir(__DIR__); # system("cat /tmp/daniel_immortal_bicomplex | sort | uniq >> result.txt"); # system("rm /tmp/daniel_immortal_bicomplex"); system("mv /tmp/daniel_immortal_bicomplex result_distance{$distance}_maxpower".MAX_POWER.".txt"); system("sort -us -o result_distance{$distance}_maxpower".MAX_POWER."_unique.txt result_distance{$distance}_maxpower".MAX_POWER.".txt"); file_put_contents(__DIR__.'/savestate.txt', $distance+1); }