Average Error: 2.8 → 0.2
Time: 3.2s
Precision: binary64
\[ \begin{array}{c}[z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x}{y - z \cdot t} \]
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+252}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(t, -z, y\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (/ (- x) t) z)))
   (if (<= (* z t) -4e+250)
     t_1
     (if (<= (* z t) 5e+252) (/ x (fma t (- z) y)) t_1))))
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 t_1 = (-x / t) / z;
	double tmp;
	if ((z * t) <= -4e+250) {
		tmp = t_1;
	} else if ((z * t) <= 5e+252) {
		tmp = x / fma(t, -z, y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x / Float64(y - Float64(z * t)))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(Float64(-x) / t) / z)
	tmp = 0.0
	if (Float64(z * t) <= -4e+250)
		tmp = t_1;
	elseif (Float64(z * t) <= 5e+252)
		tmp = Float64(x / fma(t, Float64(-z), y));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -4e+250], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 5e+252], N[(x / N[(t * (-z) + y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
t_1 := \frac{\frac{-x}{t}}{z}\\
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+250}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+252}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(t, -z, y\right)}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original2.8
Target1.9
Herbie0.2
\[\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 2 regimes
  2. if (*.f64 z t) < -3.9999999999999997e250 or 4.9999999999999997e252 < (*.f64 z t)

    1. Initial program 15.1

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

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

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

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

    if -3.9999999999999997e250 < (*.f64 z t) < 4.9999999999999997e252

    1. Initial program 0.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+250}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+252}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(t, -z, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]

Reproduce

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