Average Error: 1.5 → 0.6
Time: 6.3s
Precision: binary64
\[x + y \cdot \frac{z - t}{z - a} \]
\[\begin{array}{l} t_1 := \frac{z - t}{z - a}\\ \mathbf{if}\;y \leq -9.042638636563712 \cdot 10^{+45}:\\ \;\;\;\;x + y \cdot t_1\\ \mathbf{elif}\;y \leq 9.715510485428454 \cdot 10^{-48}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{z - a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_1, y, x\right)\\ \end{array} \]
x + y \cdot \frac{z - t}{z - a}
\begin{array}{l}
t_1 := \frac{z - t}{z - a}\\
\mathbf{if}\;y \leq -9.042638636563712 \cdot 10^{+45}:\\
\;\;\;\;x + y \cdot t_1\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_1, y, x\right)\\


\end{array}
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- z a)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (- z t) (- z a))))
   (if (<= y -9.042638636563712e+45)
     (+ x (* y t_1))
     (if (<= y 9.715510485428454e-48)
       (+ x (/ (* y (- z t)) (- z a)))
       (fma t_1 y x)))))
double code(double x, double y, double z, double t, double a) {
	return x + (y * ((z - t) / (z - a)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (z - t) / (z - a);
	double tmp;
	if (y <= -9.042638636563712e+45) {
		tmp = x + (y * t_1);
	} else if (y <= 9.715510485428454e-48) {
		tmp = x + ((y * (z - t)) / (z - a));
	} else {
		tmp = fma(t_1, y, x);
	}
	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.5
Target1.4
Herbie0.6
\[x + \frac{y}{\frac{z - a}{z - t}} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -9.0426386365637122e45

    1. Initial program 0.8

      \[x + y \cdot \frac{z - t}{z - a} \]

    if -9.0426386365637122e45 < y < 9.7155104854284541e-48

    1. Initial program 2.3

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

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

    if 9.7155104854284541e-48 < y

    1. Initial program 0.5

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

      \[\leadsto x + \color{blue}{\frac{\left(z - t\right) \cdot y}{z - a}} \]
    3. Taylor expanded in x around 0 20.3

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

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

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

Reproduce

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

  :herbie-target
  (+ x (/ y (/ (- z a) (- z t))))

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