
(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 7 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 (fma (sqrt (+ x 1.0)) (sqrt (+ x -1.0)) x)))
float code(float x) {
return logf(fmaf(sqrtf((x + 1.0f)), sqrtf((x + -1.0f)), x));
}
function code(x) return log(fma(sqrt(Float32(x + Float32(1.0))), sqrt(Float32(x + Float32(-1.0))), x)) end
\begin{array}{l}
\\
\log \left(\mathsf{fma}\left(\sqrt{x + 1}, \sqrt{x + -1}, x\right)\right)
\end{array}
Initial program 51.7%
+-commutative51.7%
difference-of-sqr-151.7%
sqrt-prod99.5%
fma-define99.6%
sub-neg99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary32 (- (log (/ (+ 0.5 (/ 0.125 (pow x 2.0))) x))))
float code(float x) {
return -logf(((0.5f + (0.125f / powf(x, 2.0f))) / x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = -log(((0.5e0 + (0.125e0 / (x ** 2.0e0))) / x))
end function
function code(x) return Float32(-log(Float32(Float32(Float32(0.5) + Float32(Float32(0.125) / (x ^ Float32(2.0)))) / x))) end
function tmp = code(x) tmp = -log(((single(0.5) + (single(0.125) / (x ^ single(2.0)))) / x)); end
\begin{array}{l}
\\
-\log \left(\frac{0.5 + \frac{0.125}{{x}^{2}}}{x}\right)
\end{array}
Initial program 51.7%
fmm-def51.7%
metadata-eval51.7%
flip-+6.1%
metadata-eval6.1%
fmm-def6.1%
div-inv6.0%
log-prod6.1%
pow26.1%
add-sqr-sqrt6.0%
fmm-def6.0%
metadata-eval6.0%
Applied egg-rr6.0%
log-rec6.0%
sub-neg6.0%
fma-undefine6.0%
unpow26.0%
associate--r+8.6%
+-inverses8.6%
metadata-eval8.6%
metadata-eval8.6%
neg-sub08.6%
Simplified8.6%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary32 (log1p (+ (fma x 2.0 -1.0) (/ -0.5 x))))
float code(float x) {
return log1pf((fmaf(x, 2.0f, -1.0f) + (-0.5f / x)));
}
function code(x) return log1p(Float32(fma(x, Float32(2.0), Float32(-1.0)) + Float32(Float32(-0.5) / x))) end
\begin{array}{l}
\\
\mathsf{log1p}\left(\mathsf{fma}\left(x, 2, -1\right) + \frac{-0.5}{x}\right)
\end{array}
Initial program 51.7%
log1p-expm1-u51.7%
expm1-undefine51.7%
add-exp-log51.7%
fmm-def51.7%
metadata-eval51.7%
Applied egg-rr51.7%
Taylor expanded in x around inf 98.6%
Taylor expanded in x around 0 49.6%
div-sub49.6%
sub-neg49.6%
*-commutative49.6%
associate-/l*98.6%
*-commutative98.6%
fmm-def98.6%
metadata-eval98.6%
Applied egg-rr98.6%
*-inverses98.6%
*-rgt-identity98.6%
distribute-neg-frac98.6%
metadata-eval98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x) :precision binary32 (log1p (* x (+ 2.0 (/ (+ -1.0 (* 0.5 (/ -1.0 x))) x)))))
float code(float x) {
return log1pf((x * (2.0f + ((-1.0f + (0.5f * (-1.0f / x))) / x))));
}
function code(x) return log1p(Float32(x * Float32(Float32(2.0) + Float32(Float32(Float32(-1.0) + Float32(Float32(0.5) * Float32(Float32(-1.0) / x))) / x)))) end
\begin{array}{l}
\\
\mathsf{log1p}\left(x \cdot \left(2 + \frac{-1 + 0.5 \cdot \frac{-1}{x}}{x}\right)\right)
\end{array}
Initial program 51.7%
log1p-expm1-u51.7%
expm1-undefine51.7%
add-exp-log51.7%
fmm-def51.7%
metadata-eval51.7%
Applied egg-rr51.7%
Taylor expanded in x around inf 98.6%
Final simplification98.6%
(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.7%
metadata-eval51.7%
flip-+6.1%
metadata-eval6.1%
fmm-def6.1%
div-inv6.0%
log-prod6.1%
pow26.1%
add-sqr-sqrt6.0%
fmm-def6.0%
metadata-eval6.0%
Applied egg-rr6.0%
log-rec6.0%
sub-neg6.0%
fma-undefine6.0%
unpow26.0%
associate--r+8.6%
+-inverses8.6%
metadata-eval8.6%
metadata-eval8.6%
neg-sub08.6%
Simplified8.6%
Taylor expanded in x around inf 98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in x around inf 97.9%
Final simplification97.9%
(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%
Final simplification97.5%
(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%
add-cube-cbrt97.4%
log-prod96.7%
Applied egg-rr-0.0%
Simplified6.1%
Final simplification6.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 2024109
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:alt
(log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0)))))
(log (+ x (sqrt (- (* x x) 1.0)))))