Average Error: 15.9 → 8.0
Time: 7.9s
Precision: binary64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := \frac{y}{\frac{a - t}{z}}\\ t_2 := \left(\mathsf{fma}\left(\frac{y}{a - t}, t, y\right) + x\right) - t_1\\ \mathbf{if}\;a \leq -1.6426802885300486 \cdot 10^{-35}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_3 := x - \frac{a \cdot y}{t}\\ \mathbf{if}\;a \leq -3.405149008362116 \cdot 10^{-109}:\\ \;\;\;\;t_3 - \frac{y \cdot z}{a - t}\\ \mathbf{elif}\;a \leq -4.3030892615262975 \cdot 10^{-119}:\\ \;\;\;\;\left(y + x\right) - t_1\\ \mathbf{elif}\;a \leq 1.1785256264895896 \cdot 10^{-269}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - a\right)\\ \mathbf{elif}\;a \leq 7.886165021559944 \cdot 10^{+50}:\\ \;\;\;\;t_3 - t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \end{array} \]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := \frac{y}{\frac{a - t}{z}}\\
t_2 := \left(\mathsf{fma}\left(\frac{y}{a - t}, t, y\right) + x\right) - t_1\\
\mathbf{if}\;a \leq -1.6426802885300486 \cdot 10^{-35}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := x - \frac{a \cdot y}{t}\\
\mathbf{if}\;a \leq -3.405149008362116 \cdot 10^{-109}:\\
\;\;\;\;t_3 - \frac{y \cdot z}{a - t}\\

\mathbf{elif}\;a \leq -4.3030892615262975 \cdot 10^{-119}:\\
\;\;\;\;\left(y + x\right) - t_1\\

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

\mathbf{elif}\;a \leq 7.886165021559944 \cdot 10^{+50}:\\
\;\;\;\;t_3 - t_1\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\


\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 (/ y (/ (- a t) z))) (t_2 (- (+ (fma (/ y (- a t)) t y) x) t_1)))
   (if (<= a -1.6426802885300486e-35)
     t_2
     (let* ((t_3 (- x (/ (* a y) t))))
       (if (<= a -3.405149008362116e-109)
         (- t_3 (/ (* y z) (- a t)))
         (if (<= a -4.3030892615262975e-119)
           (- (+ y x) t_1)
           (if (<= a 1.1785256264895896e-269)
             (+ x (* (/ y t) (- z a)))
             (if (<= a 7.886165021559944e+50) (- t_3 t_1) t_2))))))))
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 = y / ((a - t) / z);
	double t_2 = (fma((y / (a - t)), t, y) + x) - t_1;
	double tmp;
	if (a <= -1.6426802885300486e-35) {
		tmp = t_2;
	} else {
		double t_3 = x - ((a * y) / t);
		double tmp_1;
		if (a <= -3.405149008362116e-109) {
			tmp_1 = t_3 - ((y * z) / (a - t));
		} else if (a <= -4.3030892615262975e-119) {
			tmp_1 = (y + x) - t_1;
		} else if (a <= 1.1785256264895896e-269) {
			tmp_1 = x + ((y / t) * (z - a));
		} else if (a <= 7.886165021559944e+50) {
			tmp_1 = t_3 - t_1;
		} else {
			tmp_1 = t_2;
		}
		tmp = tmp_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

Original15.9
Target8.5
Herbie8.0
\[\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 5 regimes
  2. if a < -1.64268028853004857e-35 or 7.8861650215599438e50 < a

    1. Initial program 13.5

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

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

      \[\leadsto \color{blue}{\left(y + \left(\frac{y \cdot t}{a - t} + x\right)\right) - \frac{y \cdot z}{a - t}} \]
    4. Applied associate-/l*_binary649.5

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

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

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

    if -1.64268028853004857e-35 < a < -3.40514900836211584e-109

    1. Initial program 16.8

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

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

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

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

    if -3.40514900836211584e-109 < a < -4.3030892615262975e-119

    1. Initial program 16.5

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

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

      \[\leadsto \color{blue}{\left(y + \left(\frac{y \cdot t}{a - t} + x\right)\right) - \frac{y \cdot z}{a - t}} \]
    4. Applied associate-/l*_binary6414.6

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

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

    if -4.3030892615262975e-119 < a < 1.17852562648959e-269

    1. Initial program 20.2

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

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

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

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

    if 1.17852562648959e-269 < a < 7.8861650215599438e50

    1. Initial program 17.8

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

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

      \[\leadsto \color{blue}{\left(y + \left(\frac{y \cdot t}{a - t} + x\right)\right) - \frac{y \cdot z}{a - t}} \]
    4. Applied associate-/l*_binary6416.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.6426802885300486 \cdot 10^{-35}:\\ \;\;\;\;\left(\mathsf{fma}\left(\frac{y}{a - t}, t, y\right) + x\right) - \frac{y}{\frac{a - t}{z}}\\ \mathbf{elif}\;a \leq -3.405149008362116 \cdot 10^{-109}:\\ \;\;\;\;\left(x - \frac{a \cdot y}{t}\right) - \frac{y \cdot z}{a - t}\\ \mathbf{elif}\;a \leq -4.3030892615262975 \cdot 10^{-119}:\\ \;\;\;\;\left(y + x\right) - \frac{y}{\frac{a - t}{z}}\\ \mathbf{elif}\;a \leq 1.1785256264895896 \cdot 10^{-269}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - a\right)\\ \mathbf{elif}\;a \leq 7.886165021559944 \cdot 10^{+50}:\\ \;\;\;\;\left(x - \frac{a \cdot y}{t}\right) - \frac{y}{\frac{a - t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(\frac{y}{a - t}, t, y\right) + x\right) - \frac{y}{\frac{a - t}{z}}\\ \end{array} \]

Reproduce

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