private static function iBetaCF(int $m, $x, $a, $b)
{
$limits = ['x' => '[0, 1]', 'a' => '(1,∞)', 'b' => '(1,∞)'];
Support::checkLimits($limits, ['x' => $x, 'a' => $a, 'b' => $b]);
$beta = self::beta($a, $b);
$constant = $x ** $a * (1 - $x) ** $b / $beta;
for ($i = 0; $i < $m; $i++) {
if ($i == 0) {
$α = 1;
} else {
$α = ($a + $i - 1) * ($a + $b + $i - 1) * $i * ($b - $i) * $x ** 2 / ($a + 2 * $i - 1) ** 2;
}
$β₁ = $i + $i * ($b - $i) * $x / ($a + 2 * $i - 1);
$β₂ = ($a + $i) * ($a - ($a + $b) * $x + 1 + $i * (2 - $x)) / ($a + 2 * $i + 1);
$β = $β₁ + $β₂;
$α_array[] = $α;
$β_array[] = $β;
}
for ($i = $m - 1; $i >= 0; $i--) {
if ($i == $m - 1) {
$fraction_array[$i] = $α_array[$i] / $β_array[$i];
} else {
$fraction_array[$i] = $α_array[$i] / ($β_array[$i] + $fraction_array[$i + 1]);
}
}
return $constant * $fraction_array[0];
}