| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ (/ 2.0 (+ x 1.0)) (* 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 + 1.0)) / (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 + 1.0d0)) / (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 + 1.0)) / (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 + 1.0)) / (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(Float64(2.0 / Float64(x + 1.0)) / Float64(x * Float64(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 + 1.0)) / (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[(N[(2.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2}{x + 1}}{x \cdot \left(x + -1\right)}
Results
| Original | 84.1% |
|---|---|
| Target | 99.5% |
| Herbie | 99.9% |
Initial program 84.1%
Simplified84.1%
[Start]84.1 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]84.1 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]84.1 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]84.1 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]84.1 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]84.1 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]84.1 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]84.1 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]84.1 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]84.1 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr59.7%
[Start]84.1 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)
\] |
|---|---|
frac-sub [=>]59.0 | \[ \frac{1}{1 + x} - \color{blue}{\frac{2 \cdot \left(x + -1\right) - x \cdot 1}{x \cdot \left(x + -1\right)}}
\] |
frac-sub [=>]59.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 [<=]59.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 [=>]59.7 | \[ \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 [<=]59.7 | \[ \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 [<=]59.7 | \[ \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 [=>]59.7 | \[ \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 [=>]59.7 | \[ \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 [=>]59.7 | \[ \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 [<=]59.7 | \[ \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 [=>]59.7 | \[ \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 [=>]59.7 | \[ \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 [=>]59.7 | \[ \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 [<=]59.7 | \[ \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 [<=]59.7 | \[ \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)}}
\] |
Simplified59.7%
[Start]59.7 | \[ \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 - x\right)}
\] |
|---|---|
+-commutative [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \color{blue}{\left(x + 1\right)} \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
remove-double-neg [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(\color{blue}{\left(-\left(-x\right)\right)} + 1\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
metadata-eval [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(\left(-\left(-x\right)\right) + \color{blue}{\left(--1\right)}\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
distribute-neg-in [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \color{blue}{\left(-\left(\left(-x\right) + -1\right)\right)} \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
neg-mul-1 [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\left(\color{blue}{-1 \cdot x} + -1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
*-commutative [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\left(\color{blue}{x \cdot -1} + -1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
fma-udef [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\color{blue}{\mathsf{fma}\left(x, -1, -1\right)}\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
distribute-lft-neg-in [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \color{blue}{\left(-\mathsf{fma}\left(x, -1, -1\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)\right)}}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
distribute-lft-neg-in [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \color{blue}{\left(-\mathsf{fma}\left(x, -1, -1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
fma-udef [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\color{blue}{\left(x \cdot -1 + -1\right)}\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
*-commutative [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\left(\color{blue}{-1 \cdot x} + -1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
neg-mul-1 [<=]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(-\left(\color{blue}{\left(-x\right)} + -1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
distribute-neg-in [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \color{blue}{\left(\left(-\left(-x\right)\right) + \left(--1\right)\right)} \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
remove-double-neg [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(\color{blue}{x} + \left(--1\right)\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
metadata-eval [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(x + \color{blue}{1}\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
+-commutative [=>]59.7 | \[ \frac{\left(x \cdot x - x\right) - \left(x + 1\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\color{blue}{\left(x + 1\right)} \cdot \left(x \cdot x - x\right)}
\] |
Taylor expanded in x around 0 99.5%
Applied egg-rr99.9%
[Start]99.5 | \[ \frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}
\] |
|---|---|
add-log-exp [=>]34.8 | \[ \color{blue}{\log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)}
\] |
*-un-lft-identity [=>]34.8 | \[ \log \color{blue}{\left(1 \cdot e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)}
\] |
log-prod [=>]34.8 | \[ \color{blue}{\log 1 + \log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)}
\] |
metadata-eval [=>]34.8 | \[ \color{blue}{0} + \log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)
\] |
add-log-exp [<=]99.5 | \[ 0 + \color{blue}{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}
\] |
associate-/r* [=>]99.9 | \[ 0 + \color{blue}{\frac{\frac{2}{x + 1}}{x \cdot x - x}}
\] |
*-un-lft-identity [=>]99.9 | \[ 0 + \frac{\frac{2}{x + 1}}{x \cdot x - \color{blue}{1 \cdot x}}
\] |
distribute-rgt-out-- [=>]99.9 | \[ 0 + \frac{\frac{2}{x + 1}}{\color{blue}{x \cdot \left(x - 1\right)}}
\] |
sub-neg [=>]99.9 | \[ 0 + \frac{\frac{2}{x + 1}}{x \cdot \color{blue}{\left(x + \left(-1\right)\right)}}
\] |
metadata-eval [=>]99.9 | \[ 0 + \frac{\frac{2}{x + 1}}{x \cdot \left(x + \color{blue}{-1}\right)}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 777 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.2% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 584 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 576 |
| Alternative 6 | |
|---|---|
| Accuracy | 82.6% |
| Cost | 448 |
| Alternative 7 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 192 |
| Alternative 8 | |
|---|---|
| Accuracy | 3.3% |
| Cost | 64 |
herbie shell --seed 2023152
(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))))