Average Error: 23.7 → 5.2
Time: 29.5s
Precision: binary64
\[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
\[\begin{array}{l} t_1 := z \cdot \left(t - a\right)\\ t_2 := \frac{x \cdot y + t_1}{y + z \cdot \left(b - y\right)}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\frac{x}{1 - z}\\ \mathbf{elif}\;t_2 \leq -4.755410386895729 \cdot 10^{-273}:\\ \;\;\;\;\begin{array}{l} t_3 := \left(y + z \cdot b\right) - y \cdot z\\ \left(\frac{z \cdot t}{t_3} + \frac{x \cdot y}{t_3}\right) - \frac{z \cdot a}{t_3} \end{array}\\ \mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 5.6114041823469945 \cdot 10^{+301}\right):\\ \;\;\;\;\begin{array}{l} t_4 := {\left(b - y\right)}^{2}\\ \mathsf{fma}\left(\frac{y}{b - y}, \frac{x}{z}, \mathsf{fma}\left(\frac{a}{t_4}, \frac{y}{z}, \frac{t}{b - y}\right)\right) - \mathsf{fma}\left(\frac{y}{t_4}, \frac{t}{z}, \frac{a}{b - y}\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, t_1\right)}{\mathsf{fma}\left(z, b - y, y\right)}\\ \end{array} \]
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\begin{array}{l}
t_1 := z \cdot \left(t - a\right)\\
t_2 := \frac{x \cdot y + t_1}{y + z \cdot \left(b - y\right)}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\frac{x}{1 - z}\\

\mathbf{elif}\;t_2 \leq -4.755410386895729 \cdot 10^{-273}:\\
\;\;\;\;\begin{array}{l}
t_3 := \left(y + z \cdot b\right) - y \cdot z\\
\left(\frac{z \cdot t}{t_3} + \frac{x \cdot y}{t_3}\right) - \frac{z \cdot a}{t_3}
\end{array}\\

\mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 5.6114041823469945 \cdot 10^{+301}\right):\\
\;\;\;\;\begin{array}{l}
t_4 := {\left(b - y\right)}^{2}\\
\mathsf{fma}\left(\frac{y}{b - y}, \frac{x}{z}, \mathsf{fma}\left(\frac{a}{t_4}, \frac{y}{z}, \frac{t}{b - y}\right)\right) - \mathsf{fma}\left(\frac{y}{t_4}, \frac{t}{z}, \frac{a}{b - y}\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, t_1\right)}{\mathsf{fma}\left(z, b - y, y\right)}\\


\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 (* z (- t a))) (t_2 (/ (+ (* x y) t_1) (+ y (* z (- b y))))))
   (if (<= t_2 (- INFINITY))
     (/ x (- 1.0 z))
     (if (<= t_2 -4.755410386895729e-273)
       (let* ((t_3 (- (+ y (* z b)) (* y z))))
         (- (+ (/ (* z t) t_3) (/ (* x y) t_3)) (/ (* z a) t_3)))
       (if (or (<= t_2 0.0) (not (<= t_2 5.6114041823469945e+301)))
         (let* ((t_4 (pow (- b y) 2.0)))
           (-
            (fma (/ y (- b y)) (/ x z) (fma (/ a t_4) (/ y z) (/ t (- b y))))
            (fma (/ y t_4) (/ t z) (/ a (- b y)))))
         (/ (fma x y t_1) (fma z (- b y) y)))))))
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 = z * (t - a);
	double t_2 = ((x * y) + t_1) / (y + (z * (b - y)));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = x / (1.0 - z);
	} else if (t_2 <= -4.755410386895729e-273) {
		double t_3 = (y + (z * b)) - (y * z);
		tmp = (((z * t) / t_3) + ((x * y) / t_3)) - ((z * a) / t_3);
	} else if ((t_2 <= 0.0) || !(t_2 <= 5.6114041823469945e+301)) {
		double t_4 = pow((b - y), 2.0);
		tmp = fma((y / (b - y)), (x / z), fma((a / t_4), (y / z), (t / (b - y)))) - fma((y / t_4), (t / z), (a / (b - y)));
	} else {
		tmp = fma(x, y, t_1) / fma(z, (b - y), y);
	}
	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.7
Target18.7
Herbie5.2
\[\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

    1. Initial program 64.0

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

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

      \[\leadsto \color{blue}{\frac{x}{1 - z}} \]

    if -inf.0 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < -4.75541038689572916e-273

    1. Initial program 0.3

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

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

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

    if -4.75541038689572916e-273 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < -0.0 or 5.61140418234699452e301 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y))))

    1. Initial program 57.7

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

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

      \[\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)} \]
    4. Simplified8.6

      \[\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 -0.0 < (/.f64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 t a))) (+.f64 y (*.f64 z (-.f64 b y)))) < 5.61140418234699452e301

    1. Initial program 0.3

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

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

    \[\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:\\ \;\;\;\;\frac{x}{1 - z}\\ \mathbf{elif}\;\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \leq -4.755410386895729 \cdot 10^{-273}:\\ \;\;\;\;\left(\frac{z \cdot t}{\left(y + z \cdot b\right) - y \cdot z} + \frac{x \cdot y}{\left(y + z \cdot b\right) - y \cdot z}\right) - \frac{z \cdot a}{\left(y + z \cdot b\right) - y \cdot z}\\ \mathbf{elif}\;\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \leq 0 \lor \neg \left(\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \leq 5.6114041823469945 \cdot 10^{+301}\right):\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(t - a\right)\right)}{\mathsf{fma}\left(z, b - y, y\right)}\\ \end{array} \]

Reproduce

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