| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 3424 |
\[\log \left(x + \left(x + \frac{-0.5}{x}\right)\right)
\]
(FPCore (x) :precision binary32 (log (+ x (sqrt (- (* x x) 1.0)))))
(FPCore (x) :precision binary32 (- (/ -0.25 (* x x)) (log (/ 0.5 x))))
float code(float x) {
return logf((x + sqrtf(((x * x) - 1.0f))));
}
float code(float x) {
return (-0.25f / (x * x)) - logf((0.5f / x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + sqrt(((x * x) - 1.0e0))))
end function
real(4) function code(x)
real(4), intent (in) :: x
code = ((-0.25e0) / (x * x)) - log((0.5e0 / x))
end function
function code(x) return log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0))))) end
function code(x) return Float32(Float32(Float32(-0.25) / Float32(x * x)) - log(Float32(Float32(0.5) / x))) end
function tmp = code(x) tmp = log((x + sqrt(((x * x) - single(1.0))))); end
function tmp = code(x) tmp = (single(-0.25) / (x * x)) - log((single(0.5) / x)); end
\log \left(x + \sqrt{x \cdot x - 1}\right)
\frac{-0.25}{x \cdot x} - \log \left(\frac{0.5}{x}\right)
Results
| Original | 49.9% |
|---|---|
| Target | 99.2% |
| Herbie | 98.9% |
Initial program 49.9%
Taylor expanded in x around inf 98.3%
Simplified98.3%
[Start]98.3 | \[ \log \left(2 \cdot x - 0.5 \cdot \frac{1}{x}\right)
\] |
|---|---|
*-commutative [=>]98.3 | \[ \log \left(\color{blue}{x \cdot 2} - 0.5 \cdot \frac{1}{x}\right)
\] |
associate-*r/ [=>]98.3 | \[ \log \left(x \cdot 2 - \color{blue}{\frac{0.5 \cdot 1}{x}}\right)
\] |
metadata-eval [=>]98.3 | \[ \log \left(x \cdot 2 - \frac{\color{blue}{0.5}}{x}\right)
\] |
Taylor expanded in x around inf 98.1%
Simplified98.9%
[Start]98.1 | \[ \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log 2\right) - 0.25 \cdot \frac{1}{{x}^{2}}
\] |
|---|---|
cancel-sign-sub-inv [=>]98.1 | \[ \color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right) + \log 2\right) + \left(-0.25\right) \cdot \frac{1}{{x}^{2}}}
\] |
+-commutative [=>]98.1 | \[ \color{blue}{\left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log 2\right)}
\] |
log-rec [=>]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(-1 \cdot \color{blue}{\left(-\log x\right)} + \log 2\right)
\] |
distribute-rgt-neg-in [<=]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(\color{blue}{\left(--1 \cdot \log x\right)} + \log 2\right)
\] |
neg-sub0 [=>]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(\color{blue}{\left(0 - -1 \cdot \log x\right)} + \log 2\right)
\] |
associate-+l- [=>]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \color{blue}{\left(0 - \left(-1 \cdot \log x - \log 2\right)\right)}
\] |
mul-1-neg [=>]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \left(\color{blue}{\left(-\log x\right)} - \log 2\right)\right)
\] |
log-rec [<=]98.1 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \left(\color{blue}{\log \left(\frac{1}{x}\right)} - \log 2\right)\right)
\] |
log-div [<=]98.9 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \color{blue}{\log \left(\frac{\frac{1}{x}}{2}\right)}\right)
\] |
associate-/l/ [=>]98.2 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \log \color{blue}{\left(\frac{1}{2 \cdot x}\right)}\right)
\] |
associate-/r* [=>]98.9 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \log \color{blue}{\left(\frac{\frac{1}{2}}{x}\right)}\right)
\] |
metadata-eval [=>]98.9 | \[ \left(-0.25\right) \cdot \frac{1}{{x}^{2}} + \left(0 - \log \left(\frac{\color{blue}{0.5}}{x}\right)\right)
\] |
associate-+r- [=>]98.9 | \[ \color{blue}{\left(\left(-0.25\right) \cdot \frac{1}{{x}^{2}} + 0\right) - \log \left(\frac{0.5}{x}\right)}
\] |
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 3424 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 3424 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 3328 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 3296 |
| Alternative 5 | |
|---|---|
| Accuracy | 6.1% |
| Cost | 32 |
herbie shell --seed 2023141
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:herbie-target
(log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0)))))
(log (+ x (sqrt (- (* x x) 1.0)))))