| Alternative 1 | |
|---|---|
| Error | 15.3 |
| Cost | 585 |
(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))))
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));
}
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))
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));
}
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))
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 / x) / Float64(1.0 - 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)); 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 / x), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{-2}{x}}{1 - x \cdot x}
Results
| Original | 9.7 |
|---|---|
| Target | 0.3 |
| Herbie | 0.1 |
Initial program 9.7
Simplified9.7
[Start]9.7 | \[ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\] |
|---|---|
associate-+l- [=>]9.7 | \[ \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]9.7 | \[ \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)}
\] |
neg-mul-1 [=>]9.7 | \[ \frac{1}{x + 1} + \color{blue}{-1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
metadata-eval [<=]9.7 | \[ \frac{1}{x + 1} + \color{blue}{\left(-1\right)} \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
cancel-sign-sub-inv [<=]9.7 | \[ \color{blue}{\frac{1}{x + 1} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
+-commutative [=>]9.7 | \[ \frac{1}{\color{blue}{1 + x}} - 1 \cdot \left(\frac{2}{x} - \frac{1}{x - 1}\right)
\] |
*-lft-identity [=>]9.7 | \[ \frac{1}{1 + x} - \color{blue}{\left(\frac{2}{x} - \frac{1}{x - 1}\right)}
\] |
sub-neg [=>]9.7 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{\color{blue}{x + \left(-1\right)}}\right)
\] |
metadata-eval [=>]9.7 | \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right)
\] |
Applied egg-rr9.7
Applied egg-rr26.0
Simplified26.0
[Start]26.0 | \[ \frac{-\left(x + x\right)}{-\mathsf{fma}\left(x, x, -1\right)} + \left(-\frac{2}{x}\right)
\] |
|---|---|
neg-mul-1 [=>]26.0 | \[ \frac{\color{blue}{-1 \cdot \left(x + x\right)}}{-\mathsf{fma}\left(x, x, -1\right)} + \left(-\frac{2}{x}\right)
\] |
count-2 [=>]26.0 | \[ \frac{-1 \cdot \color{blue}{\left(2 \cdot x\right)}}{-\mathsf{fma}\left(x, x, -1\right)} + \left(-\frac{2}{x}\right)
\] |
associate-*r* [=>]26.0 | \[ \frac{\color{blue}{\left(-1 \cdot 2\right) \cdot x}}{-\mathsf{fma}\left(x, x, -1\right)} + \left(-\frac{2}{x}\right)
\] |
metadata-eval [=>]26.0 | \[ \frac{\color{blue}{-2} \cdot x}{-\mathsf{fma}\left(x, x, -1\right)} + \left(-\frac{2}{x}\right)
\] |
neg-mul-1 [=>]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{-1 \cdot \mathsf{fma}\left(x, x, -1\right)}} + \left(-\frac{2}{x}\right)
\] |
fma-udef [=>]26.0 | \[ \frac{-2 \cdot x}{-1 \cdot \color{blue}{\left(x \cdot x + -1\right)}} + \left(-\frac{2}{x}\right)
\] |
distribute-lft-in [=>]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{-1 \cdot \left(x \cdot x\right) + -1 \cdot -1}} + \left(-\frac{2}{x}\right)
\] |
associate-*l* [<=]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{\left(-1 \cdot x\right) \cdot x} + -1 \cdot -1} + \left(-\frac{2}{x}\right)
\] |
neg-mul-1 [<=]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{\left(-x\right)} \cdot x + -1 \cdot -1} + \left(-\frac{2}{x}\right)
\] |
metadata-eval [=>]26.0 | \[ \frac{-2 \cdot x}{\left(-x\right) \cdot x + \color{blue}{1}} + \left(-\frac{2}{x}\right)
\] |
+-commutative [<=]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{1 + \left(-x\right) \cdot x}} + \left(-\frac{2}{x}\right)
\] |
cancel-sign-sub-inv [<=]26.0 | \[ \frac{-2 \cdot x}{\color{blue}{1 - x \cdot x}} + \left(-\frac{2}{x}\right)
\] |
Applied egg-rr25.5
Simplified25.5
[Start]25.5 | \[ \frac{\left(\left(-2 \cdot x\right) \cdot \left(x \cdot 0.5\right) - 1\right) + x \cdot x}{\left(1 - x \cdot x\right) \cdot \left(x \cdot 0.5\right)}
\] |
|---|---|
*-commutative [=>]25.5 | \[ \frac{\left(\left(-2 \cdot x\right) \cdot \left(x \cdot 0.5\right) - 1\right) + x \cdot x}{\color{blue}{\left(x \cdot 0.5\right) \cdot \left(1 - x \cdot x\right)}}
\] |
associate-/r* [=>]25.5 | \[ \color{blue}{\frac{\frac{\left(\left(-2 \cdot x\right) \cdot \left(x \cdot 0.5\right) - 1\right) + x \cdot x}{x \cdot 0.5}}{1 - x \cdot x}}
\] |
Applied egg-rr25.8
Simplified0.1
[Start]25.8 | \[ \frac{\mathsf{fma}\left(x, x, -1\right)}{\left(x \cdot 0.5\right) \cdot \left(1 - x \cdot x\right)} - \frac{x \cdot x}{\left(x \cdot 0.5\right) \cdot \left(1 - x \cdot x\right)}
\] |
|---|---|
div-sub [<=]25.5 | \[ \color{blue}{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{\left(x \cdot 0.5\right) \cdot \left(1 - x \cdot x\right)}}
\] |
*-commutative [=>]25.5 | \[ \frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{\color{blue}{\left(1 - x \cdot x\right) \cdot \left(x \cdot 0.5\right)}}
\] |
associate-/r* [=>]25.5 | \[ \color{blue}{\frac{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x}}{x \cdot 0.5}}
\] |
/-rgt-identity [<=]25.5 | \[ \frac{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x}}{\color{blue}{\frac{x \cdot 0.5}{1}}}
\] |
associate-/l* [=>]25.5 | \[ \frac{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x}}{\color{blue}{\frac{x}{\frac{1}{0.5}}}}
\] |
metadata-eval [=>]25.5 | \[ \frac{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x}}{\frac{x}{\color{blue}{2}}}
\] |
associate-/l* [<=]25.5 | \[ \color{blue}{\frac{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x} \cdot 2}{x}}
\] |
associate-*r/ [<=]25.5 | \[ \color{blue}{\frac{\mathsf{fma}\left(x, x, -1\right) - x \cdot x}{1 - x \cdot x} \cdot \frac{2}{x}}
\] |
associate-*l/ [=>]25.5 | \[ \color{blue}{\frac{\left(\mathsf{fma}\left(x, x, -1\right) - x \cdot x\right) \cdot \frac{2}{x}}{1 - x \cdot x}}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 15.3 |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Error | 10.5 |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 30.8 |
| Cost | 192 |
herbie shell --seed 2023057
(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))))