Average Error: 16.5 → 6.3
Time: 9.1s
Precision: binary64
\[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
\[\begin{array}{l} t_1 := \frac{y \cdot b}{t}\\ t_2 := x + \frac{y \cdot z}{t}\\ t_3 := \frac{t_2}{\left(a + 1\right) + t_1}\\ t_4 := 1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)\\ t_5 := \mathsf{fma}\left(\frac{y}{1 + \left(a + t_1\right)}, \frac{z}{t}, \frac{x}{t_4}\right)\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;t_5\\ \mathbf{elif}\;t_3 \leq 7.791730605142854 \cdot 10^{+212}:\\ \;\;\;\;\frac{t_2}{t_4}\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_5\\ \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 := \frac{y \cdot b}{t}\\
t_2 := x + \frac{y \cdot z}{t}\\
t_3 := \frac{t_2}{\left(a + 1\right) + t_1}\\
t_4 := 1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)\\
t_5 := \mathsf{fma}\left(\frac{y}{1 + \left(a + t_1\right)}, \frac{z}{t}, \frac{x}{t_4}\right)\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;t_5\\

\mathbf{elif}\;t_3 \leq 7.791730605142854 \cdot 10^{+212}:\\
\;\;\;\;\frac{t_2}{t_4}\\

\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;t_5\\

\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 (/ (* y b) t))
        (t_2 (+ x (/ (* y z) t)))
        (t_3 (/ t_2 (+ (+ a 1.0) t_1)))
        (t_4 (+ 1.0 (fma b (/ y t) a)))
        (t_5 (fma (/ y (+ 1.0 (+ a t_1))) (/ z t) (/ x t_4))))
   (if (<= t_3 (- INFINITY))
     t_5
     (if (<= t_3 7.791730605142854e+212)
       (/ t_2 t_4)
       (if (<= t_3 INFINITY) t_5 (/ 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 = (y * b) / t;
	double t_2 = x + ((y * z) / t);
	double t_3 = t_2 / ((a + 1.0) + t_1);
	double t_4 = 1.0 + fma(b, (y / t), a);
	double t_5 = fma((y / (1.0 + (a + t_1))), (z / t), (x / t_4));
	double tmp;
	if (t_3 <= -((double) INFINITY)) {
		tmp = t_5;
	} else if (t_3 <= 7.791730605142854e+212) {
		tmp = t_2 / t_4;
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = t_5;
	} 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.5
Target12.8
Herbie6.3
\[\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 3 regimes
  2. if (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < -inf.0 or 7.791730605142854e212 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < +inf.0

    1. Initial program 46.6

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

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

      \[\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)}} \]
    4. Simplified21.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}, \frac{z}{t}, \frac{x}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\right)} \]
    5. Applied fma-udef_binary6421.9

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

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

    if -inf.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 7.791730605142854e212

    1. Initial program 6.3

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

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

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

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

    1. Initial program 64.0

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

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

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

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

Reproduce

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