Average Error: 10.2 → 5.1
Time: 7.0s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ \mathbf{if}\;\begin{array}{l} t_2 := \frac{x - y \cdot z}{t_1}\\ t_2 \leq -\infty \lor \neg \left(t_2 \leq 1.781182093012614 \cdot 10^{+307}\right) \end{array}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t_1} - \frac{y \cdot z}{t_1}\\ \end{array} \]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
\mathbf{if}\;\begin{array}{l}
t_2 := \frac{x - y \cdot z}{t_1}\\
t_2 \leq -\infty \lor \neg \left(t_2 \leq 1.781182093012614 \cdot 10^{+307}\right)
\end{array}:\\
\;\;\;\;\frac{y}{a}\\

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

Original10.2
Target1.6
Herbie5.1
\[\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 (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -inf.0 or 1.7811820930126139e307 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z)))

    1. Initial program 63.8

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

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

    if -inf.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 1.7811820930126139e307

    1. Initial program 4.0

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied add-cube-cbrt_binary644.9

      \[\leadsto \frac{x - y \cdot z}{\color{blue}{\left(\sqrt[3]{t - a \cdot z} \cdot \sqrt[3]{t - a \cdot z}\right) \cdot \sqrt[3]{t - a \cdot z}}} \]
    3. Applied *-un-lft-identity_binary644.9

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt[3]{t - a \cdot z} \cdot \sqrt[3]{t - a \cdot z}} \cdot \frac{x - y \cdot z}{\sqrt[3]{t - a \cdot z}}} \]
    5. Taylor expanded in x around 0 4.0

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

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

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

Reproduce

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