Average Error: 16.9 → 7.9
Time: 8.8s
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 := \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + t_1}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{1 + t_1}, \frac{z}{t}, \frac{x}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\right)\\ \mathbf{elif}\;t_2 \leq -8.531004817 \cdot 10^{-315}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{z + \frac{x \cdot t}{y}}{b}\\ \mathbf{elif}\;t_2 \leq 2.6117734636539717 \cdot 10^{+303}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, \frac{z}{t}, x\right)}{1 + \left(a + t_1\right)}\\ \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)) (+ (+ a 1.0) t_1))))
   (if (<= t_2 (- INFINITY))
     (fma (/ y (+ 1.0 t_1)) (/ z t) (/ x (+ 1.0 (fma b (/ y t) a))))
     (if (<= t_2 -8.531004817e-315)
       t_2
       (if (<= t_2 0.0)
         (/ (+ z (/ (* x t) y)) b)
         (if (<= t_2 2.6117734636539717e+303)
           (/ (fma y (/ z t) x) (+ 1.0 (+ a t_1)))
           (/ 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)) / ((a + 1.0) + t_1);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma((y / (1.0 + t_1)), (z / t), (x / (1.0 + fma(b, (y / t), a))));
	} else if (t_2 <= -8.531004817e-315) {
		tmp = t_2;
	} else if (t_2 <= 0.0) {
		tmp = (z + ((x * t) / y)) / b;
	} else if (t_2 <= 2.6117734636539717e+303) {
		tmp = fma(y, (z / t), x) / (1.0 + (a + t_1));
	} else {
		tmp = 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 = Float64(Float64(y * b) / t)
	t_2 = Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + t_1))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = fma(Float64(y / Float64(1.0 + t_1)), Float64(z / t), Float64(x / Float64(1.0 + fma(b, Float64(y / t), a))));
	elseif (t_2 <= -8.531004817e-315)
		tmp = t_2;
	elseif (t_2 <= 0.0)
		tmp = Float64(Float64(z + Float64(Float64(x * t) / y)) / b);
	elseif (t_2 <= 2.6117734636539717e+303)
		tmp = Float64(fma(y, Float64(z / t), x) / Float64(1.0 + Float64(a + t_1)));
	else
		tmp = 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[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(y / N[(1.0 + t$95$1), $MachinePrecision]), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(x / N[(1.0 + N[(b * N[(y / t), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -8.531004817e-315], t$95$2, If[LessEqual[t$95$2, 0.0], N[(N[(z + N[(N[(x * t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[t$95$2, 2.6117734636539717e+303], N[(N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision] / N[(1.0 + N[(a + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z / b), $MachinePrecision]]]]]]]
\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 := \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + t_1}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{1 + t_1}, \frac{z}{t}, \frac{x}{1 + \mathsf{fma}\left(b, \frac{y}{t}, a\right)}\right)\\

\mathbf{elif}\;t_2 \leq -8.531004817 \cdot 10^{-315}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{z + \frac{x \cdot t}{y}}{b}\\

\mathbf{elif}\;t_2 \leq 2.6117734636539717 \cdot 10^{+303}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, \frac{z}{t}, x\right)}{1 + \left(a + t_1\right)}\\

\mathbf{else}:\\
\;\;\;\;\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.9
Target13.7
Herbie7.9
\[\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. Simplified40.3

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

      \[\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. Simplified24.8

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{1 + \frac{y \cdot b}{t}}}, \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))) < -8.5310048173e-315

    1. Initial program 0.4

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

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

    1. Initial program 29.2

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

      \[\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. Simplified19.7

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

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

    if -0.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 2.61177346365397165e303

    1. Initial program 0.5

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

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

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

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

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

    1. Initial program 63.7

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

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

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

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

Reproduce

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