
(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
\cosh^{-1} x
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)
use fmin_fmax_functions
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
\log \left(x + \sqrt{x \cdot x - 1}\right)
(FPCore (x) :precision binary32 (if (<= x 0.5) (* 0.0 1.0) (log (fma (sqrt (fabs (- 1.0 x))) (sqrt (fabs (- -1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= 0.5f) {
tmp = 0.0f * 1.0f;
} else {
tmp = logf(fmaf(sqrtf(fabsf((1.0f - x))), sqrtf(fabsf((-1.0f - x))), x));
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.5)) tmp = Float32(Float32(0.0) * Float32(1.0)); else tmp = log(fma(sqrt(abs(Float32(Float32(1.0) - x))), sqrt(abs(Float32(Float32(-1.0) - x))), x)); end return tmp end
\begin{array}{l}
\mathbf{if}\;x \leq 0.5:\\
\;\;\;\;0 \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\sqrt{\left|1 - x\right|}, \sqrt{\left|-1 - x\right|}, x\right)\right)\\
\end{array}
if x < 0.5Initial program 14.3%
rem-square-sqrtN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
fabs-sqrN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
rem-square-sqrtN/A
lift--.f32N/A
lift-*.f32N/A
difference-of-sqr-1N/A
*-commutativeN/A
fabs-mulN/A
lower-*.f32N/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
add-flipN/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
metadata-eval55.1%
Applied rewrites55.1%
Taylor expanded in x around 0
lower-*.f32N/A
lower-+.f32N/A
lower-*.f326.7%
Applied rewrites6.7%
Taylor expanded in x around 0
Applied rewrites9.4%
Taylor expanded in undef-var around zero
Applied rewrites76.1%
if 0.5 < x Initial program 14.3%
lift-+.f32N/A
+-commutativeN/A
lift-sqrt.f32N/A
lift--.f32N/A
lift-*.f32N/A
difference-of-sqr-1N/A
sqrt-prodN/A
*-commutativeN/A
lower-fma.f32N/A
lower-sqrt.f32N/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
lower-sqrt.f32N/A
add-flipN/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
metadata-eval67.1%
Applied rewrites67.1%
(FPCore (x) :precision binary32 (if (<= x 0.5) (* 0.0 1.0) (acosh x)))
float code(float x) {
float tmp;
if (x <= 0.5f) {
tmp = 0.0f * 1.0f;
} else {
tmp = acoshf(x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.5)) tmp = Float32(Float32(0.0) * Float32(1.0)); else tmp = acosh(x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(0.5)) tmp = single(0.0) * single(1.0); else tmp = acosh(x); end tmp_2 = tmp; end
\begin{array}{l}
\mathbf{if}\;x \leq 0.5:\\
\;\;\;\;0 \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\cosh^{-1} x\\
\end{array}
if x < 0.5Initial program 14.3%
rem-square-sqrtN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
fabs-sqrN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
rem-square-sqrtN/A
lift--.f32N/A
lift-*.f32N/A
difference-of-sqr-1N/A
*-commutativeN/A
fabs-mulN/A
lower-*.f32N/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
add-flipN/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
metadata-eval55.1%
Applied rewrites55.1%
Taylor expanded in x around 0
lower-*.f32N/A
lower-+.f32N/A
lower-*.f326.7%
Applied rewrites6.7%
Taylor expanded in x around 0
Applied rewrites9.4%
Taylor expanded in undef-var around zero
Applied rewrites76.1%
if 0.5 < x Initial program 14.3%
lift-log.f32N/A
lift-+.f32N/A
lift-sqrt.f32N/A
lift--.f32N/A
lift-*.f32N/A
acosh-def-revN/A
lower-acosh.f3225.3%
Applied rewrites25.3%
(FPCore (x) :precision binary32 (* 0.0 1.0))
float code(float x) {
return 0.0f * 1.0f;
}
real(4) function code(x)
use fmin_fmax_functions
real(4), intent (in) :: x
code = 0.0e0 * 1.0e0
end function
function code(x) return Float32(Float32(0.0) * Float32(1.0)) end
function tmp = code(x) tmp = single(0.0) * single(1.0); end
0 \cdot 1
Initial program 14.3%
rem-square-sqrtN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
fabs-sqrN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
rem-square-sqrtN/A
lift--.f32N/A
lift-*.f32N/A
difference-of-sqr-1N/A
*-commutativeN/A
fabs-mulN/A
lower-*.f32N/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
add-flipN/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
metadata-eval55.1%
Applied rewrites55.1%
Taylor expanded in x around 0
lower-*.f32N/A
lower-+.f32N/A
lower-*.f326.7%
Applied rewrites6.7%
Taylor expanded in x around 0
Applied rewrites9.4%
Taylor expanded in undef-var around zero
Applied rewrites76.1%
(FPCore (x) :precision binary32 (* x 1.0))
float code(float x) {
return x * 1.0f;
}
real(4) function code(x)
use fmin_fmax_functions
real(4), intent (in) :: x
code = x * 1.0e0
end function
function code(x) return Float32(x * Float32(1.0)) end
function tmp = code(x) tmp = x * single(1.0); end
x \cdot 1
Initial program 14.3%
rem-square-sqrtN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
fabs-sqrN/A
lift-sqrt.f32N/A
lift-sqrt.f32N/A
rem-square-sqrtN/A
lift--.f32N/A
lift-*.f32N/A
difference-of-sqr-1N/A
*-commutativeN/A
fabs-mulN/A
lower-*.f32N/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
add-flipN/A
fabs-subN/A
lower-fabs.f32N/A
lower--.f32N/A
metadata-eval55.1%
Applied rewrites55.1%
Taylor expanded in x around 0
lower-*.f32N/A
lower-+.f32N/A
lower-*.f326.7%
Applied rewrites6.7%
Taylor expanded in x around 0
Applied rewrites9.4%
(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)
use fmin_fmax_functions
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
\log \left(x + \sqrt{x - 1} \cdot \sqrt{x + 1}\right)
herbie shell --seed 2025313 -o setup:search
(FPCore (x)
:name "Rust f32::acosh"
:precision binary32
:pre (>= x 1.0)
:alt
(! :herbie-platform c (log (+ x (* (sqrt (- x 1)) (sqrt (+ x 1))))))
(log (+ x (sqrt (- (* x x) 1.0)))))