
(FPCore (x) :precision binary32 (acosh x))
float code(float x) {
return acoshf(x);
}
function code(x) return acosh(x) end
function tmp = code(x) tmp = acosh(x); end
\begin{array}{l}
\\
\cosh^{-1} x
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (log (+ x (sqrt (- (* x x) 1.0)))))
float code(float x) {
return logf((x + sqrtf(((x * x) - 1.0f))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + sqrt(((x * x) - 1.0e0))))
end function
function code(x) return log(Float32(x + sqrt(Float32(Float32(x * x) - Float32(1.0))))) end
function tmp = code(x) tmp = log((x + sqrt(((x * x) - single(1.0))))); end
\begin{array}{l}
\\
\log \left(x + \sqrt{x \cdot x - 1}\right)
\end{array}
(FPCore (x) :precision binary32 (- (log (/ 0.5 x))))
float code(float x) {
return -logf((0.5f / x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = -log((0.5e0 / x))
end function
function code(x) return Float32(-log(Float32(Float32(0.5) / x))) end
function tmp = code(x) tmp = -log((single(0.5) / x)); end
\begin{array}{l}
\\
-\log \left(\frac{0.5}{x}\right)
\end{array}
Initial program 51.7%
fmm-def51.8%
metadata-eval51.8%
flip-+5.6%
metadata-eval5.6%
fmm-def5.6%
div-inv5.6%
log-prod5.5%
pow25.5%
add-sqr-sqrt5.4%
fmm-def5.4%
metadata-eval5.4%
Applied egg-rr5.4%
log-rec5.5%
sub-neg5.5%
fma-undefine5.4%
unpow25.4%
associate--r+8.1%
+-inverses8.1%
metadata-eval8.1%
metadata-eval8.1%
neg-sub08.1%
Simplified8.1%
Taylor expanded in x around inf 97.8%
(FPCore (x) :precision binary32 (log (+ x x)))
float code(float x) {
return logf((x + x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + x))
end function
function code(x) return log(Float32(x + x)) end
function tmp = code(x) tmp = log((x + x)); end
\begin{array}{l}
\\
\log \left(x + x\right)
\end{array}
Initial program 51.7%
Taylor expanded in x around inf 97.5%
(FPCore (x) :precision binary32 (- (log 0.0)))
float code(float x) {
return -logf(0.0f);
}
real(4) function code(x)
real(4), intent (in) :: x
code = -log(0.0e0)
end function
function code(x) return Float32(-log(Float32(0.0))) end
function tmp = code(x) tmp = -log(single(0.0)); end
\begin{array}{l}
\\
-\log 0
\end{array}
Initial program 51.7%
fmm-def51.8%
metadata-eval51.8%
flip-+5.6%
metadata-eval5.6%
fmm-def5.6%
div-inv5.6%
log-prod5.5%
pow25.5%
add-sqr-sqrt5.4%
fmm-def5.4%
metadata-eval5.4%
Applied egg-rr5.4%
log-rec5.5%
sub-neg5.5%
fma-undefine5.4%
unpow25.4%
associate--r+8.1%
+-inverses8.1%
metadata-eval8.1%
metadata-eval8.1%
neg-sub08.1%
Simplified8.1%
fma-undefine8.1%
difference-of-sqr--18.1%
sub-neg8.1%
metadata-eval8.1%
Applied egg-rr8.1%
Taylor expanded in x around -inf -0.0%
distribute-rgt-in-0.0%
unpow2-0.0%
rem-square-sqrt6.4%
distribute-rgt-in6.4%
metadata-eval6.4%
mul0-rgt6.4%
Simplified6.4%
(FPCore (x) :precision binary32 0.0)
float code(float x) {
return 0.0f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.0e0
end function
function code(x) return Float32(0.0) end
function tmp = code(x) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 51.7%
Taylor expanded in x around inf 97.5%
flip-+-0.0%
log-div-0.0%
+-inverses-0.0%
+-inverses-0.0%
Applied egg-rr-0.0%
+-inverses6.1%
Simplified6.1%
(FPCore (x) :precision binary32 (log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0))))))
float code(float x) {
return logf((x + (sqrtf((x - 1.0f)) * sqrtf((x + 1.0f)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = log((x + (sqrt((x - 1.0e0)) * sqrt((x + 1.0e0)))))
end function
function code(x) return log(Float32(x + Float32(sqrt(Float32(x - Float32(1.0))) * sqrt(Float32(x + Float32(1.0)))))) end
function tmp = code(x) tmp = log((x + (sqrt((x - single(1.0))) * sqrt((x + single(1.0)))))); end
\begin{array}{l}
\\
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right)
\end{array}
herbie shell --seed 2024170
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:alt
(! :herbie-platform default (log (+ x (* (sqrt (- x 1)) (sqrt (+ x 1))))))
(log (+ x (sqrt (- (* x x) 1.0)))))