Average Error: 16.0 → 5.4
Time: 5.0s
Precision: binary64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := \left(x + y\right) - \frac{y \cdot \left(z - t\right)}{a - t}\\ \mathbf{if}\;t_1 \leq -1.0228914215450133 \cdot 10^{-231}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \left(z - t\right) \cdot \frac{1}{t - a}, y\right)\\ \mathbf{elif}\;t_1 \leq 1.865968207475801 \cdot 10^{-234}:\\ \;\;\;\;x + \frac{y \cdot \left(z - a\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \left(y + \left(z - t\right) \cdot \frac{y}{t - a}\right)\\ \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
 (let* ((t_1 (- (+ x y) (/ (* y (- z t)) (- a t)))))
   (if (<= t_1 -1.0228914215450133e-231)
     (+ x (fma y (* (- z t) (/ 1.0 (- t a))) y))
     (if (<= t_1 1.865968207475801e-234)
       (+ x (/ (* y (- z a)) t))
       (+ x (+ y (* (- z t) (/ y (- t a)))))))))
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 t_1 = (x + y) - ((y * (z - t)) / (a - t));
	double tmp;
	if (t_1 <= -1.0228914215450133e-231) {
		tmp = x + fma(y, ((z - t) * (1.0 / (t - a))), y);
	} else if (t_1 <= 1.865968207475801e-234) {
		tmp = x + ((y * (z - a)) / t);
	} else {
		tmp = x + (y + ((z - t) * (y / (t - a))));
	}
	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)
	t_1 = Float64(Float64(x + y) - Float64(Float64(y * Float64(z - t)) / Float64(a - t)))
	tmp = 0.0
	if (t_1 <= -1.0228914215450133e-231)
		tmp = Float64(x + fma(y, Float64(Float64(z - t) * Float64(1.0 / Float64(t - a))), y));
	elseif (t_1 <= 1.865968207475801e-234)
		tmp = Float64(x + Float64(Float64(y * Float64(z - a)) / t));
	else
		tmp = Float64(x + Float64(y + Float64(Float64(z - t) * Float64(y / Float64(t - a)))));
	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_] := Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] - N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1.0228914215450133e-231], N[(x + N[(y * N[(N[(z - t), $MachinePrecision] * N[(1.0 / N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.865968207475801e-234], N[(x + N[(N[(y * N[(z - a), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(y + N[(N[(z - t), $MachinePrecision] * N[(y / N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := \left(x + y\right) - \frac{y \cdot \left(z - t\right)}{a - t}\\
\mathbf{if}\;t_1 \leq -1.0228914215450133 \cdot 10^{-231}:\\
\;\;\;\;x + \mathsf{fma}\left(y, \left(z - t\right) \cdot \frac{1}{t - a}, y\right)\\

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

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


\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.0
Target8.3
Herbie5.4
\[\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 (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -1.0228914215450133e-231

    1. Initial program 12.0

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

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

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

    if -1.0228914215450133e-231 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 1.8659682074758e-234

    1. Initial program 54.8

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

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

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

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

    if 1.8659682074758e-234 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 12.1

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

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

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

      \[\leadsto x + \color{blue}{\left(y + \frac{y}{t - a} \cdot \left(z - t\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.4

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

Reproduce

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