Average Error: 6.5 → 2.4
Time: 7.1s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{if}\;x \leq -6.2284847009143676 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.178828194994505 \cdot 10^{-220}:\\ \;\;\;\;x + z \cdot \frac{y - x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\
\mathbf{if}\;x \leq -6.2284847009143676 \cdot 10^{+57}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.178828194994505 \cdot 10^{-220}:\\
\;\;\;\;x + z \cdot \frac{y - x}{t}\\

\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 (fma (- y x) (/ z t) x)))
   (if (<= x -6.2284847009143676e+57)
     t_1
     (if (<= x 1.178828194994505e-220) (+ x (* z (/ (- y x) t))) 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 = fma((y - x), (z / t), x);
	double tmp;
	if (x <= -6.2284847009143676e+57) {
		tmp = t_1;
	} else if (x <= 1.178828194994505e-220) {
		tmp = x + (z * ((y - x) / t));
	} 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.5
Target1.8
Herbie2.4
\[\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 x < -6.22848470091436762e57 or 1.17882819499450501e-220 < x

    1. Initial program 7.4

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

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

    if -6.22848470091436762e57 < x < 1.17882819499450501e-220

    1. Initial program 5.2

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

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

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

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x \]
    5. Applied +-commutative_binary644.6

      \[\leadsto \color{blue}{x + z \cdot \frac{y - x}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.4

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

Reproduce

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