Average Error: 10.9 → 5.6
Time: 9.0s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right) - \frac{x}{z \cdot a}\\ \mathbf{elif}\;t_2 \leq -5.637 \cdot 10^{-320}:\\ \;\;\;\;\frac{x}{t_1} - \frac{y \cdot z}{t_1}\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{1}{\frac{a}{y}}\\ \mathbf{elif}\;t_2 \leq 2.3386699643334804 \cdot 10^{+298}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x - y \cdot z}{t_1}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right) - \frac{x}{z \cdot a}\\

\mathbf{elif}\;t_2 \leq -5.637 \cdot 10^{-320}:\\
\;\;\;\;\frac{x}{t_1} - \frac{y \cdot z}{t_1}\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{1}{\frac{a}{y}}\\

\mathbf{elif}\;t_2 \leq 2.3386699643334804 \cdot 10^{+298}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{a}\\


\end{array}
(FPCore (x y z t a) :precision binary64 (/ (- x (* y z)) (- t (* a z))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- t (* z a))) (t_2 (/ (- x (* y z)) t_1)))
   (if (<= t_2 (- INFINITY))
     (- (fma (/ y (* a a)) (/ t z) (/ y a)) (/ x (* z a)))
     (if (<= t_2 -5.637e-320)
       (- (/ x t_1) (/ (* y z) t_1))
       (if (<= t_2 0.0)
         (/ 1.0 (/ a y))
         (if (<= t_2 2.3386699643334804e+298) t_2 (/ y a)))))))
double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = t - (z * a);
	double t_2 = (x - (y * z)) / t_1;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma((y / (a * a)), (t / z), (y / a)) - (x / (z * a));
	} else if (t_2 <= -5.637e-320) {
		tmp = (x / t_1) - ((y * z) / t_1);
	} else if (t_2 <= 0.0) {
		tmp = 1.0 / (a / y);
	} else if (t_2 <= 2.3386699643334804e+298) {
		tmp = t_2;
	} else {
		tmp = y / a;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original10.9
Target1.9
Herbie5.6
\[\begin{array}{l} \mathbf{if}\;z < -32113435955957344:\\ \;\;\;\;\frac{x}{t - a \cdot z} - \frac{y}{\frac{t}{z} - a}\\ \mathbf{elif}\;z < 3.5139522372978296 \cdot 10^{-86}:\\ \;\;\;\;\left(x - y \cdot z\right) \cdot \frac{1}{t - a \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - a \cdot z} - \frac{y}{\frac{t}{z} - a}\\ \end{array} \]

Derivation

  1. Split input into 5 regimes
  2. if (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -inf.0

    1. Initial program 64.0

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied clear-num_binary6464.0

      \[\leadsto \color{blue}{\frac{1}{\frac{t - a \cdot z}{x - y \cdot z}}} \]
    3. Taylor expanded in z around inf 33.1

      \[\leadsto \color{blue}{\left(\frac{y \cdot t}{{a}^{2} \cdot z} + \frac{y}{a}\right) - \frac{x}{a \cdot z}} \]
    4. Simplified31.7

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

    if -inf.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -5.63679e-320

    1. Initial program 0.2

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied div-sub_binary640.2

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} - \frac{y \cdot z}{t - a \cdot z}} \]
    3. Simplified0.2

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a}} - \frac{y \cdot z}{t - a \cdot z} \]
    4. Simplified0.2

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{\frac{y \cdot z}{t - z \cdot a}} \]

    if -5.63679e-320 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 0.0

    1. Initial program 25.8

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied clear-num_binary6425.9

      \[\leadsto \color{blue}{\frac{1}{\frac{t - a \cdot z}{x - y \cdot z}}} \]
    3. Taylor expanded in z around inf 24.6

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{y}}} \]

    if 0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 2.33866996433348039e298

    1. Initial program 0.2

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied *-un-lft-identity_binary640.2

      \[\leadsto \frac{x - y \cdot z}{\color{blue}{1 \cdot \left(t - a \cdot z\right)}} \]
    3. Applied add-cube-cbrt_binary641.3

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x - y \cdot z} \cdot \sqrt[3]{x - y \cdot z}\right) \cdot \sqrt[3]{x - y \cdot z}}}{1 \cdot \left(t - a \cdot z\right)} \]
    4. Applied times-frac_binary641.3

      \[\leadsto \color{blue}{\frac{\sqrt[3]{x - y \cdot z} \cdot \sqrt[3]{x - y \cdot z}}{1} \cdot \frac{\sqrt[3]{x - y \cdot z}}{t - a \cdot z}} \]
    5. Simplified1.3

      \[\leadsto \color{blue}{\left(\sqrt[3]{x - y \cdot z} \cdot \sqrt[3]{x - y \cdot z}\right)} \cdot \frac{\sqrt[3]{x - y \cdot z}}{t - a \cdot z} \]
    6. Simplified1.3

      \[\leadsto \left(\sqrt[3]{x - y \cdot z} \cdot \sqrt[3]{x - y \cdot z}\right) \cdot \color{blue}{\frac{\sqrt[3]{x - y \cdot z}}{t - z \cdot a}} \]
    7. Taylor expanded in x around 0 0.2

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} - \frac{y \cdot z}{t - a \cdot z}} \]
    8. Simplified0.2

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]

    if 2.33866996433348039e298 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z)))

    1. Initial program 61.7

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Taylor expanded in z around inf 11.9

      \[\leadsto \color{blue}{\frac{y}{a}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification5.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right) - \frac{x}{z \cdot a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -5.637 \cdot 10^{-320}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y \cdot z}{t - z \cdot a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 0:\\ \;\;\;\;\frac{1}{\frac{a}{y}}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 2.3386699643334804 \cdot 10^{+298}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, A"
  :precision binary64

  :herbie-target
  (if (< z -32113435955957344.0) (- (/ x (- t (* a z))) (/ y (- (/ t z) a))) (if (< z 3.5139522372978296e-86) (* (- x (* y z)) (/ 1.0 (- t (* a z)))) (- (/ x (- t (* a z))) (/ y (- (/ t z) a)))))

  (/ (- x (* y z)) (- t (* a z))))