| Alternative 1 | |
|---|---|
| Error | 1.31% |
| Cost | 969 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.85 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;-2 \cdot \frac{\frac{1}{x \cdot x}}{-1 - x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2 + \frac{-2}{x}\\
\end{array}
\]
(FPCore (x) :precision binary64 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (* (/ (/ 1.0 (- (* x x) x)) (- -1.0 x)) -2.0))
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 / ((x * x) - x)) / (-1.0 - x)) * -2.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 = ((1.0d0 / ((x * x) - x)) / ((-1.0d0) - x)) * (-2.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 ((1.0 / ((x * x) - x)) / (-1.0 - x)) * -2.0;
}
def code(x): return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x): return ((1.0 / ((x * x) - x)) / (-1.0 - x)) * -2.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(Float64(1.0 / Float64(Float64(x * x) - x)) / Float64(-1.0 - x)) * -2.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 = ((1.0 / ((x * x) - x)) / (-1.0 - x)) * -2.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[(N[(1.0 / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{1}{x \cdot x - x}}{-1 - x} \cdot -2
Results
| Original | 15.8% |
|---|---|
| Target | 0.4% |
| Herbie | 0.11% |
Initial program 15.8
Simplified15.79
[Start]15.8 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]15.79 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]15.79 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]15.79 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]15.79 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]15.79 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]15.79 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]15.79 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]15.79 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]15.79 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr40.54
Simplified40.55
[Start]40.54 | \[ \frac{x \cdot x - \left(x + \left(1 + x\right) \cdot \left(-2 + \left(2 \cdot x - x\right)\right)\right)}{\left(1 + x\right) \cdot \mathsf{fma}\left(x, x, -x\right)}
\] |
|---|---|
associate-/r* [=>]40.55 | \[ \color{blue}{\frac{\frac{x \cdot x - \left(x + \left(1 + x\right) \cdot \left(-2 + \left(2 \cdot x - x\right)\right)\right)}{1 + x}}{\mathsf{fma}\left(x, x, -x\right)}}
\] |
Taylor expanded in x around 0 0.11
Applied egg-rr0.11
Final simplification0.11
| Alternative 1 | |
|---|---|
| Error | 1.31% |
| Cost | 969 |
| Alternative 2 | |
|---|---|
| Error | 16.67% |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Error | 1.61% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Error | 1.31% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Error | 24.11% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 0.41% |
| Cost | 704 |
| Alternative 7 | |
|---|---|
| Error | 0.11% |
| Cost | 704 |
| Alternative 8 | |
|---|---|
| Error | 24.78% |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Error | 48.57% |
| Cost | 192 |
herbie shell --seed 2023121
(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))))