Average Error: 14.6 → 0.2
Time: 3.1s
Precision: binary64
Cost: 13704
\[\frac{x}{x \cdot x + 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.306950936890764 \cdot 10^{+21}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 3.7720436768118772:\\ \;\;\;\;\frac{x}{{x}^{4} + -1} \cdot \mathsf{fma}\left(x, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= x -2.306950936890764e+21)
   (/ 1.0 x)
   (if (<= x 3.7720436768118772)
     (* (/ x (+ (pow x 4.0) -1.0)) (fma x x -1.0))
     (/ 1.0 x))))
double code(double x) {
	return x / ((x * x) + 1.0);
}
double code(double x) {
	double tmp;
	if (x <= -2.306950936890764e+21) {
		tmp = 1.0 / x;
	} else if (x <= 3.7720436768118772) {
		tmp = (x / (pow(x, 4.0) + -1.0)) * fma(x, x, -1.0);
	} else {
		tmp = 1.0 / x;
	}
	return tmp;
}
function code(x)
	return Float64(x / Float64(Float64(x * x) + 1.0))
end
function code(x)
	tmp = 0.0
	if (x <= -2.306950936890764e+21)
		tmp = Float64(1.0 / x);
	elseif (x <= 3.7720436768118772)
		tmp = Float64(Float64(x / Float64((x ^ 4.0) + -1.0)) * fma(x, x, -1.0));
	else
		tmp = Float64(1.0 / x);
	end
	return tmp
end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -2.306950936890764e+21], N[(1.0 / x), $MachinePrecision], If[LessEqual[x, 3.7720436768118772], N[(N[(x / N[(N[Power[x, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -2.306950936890764 \cdot 10^{+21}:\\
\;\;\;\;\frac{1}{x}\\

\mathbf{elif}\;x \leq 3.7720436768118772:\\
\;\;\;\;\frac{x}{{x}^{4} + -1} \cdot \mathsf{fma}\left(x, x, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\


\end{array}

Error

Target

Original14.6
Target0.1
Herbie0.2
\[\frac{1}{x + \frac{1}{x}} \]

Derivation

  1. Split input into 2 regimes
  2. if x < -2.3069509368907639e21 or 3.77204367681187724 < x

    1. Initial program 30.8

      \[\frac{x}{x \cdot x + 1} \]
    2. Taylor expanded in x around inf 0.3

      \[\leadsto \color{blue}{\frac{1}{x}} \]

    if -2.3069509368907639e21 < x < 3.77204367681187724

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1} \]
    2. Applied egg-rr0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.306950936890764 \cdot 10^{+21}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 3.7720436768118772:\\ \;\;\;\;\frac{x}{{x}^{4} + -1} \cdot \mathsf{fma}\left(x, x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]

Alternatives

Alternative 1
Error1.1
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -103406897440.48567:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 1.3683424085043775 \cdot 10^{-7}:\\ \;\;\;\;x \cdot \left(1 - x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 2
Error0.2
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8611764585819585 \cdot 10^{+29}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 3.7720436768118772:\\ \;\;\;\;\frac{x}{1 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 3
Error1.1
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -103406897440.48567:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 1.3683424085043775 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 4
Error30.6
Cost64
\[x \]

Error

Reproduce

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

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

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