Average Error: 10.1 → 0.1
Time: 9.0s
Precision: binary64
Cost: 960
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{\frac{2 + \frac{2}{x}}{-1 - x}}{1 - x \cdot x} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (/ (/ (+ 2.0 (/ 2.0 x)) (- -1.0 x)) (- 1.0 (* x x))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	return ((2.0 + (2.0 / x)) / (-1.0 - x)) / (1.0 - (x * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((2.0d0 + (2.0d0 / x)) / ((-1.0d0) - x)) / (1.0d0 - (x * x))
end function
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
	return ((2.0 + (2.0 / x)) / (-1.0 - x)) / (1.0 - (x * x));
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x):
	return ((2.0 + (2.0 / x)) / (-1.0 - x)) / (1.0 - (x * x))
function code(x)
	return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0)))
end
function code(x)
	return Float64(Float64(Float64(2.0 + Float64(2.0 / x)) / Float64(-1.0 - x)) / Float64(1.0 - Float64(x * x)))
end
function tmp = code(x)
	tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
end
function tmp = code(x)
	tmp = ((2.0 + (2.0 / x)) / (-1.0 - x)) / (1.0 - (x * x));
end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[(2.0 + N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2 + \frac{2}{x}}{-1 - x}}{1 - x \cdot x}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 10.1

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Simplified10.1

    \[\leadsto \color{blue}{\frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)} \]
    Proof
    (-.f64 (/.f64 1 (+.f64 1 x)) (-.f64 (/.f64 2 x) (/.f64 1 (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (-.f64 (/.f64 2 x) (/.f64 1 (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 1 (+.f64 x 1)) (-.f64 (/.f64 2 x) (/.f64 1 (+.f64 x (Rewrite<= metadata-eval (neg.f64 1)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 1 (+.f64 x 1)) (-.f64 (/.f64 2 x) (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 x 1))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= *-lft-identity_binary64 (*.f64 1 (-.f64 (/.f64 2 x) (/.f64 1 (-.f64 x 1)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> cancel-sign-sub-inv_binary64 (+.f64 (/.f64 1 (+.f64 x 1)) (*.f64 (neg.f64 1) (-.f64 (/.f64 2 x) (/.f64 1 (-.f64 x 1)))))): 10 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (*.f64 (Rewrite=> metadata-eval -1) (-.f64 (/.f64 2 x) (/.f64 1 (-.f64 x 1))))): 0 points increase in error, 10 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (/.f64 2 x) (/.f64 1 (-.f64 x 1)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 1 (+.f64 x 1)) (-.f64 (/.f64 2 x) (/.f64 1 (-.f64 x 1))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr26.9

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

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

    \[\leadsto \color{blue}{\frac{\frac{\left(-1 + x \cdot x\right) + \left(\left(x + -2\right) \cdot \frac{-1 - x}{x}\right) \cdot \left(x + 1\right)}{-1 - x}}{1 - x \cdot x}} \]
    Proof
    (/.f64 (/.f64 (+.f64 (+.f64 -1 (*.f64 x x)) (*.f64 (*.f64 (+.f64 x -2) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (+.f64 (Rewrite<= metadata-eval (-.f64 0 1)) (*.f64 x x)) (*.f64 (*.f64 (+.f64 x -2) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 15 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 1 (*.f64 x x)))) (*.f64 (*.f64 (+.f64 x -2) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 15 points decrease in error
    (/.f64 (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 1 (*.f64 x x)))) (*.f64 (*.f64 (+.f64 x -2) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 15 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 -2 x)) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (*.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 (+.f64 -2 x) 1)) (/.f64 (-.f64 -1 x) x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 15 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) (*.f64 1 x))) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 15 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) (Rewrite=> *-lft-identity_binary64 x)) (+.f64 x 1))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x) (Rewrite=> +-commutative_binary64 (+.f64 1 x)))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 15 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x) (+.f64 (Rewrite<= metadata-eval (-.f64 0 -1)) x))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 15 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 -1 x))))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x) (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 -1 x))))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 15 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (-.f64 -1 x)) (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x)))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 15 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (-.f64 -1 x) (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x)))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 15 points decrease in error
    (Rewrite<= associate-/r*_binary64 (/.f64 (-.f64 (neg.f64 (-.f64 1 (*.f64 x x))) (*.f64 (-.f64 -1 x) (/.f64 (*.f64 (+.f64 -2 x) (-.f64 -1 x)) x))) (*.f64 (-.f64 -1 x) (-.f64 1 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
  6. Taylor expanded in x around 0 0.1

    \[\leadsto \frac{\frac{\color{blue}{2 + 2 \cdot \frac{1}{x}}}{-1 - x}}{1 - x \cdot x} \]
  7. Simplified0.1

    \[\leadsto \frac{\frac{\color{blue}{2 + \frac{2}{x}}}{-1 - x}}{1 - x \cdot x} \]
    Proof
    (/.f64 (/.f64 (+.f64 2 (/.f64 2 x)) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 2 (/.f64 (Rewrite<= metadata-eval (*.f64 2 1)) x)) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 2 (Rewrite<= associate-*r/_binary64 (*.f64 2 (/.f64 1 x)))) (-.f64 -1 x)) (-.f64 1 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
  8. Final simplification0.1

    \[\leadsto \frac{\frac{2 + \frac{2}{x}}{-1 - x}}{1 - x \cdot x} \]

Alternatives

Alternative 1
Error0.3
Cost3017
\[\begin{array}{l} t_0 := \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x + -1}\\ \mathbf{if}\;t_0 \leq -0.1 \lor \neg \left(t_0 \leq 4 \cdot 10^{-16}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x}\\ \end{array} \]
Alternative 2
Error0.9
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{2}{x \cdot \left(x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2 + \frac{-2}{x}\\ \end{array} \]
Alternative 3
Error0.6
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2 + \frac{-2}{x}\\ \end{array} \]
Alternative 4
Error0.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x \cdot -2 + \frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{x}}{x \cdot x}\\ \end{array} \]
Alternative 5
Error31.4
Cost192
\[\frac{-2}{x} \]
Alternative 6
Error61.9
Cost64
\[-1 \]

Error

Reproduce

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