Average Error: 9.2 → 1.9
Time: 8.4s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x}{t_1}\\ \mathbf{if}\;z \leq -1.6905947623455013 \cdot 10^{+59} \lor \neg \left(z \leq 3.727078275686462 \cdot 10^{-93}\right):\\ \;\;\;\;t_2 - \frac{y}{\frac{t}{z} - a}\\ \mathbf{else}:\\ \;\;\;\;t_2 - \frac{z \cdot y}{t_1}\\ \end{array} \]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x}{t_1}\\
\mathbf{if}\;z \leq -1.6905947623455013 \cdot 10^{+59} \lor \neg \left(z \leq 3.727078275686462 \cdot 10^{-93}\right):\\
\;\;\;\;t_2 - \frac{y}{\frac{t}{z} - a}\\

\mathbf{else}:\\
\;\;\;\;t_2 - \frac{z \cdot y}{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))) (t_2 (/ x t_1)))
   (if (or (<= z -1.6905947623455013e+59) (not (<= z 3.727078275686462e-93)))
     (- t_2 (/ y (- (/ t z) a)))
     (- t_2 (/ (* 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 t_2 = x / t_1;
	double tmp;
	if ((z <= -1.6905947623455013e+59) || !(z <= 3.727078275686462e-93)) {
		tmp = t_2 - (y / ((t / z) - a));
	} else {
		tmp = t_2 - ((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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.2
Target1.8
Herbie1.9
\[\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 < -1.690594762345501e59 or 3.727078275686462e-93 < z

    1. Initial program 16.8

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

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} - \frac{y \cdot z}{t - a \cdot z}} \]
    3. Applied associate-/l*_binary6411.3

      \[\leadsto \frac{x}{t - a \cdot z} - \color{blue}{\frac{y}{\frac{t - a \cdot z}{z}}} \]
    4. Taylor expanded in t around 0 2.9

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

    if -1.690594762345501e59 < z < 3.727078275686462e-93

    1. Initial program 0.7

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

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} - \frac{y \cdot z}{t - a \cdot z}} \]
    3. Applied associate-/l*_binary643.0

      \[\leadsto \frac{x}{t - a \cdot z} - \color{blue}{\frac{y}{\frac{t - a \cdot z}{z}}} \]
    4. Taylor expanded in y around 0 0.8

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

      \[\leadsto \frac{x}{t - a \cdot z} - \color{blue}{\frac{z \cdot y}{t - a \cdot z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.6905947623455013 \cdot 10^{+59} \lor \neg \left(z \leq 3.727078275686462 \cdot 10^{-93}\right):\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y}{\frac{t}{z} - a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{z \cdot y}{t - z \cdot a}\\ \end{array} \]

Reproduce

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