Average Error: 15.7 → 0.0
Time: 4.4s
Precision: binary64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0053432650789538 \cdot 10^{+55}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 437.17389020921524:\\ \;\;\;\;\frac{x}{1 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} - {x}^{-3}\right) + \frac{1}{{x}^{5}}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1.0053432650789538 \cdot 10^{+55}:\\
\;\;\;\;\frac{1}{x}\\

\mathbf{elif}\;x \leq 437.17389020921524:\\
\;\;\;\;\frac{x}{1 + x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{x} - {x}^{-3}\right) + \frac{1}{{x}^{5}}\\

\end{array}
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= x -1.0053432650789538e+55)
   (/ 1.0 x)
   (if (<= x 437.17389020921524)
     (/ x (+ 1.0 (* x x)))
     (+ (- (/ 1.0 x) (pow x -3.0)) (/ 1.0 (pow x 5.0))))))
double code(double x) {
	return x / ((x * x) + 1.0);
}
double code(double x) {
	double tmp;
	if (x <= -1.0053432650789538e+55) {
		tmp = 1.0 / x;
	} else if (x <= 437.17389020921524) {
		tmp = x / (1.0 + (x * x));
	} else {
		tmp = ((1.0 / x) - pow(x, -3.0)) + (1.0 / pow(x, 5.0));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -1.0053432650789538e55

    1. Initial program 36.6

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

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

    if -1.0053432650789538e55 < x < 437.173890209215244

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]

    if 437.173890209215244 < x

    1. Initial program 31.4

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{x} - \frac{1}{{x}^{3}}\right) + \frac{1}{{x}^{5}}}\]
    4. Using strategy rm
    5. Applied pow-flip_binary64_8340.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0053432650789538 \cdot 10^{+55}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;x \leq 437.17389020921524:\\ \;\;\;\;\frac{x}{1 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} - {x}^{-3}\right) + \frac{1}{{x}^{5}}\\ \end{array}\]

Reproduce

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

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

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