Average Error: 3.0 → 1.6
Time: 6.4s
Precision: binary64
Cost: 7044
\[ \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 -4 \cdot 10^{+250}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (* z t) -4e+250) (/ (/ (- x) t) z) (/ x (fma (- z) t y))))
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) <= -4e+250) {
		tmp = (-x / t) / z;
	} else {
		tmp = x / fma(-z, t, y);
	}
	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) <= -4e+250)
		tmp = Float64(Float64(Float64(-x) / t) / z);
	else
		tmp = Float64(x / fma(Float64(-z), t, y));
	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], -4e+250], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], N[(x / N[((-z) * t + y), $MachinePrecision]), $MachinePrecision]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+250}:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\


\end{array}

Error

Target

Original3.0
Target1.8
Herbie1.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 2 regimes
  2. if (*.f64 z t) < -3.9999999999999997e250

    1. Initial program 15.4

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

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

      \[\leadsto \color{blue}{\frac{\frac{-x}{t}}{z}} \]
      Proof
      (/.f64 (/.f64 (neg.f64 x) t) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 (neg.f64 x) (*.f64 t z))): 44 points increase in error, 47 points decrease in error
      (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)) (*.f64 t z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 x (*.f64 t z)))): 0 points increase in error, 0 points decrease in error

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

    1. Initial program 1.7

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

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

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

Alternatives

Alternative 1
Error1.6
Cost708
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+250}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \end{array} \]
Alternative 2
Error17.3
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -255000000:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 1.08 \cdot 10^{+30}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error18.5
Cost648
\[\begin{array}{l} t_1 := \frac{\frac{-x}{z}}{t}\\ \mathbf{if}\;t \leq -1.25 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+75}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error27.5
Cost584
\[\begin{array}{l} t_1 := \frac{x}{z \cdot t}\\ \mathbf{if}\;t \leq -9.8 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{+132}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error27.0
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -9.8 \cdot 10^{+14}:\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{elif}\;t \leq 1.16 \cdot 10^{+135}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z}\\ \end{array} \]
Alternative 6
Error30.1
Cost192
\[\frac{x}{y} \]

Error

Reproduce

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