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

\mathbf{elif}\;t_4 \leq -1.300852640978506 \cdot 10^{-156}:\\
\;\;\;\;t_4 \cdot x\\

\mathbf{elif}\;t_4 \leq 0:\\
\;\;\;\;\frac{y}{\frac{z}{x}} - t_1\\

\mathbf{elif}\;t_4 \leq 4.470830814915151 \cdot 10^{+146}:\\
\;\;\;\;\begin{array}{l}
t_6 := -t_2\\
x \cdot \mathsf{fma}\left(y, \frac{1}{z}, t_6\right) + x \cdot \mathsf{fma}\left(t_6, 1, t_2\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_3 - t \cdot \frac{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 (/ (* t x) (- 1.0 z)))
        (t_2 (/ t (- 1.0 z)))
        (t_3 (/ (* y x) z))
        (t_4 (- (/ y z) t_2)))
   (if (<= t_4 (- INFINITY))
     (let* ((t_5 (cbrt t_1))) (- t_3 (* t_5 (* t_5 t_5))))
     (if (<= t_4 -1.300852640978506e-156)
       (* t_4 x)
       (if (<= t_4 0.0)
         (- (/ y (/ z x)) t_1)
         (if (<= t_4 4.470830814915151e+146)
           (let* ((t_6 (- t_2)))
             (+ (* x (fma y (/ 1.0 z) t_6)) (* x (fma t_6 1.0 t_2))))
           (- 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 * x) / (1.0 - z);
	double t_2 = t / (1.0 - z);
	double t_3 = (y * x) / z;
	double t_4 = (y / z) - t_2;
	double tmp;
	if (t_4 <= -((double) INFINITY)) {
		double t_5_1 = cbrt(t_1);
		tmp = t_3 - (t_5_1 * (t_5_1 * t_5_1));
	} else if (t_4 <= -1.300852640978506e-156) {
		tmp = t_4 * x;
	} else if (t_4 <= 0.0) {
		tmp = (y / (z / x)) - t_1;
	} else if (t_4 <= 4.470830814915151e+146) {
		double t_6 = -t_2;
		tmp = (x * fma(y, (1.0 / z), t_6)) + (x * fma(t_6, 1.0, t_2));
	} else {
		tmp = t_3 - (t * (x / (1.0 - z)));
	}
	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} - \color{blue}{\left(\sqrt[3]{\frac{t \cdot x}{1 - z}} \cdot \sqrt[3]{\frac{t \cdot x}{1 - z}}\right) \cdot \sqrt[3]{\frac{t \cdot x}{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(\frac{y}{z} - \frac{t}{\color{blue}{1 \cdot \left(1 - z\right)}}\right) \]
    3. Applied *-un-lft-identity_binary640.2

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

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

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

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

      \[\leadsto x \cdot \left(\color{blue}{\frac{1}{1} \cdot \frac{y}{z}} - \frac{1}{1} \cdot \frac{t}{1 - z}\right) \]
    8. Applied distribute-lft-out--_binary640.2

      \[\leadsto x \cdot \color{blue}{\left(\frac{1}{1} \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\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} - \frac{t}{\color{blue}{1 \cdot \left(1 - z\right)}}\right) \]
    3. Applied *-un-lft-identity_binary640.4

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z} \cdot \frac{1}{1}\right) + \mathsf{fma}\left(-\frac{t}{1 - z}, \frac{1}{1}, \frac{t}{1 - z} \cdot \frac{1}{1}\right)\right)} \]
    7. Applied distribute-rgt-in_binary640.4

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

    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} - \sqrt[3]{\frac{t \cdot x}{1 - z}} \cdot \left(\sqrt[3]{\frac{t \cdot x}{1 - z}} \cdot \sqrt[3]{\frac{t \cdot x}{1 - z}}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq -1.300852640978506 \cdot 10^{-156}:\\ \;\;\;\;\left(\frac{y}{z} - \frac{t}{1 - z}\right) \cdot x\\ \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 \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right) + x \cdot \mathsf{fma}\left(-\frac{t}{1 - z}, 1, \frac{t}{1 - z}\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)))))