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

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

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


\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) < -5e287

    1. Initial program 18.7

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{x}{y - z \cdot t}}\right)}^{3}} \]
    3. Taylor expanded in y around 0 18.7

      \[\leadsto \color{blue}{-1 \cdot \left({1}^{0.3333333333333333} \cdot \frac{x}{t \cdot z}\right)} \]
    4. 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
      (/.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 x t))) z): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (/.f64 x t))) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (/.f64 x t) z))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 t z)))): 50 points increase in error, 49 points decrease in error
      (*.f64 -1 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 x (*.f64 t z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (*.f64 (Rewrite<= pow-base-1_binary64 (pow.f64 1 1/3)) (/.f64 x (*.f64 t z)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.1

      \[\leadsto \color{blue}{\frac{-1}{z} \cdot \frac{x}{t}} \]
    6. Applied egg-rr0.1

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

    if -5e287 < (*.f64 z t) < 5.0000000000000003e299

    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 5.0000000000000003e299 < (*.f64 z t)

    1. Initial program 19.1

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{x}{y - z \cdot t}}\right)}^{3}} \]
    3. Taylor expanded in y around 0 19.1

      \[\leadsto \color{blue}{-1 \cdot \left({1}^{0.3333333333333333} \cdot \frac{x}{t \cdot z}\right)} \]
    4. 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
      (/.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 x t))) z): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (/.f64 x t))) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (/.f64 x t) z))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 t z)))): 50 points increase in error, 49 points decrease in error
      (*.f64 -1 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 x (*.f64 t z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (*.f64 (Rewrite<= pow-base-1_binary64 (pow.f64 1 1/3)) (/.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 -5 \cdot 10^{+287}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+299}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost968
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+287}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+299}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]
Alternative 2
Error19.1
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{z}}{t}\\ \mathbf{if}\;t \leq -6.677250519744025 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.6666977515880187 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 2.0415141205519829 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.0227375745711695 \cdot 10^{+183}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error19.2
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{z}}{t}\\ \mathbf{if}\;t \leq -6.677250519744025 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.6666977515880187 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 2.0415141205519829 \cdot 10^{+152}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;t \leq 6.0227375745711695 \cdot 10^{+183}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.3
Cost648
\[\begin{array}{l} \mathbf{if}\;t \leq -6.677250519744025 \cdot 10^{-102}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;t \leq 1.6666977515880187 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]
Alternative 5
Error27.0
Cost584
\[\begin{array}{l} t_1 := \frac{\frac{x}{t}}{z}\\ \mathbf{if}\;t \leq -1.0664552978003736 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.816848631449851 \cdot 10^{+185}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error27.4
Cost584
\[\begin{array}{l} t_1 := \frac{x}{z \cdot t}\\ \mathbf{if}\;t \leq -1.0664552978003736 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.816848631449851 \cdot 10^{+185}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error30.1
Cost192
\[\frac{x}{y} \]

Error

Reproduce

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