Average Error: 4.4 → 0.8
Time: 7.2s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1.3748442168295486 \cdot 10^{-34}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;t \leq 1226576968.5346966:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\sqrt{t}} \cdot \frac{z}{\sqrt{t}}\\ \end{array} \]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -1.3748442168295486 \cdot 10^{-34}:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\

\mathbf{elif}\;t \leq 1226576968.5346966:\\
\;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -1.3748442168295486e-34)
   (fma (- y x) (/ z t) x)
   (if (<= t 1226576968.5346966)
     (+ x (/ (* (- y x) z) t))
     (+ x (* (/ (- y x) (sqrt t)) (/ z (sqrt t)))))))
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 tmp;
	if (t <= -1.3748442168295486e-34) {
		tmp = fma((y - x), (z / t), x);
	} else if (t <= 1226576968.5346966) {
		tmp = x + (((y - x) * z) / t);
	} else {
		tmp = x + (((y - x) / sqrt(t)) * (z / sqrt(t)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.4
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 t < -1.3748442168295486e-34

    1. Initial program 7.2

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

    if -1.3748442168295486e-34 < t < 1226576968.5346966

    1. Initial program 0.9

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

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

    if 1226576968.5346966 < t

    1. Initial program 7.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -1.3748442168295486 \cdot 10^{-34}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;t \leq 1226576968.5346966:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\sqrt{t}} \cdot \frac{z}{\sqrt{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)))