Average Error: 16.9 → 7.6
Time: 10.9s
Precision: binary64
\[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
\[\begin{array}{l} t_1 := x + \frac{y \cdot z}{t}\\ t_2 := \frac{y \cdot b}{t}\\ t_3 := a + t_2\\ t_4 := 1 + t_3\\ t_5 := \frac{t_1}{\left(a + 1\right) + t_2}\\ \mathbf{if}\;t_5 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t_4}, \frac{z}{t}, \frac{x}{a}\right)\\ \mathbf{elif}\;t_5 \leq -2.9537964394486686 \cdot 10^{-297}:\\ \;\;\;\;\frac{-t_1}{-1 - t_3}\\ \mathbf{elif}\;t_5 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{t}{y}, \frac{x}{b}, \frac{z}{b}\right) - \mathsf{fma}\left(\frac{t}{y}, \frac{z}{b \cdot b}, \frac{a \cdot \left(z \cdot t\right)}{y \cdot \left(b \cdot b\right)}\right)\\ \mathbf{elif}\;t_5 \leq 3.129350475855435 \cdot 10^{+285}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{y}{t}, z, x\right)}{t_4}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{b}\\ \end{array} \]
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\begin{array}{l}
t_1 := x + \frac{y \cdot z}{t}\\
t_2 := \frac{y \cdot b}{t}\\
t_3 := a + t_2\\
t_4 := 1 + t_3\\
t_5 := \frac{t_1}{\left(a + 1\right) + t_2}\\
\mathbf{if}\;t_5 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t_4}, \frac{z}{t}, \frac{x}{a}\right)\\

\mathbf{elif}\;t_5 \leq -2.9537964394486686 \cdot 10^{-297}:\\
\;\;\;\;\frac{-t_1}{-1 - t_3}\\

\mathbf{elif}\;t_5 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{y}, \frac{x}{b}, \frac{z}{b}\right) - \mathsf{fma}\left(\frac{t}{y}, \frac{z}{b \cdot b}, \frac{a \cdot \left(z \cdot t\right)}{y \cdot \left(b \cdot b\right)}\right)\\

\mathbf{elif}\;t_5 \leq 3.129350475855435 \cdot 10^{+285}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{y}{t}, z, x\right)}{t_4}\\

\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\


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

Original16.9
Target13.1
Herbie7.6
\[\begin{array}{l} \mathbf{if}\;t < -1.3659085366310088 \cdot 10^{-271}:\\ \;\;\;\;1 \cdot \left(\left(x + \frac{y}{t} \cdot z\right) \cdot \frac{1}{\left(a + 1\right) + \frac{y}{t} \cdot b}\right)\\ \mathbf{elif}\;t < 3.036967103737246 \cdot 10^{-130}:\\ \;\;\;\;\frac{z}{b}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(x + \frac{y}{t} \cdot z\right) \cdot \frac{1}{\left(a + 1\right) + \frac{y}{t} \cdot b}\right)\\ \end{array} \]

Derivation

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

    1. Initial program 64.0

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < -2.95379643944866858e-297

    1. Initial program 0.3

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied add-cube-cbrt_binary640.6

      \[\leadsto \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{\color{blue}{\left(\sqrt[3]{t} \cdot \sqrt[3]{t}\right) \cdot \sqrt[3]{t}}}} \]
    3. Applied times-frac_binary641.7

      \[\leadsto \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \color{blue}{\frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}}} \]
    4. Applied frac-2neg_binary641.7

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

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

    if -2.95379643944866858e-297 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 0.0

    1. Initial program 28.5

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

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

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

    if 0.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 3.12935047585543522e285

    1. Initial program 0.5

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied add-cube-cbrt_binary640.8

      \[\leadsto \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{\color{blue}{\left(\sqrt[3]{t} \cdot \sqrt[3]{t}\right) \cdot \sqrt[3]{t}}}} \]
    3. Applied times-frac_binary642.2

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

      \[\leadsto \frac{x + \color{blue}{\frac{y}{\frac{t}{z}}}}{\left(a + 1\right) + \frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}} \]
    5. Applied *-un-lft-identity_binary645.7

      \[\leadsto \frac{x + \frac{y}{\frac{t}{z}}}{\color{blue}{1 \cdot \left(\left(a + 1\right) + \frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}\right)}} \]
    6. Applied *-un-lft-identity_binary645.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x + \frac{y}{\frac{t}{z}}\right)}}{1 \cdot \left(\left(a + 1\right) + \frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}\right)} \]
    7. Applied times-frac_binary645.7

      \[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{x + \frac{y}{\frac{t}{z}}}{\left(a + 1\right) + \frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}}} \]
    8. Simplified5.7

      \[\leadsto \color{blue}{1} \cdot \frac{x + \frac{y}{\frac{t}{z}}}{\left(a + 1\right) + \frac{y}{\sqrt[3]{t} \cdot \sqrt[3]{t}} \cdot \frac{b}{\sqrt[3]{t}}} \]
    9. Simplified2.2

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

    if 3.12935047585543522e285 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t)))

    1. Initial program 61.9

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

      \[\leadsto \color{blue}{\frac{z}{b}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification7.6

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

Reproduce

herbie shell --seed 2022067 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (if (< t -1.3659085366310088e-271) (* 1.0 (* (+ x (* (/ y t) z)) (/ 1.0 (+ (+ a 1.0) (* (/ y t) b))))) (if (< t 3.036967103737246e-130) (/ z b) (* 1.0 (* (+ x (* (/ y t) z)) (/ 1.0 (+ (+ a 1.0) (* (/ y t) b)))))))

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