Average Error: 16.2 → 7.0
Time: 12.2s
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 := 1 + \left(a + t_2\right)\\ t_4 := \frac{t_1}{\left(a + 1\right) + t_2}\\ \mathbf{if}\;t_4 \leq -7.463236257714043 \cdot 10^{-294}:\\ \;\;\;\;\frac{y}{\frac{t \cdot t_3}{z}} + \frac{x}{t_3}\\ \mathbf{elif}\;t_4 \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_4 \leq 1.5790514337013136 \cdot 10^{+300}:\\ \;\;\;\;\frac{t_1}{t_3}\\ \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 := 1 + \left(a + t_2\right)\\
t_4 := \frac{t_1}{\left(a + 1\right) + t_2}\\
\mathbf{if}\;t_4 \leq -7.463236257714043 \cdot 10^{-294}:\\
\;\;\;\;\frac{y}{\frac{t \cdot t_3}{z}} + \frac{x}{t_3}\\

\mathbf{elif}\;t_4 \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_4 \leq 1.5790514337013136 \cdot 10^{+300}:\\
\;\;\;\;\frac{t_1}{t_3}\\

\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 (+ 1.0 (+ a t_2)))
        (t_4 (/ t_1 (+ (+ a 1.0) t_2))))
   (if (<= t_4 -7.463236257714043e-294)
     (+ (/ y (/ (* t t_3) z)) (/ x t_3))
     (if (<= t_4 0.0)
       (-
        (fma (/ t y) (/ x b) (/ z b))
        (fma (/ t y) (/ z (* b b)) (/ (* a (* z t)) (* y (* b b)))))
       (if (<= t_4 1.5790514337013136e+300) (/ t_1 t_3) (/ 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 = 1.0 + (a + t_2);
	double t_4 = t_1 / ((a + 1.0) + t_2);
	double tmp;
	if (t_4 <= -7.463236257714043e-294) {
		tmp = (y / ((t * t_3) / z)) + (x / t_3);
	} else if (t_4 <= 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_4 <= 1.5790514337013136e+300) {
		tmp = t_1 / t_3;
	} 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.2
Target13.5
Herbie7.0
\[\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 (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < -7.46323625771404329e-294

    1. Initial program 7.3

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Taylor expanded in x around 0 5.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)}} \]
    3. Applied associate-/l*_binary644.3

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

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

    1. Initial program 28.6

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

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

      \[\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))) < 1.5790514337013136e300

    1. Initial program 0.5

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied *-un-lft-identity_binary640.5

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x + \frac{y \cdot z}{t}\right)}}{1 \cdot \left(\left(a + 1\right) + \frac{y \cdot b}{t}\right)} \]
    4. Applied times-frac_binary640.5

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

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

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

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

    1. Initial program 56.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \leq -7.463236257714043 \cdot 10^{-294}:\\ \;\;\;\;\frac{y}{\frac{t \cdot \left(1 + \left(a + \frac{y \cdot b}{t}\right)\right)}{z}} + \frac{x}{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 1.5790514337013136 \cdot 10^{+300}:\\ \;\;\;\;\frac{x + \frac{y \cdot z}{t}}{1 + \left(a + \frac{y \cdot b}{t}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{b}\\ \end{array} \]

Reproduce

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