Average Error: 9.7 → 0.1
Time: 11.0s
Precision: binary64
Cost: 7298
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -137437521.367165:\\ \;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\ \mathbf{elif}\;x \leq 85378974.07205185:\\ \;\;\;\;\frac{\frac{x \cdot \left(x + 1\right) + \left(x - 1\right) \cdot \left(x - 2 \cdot \left(x + 1\right)\right)}{x}}{x \cdot x + -1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{3}}\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -137437521.367165:\\
\;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{2}{{x}^{3}}\\

\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 -137437521.367165)
   (/ (/ 2.0 x) (* x x))
   (if (<= x 85378974.07205185)
     (/
      (/ (+ (* x (+ x 1.0)) (* (- x 1.0) (- x (* 2.0 (+ x 1.0))))) x)
      (+ (* x x) -1.0))
     (/ 2.0 (pow x 3.0)))))
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 <= -137437521.367165) {
		tmp = (2.0 / x) / (x * x);
	} else if (x <= 85378974.07205185) {
		tmp = (((x * (x + 1.0)) + ((x - 1.0) * (x - (2.0 * (x + 1.0))))) / x) / ((x * x) + -1.0);
	} else {
		tmp = 2.0 / pow(x, 3.0);
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Alternatives

Alternative 1
Error33.1
Cost39296
\[\sqrt[3]{\frac{2}{{x}^{3}}} \cdot \left(\sqrt[3]{\frac{2}{{x}^{3}}} \cdot \sqrt[3]{\frac{2}{{x}^{3}}}\right)\]
Alternative 2
Error26.0
Cost33472
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\sqrt{x + 1}} \cdot \frac{\sqrt[3]{1}}{\sqrt{x + 1}}\right)\]
Alternative 3
Error43.9
Cost27200
\[\frac{1}{x - 1} + \left(\sqrt{\frac{2}{x}} + \frac{1}{\sqrt{x + 1}}\right) \cdot \left(\frac{1}{\sqrt{x + 1}} - \sqrt{\frac{2}{x}}\right)\]
Alternative 4
Error43.7
Cost27200
\[\frac{1}{x - 1} + \left(\sqrt{\frac{1}{x + 1}} + \sqrt{\frac{2}{x}}\right) \cdot \left(\sqrt{\frac{1}{x + 1}} - \sqrt{\frac{2}{x}}\right)\]
Alternative 5
Error48.4
Cost26048
\[\frac{\frac{2}{\sqrt{{x}^{3}}}}{\sqrt{{x}^{3}}}\]
Alternative 6
Error10.4
Cost22208
\[\sqrt[3]{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)} \cdot \left(\sqrt[3]{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)} \cdot \sqrt[3]{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)}\right)\]
Alternative 7
Error26.2
Cost21440
\[\frac{1}{x - 1} + \sqrt[3]{\frac{1}{x + 1} - \frac{2}{x}} \cdot \left(\sqrt[3]{\frac{1}{x + 1} - \frac{2}{x}} \cdot \sqrt[3]{\frac{1}{x + 1} - \frac{2}{x}}\right)\]
Alternative 8
Error25.1
Cost20800
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{1}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1}} \cdot \frac{1}{\sqrt[3]{x + 1}}\right)\]
Alternative 9
Error25.0
Cost20672
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{\frac{1}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1}}}{\sqrt[3]{x + 1}}\right)\]
Alternative 10
Error33.0
Cost19904
\[\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{x \cdot x} \cdot \frac{\sqrt[3]{2}}{x}\]
Alternative 11
Error52.3
Cost16576
\[\frac{\left(\frac{4}{x \cdot x} + \frac{\frac{1}{x + 1} + \frac{2}{x}}{x + 1}\right) + \left(x - 1\right) \cdot \left({\left(\frac{1}{x + 1}\right)}^{3} - {\left(\frac{2}{x}\right)}^{3}\right)}{\left(x - 1\right) \cdot \left(\frac{4}{x \cdot x} + \frac{\frac{1}{x + 1} + \frac{2}{x}}{x + 1}\right)}\]
Alternative 12
Error46.5
Cost16192
\[\frac{{\left(\frac{1}{x + 1} - \frac{2}{x}\right)}^{3} + {\left(\frac{1}{x - 1}\right)}^{3}}{\frac{\frac{1}{x - 1}}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right) \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) - \frac{1}{x - 1}\right)}\]
Alternative 13
Error52.3
Cost15168
\[\frac{1}{x - 1} + \frac{{\left(\frac{1}{x + 1}\right)}^{3} - {\left(\frac{2}{x}\right)}^{3}}{\frac{4}{x \cdot x} + \frac{\frac{1}{x + 1} + \frac{2}{x}}{x + 1}}\]
Alternative 14
Error25.0
Cost14144
\[\left(\sqrt{\frac{1}{x + 1}} \cdot \sqrt{\frac{1}{x + 1}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
Alternative 15
Error26.0
Cost14144
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}\right)\]
Alternative 16
Error25.4
Cost14016
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{\frac{1}{\sqrt{x + 1}}}{\sqrt{x + 1}}\right)\]
Alternative 17
Error29.3
Cost13824
\[\frac{1}{x - 1} + \left(\sqrt[3]{{\left(\frac{1}{x + 1}\right)}^{3}} - \frac{2}{x}\right)\]
Alternative 18
Error51.1
Cost13824
\[\frac{1}{x - 1} + \sqrt[3]{{\left(\frac{1}{x + 1} - \frac{2}{x}\right)}^{3}}\]
Alternative 19
Error31.7
Cost13824
\[\sqrt[3]{{\left(\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)}^{3}}\]
Alternative 20
Error47.7
Cost13760
\[\frac{1}{x - 1} + e^{\log \left(\frac{1}{x + 1} - \frac{2}{x}\right)}\]
Alternative 21
Error61.5
Cost13760
\[\frac{1}{x - 1} + \log \left(e^{\frac{1}{x + 1} - \frac{2}{x}}\right)\]
Alternative 22
Error27.8
Cost13760
\[e^{\log \left(\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)}\]
Alternative 23
Error42.1
Cost13760
\[\log \left(e^{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)}\right)\]
Alternative 24
Error48.3
Cost13504
\[\frac{1}{x \cdot \sqrt{x}} \cdot \frac{2}{x \cdot \sqrt{x}}\]
Alternative 25
Error32.8
Cost13376
\[\frac{\sqrt{2}}{x \cdot x} \cdot \frac{\sqrt{2}}{x}\]
Alternative 26
Error48.3
Cost13376
\[\frac{2}{{x}^{1.5}} \cdot \frac{1}{{x}^{1.5}}\]
Alternative 27
Error48.3
Cost13248
\[\frac{\frac{2}{{x}^{1.5}}}{{x}^{1.5}}\]
Alternative 28
Error39.6
Cost13056
\[\sqrt[3]{\frac{8}{{x}^{9}}}\]
Alternative 29
Error30.3
Cost7936
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{1}{{x}^{3} + 1} \cdot \left(x \cdot x + \left(1 - x\right)\right)\right)\]
Alternative 30
Error25.2
Cost7808
\[\frac{x \cdot \left(x + 1\right) + \left(x - 1\right) \cdot \left(x - 2 \cdot \left(x + 1\right)\right)}{{x}^{3} - x}\]
Alternative 31
Error32.9
Cost6656
\[\frac{2}{{x}^{3}}\]
Alternative 32
Error27.4
Cost2880
\[\frac{\left(\frac{1}{x + 1} - \frac{2}{x}\right) \cdot \left(\frac{1}{x + 1} - \frac{2}{x}\right) - \frac{\frac{1}{x - 1}}{x - 1}}{\left(\frac{1}{x + 1} - \frac{2}{x}\right) - \frac{1}{x - 1}}\]
Alternative 33
Error29.2
Cost2496
\[\frac{\left(\frac{1}{x + 1} + \frac{2}{x}\right) \cdot \left(1 + \left(x - 1\right) \cdot \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)}{\left(x - 1\right) \cdot \left(\frac{1}{x + 1} + \frac{2}{x}\right)}\]
Alternative 34
Error44.1
Cost1984
\[\frac{1}{x - 1} + \frac{\frac{\frac{1}{x + 1}}{x + 1} - \frac{4}{x \cdot x}}{\frac{1}{x + 1} + \frac{2}{x}}\]
Alternative 35
Error25.2
Cost1600
\[\frac{\frac{x \cdot \left(x + 1\right) + \left(x - 1\right) \cdot \left(x - 2 \cdot \left(x + 1\right)\right)}{x}}{x \cdot x + -1}\]
Alternative 36
Error26.1
Cost1344
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \left(x - 1\right) \cdot \frac{1}{x \cdot x + -1}\right)\]
Alternative 37
Error25.7
Cost1216
\[\frac{1}{x - 1} + \frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)}\]
Alternative 38
Error9.7
Cost960
\[\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\]
Alternative 39
Error36.5
Cost576
\[\frac{1}{x - 1} + \frac{-1}{x}\]
Alternative 40
Error32.8
Cost576
\[\frac{2}{x} \cdot \frac{1}{x \cdot x}\]
Alternative 41
Error32.7
Cost448
\[\frac{\frac{2}{x \cdot x}}{x}\]
Alternative 42
Error31.0
Cost448
\[\frac{-2}{x} + x \cdot -2\]
Alternative 43
Error32.7
Cost448
\[\frac{\frac{2}{x}}{x \cdot x}\]
Alternative 44
Error30.2
Cost192
\[\frac{-2}{x}\]
Alternative 45
Error61.9
Cost64
\[1\]
Alternative 46
Error41.9
Cost64
\[0\]
Alternative 47
Error61.9
Cost64
\[-1\]

Error

Derivation

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

    1. Initial program 19.7

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
    3. Using strategy rm
    4. Applied cube-mult_binary64_24950.6

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

      \[\leadsto \color{blue}{\frac{\frac{2}{x}}{x \cdot x}}\]
    6. Simplified0.1

      \[\leadsto \color{blue}{\frac{\frac{2}{x}}{x \cdot x}}\]

    if -137437521.367164999 < x < 85378974.072051853

    1. Initial program 0.5

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

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

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

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

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\color{blue}{{x}^{3} - x}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity_binary64_24650.0

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{{x}^{3} - \color{blue}{1 \cdot x}}\]
    9. Applied unpow3_binary64_25310.0

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\color{blue}{\left(x \cdot x\right) \cdot x} - 1 \cdot x}\]
    10. Applied distribute-rgt-out--_binary64_24190.0

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\color{blue}{x \cdot \left(x \cdot x - 1\right)}}\]
    11. Applied associate-/r*_binary64_24090.0

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

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

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

    if 85378974.072051853 < x

    1. Initial program 19.7

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
    3. Simplified0.4

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Reproduce

herbie shell --seed 2021022 
(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))))