Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, B

Percentage Accurate: 96.7% → 96.7%
Time: 3.8s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
double code(double x, double y, double z, double t, double a, double b) {
	return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = x * exp(((y * (log(z) - t)) + (a * (log((1.0d0 - z)) - b))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return x * Math.exp(((y * (Math.log(z) - t)) + (a * (Math.log((1.0 - z)) - b))));
}
def code(x, y, z, t, a, b):
	return x * math.exp(((y * (math.log(z) - t)) + (a * (math.log((1.0 - z)) - b))))
function code(x, y, z, t, a, b)
	return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b)))))
end
function tmp = code(x, y, z, t, a, b)
	tmp = x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 96.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
double code(double x, double y, double z, double t, double a, double b) {
	return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = x * exp(((y * (log(z) - t)) + (a * (log((1.0d0 - z)) - b))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return x * Math.exp(((y * (Math.log(z) - t)) + (a * (Math.log((1.0 - z)) - b))));
}
def code(x, y, z, t, a, b):
	return x * math.exp(((y * (math.log(z) - t)) + (a * (math.log((1.0 - z)) - b))))
function code(x, y, z, t, a, b)
	return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b)))))
end
function tmp = code(x, y, z, t, a, b)
	tmp = x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\end{array}

Alternative 1: 96.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))
double code(double x, double y, double z, double t, double a, double b) {
	return x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = x * exp(((y * (log(z) - t)) + (a * (log((1.0d0 - z)) - b))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return x * Math.exp(((y * (Math.log(z) - t)) + (a * (Math.log((1.0 - z)) - b))));
}
def code(x, y, z, t, a, b):
	return x * math.exp(((y * (math.log(z) - t)) + (a * (math.log((1.0 - z)) - b))))
function code(x, y, z, t, a, b)
	return Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + Float64(a * Float64(log(Float64(1.0 - z)) - b)))))
end
function tmp = code(x, y, z, t, a, b)
	tmp = x * exp(((y * (log(z) - t)) + (a * (log((1.0 - z)) - b))));
