Average Error: 14.4 → 0.4
Time: 3.2s
Precision: binary64
Cost: 6784
\[\frac{1}{x + 1} - \frac{1}{x} \]
\[\frac{1}{-\mathsf{fma}\left(x, x, x\right)} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))
(FPCore (x) :precision binary64 (/ 1.0 (- (fma x x x))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / x);
}
double code(double x) {
	return 1.0 / -fma(x, x, x);
}
function code(x)
	return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / x))
end
function code(x)
	return Float64(1.0 / Float64(-fma(x, x, x)))
end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / (-N[(x * x + x), $MachinePrecision])), $MachinePrecision]
\frac{1}{x + 1} - \frac{1}{x}
\frac{1}{-\mathsf{fma}\left(x, x, x\right)}

Error

Derivation

  1. Initial program 14.4

    \[\frac{1}{x + 1} - \frac{1}{x} \]
  2. Simplified14.4

    \[\leadsto \color{blue}{\frac{1}{1 + x} + \frac{-1}{x}} \]
  3. Applied egg-rr13.8

    \[\leadsto \color{blue}{\frac{\left(1 + x\right) + \left(-x\right) \cdot 1}{\left(-x\right) \cdot \left(1 + x\right)}} \]
  4. Taylor expanded in x around 0 0.4

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

    \[\leadsto \frac{1}{\color{blue}{-\mathsf{fma}\left(x, x, x\right)}} \]
  6. Final simplification0.4

    \[\leadsto \frac{1}{-\mathsf{fma}\left(x, x, x\right)} \]

Alternatives

Alternative 1
Error1.4
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -158115409548.54633:\\ \;\;\;\;\frac{\frac{-1}{x}}{x}\\ \mathbf{elif}\;x \leq 0.036328354076812584:\\ \;\;\;\;\frac{-1}{x} + \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \end{array} \]
Alternative 2
Error2.0
Cost584
\[\begin{array}{l} t_0 := \frac{-1}{x \cdot x}\\ \mathbf{if}\;x \leq -158115409548.54633:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.036328354076812584:\\ \;\;\;\;\frac{-1}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.6
Cost584
\[\begin{array}{l} t_0 := \frac{-1}{x \cdot x}\\ \mathbf{if}\;x \leq -158115409548.54633:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.036328354076812584:\\ \;\;\;\;1 + \frac{-1}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -158115409548.54633:\\ \;\;\;\;\frac{\frac{-1}{x}}{x}\\ \mathbf{elif}\;x \leq 0.036328354076812584:\\ \;\;\;\;1 + \frac{-1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \end{array} \]
Alternative 5
Error0.4
Cost448
\[\frac{1}{x \cdot \left(-1 - x\right)} \]
Alternative 6
Error61.9
Cost192
\[\frac{1}{x} \]
Alternative 7
Error30.7
Cost192
\[\frac{-1}{x} \]
Alternative 8
Error61.9
Cost128
\[-x \]

Error

Reproduce

herbie shell --seed 2022225 
(FPCore (x)
  :name "2frac (problem 3.3.1)"
  :precision binary64
  (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))