Average Error: 4.6 → 0.5
Time: 6.6s
Precision: binary64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{y \cdot x}{z}\\ t_2 := \frac{y}{z} - \frac{t}{1 - z}\\ t_3 := x \cdot t_2\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1 - t \cdot x\\ \mathbf{elif}\;t_2 \leq -2.5784549546398096 \cdot 10^{-254}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 1.943961421763064 \cdot 10^{-188}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, t \cdot x\right)}{z}\\ \mathbf{elif}\;t_2 \leq 2.1021122769901558 \cdot 10^{+138}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1 - \frac{t \cdot x}{1 - z}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* x (- (/ y z) (/ t (- 1.0 z)))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (* y x) z)) (t_2 (- (/ y z) (/ t (- 1.0 z)))) (t_3 (* x t_2)))
   (if (<= t_2 (- INFINITY))
     (- t_1 (* t x))
     (if (<= t_2 -2.5784549546398096e-254)
       t_3
       (if (<= t_2 1.943961421763064e-188)
         (/ (fma y x (* t x)) z)
         (if (<= t_2 2.1021122769901558e+138)
           t_3
           (- t_1 (/ (* t x) (- 1.0 z)))))))))
double code(double x, double y, double z, double t) {
	return x * ((y / z) - (t / (1.0 - z)));
}
double code(double x, double y, double z, double t) {
	double t_1 = (y * x) / z;
	double t_2 = (y / z) - (t / (1.0 - z));
	double t_3 = x * t_2;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1 - (t * x);
	} else if (t_2 <= -2.5784549546398096e-254) {
		tmp = t_3;
	} else if (t_2 <= 1.943961421763064e-188) {
		tmp = fma(y, x, (t * x)) / z;
	} else if (t_2 <= 2.1021122769901558e+138) {
		tmp = t_3;
	} else {
		tmp = t_1 - ((t * x) / (1.0 - z));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x * Float64(Float64(y / z) - Float64(t / Float64(1.0 - z))))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(y * x) / z)
	t_2 = Float64(Float64(y / z) - Float64(t / Float64(1.0 - z)))
	t_3 = Float64(x * t_2)
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(t_1 - Float64(t * x));
	elseif (t_2 <= -2.5784549546398096e-254)
		tmp = t_3;
	elseif (t_2 <= 1.943961421763064e-188)
		tmp = Float64(fma(y, x, Float64(t * x)) / z);
	elseif (t_2 <= 2.1021122769901558e+138)
		tmp = t_3;
	else
		tmp = Float64(t_1 - Float64(Float64(t * x) / Float64(1.0 - z)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x * N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y / z), $MachinePrecision] - N[(t / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x * t$95$2), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(t$95$1 - N[(t * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -2.5784549546398096e-254], t$95$3, If[LessEqual[t$95$2, 1.943961421763064e-188], N[(N[(y * x + N[(t * x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$2, 2.1021122769901558e+138], t$95$3, N[(t$95$1 - N[(N[(t * x), $MachinePrecision] / N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{y \cdot x}{z}\\
t_2 := \frac{y}{z} - \frac{t}{1 - z}\\
t_3 := x \cdot t_2\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1 - t \cdot x\\

\mathbf{elif}\;t_2 \leq -2.5784549546398096 \cdot 10^{-254}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 1.943961421763064 \cdot 10^{-188}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, t \cdot x\right)}{z}\\

\mathbf{elif}\;t_2 \leq 2.1021122769901558 \cdot 10^{+138}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_1 - \frac{t \cdot x}{1 - z}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.3
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < -7.623226303312042 \cdot 10^{-196}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) < 1.4133944927702302 \cdot 10^{-211}:\\ \;\;\;\;\frac{y \cdot x}{z} + \left(-\frac{t \cdot x}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -inf.0

    1. Initial program 64.0

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in z around 0 0.3

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - t \cdot x} \]

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -2.5784549546398096e-254 or 1.9439614217630641e-188 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 2.10211227699015581e138

    1. Initial program 0.2

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]

    if -2.5784549546398096e-254 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 1.9439614217630641e-188

    1. Initial program 9.7

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in z around inf 0.9

      \[\leadsto \color{blue}{\frac{y \cdot x + t \cdot x}{z}} \]
    3. Simplified0.9

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, x, t \cdot x\right)}{z}} \]

    if 2.10211227699015581e138 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 12.3

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Taylor expanded in y around 0 2.0

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -\infty:\\ \;\;\;\;\frac{y \cdot x}{z} - t \cdot x\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq -2.5784549546398096 \cdot 10^{-254}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 1.943961421763064 \cdot 10^{-188}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, t \cdot x\right)}{z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 2.1021122769901558 \cdot 10^{+138}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}\\ \end{array} \]

Reproduce

herbie shell --seed 2022152 
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"
  :precision binary64

  :herbie-target
  (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))

  (* x (- (/ y z) (/ t (- 1.0 z)))))