Average Error: 16.3 → 6.7
Time: 9.4s
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 -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \left(t - z\right) \cdot \frac{1}{a - t}, x + y\right)\\ \mathbf{elif}\;t_1 \leq -3.105523126787935 \cdot 10^{-179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\begin{array}{l} t_2 := \frac{y \cdot z}{t}\\ \left(\left(x + \left(1 + \frac{a}{t}\right) \cdot t_2\right) + \left(\frac{a}{t} \cdot \frac{a}{t}\right) \cdot \left(t_2 - y\right)\right) - \frac{y \cdot a}{t} \end{array}\\ \mathbf{else}:\\ \;\;\;\;y + \left(x + y \cdot \frac{t - z}{a - t}\right)\\ \end{array} \]
\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 -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \left(t - z\right) \cdot \frac{1}{a - t}, x + y\right)\\

\mathbf{elif}\;t_1 \leq -3.105523126787935 \cdot 10^{-179}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\begin{array}{l}
t_2 := \frac{y \cdot z}{t}\\
\left(\left(x + \left(1 + \frac{a}{t}\right) \cdot t_2\right) + \left(\frac{a}{t} \cdot \frac{a}{t}\right) \cdot \left(t_2 - y\right)\right) - \frac{y \cdot a}{t}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;y + \left(x + y \cdot \frac{t - z}{a - t}\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 (- INFINITY))
     (fma y (* (- t z) (/ 1.0 (- a t))) (+ x y))
     (if (<= t_1 -3.105523126787935e-179)
       t_1
       (if (<= t_1 0.0)
         (let* ((t_2 (/ (* y z) t)))
           (-
            (+ (+ x (* (+ 1.0 (/ a t)) t_2)) (* (* (/ a t) (/ a t)) (- t_2 y)))
            (/ (* y a) t)))
         (+ y (+ x (* y (/ (- t z) (- a t))))))))))
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 <= -((double) INFINITY)) {
		tmp = fma(y, ((t - z) * (1.0 / (a - t))), (x + y));
	} else if (t_1 <= -3.105523126787935e-179) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		double t_2 = (y * z) / t;
		tmp = ((x + ((1.0 + (a / t)) * t_2)) + (((a / t) * (a / t)) * (t_2 - y))) - ((y * a) / t);
	} else {
		tmp = y + (x + (y * ((t - z) / (a - t))));
	}
	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.3
Target8.7
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 4 regimes
  2. if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0

    1. Initial program 64.0

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

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

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

    if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -3.1055231267879348e-179

    1. Initial program 1.3

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

    if -3.1055231267879348e-179 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0

    1. Initial program 52.8

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

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

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

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

    if 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 12.9

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

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

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

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

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

Reproduce

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