Average Error: 1.4 → 1.1
Time: 4.6s
Precision: binary64
\[x + y \cdot \frac{z - t}{a - t} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -3.9258428577443835 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{t - a}, x\right)\\ \mathbf{elif}\;y \leq 1.0514448438020326 \cdot 10^{-28}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot \left(z - t\right), \frac{1}{a - t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z - t}}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- a t)))))
(FPCore (x y z t a)
 :precision binary64
 (if (<= y -3.9258428577443835e+52)
   (fma (- t z) (/ y (- t a)) x)
   (if (<= y 1.0514448438020326e-28)
     (fma (* y (- z t)) (/ 1.0 (- a t)) x)
     (+ x (/ y (/ (- a t) (- z t)))))))
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 tmp;
	if (y <= -3.9258428577443835e+52) {
		tmp = fma((t - z), (y / (t - a)), x);
	} else if (y <= 1.0514448438020326e-28) {
		tmp = fma((y * (z - t)), (1.0 / (a - t)), x);
	} else {
		tmp = x + (y / ((a - t) / (z - t)));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(a - t))))
end
function code(x, y, z, t, a)
	tmp = 0.0
	if (y <= -3.9258428577443835e+52)
		tmp = fma(Float64(t - z), Float64(y / Float64(t - a)), x);
	elseif (y <= 1.0514448438020326e-28)
		tmp = fma(Float64(y * Float64(z - t)), Float64(1.0 / Float64(a - t)), x);
	else
		tmp = Float64(x + Float64(y / Float64(Float64(a - t) / Float64(z - t))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[y, -3.9258428577443835e+52], N[(N[(t - z), $MachinePrecision] * N[(y / N[(t - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 1.0514448438020326e-28], N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a - t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + y \cdot \frac{z - t}{a - t}
\begin{array}{l}
\mathbf{if}\;y \leq -3.9258428577443835 \cdot 10^{+52}:\\
\;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{t - a}, x\right)\\

\mathbf{elif}\;y \leq 1.0514448438020326 \cdot 10^{-28}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(z - t\right), \frac{1}{a - t}, x\right)\\

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


\end{array}

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
Herbie1.1
\[\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.92584285774438353e52

    1. Initial program 0.7

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

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

    if -3.92584285774438353e52 < y < 1.0514448438020326e-28

    1. Initial program 2.1

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Applied egg-rr2.2

      \[\leadsto x + y \cdot \color{blue}{\left(\left(z - t\right) \cdot \frac{1}{a - t}\right)} \]
    3. Applied egg-rr0.7

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

    if 1.0514448438020326e-28 < y

    1. Initial program 0.4

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

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

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

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

Reproduce

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