Average Error: 9.3 → 0.3
Time: 13.5min
Precision: binary64
Cost: 8776
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -5.287715659210365 \cdot 10^{-13} \lor \neg \left(\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0\right):\\ \;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -5.287715659210365 \cdot 10^{-13} \lor \neg \left(\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0\right):\\
\;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;2 \cdot {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 (or (<=
          (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0)))
          -5.287715659210365e-13)
         (not (<= (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0))) 0.0)))
   (/
    (+ (* (- x 1.0) (- x (* (+ 1.0 x) 2.0))) (* x (+ 1.0 x)))
    (* (- x 1.0) (* x (+ 1.0 x))))
   (* 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 (((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= -5.287715659210365e-13) || !((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 0.0)) {
		tmp = (((x - 1.0) * (x - ((1.0 + x) * 2.0))) + (x * (1.0 + x))) / ((x - 1.0) * (x * (1.0 + x)));
	} 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.3
Target0.2
Herbie0.3
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]

Alternatives

Alternative 1
Error0.5
Cost8776
\[\begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -5.287715659210365 \cdot 10^{-13} \lor \neg \left(\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0\right):\\ \;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{3}}\\ \end{array}\]
Alternative 2
Error0.5
Cost3976
\[\begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -5.287715659210365 \cdot 10^{-13} \lor \neg \left(\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0\right):\\ \;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{1 + x} + \frac{2}{x}\right) \cdot \frac{2}{x \cdot x}}{\left(x - 1\right) \cdot \left(\frac{1}{1 + x} + \frac{2}{x}\right)}\\ \end{array}\]
Alternative 3
Error9.3
Cost960
\[\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{-1}{1 - x}\]
Alternative 4
Error9.7
Cost1218
\[\begin{array}{l} \mathbf{if}\;x \leq -0.6408571067733551:\\ \;\;\;\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x}\\ \mathbf{elif}\;x \leq 0.6493219239636637:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x - 1} + \frac{-1}{x}\\ \end{array}\]
Alternative 5
Error9.8
Cost1218
\[\begin{array}{l} \mathbf{if}\;x \leq -1.00543971476338:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.6493219239636637:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x - 1} + \frac{-1}{x}\\ \end{array}\]
Alternative 6
Error9.9
Cost1090
\[\begin{array}{l} \mathbf{if}\;x \leq -1.00543971476338:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.0216753732100692:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 7
Error10.1
Cost834
\[\begin{array}{l} \mathbf{if}\;x \leq -1.00543971476338:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.0216753732100692:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 8
Error41.7
Cost64
\[0\]
Alternative 9
Error61.9
Cost64
\[1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -5.287715659e-13 or 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 0.9

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary64_11230.9

      \[\leadsto \left(\frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    4. Applied associate-/l*_binary64_10460.9

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

      \[\leadsto \left(\frac{\sqrt{1}}{\color{blue}{1 + x}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    6. Using strategy rm
    7. Applied inv-pow_binary64_11860.9

      \[\leadsto \left(\frac{\sqrt{1}}{1 + x} - \frac{2}{x}\right) + \color{blue}{{\left(x - 1\right)}^{-1}}\]
    8. Using strategy rm
    9. Applied unpow-1_binary64_11580.9

      \[\leadsto \left(\frac{\sqrt{1}}{1 + x} - \frac{2}{x}\right) + \color{blue}{\frac{1}{x - 1}}\]
    10. Applied frac-sub_binary64_11100.9

      \[\leadsto \color{blue}{\frac{\sqrt{1} \cdot x - \left(1 + x\right) \cdot 2}{\left(1 + x\right) \cdot x}} + \frac{1}{x - 1}\]
    11. Applied frac-add_binary64_11090.5

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

      \[\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(1 + x\right) \cdot x\right) \cdot \left(x - 1\right)}\]
    13. Simplified0.5

      \[\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 - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}}\]
    14. Simplified0.5

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

    if -5.287715659e-13 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0

    1. Initial program 18.6

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-exp-log_binary64_113918.8

      \[\leadsto \color{blue}{e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    4. Simplified18.8

      \[\leadsto e^{\color{blue}{\log \left(\frac{1}{x - 1} + \left(\frac{1}{1 + x} - \frac{2}{x}\right)\right)}}\]
    5. Taylor expanded around -inf 64.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq -5.287715659210365 \cdot 10^{-13} \lor \neg \left(\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 0\right):\\ \;\;\;\;\frac{\left(x - 1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \end{array}\]

Reproduce

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