| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 704 |

(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ (/ 2.0 (+ 1.0 x)) (- (* 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) {
return (2.0 / (1.0 + x)) / ((x * 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 / (1.0d0 + x)) / ((x * 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 / (1.0 + x)) / ((x * 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 / (1.0 + x)) / ((x * 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(2.0 / Float64(1.0 + x)) / Float64(Float64(x * 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 / (1.0 + x)) / ((x * 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[(2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2}{1 + x}}{x \cdot x - x}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 84.5% |
|---|---|
| Target | 99.5% |
| Herbie | 99.9% |
Initial program 86.7%
Simplified86.7%
[Start]86.7% | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]86.7% | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]86.7% | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]86.7% | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]86.7% | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]86.7% | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]86.7% | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]86.7% | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]86.7% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]86.7% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr62.9%
[Start]86.7% | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)
\] |
|---|---|
frac-sub [=>]62.2% | \[ \frac{1}{1 + x} - \color{blue}{\frac{2 \cdot \left(x + -1\right) - x \cdot 1}{x \cdot \left(x + -1\right)}}
\] |
frac-sub [=>]62.9% | \[ \color{blue}{\frac{1 \cdot \left(x \cdot \left(x + -1\right)\right) - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - x \cdot 1\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}}
\] |
*-un-lft-identity [<=]62.9% | \[ \frac{\color{blue}{x \cdot \left(x + -1\right)} - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - x \cdot 1\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
distribute-rgt-in [=>]63.0% | \[ \frac{\color{blue}{\left(x \cdot x + -1 \cdot x\right)} - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - x \cdot 1\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
neg-mul-1 [<=]63.0% | \[ \frac{\left(x \cdot x + \color{blue}{\left(-x\right)}\right) - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - x \cdot 1\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
sub-neg [<=]63.0% | \[ \frac{\color{blue}{\left(x \cdot x - x\right)} - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - x \cdot 1\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
*-rgt-identity [=>]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(2 \cdot \left(x + -1\right) - \color{blue}{x}\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
distribute-rgt-in [=>]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\color{blue}{\left(x \cdot 2 + -1 \cdot 2\right)} - x\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
metadata-eval [=>]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\left(x \cdot 2 + \color{blue}{-2}\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
metadata-eval [<=]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\left(x \cdot 2 + \color{blue}{\left(-2\right)}\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
fma-def [=>]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\color{blue}{\mathsf{fma}\left(x, 2, -2\right)} - x\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
metadata-eval [=>]63.0% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, \color{blue}{-2}\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot \left(x + -1\right)\right)}
\] |
distribute-rgt-in [=>]62.9% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \color{blue}{\left(x \cdot x + -1 \cdot x\right)}}
\] |
neg-mul-1 [<=]62.9% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x + \color{blue}{\left(-x\right)}\right)}
\] |
sub-neg [<=]62.9% | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \color{blue}{\left(x \cdot x - x\right)}}
\] |
Taylor expanded in x around 0 99.6%
Applied egg-rr99.9%
[Start]99.6% | \[ \frac{2}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
|---|---|
*-un-lft-identity [=>]99.6% | \[ \color{blue}{1 \cdot \frac{2}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}}
\] |
*-commutative [=>]99.6% | \[ \color{blue}{\frac{2}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)} \cdot 1}
\] |
associate-/r* [=>]99.9% | \[ \color{blue}{\frac{\frac{2}{1 + x}}{x \cdot x - x}} \cdot 1
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 704 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 704 |
| Alternative 6 | |
|---|---|
| Accuracy | 75.5% |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Accuracy | 83.0% |
| Cost | 448 |
| Alternative 8 | |
|---|---|
| Accuracy | 51.2% |
| Cost | 192 |
herbie shell --seed 2023263
(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))))