| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 576 |

(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ 2.0 (* x (+ (* x x) -1.0))))
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 / (x * ((x * x) + -1.0));
}
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 / (x * ((x * x) + (-1.0d0)))
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 / (x * ((x * x) + -1.0));
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x): return 2.0 / (x * ((x * x) + -1.0))
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(2.0 / Float64(x * Float64(Float64(x * x) + -1.0))) 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 / (x * ((x * x) + -1.0)); 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[(2.0 / N[(x * N[(N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{2}{x \cdot \left(x \cdot x + -1\right)}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 96.8% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 96.8%
Applied egg-rr96.8%
[Start]96.8% | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
frac-sub [=>]96.7% | \[ \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}
\] |
frac-add [=>]97.7% | \[ \color{blue}{\frac{\left(1 \cdot x - \left(x + 1\right) \cdot 2\right) \cdot \left(x - 1\right) + \left(\left(x + 1\right) \cdot x\right) \cdot 1}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}}
\] |
fma-def [=>]96.8% | \[ \frac{\color{blue}{\mathsf{fma}\left(1 \cdot x - \left(x + 1\right) \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
/-rgt-identity [<=]96.8% | \[ \frac{\mathsf{fma}\left(1 \cdot x - \color{blue}{\frac{x + 1}{1}} \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
*-un-lft-identity [<=]96.8% | \[ \frac{\mathsf{fma}\left(\color{blue}{x} - \frac{x + 1}{1} \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
/-rgt-identity [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \color{blue}{\left(x + 1\right)} \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
+-commutative [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \color{blue}{\left(1 + x\right)} \cdot 2, x - 1, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
sub-neg [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, \color{blue}{x + \left(-1\right)}, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
metadata-eval [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + \color{blue}{-1}, \left(\left(x + 1\right) \cdot x\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
*-commutative [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \color{blue}{\left(x \cdot \left(x + 1\right)\right)} \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
+-commutative [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \color{blue}{\left(1 + x\right)}\right) \cdot 1\right)}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}
\] |
*-commutative [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\color{blue}{\left(x \cdot \left(x + 1\right)\right)} \cdot \left(x - 1\right)}
\] |
+-commutative [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\left(x \cdot \color{blue}{\left(1 + x\right)}\right) \cdot \left(x - 1\right)}
\] |
sub-neg [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \color{blue}{\left(x + \left(-1\right)\right)}}
\] |
metadata-eval [=>]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \left(x + \color{blue}{-1}\right)}
\] |
Simplified96.9%
[Start]96.8% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\left(x \cdot \left(1 + x\right)\right) \cdot \left(x + -1\right)}
\] |
|---|---|
associate-*l* [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - \left(1 + x\right) \cdot 2, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{\color{blue}{x \cdot \left(\left(1 + x\right) \cdot \left(x + -1\right)\right)}}
\] |
*-commutative [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - \color{blue}{2 \cdot \left(1 + x\right)}, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{x \cdot \left(\left(1 + x\right) \cdot \left(x + -1\right)\right)}
\] |
+-commutative [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - 2 \cdot \color{blue}{\left(x + 1\right)}, x + -1, \left(x \cdot \left(1 + x\right)\right) \cdot 1\right)}{x \cdot \left(\left(1 + x\right) \cdot \left(x + -1\right)\right)}
\] |
*-rgt-identity [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - 2 \cdot \left(x + 1\right), x + -1, \color{blue}{x \cdot \left(1 + x\right)}\right)}{x \cdot \left(\left(1 + x\right) \cdot \left(x + -1\right)\right)}
\] |
+-commutative [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - 2 \cdot \left(x + 1\right), x + -1, x \cdot \color{blue}{\left(x + 1\right)}\right)}{x \cdot \left(\left(1 + x\right) \cdot \left(x + -1\right)\right)}
\] |
+-commutative [=>]96.9% | \[ \frac{\mathsf{fma}\left(x - 2 \cdot \left(x + 1\right), x + -1, x \cdot \left(x + 1\right)\right)}{x \cdot \left(\color{blue}{\left(x + 1\right)} \cdot \left(x + -1\right)\right)}
\] |
Taylor expanded in x around 0 99.9%
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ \frac{2}{x \cdot \left({x}^{2} - 1\right)}
\] |
|---|---|
sub-neg [=>]100.0% | \[ \frac{2}{x \cdot \color{blue}{\left({x}^{2} + \left(-1\right)\right)}}
\] |
unpow2 [=>]100.0% | \[ \frac{2}{x \cdot \left(\color{blue}{x \cdot x} + \left(-1\right)\right)}
\] |
metadata-eval [=>]100.0% | \[ \frac{2}{x \cdot \left(x \cdot x + \color{blue}{-1}\right)}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.6% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 192 |
| Alternative 4 | |
|---|---|
| Accuracy | 3.3% |
| Cost | 64 |
herbie shell --seed 2023277
(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))))