?

Average Error: 2.7 → 0.4
Time: 9.9s
Precision: binary64
Cost: 7816

?

\[ \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 1.5 \cdot 10^{+187}:\\ \;\;\;\;\frac{x}{\left(y + \mathsf{fma}\left(-z, t, z \cdot t\right)\right) - z \cdot t}\\ \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) 1.5e+187)
     (/ x (- (+ y (fma (- z) t (* z t))) (* z t)))
     (/ (/ 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) <= 1.5e+187) {
		tmp = x / ((y + fma(-z, t, (z * t))) - (z * t));
	} 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) <= 1.5e+187)
		tmp = Float64(x / Float64(Float64(y + fma(Float64(-z), t, Float64(z * t))) - Float64(z * t)));
	else
		tmp = Float64(Float64(x / z) / Float64(-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], 1.5e+187], N[(x / N[(N[(y + N[((-z) * t + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z * t), $MachinePrecision]), $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 1.5 \cdot 10^{+187}:\\
\;\;\;\;\frac{x}{\left(y + \mathsf{fma}\left(-z, t, z \cdot t\right)\right) - z \cdot t}\\

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


\end{array}

Error?

Target

Original2.7
Target1.7
Herbie0.4
\[\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 19.1

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

      \[\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

      [Start]19.1

      \[ -1 \cdot \left({1}^{0.3333333333333333} \cdot \frac{x}{t \cdot z}\right) \]

      mul-1-neg [=>]19.1

      \[ \color{blue}{-{1}^{0.3333333333333333} \cdot \frac{x}{t \cdot z}} \]

      *-commutative [=>]19.1

      \[ -{1}^{0.3333333333333333} \cdot \frac{x}{\color{blue}{z \cdot t}} \]

      associate-*r/ [=>]19.1

      \[ -\color{blue}{\frac{{1}^{0.3333333333333333} \cdot x}{z \cdot t}} \]

      pow-base-1 [=>]19.1

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

      *-lft-identity [=>]19.1

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

      associate-/l/ [<=]0.1

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

    if -inf.0 < (*.f64 z t) < 1.5e187

    1. Initial program 0.1

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

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

    if 1.5e187 < (*.f64 z t)

    1. Initial program 11.0

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

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

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

      [Start]12.9

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

      *-commutative [<=]12.9

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

      associate-*r/ [=>]12.9

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

      neg-mul-1 [<=]12.9

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

      *-commutative [=>]12.9

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

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

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

      [Start]12.9

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

      metadata-eval [<=]12.9

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

      associate-/r* [=>]2.9

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

      times-frac [<=]2.9

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

      *-lft-identity [=>]2.9

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

      neg-mul-1 [<=]2.9

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

      associate-/r* [<=]12.9

      \[ \color{blue}{\frac{x}{t \cdot \left(-z\right)}} \]

      distribute-rgt-neg-out [=>]12.9

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

      *-commutative [=>]12.9

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

      distribute-rgt-neg-in [=>]12.9

      \[ \frac{x}{\color{blue}{z \cdot \left(-t\right)}} \]

      associate-/r* [=>]2.5

      \[ \color{blue}{\frac{\frac{x}{z}}{-t}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error0.4
Cost968
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -\infty:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 1.5 \cdot 10^{+187}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{-t}\\ \end{array} \]
Alternative 2
Error19.1
Cost914
\[\begin{array}{l} \mathbf{if}\;z \leq -3.9 \cdot 10^{+141} \lor \neg \left(z \leq -1.45 \cdot 10^{+86} \lor \neg \left(z \leq -165000000\right) \land z \leq 1.22 \cdot 10^{-120}\right):\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error19.1
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;z \leq -1.85 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{+86}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \leq -17000:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error18.5
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{x}{z}}{-t}\\ \mathbf{if}\;z \leq -1.75 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+86}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \leq -12500000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-120}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]
Alternative 5
Error27.3
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1.65 \cdot 10^{+179} \lor \neg \left(z \leq 135\right):\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 6
Error30.1
Cost192
\[\frac{x}{y} \]

Error

Reproduce?

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