| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 969 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.85 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{\frac{1}{x \cdot x}}{-1 - x} \cdot -2\\
\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 (/ (/ 2.0 (+ x 1.0)) (- (* 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 / (x + 1.0)) / ((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 / (x + 1.0d0)) / ((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 / (x + 1.0)) / ((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 / (x + 1.0)) / ((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(x + 1.0)) / 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 / (x + 1.0)) / ((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[(x + 1.0), $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}{x + 1}}{x \cdot x - x}
Results
| Original | 10.1 |
|---|---|
| Target | 0.3 |
| Herbie | 0.1 |
Initial program 10.1
Simplified10.1
[Start]10.1 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]10.1 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]10.1 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]10.1 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]10.1 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]10.1 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]10.1 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]10.1 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]10.1 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]10.1 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr25.9
Simplified25.9
[Start]25.9 | \[ \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* [=>]25.9 | \[ \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.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 969 |
| Alternative 2 | |
|---|---|
| Error | 10.7 |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Error | 10.7 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 15.2 |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Error | 0.3 |
| Cost | 704 |
| Alternative 6 | |
|---|---|
| Error | 15.7 |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Error | 15.4 |
| Cost | 584 |
| Alternative 8 | |
|---|---|
| Error | 31.1 |
| Cost | 192 |
herbie shell --seed 2023018
(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))))