Average Error: 15.2 → 0.1
Time: 4.0s
Precision: binary64
Cost: 13704
\[\frac{x}{x \cdot x + 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1712206825566497 \cdot 10^{+38}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 23.744287494643725:\\ \;\;\;\;\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 -3.1712206825566497e+38)
   (/ 1.0 x)
   (if (<= x 23.744287494643725)
     (* (/ 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 <= -3.1712206825566497e+38) {
		tmp = 1.0 / x;
	} else if (x <= 23.744287494643725) {
		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 <= -3.1712206825566497e+38)
		tmp = Float64(1.0 / x);
	elseif (x <= 23.744287494643725)
		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, -3.1712206825566497e+38], N[(1.0 / x), $MachinePrecision], If[LessEqual[x, 23.744287494643725], 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 -3.1712206825566497 \cdot 10^{+38}:\\
\;\;\;\;\frac{1}{x}\\

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

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


\end{array}

Error

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -3.17122068255665e38 or 23.744287494643725 < x

    1. Initial program 32.3

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

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

    if -3.17122068255665e38 < x < 23.744287494643725

    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.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.1712206825566497 \cdot 10^{+38}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 23.744287494643725:\\ \;\;\;\;\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 -4279664386679.3286:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 1.9528963858121105 \cdot 10^{-8}:\\ \;\;\;\;x \cdot \left(1 - x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 2
Error0.1
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9227707933154306 \cdot 10^{+39}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 23.744287494643725:\\ \;\;\;\;\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 -4279664386679.3286:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 1.9528963858121105 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 4
Error31.1
Cost64
\[x \]

Error

Reproduce

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

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

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