Average Error: 10.5 → 2.0
Time: 6.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}\\ t_3 := \frac{-y}{\frac{t}{z} - a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -1.4270783779407967 \cdot 10^{-308}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2.725755847603695 \cdot 10^{+272}\right):\\ \;\;\;\;t_3\\ \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\\
t_2 := \frac{x - y \cdot z}{t_1}\\
t_3 := \frac{-y}{\frac{t}{z} - a}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq -1.4270783779407967 \cdot 10^{-308}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0 \lor \neg \left(t_2 \leq 2.725755847603695 \cdot 10^{+272}\right):\\
\;\;\;\;t_3\\

\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)))
        (t_2 (/ (- x (* y z)) t_1))
        (t_3 (/ (- y) (- (/ t z) a))))
   (if (<= t_2 (- INFINITY))
     t_3
     (if (<= t_2 -1.4270783779407967e-308)
       t_2
       (if (or (<= t_2 0.0) (not (<= t_2 2.725755847603695e+272)))
         t_3
         (- (/ 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 t_3 = -y / ((t / z) - a);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_3;
	} else if (t_2 <= -1.4270783779407967e-308) {
		tmp = t_2;
	} else if ((t_2 <= 0.0) || !(t_2 <= 2.725755847603695e+272)) {
		tmp = t_3;
	} 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.5
Target1.6
Herbie2.0
\[\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 3 regimes
  2. if (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -inf.0 or -1.4270783779407967e-308 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -0.0 or 2.7257558476036951e272 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z)))

    1. Initial program 39.5

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Using strategy rm
    3. Applied div-inv_binary6439.5

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

      \[\leadsto \left(x - y \cdot z\right) \cdot \color{blue}{\frac{1}{t - z \cdot a}} \]
    5. Taylor expanded around 0 41.6

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    6. Simplified7.3

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

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

    1. Initial program 0.2

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Using strategy rm
    3. Applied clear-num_binary640.4

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

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

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

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

    if -0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 2.7257558476036951e272

    1. Initial program 0.2

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

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

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

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

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

Reproduce

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