Average Error: 2.8 → 0.2
Time: 15.9s
Precision: binary64
Cost: 7688
\[ \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{x}{t} \cdot \left(\frac{-1}{z} + \frac{\frac{-1}{z}}{z} \cdot \frac{y}{t}\right)\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+277}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, t \cdot \left(-\frac{z}{x}\right)\right)}\\ \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) (+ (/ -1.0 z) (* (/ (/ -1.0 z) z) (/ y t))))
   (if (<= (* z t) 5e+277)
     (/ x (- y (* z t)))
     (/ 1.0 (fma y (/ 1.0 x) (* t (- (/ z x))))))))
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) * ((-1.0 / z) + (((-1.0 / z) / z) * (y / t)));
	} else if ((z * t) <= 5e+277) {
		tmp = x / (y - (z * t));
	} else {
		tmp = 1.0 / fma(y, (1.0 / x), (t * -(z / x)));
	}
	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(x / t) * Float64(Float64(-1.0 / z) + Float64(Float64(Float64(-1.0 / z) / z) * Float64(y / t))));
	elseif (Float64(z * t) <= 5e+277)
		tmp = Float64(x / Float64(y - Float64(z * t)));
	else
		tmp = Float64(1.0 / fma(y, Float64(1.0 / x), Float64(t * Float64(-Float64(z / x)))));
	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] * N[(N[(-1.0 / z), $MachinePrecision] + N[(N[(N[(-1.0 / z), $MachinePrecision] / z), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+277], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(y * N[(1.0 / x), $MachinePrecision] + N[(t * (-N[(z / x), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty:\\
\;\;\;\;\frac{x}{t} \cdot \left(\frac{-1}{z} + \frac{\frac{-1}{z}}{z} \cdot \frac{y}{t}\right)\\

\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+277}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\

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


\end{array}

Error

Target

Original2.8
Target1.8
Herbie0.2
\[\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 21.0

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

      \[\leadsto \color{blue}{\frac{1}{y - z \cdot t} \cdot x} \]
    3. Taylor expanded in y around 0 23.1

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot x}{{t}^{2} \cdot {z}^{2}} + -1 \cdot \frac{x}{t \cdot z}} \]
    4. Simplified0.1

      \[\leadsto \color{blue}{\frac{x}{t} \cdot \left(\frac{-1}{z} + \frac{\frac{-1}{z}}{z} \cdot \frac{y}{t}\right)} \]
      Proof
      (*.f64 (/.f64 x t) (+.f64 (/.f64 -1 z) (*.f64 (/.f64 (/.f64 -1 z) z) (/.f64 y t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 x t) (+.f64 (/.f64 -1 z) (*.f64 (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 z z))) (/.f64 y t)))): 1 points increase in error, 5 points decrease in error
      (*.f64 (/.f64 x t) (+.f64 (/.f64 -1 z) (*.f64 (/.f64 -1 (Rewrite<= unpow2_binary64 (pow.f64 z 2))) (/.f64 y t)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (*.f64 (*.f64 (/.f64 -1 (pow.f64 z 2)) (/.f64 y t)) (/.f64 x t)))): 0 points increase in error, 1 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (Rewrite<= associate-*r*_binary64 (*.f64 (/.f64 -1 (pow.f64 z 2)) (*.f64 (/.f64 y t) (/.f64 x t))))): 11 points increase in error, 6 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (*.f64 (/.f64 -1 (pow.f64 z 2)) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 t t))))): 27 points increase in error, 6 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (*.f64 (/.f64 -1 (pow.f64 z 2)) (/.f64 (*.f64 y x) (Rewrite<= unpow2_binary64 (pow.f64 t 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (*.f64 y x)) (*.f64 (pow.f64 z 2) (pow.f64 t 2))))): 4 points increase in error, 10 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (/.f64 (*.f64 -1 (*.f64 y x)) (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 t 2) (pow.f64 z 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 -1 z) (/.f64 x t)) (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (*.f64 y x) (*.f64 (pow.f64 t 2) (pow.f64 z 2)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 x) (*.f64 z t))) (*.f64 -1 (/.f64 (*.f64 y x) (*.f64 (pow.f64 t 2) (pow.f64 z 2))))): 12 points increase in error, 20 points decrease in error
      (+.f64 (/.f64 (*.f64 -1 x) (Rewrite<= *-commutative_binary64 (*.f64 t z))) (*.f64 -1 (/.f64 (*.f64 y x) (*.f64 (pow.f64 t 2) (pow.f64 z 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 x (*.f64 t z)))) (*.f64 -1 (/.f64 (*.f64 y x) (*.f64 (pow.f64 t 2) (pow.f64 z 2))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) (*.f64 (pow.f64 t 2) (pow.f64 z 2)))) (*.f64 -1 (/.f64 x (*.f64 t z))))): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (*.f64 z t) < 4.99999999999999982e277

    1. Initial program 0.1

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

    if 4.99999999999999982e277 < (*.f64 z t)

    1. Initial program 18.6

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

      \[\leadsto \color{blue}{\frac{1}{y - z \cdot t} \cdot x} \]
    3. Applied egg-rr18.8

      \[\leadsto \color{blue}{\frac{1}{\frac{y - z \cdot t}{x}}} \]
    4. Applied egg-rr39.0

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(y, \frac{1}{x}, -\frac{z}{x} \cdot \frac{t}{1}\right) + \mathsf{fma}\left(-\frac{z}{x}, \frac{t}{1}, \frac{z}{x} \cdot \frac{t}{1}\right)}} \]
    5. Taylor expanded in z around 0 19.2

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(y, \frac{1}{x}, -\frac{z}{x} \cdot \frac{t}{1}\right) + \color{blue}{0}} \]
      Proof
      0: 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul0-rgt_binary64 (*.f64 z 0)): 0 points increase in error, 0 points decrease in error
      (*.f64 z (Rewrite<= mul0-lft_binary64 (*.f64 0 (/.f64 t x)))): 26 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 (Rewrite<= metadata-eval (+.f64 -1 1)) (/.f64 t x))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 -1 (/.f64 t x)) (/.f64 t x)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error13.1
Cost1424
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 50000000000:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \cdot t \leq 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 3 \cdot 10^{+53}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\frac{x}{z}}{t}\\ \end{array} \]
Alternative 2
Error13.0
Cost1424
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+48}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 50000000000:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \cdot t \leq 10^{+45}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;z \cdot t \leq 3 \cdot 10^{+53}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\frac{x}{z}}{t}\\ \end{array} \]
Alternative 3
Error0.2
Cost1348
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -\infty:\\ \;\;\;\;\frac{x}{t} \cdot \left(\frac{-1}{z} + \frac{\frac{-1}{z}}{z} \cdot \frac{y}{t}\right)\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+238}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]
Alternative 4
Error0.2
Cost968
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -\infty:\\ \;\;\;\;\frac{-\frac{x}{z}}{t}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+238}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \end{array} \]
Alternative 5
Error13.2
Cost904
\[\begin{array}{l} t_1 := \frac{-\frac{x}{z}}{t}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+29}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error24.3
Cost840
\[\begin{array}{l} t_1 := \frac{x}{z \cdot t}\\ \mathbf{if}\;z \cdot t \leq -1.0165297996037791 \cdot 10^{+219}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 9.553077861091088 \cdot 10^{+124}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error29.6
Cost192
\[\frac{x}{y} \]

Error

Reproduce

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