Average Error: 15.0 → 1.0
Time: 1.8s
Precision: binary64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x \cdot x + 1} \leq -7.6031176681605265 \cdot 10^{-289}:\\ \;\;\;\;\frac{\frac{x}{\sqrt{x \cdot x + 1}}}{\sqrt{x \cdot x + 1}}\\ \mathbf{elif}\;\frac{x}{x \cdot x + 1} \leq 0:\\ \;\;\;\;\frac{1}{x} - \frac{1}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{x \cdot x + 1}} \cdot \frac{1}{\sqrt{x \cdot x + 1}}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x \cdot x + 1} \leq -7.6031176681605265 \cdot 10^{-289}:\\
\;\;\;\;\frac{\frac{x}{\sqrt{x \cdot x + 1}}}{\sqrt{x \cdot x + 1}}\\

\mathbf{elif}\;\frac{x}{x \cdot x + 1} \leq 0:\\
\;\;\;\;\frac{1}{x} - \frac{1}{{x}^{3}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\sqrt{x \cdot x + 1}} \cdot \frac{1}{\sqrt{x \cdot x + 1}}\\

\end{array}
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (/ x (+ (* x x) 1.0)) -7.6031176681605265e-289)
   (/ (/ x (sqrt (+ (* x x) 1.0))) (sqrt (+ (* x x) 1.0)))
   (if (<= (/ x (+ (* x x) 1.0)) 0.0)
     (- (/ 1.0 x) (/ 1.0 (pow x 3.0)))
     (* (/ x (sqrt (+ (* x x) 1.0))) (/ 1.0 (sqrt (+ (* x x) 1.0)))))))
double code(double x) {
	return x / ((x * x) + 1.0);
}
double code(double x) {
	double tmp;
	if ((x / ((x * x) + 1.0)) <= -7.6031176681605265e-289) {
		tmp = (x / sqrt((x * x) + 1.0)) / sqrt((x * x) + 1.0);
	} else if ((x / ((x * x) + 1.0)) <= 0.0) {
		tmp = (1.0 / x) - (1.0 / pow(x, 3.0));
	} else {
		tmp = (x / sqrt((x * x) + 1.0)) * (1.0 / sqrt((x * x) + 1.0));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 x (+.f64 (*.f64 x x) 1)) < -7.6031176681605265e-289

    1. Initial program 0.1

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary640.1

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity_binary640.1

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac_binary640.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
    6. Simplified0.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x \cdot x}}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}\]
    7. Simplified0.0

      \[\leadsto \frac{1}{\sqrt{1 + x \cdot x}} \cdot \color{blue}{\frac{x}{\sqrt{1 + x \cdot x}}}\]
    8. Using strategy rm
    9. Applied associate-*l/_binary640.0

      \[\leadsto \color{blue}{\frac{1 \cdot \frac{x}{\sqrt{1 + x \cdot x}}}{\sqrt{1 + x \cdot x}}}\]
    10. Simplified0.0

      \[\leadsto \frac{\color{blue}{\frac{x}{\sqrt{1 + x \cdot x}}}}{\sqrt{1 + x \cdot x}}\]

    if -7.6031176681605265e-289 < (/.f64 x (+.f64 (*.f64 x x) 1)) < -0.0

    1. Initial program 56.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6456.0

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity_binary6456.0

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac_binary6456.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
    6. Simplified56.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x \cdot x}}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}\]
    7. Simplified56.0

      \[\leadsto \frac{1}{\sqrt{1 + x \cdot x}} \cdot \color{blue}{\frac{x}{\sqrt{1 + x \cdot x}}}\]
    8. Taylor expanded around inf 3.8

      \[\leadsto \color{blue}{\frac{1}{x} - \frac{1}{{x}^{3}}}\]

    if -0.0 < (/.f64 x (+.f64 (*.f64 x x) 1))

    1. Initial program 0.1

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary640.1

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity_binary640.1

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac_binary640.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x \cdot x + 1} \leq -7.6031176681605265 \cdot 10^{-289}:\\ \;\;\;\;\frac{\frac{x}{\sqrt{x \cdot x + 1}}}{\sqrt{x \cdot x + 1}}\\ \mathbf{elif}\;\frac{x}{x \cdot x + 1} \leq 0:\\ \;\;\;\;\frac{1}{x} - \frac{1}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{x \cdot x + 1}} \cdot \frac{1}{\sqrt{x \cdot x + 1}}\\ \end{array}\]

Alternatives

Reproduce

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

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

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