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

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

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


\end{array}

Error

Target

Original3.0
Target1.8
Herbie0.5
\[\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) < -4.99999999999999992e212

    1. Initial program 13.0

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

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

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

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

      \[\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 (/.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x)) t) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 (*.f64 -1 x) (*.f64 t z))): 54 points increase in error, 49 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 -4.99999999999999992e212 < (*.f64 z t) < 4.9999999999999995e201

    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 4.9999999999999995e201 < (*.f64 z t)

    1. Initial program 12.0

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

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

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

      \[\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)))): 4 points increase in error, 3 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)))): 1 points increase in error, 0 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))))): 14 points increase in error, 7 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))))): 26 points increase in error, 8 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))))): 7 points increase in error, 9 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))))): 23 points increase in error, 24 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
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost1608
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+212}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+201}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t} \cdot \left(\frac{-1}{z} + \frac{\frac{-1}{z}}{z} \cdot \frac{y}{t}\right)\\ \end{array} \]
Alternative 2
Error1.0
Cost968
\[\begin{array}{l} t_1 := \frac{\frac{-x}{t}}{z}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+212}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+136}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error19.3
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{z}}{t}\\ \mathbf{if}\;t \leq -7.476464447548453 \cdot 10^{-16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.938703665817206 \cdot 10^{-132}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 2.4568761371188427 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.90939663319294 \cdot 10^{+91}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error19.3
Cost912
\[\begin{array}{l} t_1 := \frac{\frac{-x}{z}}{t}\\ \mathbf{if}\;t \leq -7.476464447548453 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;t \leq 7.938703665817206 \cdot 10^{-132}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 2.4568761371188427 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.90939663319294 \cdot 10^{+91}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error19.2
Cost912
\[\begin{array}{l} \mathbf{if}\;t \leq -7.476464447548453 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{-x}{t}}{z}\\ \mathbf{elif}\;t \leq 7.938703665817206 \cdot 10^{-132}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 2.4568761371188427 \cdot 10^{-107}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;t \leq 9.90939663319294 \cdot 10^{+91}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \end{array} \]
Alternative 6
Error27.8
Cost584
\[\begin{array}{l} t_1 := \frac{x}{z \cdot t}\\ \mathbf{if}\;z \leq -2.1144801066823753 \cdot 10^{+174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.15840530761449 \cdot 10^{-84}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error27.3
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1144801066823753 \cdot 10^{+174}:\\ \;\;\;\;\frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;z \leq 1.15840530761449 \cdot 10^{-84}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z \cdot t}\\ \end{array} \]
Alternative 8
Error30.3
Cost192
\[\frac{x}{y} \]

Error

Reproduce

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