Average Error: 17.3 → 8.7
Time: 7.9s
Precision: binary64
\[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
\[\begin{array}{l} t_1 := \frac{x}{1 + \left(a + \frac{b \cdot y}{t}\right)}\\ \mathbf{if}\;b \leq -5.847993058855016 \cdot 10^{+71}:\\ \;\;\;\;\frac{z}{b} + t_1\\ \mathbf{elif}\;b \leq 8.803249001269132 \cdot 10^{+124}:\\ \;\;\;\;t_1 + z \cdot \frac{y}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(t, a, t\right)\right)}\\ \mathbf{elif}\;b \leq 5.257518677882633 \cdot 10^{+271}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \frac{z}{t}, x\right)}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\begin{array}{l}
t_1 := \frac{x}{1 + \left(a + \frac{b \cdot y}{t}\right)}\\
\mathbf{if}\;b \leq -5.847993058855016 \cdot 10^{+71}:\\
\;\;\;\;\frac{z}{b} + t_1\\

\mathbf{elif}\;b \leq 8.803249001269132 \cdot 10^{+124}:\\
\;\;\;\;t_1 + z \cdot \frac{y}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(t, a, t\right)\right)}\\

\mathbf{elif}\;b \leq 5.257518677882633 \cdot 10^{+271}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \frac{z}{t}, x\right)}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\\

\mathbf{else}:\\
\;\;\;\;\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)\\


\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 (+ 1.0 (+ a (/ (* b y) t))))))
   (if (<= b -5.847993058855016e+71)
     (+ (/ z b) t_1)
     (if (<= b 8.803249001269132e+124)
       (+ t_1 (* z (/ y (fma y b (fma t a t)))))
       (if (<= b 5.257518677882633e+271)
         (/ (fma y (/ z t) x) (+ 1.0 (fma b (/ y t) a)))
         (-
          (fma (/ t y) (/ x b) (/ z b))
          (fma (/ t y) (/ z (* b b)) (/ (* a (* z t)) (* y (* b 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 / (1.0 + (a + ((b * y) / t)));
	double tmp;
	if (b <= -5.847993058855016e+71) {
		tmp = (z / b) + t_1;
	} else if (b <= 8.803249001269132e+124) {
		tmp = t_1 + (z * (y / fma(y, b, fma(t, a, t))));
	} else if (b <= 5.257518677882633e+271) {
		tmp = fma(y, (z / t), x) / (1.0 + fma(b, (y / t), a));
	} else {
		tmp = fma((t / y), (x / b), (z / b)) - fma((t / y), (z / (b * b)), ((a * (z * t)) / (y * (b * 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

Original17.3
Target13.4
Herbie8.7
\[\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 4 regimes
  2. if b < -5.8479930588550161e71

    1. Initial program 23.8

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Simplified20.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 23.0

      \[\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. Taylor expanded in y around inf 13.8

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

    if -5.8479930588550161e71 < b < 8.8032490012691316e124

    1. Initial program 13.2

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Simplified14.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 z around 0 11.1

      \[\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. Taylor expanded in z around inf 8.6

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

      \[\leadsto \color{blue}{\frac{y \cdot z}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(a, t, t\right)\right)}} + \frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)} \]
    6. Applied associate-/l*_binary647.2

      \[\leadsto \color{blue}{\frac{y}{\frac{\mathsf{fma}\left(y, b, \mathsf{fma}\left(a, t, t\right)\right)}{z}}} + \frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)} \]
    7. Applied associate-/r/_binary644.4

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

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

    if 8.8032490012691316e124 < b < 5.25751867788263e271

    1. Initial program 26.2

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

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

    if 5.25751867788263e271 < b

    1. Initial program 26.9

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

      \[\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 23.4

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

      \[\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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.847993058855016 \cdot 10^{+71}:\\ \;\;\;\;\frac{z}{b} + \frac{x}{1 + \left(a + \frac{b \cdot y}{t}\right)}\\ \mathbf{elif}\;b \leq 8.803249001269132 \cdot 10^{+124}:\\ \;\;\;\;\frac{x}{1 + \left(a + \frac{b \cdot y}{t}\right)} + z \cdot \frac{y}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(t, a, t\right)\right)}\\ \mathbf{elif}\;b \leq 5.257518677882633 \cdot 10^{+271}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \frac{z}{t}, x\right)}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]

Reproduce

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