Average Error: 16.6 → 6.7
Time: 10.5s
Precision: binary64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := x + \frac{y}{t} \cdot \left(z - a\right)\\ \mathbf{if}\;t \leq -1.294458439019683 \cdot 10^{+97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.3862866475908086 \cdot 10^{-258}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \mathbf{elif}\;t \leq 2.424014653994123 \cdot 10^{+20}:\\ \;\;\;\;y + \left(x + \frac{t - z}{\frac{a - t}{y}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := x + \frac{y}{t} \cdot \left(z - a\right)\\
\mathbf{if}\;t \leq -1.294458439019683 \cdot 10^{+97}:\\
\;\;\;\;t_1\\

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

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\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 t) (- z a)))))
   (if (<= t -1.294458439019683e+97)
     t_1
     (if (<= t 2.3862866475908086e-258)
       (+ x (fma y (/ (- t z) (- a t)) y))
       (if (<= t 2.424014653994123e+20)
         (+ y (+ x (/ (- t z) (/ (- a t) y))))
         t_1)))))
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 / t) * (z - a));
	double tmp;
	if (t <= -1.294458439019683e+97) {
		tmp = t_1;
	} else if (t <= 2.3862866475908086e-258) {
		tmp = x + fma(y, ((t - z) / (a - t)), y);
	} else if (t <= 2.424014653994123e+20) {
		tmp = y + (x + ((t - z) / ((a - t) / y)));
	} else {
		tmp = 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

Original16.6
Target8.8
Herbie6.7
\[\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.294458439019683e97 or 242401465399412294000 < t

    1. Initial program 28.5

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

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

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

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

    if -1.294458439019683e97 < t < 2.3862866475908086e-258

    1. Initial program 8.0

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

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

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

    if 2.3862866475908086e-258 < t < 242401465399412294000

    1. Initial program 6.4

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -1.294458439019683 \cdot 10^{+97}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - a\right)\\ \mathbf{elif}\;t \leq 2.3862866475908086 \cdot 10^{-258}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \mathbf{elif}\;t \leq 2.424014653994123 \cdot 10^{+20}:\\ \;\;\;\;y + \left(x + \frac{t - z}{\frac{a - t}{y}}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - a\right)\\ \end{array} \]

Reproduce

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