Average Error: 4.5 → 2.1
Time: 9.8s
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{y}{z} - \frac{t}{1 - z}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y \cdot x, \frac{1}{z}, t_1\right)\\ \mathbf{elif}\;t_2 \leq -1.4854737382240352 \cdot 10^{-143} \lor \neg \left(t_2 \leq 3.277712234425198 \cdot 10^{-207}\right):\\ \;\;\;\;t_2 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{y \cdot x}{z}, t_1\right)\\ \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{y}{z} - \frac{t}{1 - z}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, \frac{1}{z}, t_1\right)\\

\mathbf{elif}\;t_2 \leq -1.4854737382240352 \cdot 10^{-143} \lor \neg \left(t_2 \leq 3.277712234425198 \cdot 10^{-207}\right):\\
\;\;\;\;t_2 \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{y \cdot x}{z}, t_1\right)\\


\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 (- (/ y z) (/ t (- 1.0 z)))))
   (if (<= t_2 (- INFINITY))
     (fma (* y x) (/ 1.0 z) t_1)
     (if (or (<= t_2 -1.4854737382240352e-143)
             (not (<= t_2 3.277712234425198e-207)))
       (* t_2 x)
       (fma 1.0 (/ (* y x) z) t_1)))))
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 = (y / z) - (t / (1.0 - z));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma((y * x), (1.0 / z), t_1);
	} else if ((t_2 <= -1.4854737382240352e-143) || !(t_2 <= 3.277712234425198e-207)) {
		tmp = t_2 * x;
	} else {
		tmp = fma(1.0, ((y * x) / z), t_1);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.5
Target4.4
Herbie2.1
\[\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 3 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.2

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

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

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

    if -inf.0 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < -1.48547373822403518e-143 or 3.2777122344251982e-207 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z)))

    1. Initial program 2.2

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

    if -1.48547373822403518e-143 < (-.f64 (/.f64 y z) (/.f64 t (-.f64 1 z))) < 3.2777122344251982e-207

    1. Initial program 5.7

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{y \cdot x}{z}} - \frac{t \cdot x}{1 - z} \]
    4. Applied fma-neg_binary641.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{y \cdot x}{z}, -\frac{t \cdot x}{1 - z}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y \cdot x, \frac{1}{z}, -\frac{t \cdot x}{1 - z}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \leq -1.4854737382240352 \cdot 10^{-143} \lor \neg \left(\frac{y}{z} - \frac{t}{1 - z} \leq 3.277712234425198 \cdot 10^{-207}\right):\\ \;\;\;\;\left(\frac{y}{z} - \frac{t}{1 - z}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{y \cdot x}{z}, -\frac{t \cdot x}{1 - z}\right)\\ \end{array} \]

Reproduce

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