Average Error: 6.7 → 0.8
Time: 9.5s
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:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{elif}\;t_1 \leq 7.579611590072021 \cdot 10^{+288}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \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:\\
\;\;\;\;x + z \cdot \frac{y - x}{t}\\

\mathbf{elif}\;t_1 \leq 7.579611590072021 \cdot 10^{+288}:\\
\;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\


\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 (<= t_1 (- INFINITY))
     (+ x (* z (/ (- y x) t)))
     (if (<= t_1 7.579611590072021e+288)
       (- (+ x (/ (* y z) t)) (/ (* x z) t))
       (fma (- y x) (/ z t) x)))))
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)) {
		tmp = x + (z * ((y - x) / t));
	} else if (t_1 <= 7.579611590072021e+288) {
		tmp = (x + ((y * z) / t)) - ((x * z) / t);
	} else {
		tmp = fma((y - x), (z / t), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.7
Target1.9
Herbie0.8
\[\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 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -inf.0

    1. Initial program 64.0

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

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

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \frac{z}{t} + x} \]
    4. Simplified0.2

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

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

    1. Initial program 0.8

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

      \[\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}} \]

    if 7.5796115900720211e288 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 46.0

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

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

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

Reproduce

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