| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 713 |
(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(-2.0 / Float64(Float64(x + 1.0) * Float64(x - Float64(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[(-2.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{-2}{\left(x + 1\right) \cdot \left(x - x \cdot x\right)}
Results
| Original | 9.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
Initial program 9.9
Simplified9.9
[Start]9.9 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]9.9 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]9.9 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]9.9 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]9.9 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]9.9 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]9.9 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]9.9 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]9.9 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]9.9 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr10.0
Simplified10.0
[Start]10.0 | \[ \frac{1}{1 + x} - \frac{\frac{-2 + \left(2 \cdot x - x\right)}{x}}{1} \cdot \frac{1}{x + -1}
\] |
|---|---|
*-commutative [=>]10.0 | \[ \frac{1}{1 + x} - \color{blue}{\frac{1}{x + -1} \cdot \frac{\frac{-2 + \left(2 \cdot x - x\right)}{x}}{1}}
\] |
/-rgt-identity [=>]10.0 | \[ \frac{1}{1 + x} - \frac{1}{x + -1} \cdot \color{blue}{\frac{-2 + \left(2 \cdot x - x\right)}{x}}
\] |
*-commutative [=>]10.0 | \[ \frac{1}{1 + x} - \frac{1}{x + -1} \cdot \frac{-2 + \left(\color{blue}{x \cdot 2} - x\right)}{x}
\] |
Applied egg-rr25.8
Simplified25.8
[Start]25.8 | \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(x + -2\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}
\] |
|---|---|
associate-/r* [=>]25.8 | \[ \color{blue}{\frac{\frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(x + -2\right)}{1 + x}}{x \cdot x - x}}
\] |
sub-neg [=>]25.8 | \[ \frac{\frac{\color{blue}{\left(x \cdot x - x\right) + \left(-\left(1 + x\right) \cdot \left(x + -2\right)\right)}}{1 + x}}{x \cdot x - x}
\] |
distribute-rgt-neg-in [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \color{blue}{\left(1 + x\right) \cdot \left(-\left(x + -2\right)\right)}}{1 + x}}{x \cdot x - x}
\] |
+-commutative [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \color{blue}{\left(x + 1\right)} \cdot \left(-\left(x + -2\right)\right)}{1 + x}}{x \cdot x - x}
\] |
+-commutative [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \left(x + 1\right) \cdot \left(-\color{blue}{\left(-2 + x\right)}\right)}{1 + x}}{x \cdot x - x}
\] |
distribute-neg-in [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \left(x + 1\right) \cdot \color{blue}{\left(\left(--2\right) + \left(-x\right)\right)}}{1 + x}}{x \cdot x - x}
\] |
metadata-eval [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \left(x + 1\right) \cdot \left(\color{blue}{2} + \left(-x\right)\right)}{1 + x}}{x \cdot x - x}
\] |
sub-neg [<=]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \left(x + 1\right) \cdot \color{blue}{\left(2 - x\right)}}{1 + x}}{x \cdot x - x}
\] |
+-commutative [=>]25.8 | \[ \frac{\frac{\left(x \cdot x - x\right) + \left(x + 1\right) \cdot \left(2 - x\right)}{\color{blue}{x + 1}}}{x \cdot x - x}
\] |
Taylor expanded in x around 0 0.1
Applied egg-rr0.1
Simplified0.3
[Start]0.1 | \[ -\frac{\frac{2}{x + 1}}{-\left(x \cdot x - x\right)}
\] |
|---|---|
associate-/l/ [=>]0.3 | \[ -\color{blue}{\frac{2}{\left(-\left(x \cdot x - x\right)\right) \cdot \left(x + 1\right)}}
\] |
distribute-neg-frac [=>]0.3 | \[ \color{blue}{\frac{-2}{\left(-\left(x \cdot x - x\right)\right) \cdot \left(x + 1\right)}}
\] |
metadata-eval [=>]0.3 | \[ \frac{\color{blue}{-2}}{\left(-\left(x \cdot x - x\right)\right) \cdot \left(x + 1\right)}
\] |
*-commutative [=>]0.3 | \[ \frac{-2}{\color{blue}{\left(x + 1\right) \cdot \left(-\left(x \cdot x - x\right)\right)}}
\] |
neg-sub0 [=>]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \color{blue}{\left(0 - \left(x \cdot x - x\right)\right)}}
\] |
sub-neg [=>]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \left(0 - \color{blue}{\left(x \cdot x + \left(-x\right)\right)}\right)}
\] |
+-commutative [<=]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \left(0 - \color{blue}{\left(\left(-x\right) + x \cdot x\right)}\right)}
\] |
associate--r+ [=>]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \color{blue}{\left(\left(0 - \left(-x\right)\right) - x \cdot x\right)}}
\] |
neg-sub0 [<=]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \left(\color{blue}{\left(-\left(-x\right)\right)} - x \cdot x\right)}
\] |
remove-double-neg [=>]0.3 | \[ \frac{-2}{\left(x + 1\right) \cdot \left(\color{blue}{x} - x \cdot x\right)}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 713 |
| Alternative 2 | |
|---|---|
| Error | 15.5 |
| Cost | 585 |
| Alternative 3 | |
|---|---|
| Error | 10.8 |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Error | 30.9 |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Error | 61.9 |
| Cost | 64 |
| Alternative 6 | |
|---|---|
| Error | 61.9 |
| Cost | 64 |
herbie shell --seed 2023059
(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))))