Average Error: 16.6 → 8.5
Time: 12.6s
Precision: binary64
\[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y, b, \mathsf{fma}\left(a, t, t\right)\right)\\ t_2 := \frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)}\\ t_3 := \mathsf{fma}\left(\frac{y}{t}, b, a + 1\right)\\ \mathbf{if}\;y \leq -2.92358255090034 \cdot 10^{+218}:\\ \;\;\;\;\frac{z + \frac{x}{\frac{y}{t}}}{b}\\ \mathbf{elif}\;y \leq -4.153248664088116 \cdot 10^{+41}:\\ \;\;\;\;\frac{y}{\frac{t_1}{z}} + t_2\\ \mathbf{elif}\;y \leq 6.457215214193913 \cdot 10^{+92}:\\ \;\;\;\;t_2 + \frac{y \cdot z}{t_1}\\ \mathbf{elif}\;y \leq 1.837792064448072 \cdot 10^{+253}:\\ \;\;\;\;\frac{y}{t_3} \cdot \frac{z}{t} + \frac{x}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 + \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 (fma y b (fma a t t)))
        (t_2 (/ x (+ 1.0 (+ a (/ (* y b) t)))))
        (t_3 (fma (/ y t) b (+ a 1.0))))
   (if (<= y -2.92358255090034e+218)
     (/ (+ z (/ x (/ y t))) b)
     (if (<= y -4.153248664088116e+41)
       (+ (/ y (/ t_1 z)) t_2)
       (if (<= y 6.457215214193913e+92)
         (+ t_2 (/ (* y z) t_1))
         (if (<= y 1.837792064448072e+253)
           (+ (* (/ y t_3) (/ z t)) (/ x t_3))
           (+ t_2 (/ 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 = fma(y, b, fma(a, t, t));
	double t_2 = x / (1.0 + (a + ((y * b) / t)));
	double t_3 = fma((y / t), b, (a + 1.0));
	double tmp;
	if (y <= -2.92358255090034e+218) {
		tmp = (z + (x / (y / t))) / b;
	} else if (y <= -4.153248664088116e+41) {
		tmp = (y / (t_1 / z)) + t_2;
	} else if (y <= 6.457215214193913e+92) {
		tmp = t_2 + ((y * z) / t_1);
	} else if (y <= 1.837792064448072e+253) {
		tmp = ((y / t_3) * (z / t)) + (x / t_3);
	} else {
		tmp = t_2 + (z / b);
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t)))
end
function code(x, y, z, t, a, b)
	t_1 = fma(y, b, fma(a, t, t))
	t_2 = Float64(x / Float64(1.0 + Float64(a + Float64(Float64(y * b) / t))))
	t_3 = fma(Float64(y / t), b, Float64(a + 1.0))
	tmp = 0.0
	if (y <= -2.92358255090034e+218)
		tmp = Float64(Float64(z + Float64(x / Float64(y / t))) / b);
	elseif (y <= -4.153248664088116e+41)
		tmp = Float64(Float64(y / Float64(t_1 / z)) + t_2);
	elseif (y <= 6.457215214193913e+92)
		tmp = Float64(t_2 + Float64(Float64(y * z) / t_1));
	elseif (y <= 1.837792064448072e+253)
		tmp = Float64(Float64(Float64(y / t_3) * Float64(z / t)) + Float64(x / t_3));
	else
		tmp = Float64(t_2 + Float64(z / b));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * b + N[(a * t + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(1.0 + N[(a + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y / t), $MachinePrecision] * b + N[(a + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.92358255090034e+218], N[(N[(z + N[(x / N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[y, -4.153248664088116e+41], N[(N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[y, 6.457215214193913e+92], N[(t$95$2 + N[(N[(y * z), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.837792064448072e+253], N[(N[(N[(y / t$95$3), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision] + N[(x / t$95$3), $MachinePrecision]), $MachinePrecision], N[(t$95$2 + N[(z / b), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, b, \mathsf{fma}\left(a, t, t\right)\right)\\
t_2 := \frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)}\\
t_3 := \mathsf{fma}\left(\frac{y}{t}, b, a + 1\right)\\
\mathbf{if}\;y \leq -2.92358255090034 \cdot 10^{+218}:\\
\;\;\;\;\frac{z + \frac{x}{\frac{y}{t}}}{b}\\

\mathbf{elif}\;y \leq -4.153248664088116 \cdot 10^{+41}:\\
\;\;\;\;\frac{y}{\frac{t_1}{z}} + t_2\\

\mathbf{elif}\;y \leq 6.457215214193913 \cdot 10^{+92}:\\
\;\;\;\;t_2 + \frac{y \cdot z}{t_1}\\

\mathbf{elif}\;y \leq 1.837792064448072 \cdot 10^{+253}:\\
\;\;\;\;\frac{y}{t_3} \cdot \frac{z}{t} + \frac{x}{t_3}\\

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


\end{array}

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.6
Target13.8
Herbie8.5
\[\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 y < -2.92358255090034003e218

    1. Initial program 44.2

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Taylor expanded in x around 0 43.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)}} \]
    3. Simplified30.6

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

      \[\leadsto \color{blue}{\frac{\frac{t \cdot x}{y} + z}{b}} \]
    5. Simplified17.7

      \[\leadsto \color{blue}{\frac{z + \frac{x}{\frac{y}{t}}}{b}} \]

    if -2.92358255090034003e218 < y < -4.1532486640881158e41

    1. Initial program 26.8

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Taylor expanded in x around 0 24.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. Taylor expanded in z around inf 19.9

      \[\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)} \]
    4. Simplified15.8

      \[\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)} \]

    if -4.1532486640881158e41 < y < 6.45721521419391295e92

    1. Initial program 6.2

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

      \[\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. Taylor expanded in a around 0 2.7

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

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

    if 6.45721521419391295e92 < y < 1.83779206444807207e253

    1. Initial program 33.5

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Taylor expanded in x around 0 31.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)}} \]
    3. Simplified20.7

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

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

    if 1.83779206444807207e253 < y

    1. Initial program 41.1

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

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

      \[\leadsto \color{blue}{\frac{z}{b}} + \frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification8.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.92358255090034 \cdot 10^{+218}:\\ \;\;\;\;\frac{z + \frac{x}{\frac{y}{t}}}{b}\\ \mathbf{elif}\;y \leq -4.153248664088116 \cdot 10^{+41}:\\ \;\;\;\;\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)}\\ \mathbf{elif}\;y \leq 6.457215214193913 \cdot 10^{+92}:\\ \;\;\;\;\frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)} + \frac{y \cdot z}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(a, t, t\right)\right)}\\ \mathbf{elif}\;y \leq 1.837792064448072 \cdot 10^{+253}:\\ \;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{y}{t}, b, a + 1\right)} \cdot \frac{z}{t} + \frac{x}{\mathsf{fma}\left(\frac{y}{t}, b, a + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{1 + \left(a + \frac{y \cdot b}{t}\right)} + \frac{z}{b}\\ \end{array} \]

Reproduce

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