Average Error: 23.5 → 5.3
Time: 23.1s
Precision: binary64
\[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
\[\begin{array}{l} t_1 := {\left(y - b\right)}^{2}\\ t_2 := \frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}\\ t_3 := \mathsf{fma}\left(\frac{y}{z}, \frac{a}{t_1}, \frac{a}{y - b}\right) - \mathsf{fma}\left(\frac{y}{z}, \frac{x}{y - b}, \mathsf{fma}\left(\frac{y}{z}, \frac{t}{t_1}, \frac{t}{y - b}\right)\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_4 := \frac{\left(x \cdot y + z \cdot t\right) - z \cdot a}{\mathsf{fma}\left(z, b - y, y\right)}\\ \mathbf{if}\;t_2 \leq -4.61931178241969 \cdot 10^{-281}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\begin{array}{l} t_5 := {\left(b - y\right)}^{2}\\ \mathsf{fma}\left(\frac{y}{b - y}, \frac{x}{z}, \mathsf{fma}\left(\frac{a}{t_5}, \frac{y}{z}, \frac{t}{b - y}\right)\right) - \mathsf{fma}\left(\frac{y}{t_5}, \frac{t}{z}, \frac{a}{b - y}\right) \end{array}\\ \mathbf{elif}\;t_2 \leq 1.650311778742995 \cdot 10^{+294}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;\frac{x}{1 - z}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array}\\ \end{array} \]
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\begin{array}{l}
t_1 := {\left(y - b\right)}^{2}\\
t_2 := \frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}\\
t_3 := \mathsf{fma}\left(\frac{y}{z}, \frac{a}{t_1}, \frac{a}{y - b}\right) - \mathsf{fma}\left(\frac{y}{z}, \frac{x}{y - b}, \mathsf{fma}\left(\frac{y}{z}, \frac{t}{t_1}, \frac{t}{y - b}\right)\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_4 := \frac{\left(x \cdot y + z \cdot t\right) - z \cdot a}{\mathsf{fma}\left(z, b - y, y\right)}\\
\mathbf{if}\;t_2 \leq -4.61931178241969 \cdot 10^{-281}:\\
\;\;\;\;t_4\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\begin{array}{l}
t_5 := {\left(b - y\right)}^{2}\\
\mathsf{fma}\left(\frac{y}{b - y}, \frac{x}{z}, \mathsf{fma}\left(\frac{a}{t_5}, \frac{y}{z}, \frac{t}{b - y}\right)\right) - \mathsf{fma}\left(\frac{y}{t_5}, \frac{t}{z}, \frac{a}{b - y}\right)
\end{array}\\

\mathbf{elif}\;t_2 \leq 1.650311778742995 \cdot 10^{+294}:\\
\;\;\;\;t_4\\

\mathbf{elif}\;t_2 \leq \infty:\\
\;\;\;\;\frac{x}{1 - z}\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}\\


\end{array}
(FPCore (x y z t a b)
 :precision binary64
 (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (pow (- y b) 2.0))
        (t_2 (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))
        (t_3
         (-
          (fma (/ y z) (/ a t_1) (/ a (- y b)))
          (fma (/ y z) (/ x (- y b)) (fma (/ y z) (/ t t_1) (/ t (- y b)))))))
   (if (<= t_2 (- INFINITY))
     t_3
     (let* ((t_4 (/ (- (+ (* x y) (* z t)) (* z a)) (fma z (- b y) y))))
       (if (<= t_2 -4.61931178241969e-281)
         t_4
         (if (<= t_2 0.0)
           (let* ((t_5 (pow (- b y) 2.0)))
             (-
              (fma (/ y (- b y)) (/ x z) (fma (/ a t_5) (/ y z) (/ t (- b y))))
              (fma (/ y t_5) (/ t z) (/ a (- b y)))))
           (if (<= t_2 1.650311778742995e+294)
             t_4
             (if (<= t_2 INFINITY) (/ x (- 1.0 z)) t_3))))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = pow((y - b), 2.0);
	double t_2 = ((x * y) + (z * (t - a))) / (y + (z * (b - y)));
	double t_3 = fma((y / z), (a / t_1), (a / (y - b))) - fma((y / z), (x / (y - b)), fma((y / z), (t / t_1), (t / (y - b))));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_3;
	} else {
		double t_4 = (((x * y) + (z * t)) - (z * a)) / fma(z, (b - y), y);
		double tmp_1;
		if (t_2 <= -4.61931178241969e-281) {
			tmp_1 = t_4;
		} else if (t_2 <= 0.0) {
			double t_5 = pow((b - y), 2.0);
			tmp_1 = fma((y / (b - y)), (x / z), fma((a / t_5), (y / z), (t / (b - y)))) - fma((y / t_5), (t / z), (a / (b - y)));
		} else if (t_2 <= 1.650311778742995e+294) {
			tmp_1 = t_4;
		} else if (t_2 <= ((double) INFINITY)) {
			tmp_1 = x / (1.0 - z);
		} else {
			tmp_1 = t_3;
		}
		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

Bits error versus b

Target

Original23.5
Target18.4
Herbie5.3
\[\frac{z \cdot t + y \cdot x}{y + z \cdot \left(b - y\right)} - \frac{a}{\left(b - y\right) + \frac{y}{z}} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < -inf.0 or +inf.0 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y))))

    1. Initial program 64.0

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Taylor expanded in z around -inf 40.3

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

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

    if -inf.0 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < -4.6193117824196899e-281 or 0.0 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < 1.6503117787429951e294

    1. Initial program 0.3

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Taylor expanded in y around 0 0.3

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

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

      \[\leadsto \frac{x \cdot y + z \cdot \color{blue}{\left(t + \left(-a\right)\right)}}{\mathsf{fma}\left(z, b - y, y\right)} \]
    5. Applied distribute-rgt-in_binary640.3

      \[\leadsto \frac{x \cdot y + \color{blue}{\left(t \cdot z + \left(-a\right) \cdot z\right)}}{\mathsf{fma}\left(z, b - y, y\right)} \]
    6. Applied associate-+r+_binary640.3

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

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

    1. Initial program 44.2

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Taylor expanded in z around inf 18.6

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

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

    if 1.6503117787429951e294 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < +inf.0

    1. Initial program 61.9

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Taylor expanded in y around inf 29.7

      \[\leadsto \color{blue}{\frac{x}{1 - z}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.3

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

Reproduce

herbie shell --seed 2022077 
(FPCore (x y z t a b)
  :name "Development.Shake.Progress:decay from shake-0.15.5"
  :precision binary64

  :herbie-target
  (- (/ (+ (* z t) (* y x)) (+ y (* z (- b y)))) (/ a (+ (- b y) (/ y z))))

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