Average Error: 9.9 → 0.1
Time: 2.5s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -148.30320228357058:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x}}{x \cdot x}\right)\\ \mathbf{elif}\;x \leq 105.62426959319559:\\ \;\;\;\;\frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)} + \frac{1}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -148.30320228357058:\\
\;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x}}{x \cdot x}\right)\\

\mathbf{elif}\;x \leq 105.62426959319559:\\
\;\;\;\;\frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)} + \frac{1}{x - 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\

\end{array}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -148.30320228357058)
   (+ (/ 2.0 (pow x 7.0)) (+ (/ 2.0 (pow x 5.0)) (/ (/ 2.0 x) (* x x))))
   (if (<= x 105.62426959319559)
     (+ (/ (- x (* 2.0 (+ x 1.0))) (* x (+ x 1.0))) (/ 1.0 (- x 1.0)))
     (+ (/ 2.0 (pow x 7.0)) (+ (/ 2.0 (pow x 5.0)) (/ (/ 2.0 (* x x)) x))))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -148.30320228357058) {
		tmp = (2.0 / pow(x, 7.0)) + ((2.0 / pow(x, 5.0)) + ((2.0 / x) / (x * x)));
	} else if (x <= 105.62426959319559) {
		tmp = ((x - (2.0 * (x + 1.0))) / (x * (x + 1.0))) + (1.0 / (x - 1.0));
	} else {
		tmp = (2.0 / pow(x, 7.0)) + ((2.0 / pow(x, 5.0)) + ((2.0 / (x * x)) / x));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.9
Target0.3
Herbie0.1
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]

Derivation

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

    1. Initial program 20.6

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around inf 0.5

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)}\]
    4. Using strategy rm
    5. Applied cube-mult_binary640.6

      \[\leadsto \frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{\color{blue}{x \cdot \left(x \cdot x\right)}}\right)\]
    6. Applied associate-/r*_binary640.1

      \[\leadsto \frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \color{blue}{\frac{\frac{2}{x}}{x \cdot x}}\right)\]

    if -148.303202283570585 < x < 105.624269593195592

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied frac-sub_binary640.0

      \[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}\]
    4. Simplified0.0

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

      \[\leadsto \frac{x - \left(1 + x\right) \cdot 2}{\color{blue}{x \cdot \left(1 + x\right)}} + \frac{1}{x - 1}\]

    if 105.624269593195592 < x

    1. Initial program 19.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around inf 0.5

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)}\]
    4. Using strategy rm
    5. Applied unpow3_binary640.5

      \[\leadsto \frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{\color{blue}{\left(x \cdot x\right) \cdot x}}\right)\]
    6. Applied associate-/r*_binary640.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -148.30320228357058:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x}}{x \cdot x}\right)\\ \mathbf{elif}\;x \leq 105.62426959319559:\\ \;\;\;\;\frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)} + \frac{1}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020224 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))