Average Error: 2.8 → 0.6
Time: 3.7s
Precision: binary64
\[ \begin{array}{c}[z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x}{y - z \cdot t} \]
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -9.471189559324319 \cdot 10^{+123}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, t \cdot \frac{-z}{x}\right)}\\ \mathbf{elif}\;z \cdot t \leq 2.8428336325098687 \cdot 10^{+246}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \frac{-t}{x}}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (* z t) -9.471189559324319e+123)
   (/ 1.0 (fma y (/ 1.0 x) (* t (/ (- z) x))))
   (if (<= (* z t) 2.8428336325098687e+246)
     (/ x (- y (* z t)))
     (/ 1.0 (* z (/ (- t) x))))))
double code(double x, double y, double z, double t) {
	return x / (y - (z * t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z * t) <= -9.471189559324319e+123) {
		tmp = 1.0 / fma(y, (1.0 / x), (t * (-z / x)));
	} else if ((z * t) <= 2.8428336325098687e+246) {
		tmp = x / (y - (z * t));
	} else {
		tmp = 1.0 / (z * (-t / x));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x / Float64(y - Float64(z * t)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(z * t) <= -9.471189559324319e+123)
		tmp = Float64(1.0 / fma(y, Float64(1.0 / x), Float64(t * Float64(Float64(-z) / x))));
	elseif (Float64(z * t) <= 2.8428336325098687e+246)
		tmp = Float64(x / Float64(y - Float64(z * t)));
	else
		tmp = Float64(1.0 / Float64(z * Float64(Float64(-t) / x)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], -9.471189559324319e+123], N[(1.0 / N[(y * N[(1.0 / x), $MachinePrecision] + N[(t * N[((-z) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2.8428336325098687e+246], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[((-t) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -9.471189559324319 \cdot 10^{+123}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, t \cdot \frac{-z}{x}\right)}\\

\mathbf{elif}\;z \cdot t \leq 2.8428336325098687 \cdot 10^{+246}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \frac{-t}{x}}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.8
Target1.8
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;x < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;\frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\ \mathbf{elif}\;x < 2.1378306434876444 \cdot 10^{+131}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 z t) < -9.47118955932431904e123

    1. Initial program 8.0

      \[\frac{x}{y - z \cdot t} \]
    2. Applied egg-rr8.0

      \[\leadsto \color{blue}{x \cdot \frac{1}{y - z \cdot t}} \]
    3. Applied egg-rr8.5

      \[\leadsto \color{blue}{\frac{1}{\frac{y - z \cdot t}{x}}} \]
    4. Applied egg-rr32.4

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(y, \frac{1}{x}, -\frac{z}{x} \cdot \frac{t}{1}\right) + \mathsf{fma}\left(-\frac{z}{x}, \frac{t}{1}, \frac{z}{x} \cdot \frac{t}{1}\right)}} \]
    5. Taylor expanded in z around 0 2.4

      \[\leadsto \frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, -\frac{z}{x} \cdot \frac{t}{1}\right) + \color{blue}{0}} \]

    if -9.47118955932431904e123 < (*.f64 z t) < 2.8428336325098687e246

    1. Initial program 0.1

      \[\frac{x}{y - z \cdot t} \]

    if 2.8428336325098687e246 < (*.f64 z t)

    1. Initial program 14.9

      \[\frac{x}{y - z \cdot t} \]
    2. Applied egg-rr14.9

      \[\leadsto \color{blue}{x \cdot \frac{1}{y - z \cdot t}} \]
    3. Applied egg-rr15.1

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

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{t \cdot z}{x}}} \]
    5. Simplified1.7

      \[\leadsto \frac{1}{\color{blue}{\left(-\frac{t}{x}\right) \cdot z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot t \leq -9.471189559324319 \cdot 10^{+123}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, t \cdot \frac{-z}{x}\right)}\\ \mathbf{elif}\;z \cdot t \leq 2.8428336325098687 \cdot 10^{+246}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{z \cdot \frac{-t}{x}}\\ \end{array} \]

Reproduce

herbie shell --seed 2022151 
(FPCore (x y z t)
  :name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (if (< x -1.618195973607049e+50) (/ 1.0 (- (/ y x) (* (/ z x) t))) (if (< x 2.1378306434876444e+131) (/ x (- y (* z t))) (/ 1.0 (- (/ y x) (* (/ z x) t)))))

  (/ x (- y (* z t))))