
(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 5 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 (/ (/ 0.125 x) x)) x))))
float code(float x) {
return -logf(((0.5f + ((0.125f / x) / x)) / x));
}
real(4) function code(x)
real(4), intent (in) :: x
code = -log(((0.5e0 + ((0.125e0 / x) / x)) / x))
end function
function code(x) return Float32(-log(Float32(Float32(Float32(0.5) + Float32(Float32(Float32(0.125) / x) / x)) / x))) end
function tmp = code(x) tmp = -log(((single(0.5) + ((single(0.125) / x) / x)) / x)); end
\begin{array}{l}
\\
-\log \left(\frac{0.5 + \frac{\frac{0.125}{x}}{x}}{x}\right)
\end{array}
Initial program 50.2%
flip-+7.9%
div-inv7.9%
log-prod7.9%
pow27.9%
add-sqr-sqrt7.6%
fma-neg7.6%
metadata-eval7.6%
fma-neg7.6%
metadata-eval7.6%
Applied egg-rr7.6%
log-rec7.6%
sub-neg7.6%
fma-undefine7.6%
unpow27.6%
associate--r+9.9%
+-inverses9.9%
metadata-eval9.9%
metadata-eval9.9%
neg-sub09.9%
Simplified9.9%
Taylor expanded in x around inf 99.1%
un-div-inv99.1%
unpow299.1%
associate-/r*99.1%
Applied egg-rr99.1%
Final simplification99.1%
(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 50.2%
flip-+7.9%
div-inv7.9%
log-prod7.9%
pow27.9%
add-sqr-sqrt7.6%
fma-neg7.6%
metadata-eval7.6%
fma-neg7.6%
metadata-eval7.6%
Applied egg-rr7.6%
log-rec7.6%
sub-neg7.6%
fma-undefine7.6%
unpow27.6%
associate--r+9.9%
+-inverses9.9%
metadata-eval9.9%
metadata-eval9.9%
neg-sub09.9%
Simplified9.9%
Taylor expanded in x around inf 97.7%
Final simplification97.7%
(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 50.2%
Taylor expanded in x around inf 96.3%
Final simplification96.3%
(FPCore (x) :precision binary32 (- (log1p -1.0)))
float code(float x) {
return -log1pf(-1.0f);
}
function code(x) return Float32(-log1p(Float32(-1.0))) end
\begin{array}{l}
\\
-\mathsf{log1p}\left(-1\right)
\end{array}
Initial program 50.2%
flip-+7.9%
div-inv7.9%
log-prod7.9%
pow27.9%
add-sqr-sqrt7.6%
fma-neg7.6%
metadata-eval7.6%
fma-neg7.6%
metadata-eval7.6%
Applied egg-rr7.6%
log-rec7.6%
sub-neg7.6%
fma-undefine7.6%
unpow27.6%
associate--r+9.9%
+-inverses9.9%
metadata-eval9.9%
metadata-eval9.9%
neg-sub09.9%
Simplified9.9%
Taylor expanded in x around inf 97.7%
log1p-expm1-u18.2%
expm1-undefine18.2%
add-exp-log18.2%
Applied egg-rr18.2%
Taylor expanded in x around inf 6.4%
Final simplification6.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 50.2%
Taylor expanded in x around inf 96.3%
add-sqr-sqrt96.3%
log-prod96.3%
flip-+-0.0%
difference-of-squares-0.0%
+-inverses-0.0%
metadata-eval-0.0%
+-inverses-0.0%
metadata-eval-0.0%
associate-*r/-0.0%
metadata-eval-0.0%
+-inverses-0.0%
unpow2-0.0%
unpow2-0.0%
metadata-eval-0.0%
+-inverses-0.0%
flip-+17.6%
sqrt-unprod30.2%
add-sqr-sqrt30.2%
count-230.2%
sum-log30.2%
flip-+-0.0%
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 2024078
(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)))))