Average Error: 16.3 → 7.3
Time: 6.7s
Precision: binary64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1.2329906028711256 \cdot 10^{+76}:\\ \;\;\;\;x + \left(z - a\right) \cdot \frac{y}{t}\\ \mathbf{elif}\;t \leq 5.7773904303314184 \cdot 10^{+162}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a - t}, x + y\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{t}{a - z}}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (if (<= t -1.2329906028711256e+76)
   (+ x (* (- z a) (/ y t)))
   (if (<= t 5.7773904303314184e+162)
     (fma y (/ (- t z) (- a t)) (+ x y))
     (- x (/ y (/ t (- a z)))))))
double code(double x, double y, double z, double t, double a) {
	return (x + y) - (((z - t) * y) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if (t <= -1.2329906028711256e+76) {
		tmp = x + ((z - a) * (y / t));
	} else if (t <= 5.7773904303314184e+162) {
		tmp = fma(y, ((t - z) / (a - t)), (x + y));
	} else {
		tmp = x - (y / (t / (a - z)));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t)))
end
function code(x, y, z, t, a)
	tmp = 0.0
	if (t <= -1.2329906028711256e+76)
		tmp = Float64(x + Float64(Float64(z - a) * Float64(y / t)));
	elseif (t <= 5.7773904303314184e+162)
		tmp = fma(y, Float64(Float64(t - z) / Float64(a - t)), Float64(x + y));
	else
		tmp = Float64(x - Float64(y / Float64(t / Float64(a - z))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -1.2329906028711256e+76], N[(x + N[(N[(z - a), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 5.7773904303314184e+162], N[(y * N[(N[(t - z), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / N[(t / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -1.2329906028711256 \cdot 10^{+76}:\\
\;\;\;\;x + \left(z - a\right) \cdot \frac{y}{t}\\

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original16.3
Target8.5
Herbie7.3
\[\begin{array}{l} \mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < -1.3664970889390727 \cdot 10^{-7}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \mathbf{elif}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < 1.4754293444577233 \cdot 10^{-239}:\\ \;\;\;\;\frac{y \cdot \left(a - z\right) - x \cdot t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if t < -1.2329906028711256e76

    1. Initial program 28.4

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Simplified18.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, x + y\right)} \]
    3. Taylor expanded in t around inf 15.4

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

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - a\right)} \]
    5. Applied *-commutative_binary648.8

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

    if -1.2329906028711256e76 < t < 5.77739043033141842e162

    1. Initial program 9.6

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Simplified7.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, x + y\right)} \]
    3. Applied div-inv_binary647.1

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

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

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{{\left(t - z\right)}^{1}} \cdot {\left(\frac{1}{a - t}\right)}^{1}, x + y\right) \]
    6. Applied pow-prod-down_binary647.1

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

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

    if 5.77739043033141842e162 < t

    1. Initial program 32.8

      \[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
    2. Simplified22.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, x + y\right)} \]
    3. Taylor expanded in t around inf 16.1

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

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

      \[\leadsto x + \color{blue}{-1 \cdot \frac{y \cdot a - y \cdot z}{t}} \]
    6. Simplified5.6

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

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

Reproduce

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

  :herbie-target
  (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))

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