Average Error: 9.7 → 0.1
Time: 11.0s
Precision: binary64
Cost: 7298
Math TeX FPCore C \[\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;
}
Try it out Enter valid numbers for all inputs
Target Original 9.7 Target 0.2 Herbie 0.1
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]
Alternatives Alternative 1 Error 33.1 Cost 39296
\[\sqrt[3]{\frac{2}{{x}^{3}}} \cdot \left(\sqrt[3]{\frac{2}{{x}^{3}}} \cdot \sqrt[3]{\frac{2}{{x}^{3}}}\right)\]
Alternative 2 Error 26.0 Cost 33472
\[\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 Error 43.9 Cost 27200
\[\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 Error 43.7 Cost 27200
\[\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 Error 48.4 Cost 26048
\[\frac{\frac{2}{\sqrt{{x}^{3}}}}{\sqrt{{x}^{3}}}\]
Alternative 6 Error 10.4 Cost 22208
\[\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 Error 26.2 Cost 21440
\[\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 Error 25.1 Cost 20800
\[\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 Error 25.0 Cost 20672
\[\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 Error 33.0 Cost 19904
\[\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{x \cdot x} \cdot \frac{\sqrt[3]{2}}{x}\]
Alternative 11 Error 52.3 Cost 16576
\[\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 Error 46.5 Cost 16192
\[\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 Error 52.3 Cost 15168
\[\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 Error 25.0 Cost 14144
\[\left(\sqrt{\frac{1}{x + 1}} \cdot \sqrt{\frac{1}{x + 1}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
Alternative 15 Error 26.0 Cost 14144
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}\right)\]
Alternative 16 Error 25.4 Cost 14016
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \frac{\frac{1}{\sqrt{x + 1}}}{\sqrt{x + 1}}\right)\]
Alternative 17 Error 29.3 Cost 13824
\[\frac{1}{x - 1} + \left(\sqrt[3]{{\left(\frac{1}{x + 1}\right)}^{3}} - \frac{2}{x}\right)\]
Alternative 18 Error 51.1 Cost 13824
\[\frac{1}{x - 1} + \sqrt[3]{{\left(\frac{1}{x + 1} - \frac{2}{x}\right)}^{3}}\]
Alternative 19 Error 31.7 Cost 13824
\[\sqrt[3]{{\left(\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)}^{3}}\]
Alternative 20 Error 47.7 Cost 13760
\[\frac{1}{x - 1} + e^{\log \left(\frac{1}{x + 1} - \frac{2}{x}\right)}\]
Alternative 21 Error 61.5 Cost 13760
\[\frac{1}{x - 1} + \log \left(e^{\frac{1}{x + 1} - \frac{2}{x}}\right)\]
Alternative 22 Error 27.8 Cost 13760
\[e^{\log \left(\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)}\]
Alternative 23 Error 42.1 Cost 13760
\[\log \left(e^{\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)}\right)\]
Alternative 24 Error 48.3 Cost 13504
\[\frac{1}{x \cdot \sqrt{x}} \cdot \frac{2}{x \cdot \sqrt{x}}\]
Alternative 25 Error 32.8 Cost 13376
\[\frac{\sqrt{2}}{x \cdot x} \cdot \frac{\sqrt{2}}{x}\]
Alternative 26 Error 48.3 Cost 13376
\[\frac{2}{{x}^{1.5}} \cdot \frac{1}{{x}^{1.5}}\]
Alternative 27 Error 48.3 Cost 13248
\[\frac{\frac{2}{{x}^{1.5}}}{{x}^{1.5}}\]
Alternative 28 Error 39.6 Cost 13056
\[\sqrt[3]{\frac{8}{{x}^{9}}}\]
Alternative 29 Error 30.3 Cost 7936
\[\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 Error 25.2 Cost 7808
\[\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 Error 32.9 Cost 6656
\[\frac{2}{{x}^{3}}\]
Alternative 32 Error 27.4 Cost 2880
\[\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 Error 29.2 Cost 2496
\[\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 Error 44.1 Cost 1984
\[\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 Error 25.2 Cost 1600
\[\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 Error 26.1 Cost 1344
\[\frac{1}{x - 1} + \left(\frac{-2}{x} + \left(x - 1\right) \cdot \frac{1}{x \cdot x + -1}\right)\]
Alternative 37 Error 25.7 Cost 1216
\[\frac{1}{x - 1} + \frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)}\]
Alternative 38 Error 9.7 Cost 960
\[\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\]
Alternative 39 Error 36.5 Cost 576
\[\frac{1}{x - 1} + \frac{-1}{x}\]
Alternative 40 Error 32.8 Cost 576
\[\frac{2}{x} \cdot \frac{1}{x \cdot x}\]
Alternative 41 Error 32.7 Cost 448
\[\frac{\frac{2}{x \cdot x}}{x}\]
Alternative 42 Error 31.0 Cost 448
\[\frac{-2}{x} + x \cdot -2\]
Alternative 43 Error 32.7 Cost 448
\[\frac{\frac{2}{x}}{x \cdot x}\]
Alternative 44 Error 30.2 Cost 192
\[\frac{-2}{x}\]
Alternative 45 Error 61.9 Cost 64
\[1\]
Alternative 46 Error 41.9 Cost 64
\[0\]
Alternative 47 Error 61.9 Cost 64
\[-1\]
Error Derivation Split input into 3 regimes if x < -137437521.367164999 Initial program 19.7
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
Taylor expanded around inf 0.5
\[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
Using strategy rm Applied cube-mult_binary64_2495 0.6
\[\leadsto \frac{2}{\color{blue}{x \cdot \left(x \cdot x\right)}}\]
Applied associate-/r*_binary64_2409 0.1
\[\leadsto \color{blue}{\frac{\frac{2}{x}}{x \cdot x}}\]
Simplified0.1
\[\leadsto \color{blue}{\frac{\frac{2}{x}}{x \cdot x}}\]
if -137437521.367164999 < x < 85378974.072051853 Initial program 0.5
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
Using strategy rm Applied frac-sub_binary64_2474 0.5
\[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}\]
Applied frac-add_binary64_2473 0.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)}}\]
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)}\]
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}}\]
Using strategy rm Applied *-un-lft-identity_binary64_2465 0.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}}\]
Applied unpow3_binary64_2531 0.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}\]
Applied distribute-rgt-out--_binary64_2419 0.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)}}\]
Applied associate-/r*_binary64_2409 0.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}}\]
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}\]
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 Initial program 19.7
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
Taylor expanded around inf 0.4
\[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
Simplified0.4
\[\leadsto \color{blue}{\frac{2}{{x}^{3}}}\]
Recombined 3 regimes into one program. 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))))