end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}
\end{array}
Derivation
  1. Initial program 96.1%

    \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 54.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - z\right)\\ t_2 := a \cdot \left(t\_1 - b\right)\\ t_3 := x \cdot e^{y \cdot \left(\log z - t\right) + t\_2}\\ \mathbf{if}\;t\_3 \leq -2 \cdot 10^{+59}:\\ \;\;\;\;x \cdot t\_2\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+168}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;e^{t\_2}\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (log (- 1.0 z)))
        (t_2 (* a (- t_1 b)))
        (t_3 (* x (exp (+ (* y (- (log z) t)) t_2)))))
   (if (<= t_3 -2e+59) (* x t_2) (if (<= t_3 5e+168) t_1 (exp t_2)))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double t_3 = x * exp(((y * (log(z) - t)) + t_2));
	double tmp;
	if (t_3 <= -2e+59) {
		tmp = x * t_2;
	} else if (t_3 <= 5e+168) {
		tmp = t_1;
	} else {
		tmp = exp(t_2);
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_1 = log((1.0d0 - z))
    t_2 = a * (t_1 - b)
    t_3 = x * exp(((y * (log(z) - t)) + t_2))
    if (t_3 <= (-2d+59)) then
        tmp = x * t_2
    else if (t_3 <= 5d+168) then
        tmp = t_1
    else
        tmp = exp(t_2)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = Math.log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double t_3 = x * Math.exp(((y * (Math.log(z) - t)) + t_2));
	double tmp;
	if (t_3 <= -2e+59) {
		tmp = x * t_2;
	} else if (t_3 <= 5e+168) {
		tmp = t_1;
	} else {
		tmp = Math.exp(t_2);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = math.log((1.0 - z))
	t_2 = a * (t_1 - b)
	t_3 = x * math.exp(((y * (math.log(z) - t)) + t_2))
	tmp = 0
	if t_3 <= -2e+59:
		tmp = x * t_2
	elif t_3 <= 5e+168:
		tmp = t_1
	else:
		tmp = math.exp(t_2)
	return tmp
function code(x, y, z, t, a, b)
	t_1 = log(Float64(1.0 - z))
	t_2 = Float64(a * Float64(t_1 - b))
	t_3 = Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + t_2)))
	tmp = 0.0
	if (t_3 <= -2e+59)
		tmp = Float64(x * t_2);
	elseif (t_3 <= 5e+168)
		tmp = t_1;
	else
		tmp = exp(t_2);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = log((1.0 - z));
	t_2 = a * (t_1 - b);
	t_3 = x * exp(((y * (log(z) - t)) + t_2));
	tmp = 0.0;
	if (t_3 <= -2e+59)
		tmp = x * t_2;
	elseif (t_3 <= 5e+168)
		tmp = t_1;
	else
		tmp = exp(t_2);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(a * N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -2e+59], N[(x * t$95$2), $MachinePrecision], If[LessEqual[t$95$3, 5e+168], t$95$1, N[Exp[t$95$2], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - z\right)\\
t_2 := a \cdot \left(t\_1 - b\right)\\
t_3 := x \cdot e^{y \cdot \left(\log z - t\right) + t\_2}\\
\mathbf{if}\;t\_3 \leq -2 \cdot 10^{+59}:\\
\;\;\;\;x \cdot t\_2\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+168}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;e^{t\_2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))))) < -1.99999999999999994e59

    1. Initial program 100.0%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto x \cdot \color{blue}{e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites21.6%

      \[\leadsto x \cdot \color{blue}{\left(a \cdot \left(\log \left(1 - z\right) - b\right)\right)} \]

    if -1.99999999999999994e59 < (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))))) < 4.99999999999999967e168

    1. Initial program 96.8%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right) + y \cdot \left(\frac{1}{6} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{3}\right)\right)\right) + \frac{1}{2} \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right)\right)} \]
    4. Applied rewrites67.8%

      \[\leadsto \color{blue}{\log \left(1 - z\right)} \]

    if 4.99999999999999967e168 < (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b)))))

    1. Initial program 90.1%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites90.1%

      \[\leadsto \color{blue}{e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    5. Taylor expanded in y around 0

      \[\leadsto e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    6. Applied rewrites49.4%

      \[\leadsto e^{a \cdot \left(\log \left(1 - z\right) - b\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    7. Taylor expanded in y around 0

      \[\leadsto e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    8. Applied rewrites31.3%

      \[\leadsto e^{\log z - t} \]
    9. Taylor expanded in y around -inf

      \[\leadsto e^{-1 \cdot \left(y \cdot \left(-1 \cdot \left(\log z - t\right) + -1 \cdot \frac{a \cdot \left(\log \left(1 - z\right) - b\right)}{y}\right)\right)} \]
    10. Applied rewrites49.4%

      \[\leadsto e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 65.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := a \cdot \left(\log \left(1 - z\right) - b\right)\\ t_2 := e^{y \cdot \left(\log z - t\right) + t\_1}\\ \mathbf{if}\;x \cdot t\_2 \leq -5 \cdot 10^{-274}:\\ \;\;\;\;x \cdot t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* a (- (log (- 1.0 z)) b)))
        (t_2 (exp (+ (* y (- (log z) t)) t_1))))
   (if (<= (* x t_2) -5e-274) (* x t_1) t_2)))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = a * (log((1.0 - z)) - b);
	double t_2 = exp(((y * (log(z) - t)) + t_1));
	double tmp;
	if ((x * t_2) <= -5e-274) {
		tmp = x * t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = a * (log((1.0d0 - z)) - b)
    t_2 = exp(((y * (log(z) - t)) + t_1))
    if ((x * t_2) <= (-5d-274)) then
        tmp = x * t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = a * (Math.log((1.0 - z)) - b);
	double t_2 = Math.exp(((y * (Math.log(z) - t)) + t_1));
	double tmp;
	if ((x * t_2) <= -5e-274) {
		tmp = x * t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = a * (math.log((1.0 - z)) - b)
	t_2 = math.exp(((y * (math.log(z) - t)) + t_1))
	tmp = 0
	if (x * t_2) <= -5e-274:
		tmp = x * t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(a * Float64(log(Float64(1.0 - z)) - b))
	t_2 = exp(Float64(Float64(y * Float64(log(z) - t)) + t_1))
	tmp = 0.0
	if (Float64(x * t_2) <= -5e-274)
		tmp = Float64(x * t_1);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = a * (log((1.0 - z)) - b);
	t_2 = exp(((y * (log(z) - t)) + t_1));
	tmp = 0.0;
	if ((x * t_2) <= -5e-274)
		tmp = x * t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * N[(N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x * t$95$2), $MachinePrecision], -5e-274], N[(x * t$95$1), $MachinePrecision], t$95$2]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := a \cdot \left(\log \left(1 - z\right) - b\right)\\
t_2 := e^{y \cdot \left(\log z - t\right) + t\_1}\\
\mathbf{if}\;x \cdot t\_2 \leq -5 \cdot 10^{-274}:\\
\;\;\;\;x \cdot t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))))) < -5e-274

    1. Initial program 98.6%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto x \cdot \color{blue}{e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites17.8%

      \[\leadsto x \cdot \color{blue}{\left(a \cdot \left(\log \left(1 - z\right) - b\right)\right)} \]

    if -5e-274 < (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b)))))

    1. Initial program 95.2%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites84.1%

      \[\leadsto \color{blue}{e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 42.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - z\right)\\ t_2 := a \cdot \left(t\_1 - b\right)\\ \mathbf{if}\;x \cdot e^{y \cdot \left(\log z - t\right) + t\_2} \leq 10^{+211}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (log (- 1.0 z))) (t_2 (* a (- t_1 b))))
   (if (<= (* x (exp (+ (* y (- (log z) t)) t_2))) 1e+211) t_1 t_2)))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double tmp;
	if ((x * exp(((y * (log(z) - t)) + t_2))) <= 1e+211) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = log((1.0d0 - z))
    t_2 = a * (t_1 - b)
    if ((x * exp(((y * (log(z) - t)) + t_2))) <= 1d+211) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = Math.log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double tmp;
	if ((x * Math.exp(((y * (Math.log(z) - t)) + t_2))) <= 1e+211) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = math.log((1.0 - z))
	t_2 = a * (t_1 - b)
	tmp = 0
	if (x * math.exp(((y * (math.log(z) - t)) + t_2))) <= 1e+211:
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = log(Float64(1.0 - z))
	t_2 = Float64(a * Float64(t_1 - b))
	tmp = 0.0
	if (Float64(x * exp(Float64(Float64(y * Float64(log(z) - t)) + t_2))) <= 1e+211)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = log((1.0 - z));
	t_2 = a * (t_1 - b);
	tmp = 0.0;
	if ((x * exp(((y * (log(z) - t)) + t_2))) <= 1e+211)
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(a * N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * N[Exp[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 1e+211], t$95$1, t$95$2]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - z\right)\\
t_2 := a \cdot \left(t\_1 - b\right)\\
\mathbf{if}\;x \cdot e^{y \cdot \left(\log z - t\right) + t\_2} \leq 10^{+211}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))))) < 9.9999999999999996e210

    1. Initial program 97.2%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right) + y \cdot \left(\frac{1}{6} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{3}\right)\right)\right) + \frac{1}{2} \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right)\right)} \]
    4. Applied rewrites50.3%

      \[\leadsto \color{blue}{\log \left(1 - z\right)} \]

    if 9.9999999999999996e210 < (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b)))))

    1. Initial program 91.8%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites91.8%

      \[\leadsto \color{blue}{e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    5. Taylor expanded in y around inf

      \[\leadsto \color{blue}{x \cdot e^{\left(a \cdot \left(\log \left(1 - z\right) - b\right) + y \cdot \log z\right) - t \cdot y}} \]
    6. Applied rewrites24.5%

      \[\leadsto \color{blue}{a \cdot \left(\log \left(1 - z\right) - b\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 43.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - z\right)\\ t_2 := y \cdot \left(\log z - t\right)\\ \mathbf{if}\;x \cdot e^{t\_2 + a \cdot \left(t\_1 - b\right)} \leq 5 \cdot 10^{+168}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (log (- 1.0 z))) (t_2 (* y (- (log z) t))))
   (if (<= (* x (exp (+ t_2 (* a (- t_1 b))))) 5e+168) t_1 t_2)))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = log((1.0 - z));
	double t_2 = y * (log(z) - t);
	double tmp;
	if ((x * exp((t_2 + (a * (t_1 - b))))) <= 5e+168) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = log((1.0d0 - z))
    t_2 = y * (log(z) - t)
    if ((x * exp((t_2 + (a * (t_1 - b))))) <= 5d+168) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = Math.log((1.0 - z));
	double t_2 = y * (Math.log(z) - t);
	double tmp;
	if ((x * Math.exp((t_2 + (a * (t_1 - b))))) <= 5e+168) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = math.log((1.0 - z))
	t_2 = y * (math.log(z) - t)
	tmp = 0
	if (x * math.exp((t_2 + (a * (t_1 - b))))) <= 5e+168:
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = log(Float64(1.0 - z))
	t_2 = Float64(y * Float64(log(z) - t))
	tmp = 0.0
	if (Float64(x * exp(Float64(t_2 + Float64(a * Float64(t_1 - b))))) <= 5e+168)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = log((1.0 - z));
	t_2 = y * (log(z) - t);
	tmp = 0.0;
	if ((x * exp((t_2 + (a * (t_1 - b))))) <= 5e+168)
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * N[Exp[N[(t$95$2 + N[(a * N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e+168], t$95$1, t$95$2]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - z\right)\\
t_2 := y \cdot \left(\log z - t\right)\\
\mathbf{if}\;x \cdot e^{t\_2 + a \cdot \left(t\_1 - b\right)} \leq 5 \cdot 10^{+168}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))))) < 4.99999999999999967e168

    1. Initial program 97.6%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right) + y \cdot \left(\frac{1}{6} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{3}\right)\right)\right) + \frac{1}{2} \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right)\right)} \]
    4. Applied rewrites50.5%

      \[\leadsto \color{blue}{\log \left(1 - z\right)} \]

    if 4.99999999999999967e168 < (*.f64 x (exp.f64 (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b)))))

    1. Initial program 90.1%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(\frac{1}{2} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right) + x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right)\right)} \]
    4. Applied rewrites14.9%

      \[\leadsto \color{blue}{y \cdot \left(\log z - t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 48.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - z\right)\\ t_2 := a \cdot \left(t\_1 - b\right)\\ \mathbf{if}\;y \cdot \left(\log z - t\right) + t\_2 \leq -1 \cdot 10^{-179}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (log (- 1.0 z))) (t_2 (* a (- t_1 b))))
   (if (<= (+ (* y (- (log z) t)) t_2) -1e-179) t_1 (* x t_2))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double tmp;
	if (((y * (log(z) - t)) + t_2) <= -1e-179) {
		tmp = t_1;
	} else {
		tmp = x * t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = log((1.0d0 - z))
    t_2 = a * (t_1 - b)
    if (((y * (log(z) - t)) + t_2) <= (-1d-179)) then
        tmp = t_1
    else
        tmp = x * t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = Math.log((1.0 - z));
	double t_2 = a * (t_1 - b);
	double tmp;
	if (((y * (Math.log(z) - t)) + t_2) <= -1e-179) {
		tmp = t_1;
	} else {
		tmp = x * t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = math.log((1.0 - z))
	t_2 = a * (t_1 - b)
	tmp = 0
	if ((y * (math.log(z) - t)) + t_2) <= -1e-179:
		tmp = t_1
	else:
		tmp = x * t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = log(Float64(1.0 - z))
	t_2 = Float64(a * Float64(t_1 - b))
	tmp = 0.0
	if (Float64(Float64(y * Float64(log(z) - t)) + t_2) <= -1e-179)
		tmp = t_1;
	else
		tmp = Float64(x * t_2);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = log((1.0 - z));
	t_2 = a * (t_1 - b);
	tmp = 0.0;
	if (((y * (log(z) - t)) + t_2) <= -1e-179)
		tmp = t_1;
	else
		tmp = x * t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(a * N[(t$95$1 - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(y * N[(N[Log[z], $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], -1e-179], t$95$1, N[(x * t$95$2), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - z\right)\\
t_2 := a \cdot \left(t\_1 - b\right)\\
\mathbf{if}\;y \cdot \left(\log z - t\right) + t\_2 \leq -1 \cdot 10^{-179}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;x \cdot t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b))) < -1e-179

    1. Initial program 95.6%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right) + y \cdot \left(\frac{1}{6} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{3}\right)\right)\right) + \frac{1}{2} \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right)\right)} \]
    4. Applied rewrites77.2%

      \[\leadsto \color{blue}{\log \left(1 - z\right)} \]

    if -1e-179 < (+.f64 (*.f64 y (-.f64 (log.f64 z) t)) (*.f64 a (-.f64 (log.f64 (-.f64 #s(literal 1 binary64) z)) b)))

    1. Initial program 96.8%

      \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto x \cdot \color{blue}{e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
    4. Applied rewrites20.9%

      \[\leadsto x \cdot \color{blue}{\left(a \cdot \left(\log \left(1 - z\right) - b\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 40.2% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \log \left(1 - z\right) \end{array} \]
(FPCore (x y z t a b) :precision binary64 (log (- 1.0 z)))
double code(double x, double y, double z, double t, double a, double b) {
	return log((1.0 - z));
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = log((1.0d0 - z))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return Math.log((1.0 - z));
}
def code(x, y, z, t, a, b):
	return math.log((1.0 - z))
function code(x, y, z, t, a, b)
	return log(Float64(1.0 - z))
end
function tmp = code(x, y, z, t, a, b)
	tmp = log((1.0 - z));
end
code[x_, y_, z_, t_, a_, b_] := N[Log[N[(1.0 - z), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left(1 - z\right)
\end{array}
Derivation
  1. Initial program 96.1%

    \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in y around 0

    \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + y \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right) + y \cdot \left(\frac{1}{6} \cdot \left(x \cdot \left(y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{3}\right)\right)\right) + \frac{1}{2} \cdot \left(x \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot {\left(\log z - t\right)}^{2}\right)\right)\right)\right)} \]
  4. Applied rewrites41.3%

    \[\leadsto \color{blue}{\log \left(1 - z\right)} \]
  5. Add Preprocessing

Alternative 8: 2.7% accurate, 82.0× speedup?

\[\begin{array}{l} \\ 1 - z \end{array} \]
(FPCore (x y z t a b) :precision binary64 (- 1.0 z))
double code(double x, double y, double z, double t, double a, double b) {
	return 1.0 - z;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = 1.0d0 - z
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return 1.0 - z;
}
def code(x, y, z, t, a, b):
	return 1.0 - z
function code(x, y, z, t, a, b)
	return Float64(1.0 - z)
end
function tmp = code(x, y, z, t, a, b)
	tmp = 1.0 - z;
end
code[x_, y_, z_, t_, a_, b_] := N[(1.0 - z), $MachinePrecision]
\begin{array}{l}

\\
1 - z
\end{array}
Derivation
  1. Initial program 96.1%

    \[x \cdot e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in y around 0

    \[\leadsto \color{blue}{x \cdot e^{a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
  4. Applied rewrites61.3%

    \[\leadsto \color{blue}{e^{y \cdot \left(\log z - t\right) + a \cdot \left(\log \left(1 - z\right) - b\right)}} \]
  5. Taylor expanded in y around 0

    \[\leadsto e^{a \cdot \left(\log \left(1 - z\right) - b\right)} + \color{blue}{y \cdot \left(e^{a \cdot \left(\log \left(1 - z\right) - b\right)} \cdot \left(\log z - t\right)\right)} \]
  6. Applied rewrites2.8%

    \[\leadsto 1 - \color{blue}{z} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024313 
(FPCore (x y z t a b)
  :name "Numeric.SpecFunctions:incompleteBetaApprox from math-functions-0.1.5.2, B"
  :precision binary64
  (* x (exp (+ (* y (- (log z) t)) (* a (- (log (- 1.0 z)) b))))))