Average Error: 10.1 → 0.1
Time: 9.5s
Precision: binary64
Cost: 832
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{\frac{1}{1 + x}}{\left(1 - x\right) \cdot \left(x \cdot -0.5\right)} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ (/ 1.0 (+ 1.0 x)) (* (- 1.0 x) (* x -0.5))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	return (1.0 / (1.0 + x)) / ((1.0 - x) * (x * -0.5));
}
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 = (1.0d0 / (1.0d0 + x)) / ((1.0d0 - x) * (x * (-0.5d0)))
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 (1.0 / (1.0 + x)) / ((1.0 - x) * (x * -0.5));
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x):
	return (1.0 / (1.0 + x)) / ((1.0 - x) * (x * -0.5))
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(1.0 / Float64(1.0 + x)) / Float64(Float64(1.0 - x) * Float64(x * -0.5)))
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 = (1.0 / (1.0 + x)) / ((1.0 - x) * (x * -0.5));
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[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{1}{1 + x}}{\left(1 - x\right) \cdot \left(x \cdot -0.5\right)}

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{1}{x + -1} + \frac{-2}{x}\right)} \]
    Proof
    (+.f64 (/.f64 1 (+.f64 1 x)) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (+.f64 x (Rewrite<= metadata-eval (neg.f64 1)))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 x 1))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (/.f64 (Rewrite<= metadata-eval (neg.f64 2)) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 2 x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= +-commutative_binary64 (+.f64 (neg.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)) (neg.f64 (/.f64 2 x))) (/.f64 1 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= sub-neg_binary64 (-.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.1

    \[\leadsto \frac{1}{1 + x} + \color{blue}{\frac{\left(1 - x\right) + \left(x \cdot -0.5\right) \cdot -1}{\left(x \cdot -0.5\right) \cdot \left(1 - x\right)}} \]
  4. Applied egg-rr29.7

    \[\leadsto \frac{1}{1 + x} + \frac{\left(1 - x\right) + \left(x \cdot -0.5\right) \cdot -1}{\color{blue}{\frac{\left(1 - x \cdot x\right) \cdot \left(x \cdot -0.5\right)}{1 + x}}} \]
  5. Applied egg-rr25.6

    \[\leadsto \color{blue}{\frac{\frac{\left(1 - x\right) \cdot \left(x \cdot -0.5\right) + \mathsf{fma}\left(x, 0.5, 1 - x\right) \cdot \left(1 + x\right)}{1 + x}}{\left(1 - x\right) \cdot \left(x \cdot -0.5\right)}} \]
  6. Taylor expanded in x around 0 0.1

    \[\leadsto \frac{\frac{\color{blue}{1}}{1 + x}}{\left(1 - x\right) \cdot \left(x \cdot -0.5\right)} \]
  7. Final simplification0.1

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

Alternatives

Alternative 1
Error10.7
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;\left(1 - x\right) + \left(\frac{-2}{x} + \left(-1 - x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{x}\\ \end{array} \]
Alternative 2
Error10.7
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\ \mathbf{elif}\;x \leq 2.3019013803346983 \cdot 10^{+47}:\\ \;\;\;\;1 + \left(\frac{1}{x + -1} + \frac{-2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{x}\\ \end{array} \]
Alternative 3
Error10.7
Cost840
\[\begin{array}{l} t_0 := \frac{1}{x} - \frac{1}{x}\\ \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;x \cdot -2 - \frac{1}{x} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error10.7
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;x \cdot -2 - \frac{1}{x} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{x}\\ \end{array} \]
Alternative 5
Error10.9
Cost712
\[\begin{array}{l} t_0 := \frac{1}{x} - \frac{1}{x}\\ \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error15.9
Cost584
\[\begin{array}{l} t_0 := \frac{-1}{x \cdot x}\\ \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.197567273403724 \cdot 10^{-11}:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error15.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -243.54155772717786:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot x}\\ \end{array} \]
Alternative 8
Error61.8
Cost192
\[\frac{1}{x} \]
Alternative 9
Error56.4
Cost192
\[\frac{-1}{x} \]
Alternative 10
Error30.8
Cost192
\[\frac{-2}{x} \]
Alternative 11
Error62.1
Cost128
\[-x \]

Error

Reproduce

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