Average Error: 4.8 → 0.8
Time: 2.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 -1.1908000961162953 \cdot 10^{+300}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y - x}{t}, x\right)\\ \mathbf{elif}\;t_1 \leq 1.1925362134991726 \cdot 10^{+242}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \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 -1.1908000961162953 \cdot 10^{+300}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y - x}{t}, x\right)\\

\mathbf{elif}\;t_1 \leq 1.1925362134991726 \cdot 10^{+242}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\


\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 -1.1908000961162953e+300)
     (fma z (/ (- y x) t) x)
     (if (<= t_1 1.1925362134991726e+242) t_1 (+ x (/ (- y x) (/ t z)))))))
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 <= -1.1908000961162953e+300) {
		tmp = fma(z, ((y - x) / t), x);
	} else if (t_1 <= 1.1925362134991726e+242) {
		tmp = t_1;
	} else {
		tmp = x + ((y - x) / (t / z));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target1.5
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)) < -1.19080009611629529e300

    1. Initial program 13.2

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Applied associate-/l*_binary640.1

      \[\leadsto x + \color{blue}{\frac{y - x}{\frac{t}{z}}} \]
    3. Taylor expanded in x around 0 22.6

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

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

    if -1.19080009611629529e300 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 1.19253621349917263e242

    1. Initial program 0.8

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

    if 1.19253621349917263e242 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 10.1

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Applied associate-/l*_binary641.0

      \[\leadsto x + \color{blue}{\frac{y - x}{\frac{t}{z}}} \]
  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 -1.1908000961162953 \cdot 10^{+300}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y - x}{t}, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 1.1925362134991726 \cdot 10^{+242}:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Reproduce

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