Average Error: 15.2 → 0.0
Time: 2.5s
Precision: binary64
\[\frac{x}{x \cdot x + 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x} - {x}^{-3}\\ \mathbf{if}\;x \leq -500000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10000000000:\\ \;\;\;\;\frac{x}{\frac{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}{{\left(\mathsf{fma}\left(x, x, 1\right)\right)}^{-0.5}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (/ 1.0 x) (pow x -3.0))))
   (if (<= x -500000.0)
     t_0
     (if (<= x 10000000000.0)
       (/ x (/ (sqrt (fma x x 1.0)) (pow (fma x x 1.0) -0.5)))
       t_0))))
double code(double x) {
	return x / ((x * x) + 1.0);
}
double code(double x) {
	double t_0 = (1.0 / x) - pow(x, -3.0);
	double tmp;
	if (x <= -500000.0) {
		tmp = t_0;
	} else if (x <= 10000000000.0) {
		tmp = x / (sqrt(fma(x, x, 1.0)) / pow(fma(x, x, 1.0), -0.5));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x)
	return Float64(x / Float64(Float64(x * x) + 1.0))
end
function code(x)
	t_0 = Float64(Float64(1.0 / x) - (x ^ -3.0))
	tmp = 0.0
	if (x <= -500000.0)
		tmp = t_0;
	elseif (x <= 10000000000.0)
		tmp = Float64(x / Float64(sqrt(fma(x, x, 1.0)) / (fma(x, x, 1.0) ^ -0.5)));
	else
		tmp = t_0;
	end
	return tmp
end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(1.0 / x), $MachinePrecision] - N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -500000.0], t$95$0, If[LessEqual[x, 10000000000.0], N[(x / N[(N[Sqrt[N[(x * x + 1.0), $MachinePrecision]], $MachinePrecision] / N[Power[N[(x * x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
t_0 := \frac{1}{x} - {x}^{-3}\\
\mathbf{if}\;x \leq -500000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 10000000000:\\
\;\;\;\;\frac{x}{\frac{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}{{\left(\mathsf{fma}\left(x, x, 1\right)\right)}^{-0.5}}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Target

Original15.2
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}} \]

Derivation

  1. Split input into 2 regimes
  2. if x < -5e5 or 1e10 < x

    1. Initial program 30.9

      \[\frac{x}{x \cdot x + 1} \]
    2. Simplified30.9

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(x, x, 1\right)}} \]
    3. Taylor expanded in x around inf 0.0

      \[\leadsto \color{blue}{\frac{1}{x} - \frac{1}{{x}^{3}}} \]
    4. Applied egg-rr0.0

      \[\leadsto \color{blue}{\left(-{x}^{-3}\right) + \frac{1}{x}} \]

    if -5e5 < x < 1e10

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1} \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(x, x, 1\right)}} \]
    3. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(x, x, 1\right)}} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}} \]
    4. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{x}{\frac{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}{{\left(\mathsf{fma}\left(x, x, 1\right)\right)}^{-0.5}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -500000:\\ \;\;\;\;\frac{1}{x} - {x}^{-3}\\ \mathbf{elif}\;x \leq 10000000000:\\ \;\;\;\;\frac{x}{\frac{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}{{\left(\mathsf{fma}\left(x, x, 1\right)\right)}^{-0.5}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - {x}^{-3}\\ \end{array} \]

Reproduce

herbie shell --seed 2022155 
(FPCore (x)
  :name "x / (x^2 + 1)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ x (/ 1.0 x)))

  (/ x (+ (* x x) 1.0)))