Average Error: 10.7 → 1.8
Time: 6.8s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ \mathbf{if}\;z \leq -2.9630879677667778 \cdot 10^{+32} \lor \neg \left(z \leq 1.4041294918823914 \cdot 10^{-60}\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{x}{t_1}, \frac{-y}{\frac{t}{z} - a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, x, z \cdot \left(-y\right)\right) + \mathsf{fma}\left(-z, y, z \cdot y\right)}{t_1}\\ \end{array} \]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
\mathbf{if}\;z \leq -2.9630879677667778 \cdot 10^{+32} \lor \neg \left(z \leq 1.4041294918823914 \cdot 10^{-60}\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{x}{t_1}, \frac{-y}{\frac{t}{z} - a}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, x, z \cdot \left(-y\right)\right) + \mathsf{fma}\left(-z, y, z \cdot y\right)}{t_1}\\


\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))))
   (if (or (<= z -2.9630879677667778e+32) (not (<= z 1.4041294918823914e-60)))
     (fma 1.0 (/ x t_1) (/ (- y) (- (/ t z) a)))
     (/ (+ (fma 1.0 x (* z (- y))) (fma (- z) y (* z y))) t_1))))
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 tmp;
	if ((z <= -2.9630879677667778e+32) || !(z <= 1.4041294918823914e-60)) {
		tmp = fma(1.0, (x / t_1), (-y / ((t / z) - a)));
	} else {
		tmp = (fma(1.0, x, (z * -y)) + fma(-z, y, (z * y))) / t_1;
	}
	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.7
Target1.8
Herbie1.8
\[\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 2 regimes
  2. if z < -2.9630879677667778e32 or 1.40412949188239141e-60 < z

    1. Initial program 19.9

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

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

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

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{\frac{y \cdot z}{t - z \cdot a}} \]
    5. Applied *-un-lft-identity_binary6419.9

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

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

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{y} \cdot \frac{z}{t - z \cdot a} \]
    8. Applied *-un-lft-identity_binary6413.1

      \[\leadsto \color{blue}{1 \cdot \frac{x}{t - z \cdot a}} - y \cdot \frac{z}{t - z \cdot a} \]
    9. Applied fma-neg_binary6413.1

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

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

    if -2.9630879677667778e32 < z < 1.40412949188239141e-60

    1. Initial program 0.4

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

      \[\leadsto \frac{\color{blue}{1 \cdot x} - y \cdot z}{t - a \cdot z} \]
    3. Applied prod-diff_binary640.4

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(1, x, -z \cdot y\right) + \mathsf{fma}\left(-z, y, z \cdot y\right)}}{t - a \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.9630879677667778 \cdot 10^{+32} \lor \neg \left(z \leq 1.4041294918823914 \cdot 10^{-60}\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{x}{t - z \cdot a}, \frac{-y}{\frac{t}{z} - a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, x, z \cdot \left(-y\right)\right) + \mathsf{fma}\left(-z, y, z \cdot y\right)}{t - z \cdot a}\\ \end{array} \]

Reproduce

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