Average Error: 6.7 → 1.0
Time: 6.8s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 8.064645597670005 \cdot 10^{+272}\right):\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 8.064645597670005 \cdot 10^{+272}\right):\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* (- y x) z) t))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 8.064645597670005e+272)))
     (fma (- y x) (/ z t) x)
     t_1)))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = x + (((y - x) * z) / t);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 8.064645597670005e+272)) {
		tmp = fma((y - x), (z / t), x);
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.7
Target2.3
Herbie1.0
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -inf.0 or 8.064645597670005e272 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 47.1

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Simplified1.9

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

    if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 8.064645597670005e272

    1. Initial program 0.8

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Simplified2.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Taylor expanded in y around 0 0.8

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{z \cdot x}{t}} \]
    4. Applied add-cube-cbrt_binary641.0

      \[\leadsto \left(\frac{y \cdot z}{t} + x\right) - \color{blue}{\left(\sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}\right) \cdot \sqrt[3]{\frac{z \cdot x}{t}}} \]
    5. Applied add-cube-cbrt_binary642.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{y \cdot z}{t} + x} \cdot \sqrt[3]{\frac{y \cdot z}{t} + x}, \sqrt[3]{\frac{y \cdot z}{t} + x}, -\sqrt[3]{\frac{z \cdot x}{t}} \cdot \left(\sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\frac{z \cdot x}{t}}, \sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}, \sqrt[3]{\frac{z \cdot x}{t}} \cdot \left(\sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}\right)\right)} \]
    7. Simplified0.8

      \[\leadsto \color{blue}{\left(x + \frac{z \cdot \left(y - x\right)}{t}\right)} + \mathsf{fma}\left(-\sqrt[3]{\frac{z \cdot x}{t}}, \sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}, \sqrt[3]{\frac{z \cdot x}{t}} \cdot \left(\sqrt[3]{\frac{z \cdot x}{t}} \cdot \sqrt[3]{\frac{z \cdot x}{t}}\right)\right) \]
    8. Simplified0.8

      \[\leadsto \left(x + \frac{z \cdot \left(y - x\right)}{t}\right) + \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -\infty \lor \neg \left(x + \frac{\left(y - x\right) \cdot z}{t} \leq 8.064645597670005 \cdot 10^{+272}\right):\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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