Average Error: 10.5 → 2.7
Time: 6.6s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1.499229788012242 \cdot 10^{+305} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq -2.933085464116 \cdot 10^{-313} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq 0\right) \land \frac{x - y \cdot z}{t - z \cdot a} \leq 5.1692620256296 \cdot 10^{+238}\right):\\ \;\;\;\;\frac{-y}{\frac{t}{z} - a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \end{array}\]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
\mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1.499229788012242 \cdot 10^{+305} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq -2.933085464116 \cdot 10^{-313} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq 0\right) \land \frac{x - y \cdot z}{t - z \cdot a} \leq 5.1692620256296 \cdot 10^{+238}\right):\\
\;\;\;\;\frac{-y}{\frac{t}{z} - a}\\

\mathbf{else}:\\
\;\;\;\;\frac{x - y \cdot z}{t - z \cdot 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
 (if (or (<= (/ (- x (* y z)) (- t (* z a))) -1.499229788012242e+305)
         (not
          (or (<= (/ (- x (* y z)) (- t (* z a))) -2.933085464116e-313)
              (and (not (<= (/ (- x (* y z)) (- t (* z a))) 0.0))
                   (<=
                    (/ (- x (* y z)) (- t (* z a)))
                    5.1692620256296e+238)))))
   (/ (- y) (- (/ t z) a))
   (/ (- x (* y z)) (- t (* z 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 tmp;
	if ((((x - (y * z)) / (t - (z * a))) <= -1.499229788012242e+305) || !((((x - (y * z)) / (t - (z * a))) <= -2.933085464116e-313) || (!(((x - (y * z)) / (t - (z * a))) <= 0.0) && (((x - (y * z)) / (t - (z * a))) <= 5.1692620256296e+238)))) {
		tmp = -y / ((t / z) - a);
	} else {
		tmp = (x - (y * z)) / (t - (z * a));
	}
	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.7
Herbie2.7
\[\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))) < -1.49922978801224198e305 or -2.93308546412e-313 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -0.0 or 5.16926202562959997e238 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z)))

    1. Initial program 37.7

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

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

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

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

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

    if -1.49922978801224198e305 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -2.93308546412e-313 or -0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 5.16926202562959997e238

    1. Initial program 0.2

      \[\frac{x - y \cdot z}{t - a \cdot z}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1.499229788012242 \cdot 10^{+305} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq -2.933085464116 \cdot 10^{-313} \lor \neg \left(\frac{x - y \cdot z}{t - z \cdot a} \leq 0\right) \land \frac{x - y \cdot z}{t - z \cdot a} \leq 5.1692620256296 \cdot 10^{+238}\right):\\ \;\;\;\;\frac{-y}{\frac{t}{z} - a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \end{array}\]

Reproduce

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