Average Error: 1.4 → 0.4
Time: 4.7s
Precision: binary64
\[x + y \cdot \frac{z - t}{a - t} \]
\[\begin{array}{l} t_1 := \frac{z - t}{a - t}\\ \mathbf{if}\;y \leq -3.694153495670011 \cdot 10^{-41}:\\ \;\;\;\;\mathsf{fma}\left(y, t_1, x\right)\\ \mathbf{elif}\;y \leq 0.009889904661523138:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot t_1\\ \end{array} \]
x + y \cdot \frac{z - t}{a - t}
\begin{array}{l}
t_1 := \frac{z - t}{a - t}\\
\mathbf{if}\;y \leq -3.694153495670011 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(y, t_1, x\right)\\

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

\mathbf{else}:\\
\;\;\;\;x + y \cdot t_1\\


\end{array}
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- a t)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (- z t) (- a t))))
   (if (<= y -3.694153495670011e-41)
     (fma y t_1 x)
     (if (<= y 0.009889904661523138)
       (+ x (/ (* y (- z t)) (- a t)))
       (+ x (* y t_1))))))
double code(double x, double y, double z, double t, double a) {
	return x + (y * ((z - t) / (a - t)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (z - t) / (a - t);
	double tmp;
	if (y <= -3.694153495670011e-41) {
		tmp = fma(y, t_1, x);
	} else if (y <= 0.009889904661523138) {
		tmp = x + ((y * (z - t)) / (a - t));
	} else {
		tmp = x + (y * t_1);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original1.4
Target0.4
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y < -8.508084860551241 \cdot 10^{-17}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -3.69415349567001088e-41

    1. Initial program 0.5

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified0.5

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

    if -3.69415349567001088e-41 < y < 0.00988990466152313806

    1. Initial program 2.3

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Taylor expanded in y around 0 0.3

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

    if 0.00988990466152313806 < y

    1. Initial program 0.6

      \[x + y \cdot \frac{z - t}{a - t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

herbie shell --seed 2022097 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisLine from plot-0.2.3.4, B"
  :precision binary64

  :herbie-target
  (if (< y -8.508084860551241e-17) (+ x (* y (/ (- z t) (- a t)))) (if (< y 2.894426862792089e-49) (+ x (* (* y (- z t)) (/ 1.0 (- a t)))) (+ x (* y (/ (- z t) (- a t))))))

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