Average Error: 15.2 → 0.6
Time: 2.1s
Precision: binary64
\[\frac{x}{x \cdot x + 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x} + \left(\frac{1}{{x}^{5}} + \left(\frac{-1}{{x}^{3}} + \frac{-1}{{x}^{7}}\right)\right)\\ \mathbf{if}\;x \leq -2.0638873862964478 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 9.855467159272824 \cdot 10^{-10}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(x, x, 1\right)}\\ \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)
          (+
           (/ 1.0 (pow x 5.0))
           (+ (/ -1.0 (pow x 3.0)) (/ -1.0 (pow x 7.0)))))))
   (if (<= x -2.0638873862964478e+25)
     t_0
     (if (<= x 9.855467159272824e-10) (/ x (fma x x 1.0)) t_0))))
double code(double x) {
	return x / ((x * x) + 1.0);
}
double code(double x) {
	double t_0 = (1.0 / x) + ((1.0 / pow(x, 5.0)) + ((-1.0 / pow(x, 3.0)) + (-1.0 / pow(x, 7.0))));
	double tmp;
	if (x <= -2.0638873862964478e+25) {
		tmp = t_0;
	} else if (x <= 9.855467159272824e-10) {
		tmp = x / fma(x, x, 1.0);
	} 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) + Float64(Float64(1.0 / (x ^ 5.0)) + Float64(Float64(-1.0 / (x ^ 3.0)) + Float64(-1.0 / (x ^ 7.0)))))
	tmp = 0.0
	if (x <= -2.0638873862964478e+25)
		tmp = t_0;
	elseif (x <= 9.855467159272824e-10)
		tmp = Float64(x / fma(x, x, 1.0));
	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[(N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.0638873862964478e+25], t$95$0, If[LessEqual[x, 9.855467159272824e-10], N[(x / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
t_0 := \frac{1}{x} + \left(\frac{1}{{x}^{5}} + \left(\frac{-1}{{x}^{3}} + \frac{-1}{{x}^{7}}\right)\right)\\
\mathbf{if}\;x \leq -2.0638873862964478 \cdot 10^{+25}:\\
\;\;\;\;t_0\\

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

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


\end{array}

Error

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -2.0638873862964478e25 or 9.855467159272824e-10 < x

    1. Initial program 31.1

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \left(\frac{1}{{x}^{3}} + \frac{1}{{x}^{7}}\right)} \]
    4. Simplified1.1

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

    if -2.0638873862964478e25 < x < 9.855467159272824e-10

    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. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.0638873862964478 \cdot 10^{+25}:\\ \;\;\;\;\frac{1}{x} + \left(\frac{1}{{x}^{5}} + \left(\frac{-1}{{x}^{3}} + \frac{-1}{{x}^{7}}\right)\right)\\ \mathbf{elif}\;x \leq 9.855467159272824 \cdot 10^{-10}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(x, x, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(\frac{1}{{x}^{5}} + \left(\frac{-1}{{x}^{3}} + \frac{-1}{{x}^{7}}\right)\right)\\ \end{array} \]

Reproduce

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

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

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