Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $counter = 1;
- ini_set("precision",13);
- $maxsteps = 0;
- $str = file_get_contents(".log");
- got_back:
- $array = [3, //a in a/2^k x + b/2^k >= 0
- 1, //k's max value
- 1, //b lol
- 1]; //x's min value
- print "Randomized test #$counter\n";
- $str .= "#$counter : ";
- for ($i = 1; $i > 0; $i++) {
- $temp = [3*$array[0]/(2**$array[1]),
- min(rand(1,intval(log(3*$array[0])/log(2))),intval(log(3*$array[0])/log(2))),
- 3*$array[2]/(2**$array[1]),
- ceil(max($array[3],(3*$array[2]+1)/(2**(intval(log(3*$array[0])/log(2))+1)-3*$array[0])))];
- $temp[3] = ceil($temp[3]);
- print "Step $i : (".round($temp[0],5)."a_0+".round($temp[2],5).")/2^k>=a_0 iff k<=".round(intval(log(3*$array[0])/log(2)),5)." when a_0>=".round($temp[3],5).". ";
- $fullcounter++;
- print "We'll choose k=".round($temp[1],3);
- $minmax = max($minmax,$temp[3]);
- $avgxmin += $temp[3];
- $maxk = max($maxk,round(intval(log(3*$array[0])/log(2)),5));
- $avgkmax += round(intval(log(3*$array[0])/log(2)),5);
- $array = $temp;
- if ($temp[1] <= 0) {
- print "...\nOh wait, we had k>0. Contradiction !\n\n";
- $maxsteps = max($maxsteps,$i);
- $avgsteps += $i;
- print "(Average nĀ° of steps : ".($avgsteps/$counter).", average minimal value of a_0 required in a step : ".($avgxmin/$counter).", average max k : ".($avgkmax/$counter).")\n\n\n\n";
- $str .= "Average nĀ° of steps : ".($avgsteps/$counter).", average minimal value of a_0 required in a step : ".($avgxmin/$fullcounter).", average max k : ".($avgkmax/$fullcounter)."\n";
- if ($counter % 100 == 0) { file_put_contents(".log",$str); }
- $counter++;
- goto got_back;
- }
- print "\n";
- }
- goto got_back;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement