Average Error: 9.9 → 0.8
Time: 3.4s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1}\\ \mathbf{if}\;t_0 \leq -13484.940053211456 \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\ \end{array} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1}\\
\mathbf{if}\;t_0 \leq -13484.940053211456 \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\


\end{array}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0)))))
   (if (or (<= t_0 -13484.940053211456) (not (<= t_0 0.0)))
     t_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 t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0));
	double tmp;
	if ((t_0 <= -13484.940053211456) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = (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.8
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -13484.940053211456 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} \]

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

    1. Initial program 19.0

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}} \]
    3. Applied cube-mult_binary641.1

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

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

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

Reproduce

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