Average Error: 2.8 → 0.1
Time: 7.0s
Precision: binary64
Cost: 7304
\[ \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 -\infty:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+288}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (* z t) (- INFINITY))
   (/ (/ (- x) t) z)
   (if (<= (* z t) 2e+288) (/ x (fma (- z) t y)) (/ (/ (- x) z) t))))
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) <= -((double) INFINITY)) {
		tmp = (-x / t) / z;
	} else if ((z * t) <= 2e+288) {
		tmp = x / fma(-z, t, y);
	} else {
		tmp = (-x / z) / t;
	}
	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) <= Float64(-Inf))
		tmp = Float64(Float64(Float64(-x) / t) / z);
	elseif (Float64(z * t) <= 2e+288)
		tmp = Float64(x / fma(Float64(-z), t, y));
	else
		tmp = Float64(Float64(Float64(-x) / z) / t);
	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], (-Infinity)], N[(N[((-x) / t), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+288], N[(x / N[((-z) * t + y), $MachinePrecision]), $MachinePrecision], N[(N[((-x) / z), $MachinePrecision] / t), $MachinePrecision]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty:\\
\;\;\;\;\frac{\frac{-x}{t}}{z}\\

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

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


\end{array}

Error

Target

Original2.8
Target1.7
Herbie0.1
\[\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) < -inf.0

    1. Initial program 20.4

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

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

      \[\leadsto \color{blue}{\frac{\frac{-x}{z}}{t}} \]
      Proof
      (/.f64 (/.f64 (neg.f64 x) z) t): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 (neg.f64 x) (*.f64 z t))): 66 points increase in error, 47 points decrease in error
      (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)) (*.f64 z t)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 x) (Rewrite=> *-commutative_binary64 (*.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
    4. Taylor expanded in x around 0 20.4

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

      \[\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))): 74 points increase in error, 36 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 -inf.0 < (*.f64 z t) < 2e288

    1. Initial program 0.1

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

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

    if 2e288 < (*.f64 z t)

    1. Initial program 18.6

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

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

      \[\leadsto \color{blue}{\frac{\frac{-x}{z}}{t}} \]
      Proof
      (/.f64 (/.f64 (neg.f64 x) z) t): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 (neg.f64 x) (*.f64 z t))): 66 points increase in error, 47 points decrease in error
      (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)) (*.f64 z t)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 -1 x) (Rewrite=> *-commutative_binary64 (*.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
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost968
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -\infty:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+288}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]
Alternative 2
Error18.1
Cost912
\[\begin{array}{l} t_1 := \frac{-x}{z \cdot t}\\ \mathbf{if}\;y \leq -4.2 \cdot 10^{+31}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq -14.5:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{-60}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error19.2
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{+56}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq -11:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{-61}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 4
Error19.3
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{+56}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq -13:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-60}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 5
Error27.1
Cost584
\[\begin{array}{l} t_1 := \frac{x}{z \cdot t}\\ \mathbf{if}\;z \leq -7.8 \cdot 10^{+173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-31}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error26.7
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{+168}:\\ \;\;\;\;\frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-31}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z \cdot t}\\ \end{array} \]
Alternative 7
Error29.8
Cost192
\[\frac{x}{y} \]

Error

Reproduce

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