?

Average Accuracy: 95.8% → 99.4%
Time: 13.9s
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^{+181}:\\ \;\;\;\;\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+181) (/ 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+181) {
		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+181)
		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+181], 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^{+181}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\

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


\end{array}

Error?

Target

Original95.8%
Target97.4%
Herbie99.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 69.6%

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

      \[\leadsto \color{blue}{{\left(\frac{y - z \cdot t}{x}\right)}^{-1}} \]
      Proof

      [Start]69.6

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

      clear-num [=>]69.6

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

      inv-pow [=>]69.6

      \[ \color{blue}{{\left(\frac{y - z \cdot t}{x}\right)}^{-1}} \]
    3. Applied egg-rr69.6%

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

      [Start]69.6

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

      unpow-1 [=>]69.6

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

      clear-num [<=]69.6

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

      add-sqr-sqrt [=>]69.6

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

      associate-/r* [=>]69.6

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

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

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

      [Start]69.6

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

      mul-1-neg [=>]69.6

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

      associate-/r* [=>]99.9

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

      distribute-neg-frac [=>]99.9

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

    if -inf.0 < (*.f64 z t) < 1.9999999999999998e181

    1. Initial program 99.8%

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

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

      [Start]99.8

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

      sub-neg [=>]99.8

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

      +-commutative [=>]99.8

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

      distribute-lft-neg-in [=>]99.8

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

      fma-def [=>]99.8

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

    if 1.9999999999999998e181 < (*.f64 z t)

    1. Initial program 84.2%

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

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

      [Start]84.2

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

      sub-neg [=>]84.2

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

      +-commutative [=>]84.2

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

      distribute-lft-neg-in [=>]84.2

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

      fma-def [=>]84.2

      \[ \frac{x}{\color{blue}{\mathsf{fma}\left(-z, t, y\right)}} \]
    3. Taylor expanded in z around inf 81.1%

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

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

      [Start]81.1

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

      associate-*r/ [=>]81.1

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

      neg-mul-1 [<=]81.1

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

      associate-/l/ [<=]96.4

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

    \[\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^{+181}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-z, t, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy79.8%
Cost1164
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;z \cdot t \leq -9 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 10^{-15}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+199}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy79.8%
Cost1164
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -9 \cdot 10^{+14}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 10^{-15}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+181}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]
Alternative 3
Accuracy99.4%
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^{+181}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]
Alternative 4
Accuracy76.9%
Cost905
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{-7} \lor \neg \left(z \cdot t \leq 10^{-15}\right):\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 5
Accuracy62.1%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -4.7 \cdot 10^{+109} \lor \neg \left(z \cdot t \leq 2.2 \cdot 10^{+118}\right):\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 6
Accuracy61.9%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+96} \lor \neg \left(z \cdot t \leq 5 \cdot 10^{+107}\right):\\ \;\;\;\;\frac{\frac{x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 7
Accuracy52.7%
Cost192
\[\frac{x}{y} \]

Error

Reproduce?

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