Average Error: 10.8 → 4.5
Time: 5.6s
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}\\ t_3 := t_2 - y \cdot \frac{z}{t_1}\\ t_4 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_4 \leq -1.3626397029500643 \cdot 10^{-289}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_4 \leq 0:\\ \;\;\;\;\frac{y - \frac{x}{z}}{a}\\ \mathbf{elif}\;t_4 \leq \infty:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2 + \mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right)\\ \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))
        (t_3 (- t_2 (* y (/ z t_1))))
        (t_4 (/ (- x (* y z)) t_1)))
   (if (<= t_4 -1.3626397029500643e-289)
     t_3
     (if (<= t_4 0.0)
       (/ (- y (/ x z)) a)
       (if (<= t_4 INFINITY)
         t_3
         (+ t_2 (fma (/ y (* a a)) (/ t z) (/ y 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 t_1 = t - (z * a);
	double t_2 = x / t_1;
	double t_3 = t_2 - (y * (z / t_1));
	double t_4 = (x - (y * z)) / t_1;
	double tmp;
	if (t_4 <= -1.3626397029500643e-289) {
		tmp = t_3;
	} else if (t_4 <= 0.0) {
		tmp = (y - (x / z)) / a;
	} else if (t_4 <= ((double) INFINITY)) {
		tmp = t_3;
	} else {
		tmp = t_2 + fma((y / (a * a)), (t / z), (y / a));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(a * z)))
end
function code(x, y, z, t, a)
	t_1 = Float64(t - Float64(z * a))
	t_2 = Float64(x / t_1)
	t_3 = Float64(t_2 - Float64(y * Float64(z / t_1)))
	t_4 = Float64(Float64(x - Float64(y * z)) / t_1)
	tmp = 0.0
	if (t_4 <= -1.3626397029500643e-289)
		tmp = t_3;
	elseif (t_4 <= 0.0)
		tmp = Float64(Float64(y - Float64(x / z)) / a);
	elseif (t_4 <= Inf)
		tmp = t_3;
	else
		tmp = Float64(t_2 + fma(Float64(y / Float64(a * a)), Float64(t / z), Float64(y / a)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 - N[(y * N[(z / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$4, -1.3626397029500643e-289], t$95$3, If[LessEqual[t$95$4, 0.0], N[(N[(y - N[(x / z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[t$95$4, Infinity], t$95$3, N[(t$95$2 + N[(N[(y / N[(a * a), $MachinePrecision]), $MachinePrecision] * N[(t / z), $MachinePrecision] + N[(y / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x}{t_1}\\
t_3 := t_2 - y \cdot \frac{z}{t_1}\\
t_4 := \frac{x - y \cdot z}{t_1}\\
\mathbf{if}\;t_4 \leq -1.3626397029500643 \cdot 10^{-289}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_4 \leq 0:\\
\;\;\;\;\frac{y - \frac{x}{z}}{a}\\

\mathbf{elif}\;t_4 \leq \infty:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_2 + \mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original10.8
Target1.8
Herbie4.5
\[\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))) < -1.3626397029500643e-289 or 0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < +inf.0

    1. Initial program 5.2

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

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

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

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{\left(z \cdot \frac{1}{t - z \cdot a}\right)} \cdot y \]
    5. Applied egg-rr2.3

      \[\leadsto \frac{x}{t - z \cdot a} - \left(z \cdot \color{blue}{{\left(\frac{1}{\sqrt[3]{t - z \cdot a}}\right)}^{3}}\right) \cdot y \]
    6. Applied egg-rr1.8

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

    if -1.3626397029500643e-289 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 0.0

    1. Initial program 24.0

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

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

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

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

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

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

    1. Initial program 64.0

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

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

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

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

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{\left(-\left(\frac{y \cdot t}{{a}^{2} \cdot z} + \frac{y}{a}\right)\right)} \]
    6. Simplified0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1.3626397029500643 \cdot 10^{-289}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - y \cdot \frac{z}{t - z \cdot a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 0:\\ \;\;\;\;\frac{y - \frac{x}{z}}{a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq \infty:\\ \;\;\;\;\frac{x}{t - z \cdot a} - y \cdot \frac{z}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a} + \mathsf{fma}\left(\frac{y}{a \cdot a}, \frac{t}{z}, \frac{y}{a}\right)\\ \end{array} \]

Reproduce

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