* include_once 'Math/Fibonacci.php'; * * $idx = 20; * echo "Calculate F($idx), fast equation = "; * $fib =& Math_Fibonacci::term($idx); * echo $fib->toString()."\n"; * // Calculate F(20), fast equation = 6765 * * $idx = 55; * echo "Calculate F($idx), lookup table = "; * $fib =& Math_Fibonacci::term($idx); * echo $fib->toString()."\n"; * // Calculate F(55), lookup table = 139583862445 * * $idx = 502; * echo "Calculate F($idx), addition loop = "; * $fib = Math_Fibonacci::term($idx); * echo $fib->toString()."\n"; * // Calculate F(502), addition loop = 365014740723634211012237077906479355996081581501455497852747829366800199361550174096573645929019489792751 * * echo "\nSeries from F(0) to F(10):\n"; * $series = Math_Fibonacci::series(10); * foreach ($series as $n=>$fib) { * echo "n = $n, F(n) = ".$fib->toString()."\n"; * } * // Series from F(0) to F(10): * // n = 0, F(n) = 0 * // n = 1, F(n) = 1 * // n = 2, F(n) = 1 * // n = 3, F(n) = 2 * // n = 4, F(n) = 3 * // n = 5, F(n) = 5 * // n = 6, F(n) = 8 * // n = 7, F(n) = 13 * // n = 8, F(n) = 21 * // n = 9, F(n) = 34 * // n = 10, F(n) = 55 * * echo "\nand now from F(11) to F(19):\n"; * $series = Math_Fibonacci::series(11, 19); * foreach ($series as $n=>$fib) { * echo "n = $n, F(n) = ".$fib->toString()."\n"; * } * // and now from F(11) to F(19): * // n = 11, F(n) = 89 * // n = 12, F(n) = 144 * // n = 13, F(n) = 233 * // n = 14, F(n) = 377 * // n = 15, F(n) = 610 * // n = 16, F(n) = 987 * // n = 17, F(n) = 1597 * // n = 18, F(n) = 2584 * // n = 19, F(n) = 4181 * * echo "\nChecking if 26 and 4181 are Fibonacci numbers\n"; * $verb = Math_Fibonacci::isFibonacci(new Math_Integer(26)) ? 'is' : 'is not'; * echo "26 $verb a Fibonacci number\n"; * // 26 is not a Fibonacci number * $verb = Math_Fibonacci::isFibonacci(new Math_Integer(4181)) ? 'is' : 'is not'; * echo "4181 $verb a Fibonacci number\n"; * // 4181 is a Fibonacci number * * echo "\nDecompose 34512\n"; * $decarr = Math_Fibonacci::decompose(new Math_Integer(34512)); * foreach ($decarr as $fib) { * $index = Math_Fibonacci::getIndexOf($fib); * echo "F(".$index->toString().") = ".$fib->toString()."\n"; * } * // Decompose 34512 * // F(23) = 28657 * // F(19) = 4181 * // F(17) = 1597 * // F(10) = 55 * // F(8) = 21 * // F(2) = 1 * * echo "\nF(n) closest to 314156 is: "; * $fib = Math_Fibonacci::closestTo(new Math_Integer(314156)); * echo $fib->toString()."\n\n"; * // F(n) closest to 314156 is: 317811 * * echo 'The index for 1597 is : '; * $idx = Math_Fibonacci::getIndexOf(new Math_Integer(1597)); * echo $idx->toString()."\n\n"; * // The index for 1597 is : 17 * * $bigint = '3141579834521345220291'; * echo "Finding the Fibonacci numbers that add up to $bigint\n"; * $series = Math_Fibonacci::decompose(new Math_Integer($bigint)); * foreach ($series as $fib) { * $index = Math_Fibonacci::getIndexOf($fib); * echo "F(".$index->toString().") = ".$fib->toString()."\n"; * } * // Finding the Fibonacci numbers that add up to 3141579834521345220291 * // F(104) = 2427893228399975082453 * // F(101) = 573147844013817084101 * // F(98) = 135301852344706746049 * // F(91) = 4660046610375530309 * // F(86) = 420196140727489673 * // F(83) = 99194853094755497 * // F(81) = 37889062373143906 * // F(79) = 14472334024676221 * // F(76) = 3416454622906707 * // F(74) = 1304969544928657 * // F(71) = 308061521170129 * // F(68) = 72723460248141 * // F(63) = 6557470319842 * // F(60) = 1548008755920 * // F(57) = 365435296162 * // F(53) = 53316291173 * // F(51) = 20365011074 * // F(49) = 7778742049 * // F(44) = 701408733 * // F(37) = 24157817 * // F(31) = 1346269 * // F(26) = 121393 * // F(20) = 6765 * // F(16) = 987 * // F(13) = 233 * // F(8) = 21 * // F(6) = 8 * // F(3) = 2 * *