Average Error: 4.7 → 0.7
Time: 13.9s
Precision: binary64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
\[\begin{array}{l} t_1 := \frac{t}{1 - z}\\ t_2 := \frac{y}{z} - t_1\\ t_3 := \frac{y \cdot x}{z}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\begin{array}{l} t_4 := \sqrt[3]{1 - z}\\ t_3 - \frac{t}{t_4 \cdot t_4} \cdot \frac{x}{t_4} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_5 := -t_1\\ \mathbf{if}\;t_2 \leq -1.300852640978506 \cdot 10^{-156}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(1, \frac{y}{z}, t_5\right)\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{y}{\frac{z}{x}} - \frac{t \cdot x}{1 - z}\\ \mathbf{elif}\;t_2 \leq 4.470830814915151 \cdot 10^{+146}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, t_5\right) + \mathsf{fma}\left(t_5, 1, t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_3 - t \cdot \frac{x}{1 - z}\\ \end{array}\\ \end{array} \]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
t_1 := \frac{t}{1 - z}\\
t_2 := \frac{y}{z} - t_1\\
t_3 := \frac{y \cdot x}{z}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
t_4 := \sqrt[3]{1 - z}\\
t_3 - \frac{t}{t_4 \cdot t_4} \cdot \frac{x}{t_4}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_5 := -t_1\\
\mathbf{if}\;t_2 \leq -1.300852640978506 \cdot 10^{-156}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(1, \frac{y}{z}, t_5\right)\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{y}{\frac{z}{x}} - \frac{t \cdot x}{1 - z}\\

\mathbf{elif}\;t_2 \leq 4.470830814915151 \cdot 10^{+146}:\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, t_5\right) + \mathsf{fma}\left(t_5, 1, t_1\right)\right)\\

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


\end{array}\\


\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 (/ t (- 1.0 z))) (t_2 (- (/ y z) t_1)) (t_3 (/ (* y x) z)))
   (if (<= t_2 (- INFINITY))
     (let* ((t_4 (cbrt (- 1.0 z)))) (- t_3 (* (/ t (* t_4 t_4)) (/ x t_4))))
     (let* ((t_5 (- t_1)))
       (if (<= t_2 -1.300852640978506e-156)
         (* x (fma 1.0 (/ y z) t_5))
         (if (<= t_2 0.0)
           (- (/ y (/ z x)) (/ (* t x) (- 1.0 z)))
           (if (<= t_2 4.470830814915151e+146)
             (* x (+ (fma y (/ 1.0 z) t_5) (fma t_5 1.0 t_1)))
             (- t_3 (* 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 = t / (1.0 - z);
	double t_2 = (y / z) - t_1;
	double t_3 = (y * x) / z;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		double t_4_1 = cbrt(1.0 - z);
		tmp = t_3 - ((t / (t_4_1 * t_4_1)) * (x / t_4_1));
	} else {
		double t_5 = -t_1;
		double tmp_2;
		if (t_2 <= -1.300852640978506e-156) {
			tmp_2 = x * fma(1.0, (y / z), t_5);
		} else if (t_2 <= 0.0) {
			tmp_2 = (y / (z / x)) - ((t * x) / (1.0 - z));
		} else if (t_2 <= 4.470830814915151e+146) {
			tmp_2 = x * (fma(y, (1.0 / z), t_5) + fma(t_5, 1.0, t_1));
		} else {
			tmp_2 = t_3 - (t * (x / (1.0 - z)));
		}
		tmp = tmp_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.7
Target4.4
Herbie0.7
\[\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 5 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 y around 0 0.3

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
    3. Applied add-cube-cbrt_binary640.3

      \[\leadsto \frac{y \cdot x}{z} - \frac{t \cdot x}{\color{blue}{\left(\sqrt[3]{1 - z} \cdot \sqrt[3]{1 - z}\right) \cdot \sqrt[3]{1 - z}}} \]
    4. Applied times-frac_binary640.3

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

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -1.3008526409785059e-156

    1. Initial program 0.2

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Applied *-un-lft-identity_binary640.2

      \[\leadsto x \cdot \left(\color{blue}{1 \cdot \frac{y}{z}} - \frac{t}{1 - z}\right) \]
    3. Applied fma-neg_binary640.2

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

    if -1.3008526409785059e-156 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 0.0

    1. Initial program 9.0

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
    3. Applied associate-/l*_binary641.3

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

    if 0.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 4.47083081491515058e146

    1. Initial program 0.4

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \]
    2. Applied *-un-lft-identity_binary640.4

      \[\leadsto x \cdot \left(\frac{y}{z} - \color{blue}{1 \cdot \frac{t}{1 - z}}\right) \]
    3. Applied div-inv_binary640.4

      \[\leadsto x \cdot \left(\color{blue}{y \cdot \frac{1}{z}} - 1 \cdot \frac{t}{1 - z}\right) \]
    4. Applied prod-diff_binary640.4

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

    if 4.47083081491515058e146 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 13.0

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} - \frac{t \cdot x}{1 - z}} \]
    3. Applied *-un-lft-identity_binary642.3

      \[\leadsto \frac{y \cdot x}{z} - \frac{t \cdot x}{\color{blue}{1 \cdot \left(1 - z\right)}} \]
    4. Applied times-frac_binary642.4

      \[\leadsto \frac{y \cdot x}{z} - \color{blue}{\frac{t}{1} \cdot \frac{x}{1 - z}} \]
    5. Simplified2.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -\infty:\\ \;\;\;\;\frac{y \cdot x}{z} - \frac{t}{\sqrt[3]{1 - z} \cdot \sqrt[3]{1 - z}} \cdot \frac{x}{\sqrt[3]{1 - z}}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq -1.300852640978506 \cdot 10^{-156}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(1, \frac{y}{z}, -\frac{t}{1 - z}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 0:\\ \;\;\;\;\frac{y}{\frac{z}{x}} - \frac{t \cdot x}{1 - z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq 4.470830814915151 \cdot 10^{+146}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right) + \mathsf{fma}\left(-\frac{t}{1 - z}, 1, \frac{t}{1 - z}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z} - t \cdot \frac{x}{1 - z}\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(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)))))