
(FPCore (x) :precision binary32 (asinh x))
float code(float x) {
return asinhf(x);
}
function code(x) return asinh(x) end
function tmp = code(x) tmp = asinh(x); end
\sinh^{-1} x
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
float code(float x) {
return copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
}
function code(x) return copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x) end
function tmp = code(x) tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + single(1.0)))))); end
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
(FPCore (x) :precision binary32 (copysign (asinh (fabs x)) x))
float code(float x) {
return copysignf(asinhf(fabsf(x)), x);
}
function code(x) return copysign(asinh(abs(x)), x) end
function tmp = code(x) tmp = sign(x) * abs(asinh(abs(x))); end
\mathsf{copysign}\left(\sinh^{-1} \left(\left|x\right|\right), x\right)
Initial program 37.7%
lift-log.f32N/A
lift-+.f32N/A
lift-sqrt.f32N/A
lift-+.f32N/A
lift-*.f32N/A
sqr-abs-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
asinh-def-revN/A
lower-asinh.f3299.6%
Applied rewrites99.6%
(FPCore (x) :precision binary32 (* (copysign 1.0 x) (if (<= (fabs x) 1.0) (copysign (* -1.0 (fabs x)) (fabs x)) (copysign (log (/ 0.5 (fabs x))) (fabs x)))))
float code(float x) {
float tmp;
if (fabsf(x) <= 1.0f) {
tmp = copysignf((-1.0f * fabsf(x)), fabsf(x));
} else {
tmp = copysignf(logf((0.5f / fabsf(x))), fabsf(x));
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(1.0)) tmp = copysign(Float32(Float32(-1.0) * abs(x)), abs(x)); else tmp = copysign(log(Float32(Float32(0.5) / abs(x))), abs(x)); end return Float32(copysign(Float32(1.0), x) * tmp) end
function tmp_2 = code(x) tmp = single(0.0); if (abs(x) <= single(1.0)) tmp = sign(abs(x)) * abs((single(-1.0) * abs(x))); else tmp = sign(abs(x)) * abs(log((single(0.5) / abs(x)))); end tmp_2 = (sign(x) * abs(single(1.0))) * tmp; end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(-1 \cdot \left|x\right|, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{\left|x\right|}\right), \left|x\right|\right)\\
\end{array}
if x < 1Initial program 37.7%
Taylor expanded in x around -inf
lower-*.f3229.5%
Applied rewrites29.5%
lift-*.f32N/A
mul-1-negN/A
lower-neg.f3229.5%
Applied rewrites29.5%
lift-+.f32N/A
+-commutativeN/A
add-flipN/A
lower--.f32N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-neg.f32N/A
lift-neg.f32N/A
sqr-neg-revN/A
rem-sqrt-square-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
Applied rewrites29.5%
Taylor expanded in x around 0
lower-*.f3254.5%
Applied rewrites54.5%
if 1 < x Initial program 37.7%
Taylor expanded in x around -inf
lower-*.f3229.5%
Applied rewrites29.5%
lift-*.f32N/A
mul-1-negN/A
lower-neg.f3229.5%
Applied rewrites29.5%
lift-+.f32N/A
+-commutativeN/A
add-flipN/A
lower--.f32N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-neg.f32N/A
lift-neg.f32N/A
sqr-neg-revN/A
rem-sqrt-square-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
Applied rewrites29.5%
Taylor expanded in x around inf
lower-/.f3226.7%
Applied rewrites26.7%
(FPCore (x) :precision binary32 (* (copysign 1.0 x) (if (<= (fabs x) 1.0) (copysign (* -1.0 (fabs x)) (fabs x)) (copysign (log (+ (fabs (fabs x)) (fabs x))) (fabs x)))))
float code(float x) {
float tmp;
if (fabsf(x) <= 1.0f) {
tmp = copysignf((-1.0f * fabsf(x)), fabsf(x));
} else {
tmp = copysignf(logf((fabsf(fabsf(x)) + fabsf(x))), fabsf(x));
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(1.0)) tmp = copysign(Float32(Float32(-1.0) * abs(x)), abs(x)); else tmp = copysign(log(Float32(abs(abs(x)) + abs(x))), abs(x)); end return Float32(copysign(Float32(1.0), x) * tmp) end
function tmp_2 = code(x) tmp = single(0.0); if (abs(x) <= single(1.0)) tmp = sign(abs(x)) * abs((single(-1.0) * abs(x))); else tmp = sign(abs(x)) * abs(log((abs(abs(x)) + abs(x)))); end tmp_2 = (sign(x) * abs(single(1.0))) * tmp; end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(-1 \cdot \left|x\right|, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|\left|x\right|\right| + \left|x\right|\right), \left|x\right|\right)\\
\end{array}
if x < 1Initial program 37.7%
Taylor expanded in x around -inf
lower-*.f3229.5%
Applied rewrites29.5%
lift-*.f32N/A
mul-1-negN/A
lower-neg.f3229.5%
Applied rewrites29.5%
lift-+.f32N/A
+-commutativeN/A
add-flipN/A
lower--.f32N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-neg.f32N/A
lift-neg.f32N/A
sqr-neg-revN/A
rem-sqrt-square-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
Applied rewrites29.5%
Taylor expanded in x around 0
lower-*.f3254.5%
Applied rewrites54.5%
if 1 < x Initial program 37.7%
Taylor expanded in x around inf
lower-*.f32N/A
lower-+.f32N/A
lower-/.f32N/A
lower-fabs.f3229.4%
Applied rewrites29.4%
lift-*.f32N/A
*-commutativeN/A
lift-+.f32N/A
lift-/.f32N/A
sum-to-mult-revN/A
+-commutativeN/A
lower-+.f3229.4%
Applied rewrites29.4%
(FPCore (x) :precision binary32 (* (copysign 1.0 x) (if (<= (fabs x) 1.0) (copysign (* -1.0 (fabs x)) (fabs x)) (copysign (log (+ 1.0 (fabs (fabs x)))) (fabs x)))))
float code(float x) {
float tmp;
if (fabsf(x) <= 1.0f) {
tmp = copysignf((-1.0f * fabsf(x)), fabsf(x));
} else {
tmp = copysignf(logf((1.0f + fabsf(fabsf(x)))), fabsf(x));
}
return copysignf(1.0f, x) * tmp;
}
function code(x) tmp = Float32(0.0) if (abs(x) <= Float32(1.0)) tmp = copysign(Float32(Float32(-1.0) * abs(x)), abs(x)); else tmp = copysign(log(Float32(Float32(1.0) + abs(abs(x)))), abs(x)); end return Float32(copysign(Float32(1.0), x) * tmp) end
function tmp_2 = code(x) tmp = single(0.0); if (abs(x) <= single(1.0)) tmp = sign(abs(x)) * abs((single(-1.0) * abs(x))); else tmp = sign(abs(x)) * abs(log((single(1.0) + abs(abs(x))))); end tmp_2 = (sign(x) * abs(single(1.0))) * tmp; end
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(-1 \cdot \left|x\right|, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(1 + \left|\left|x\right|\right|\right), \left|x\right|\right)\\
\end{array}
if x < 1Initial program 37.7%
Taylor expanded in x around -inf
lower-*.f3229.5%
Applied rewrites29.5%
lift-*.f32N/A
mul-1-negN/A
lower-neg.f3229.5%
Applied rewrites29.5%
lift-+.f32N/A
+-commutativeN/A
add-flipN/A
lower--.f32N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-neg.f32N/A
lift-neg.f32N/A
sqr-neg-revN/A
rem-sqrt-square-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
Applied rewrites29.5%
Taylor expanded in x around 0
lower-*.f3254.5%
Applied rewrites54.5%
if 1 < x Initial program 37.7%
Taylor expanded in x around 0
lower-+.f32N/A
lower-fabs.f3231.4%
Applied rewrites31.4%
(FPCore (x) :precision binary32 (copysign (* -1.0 x) x))
float code(float x) {
return copysignf((-1.0f * x), x);
}
function code(x) return copysign(Float32(Float32(-1.0) * x), x) end
function tmp = code(x) tmp = sign(x) * abs((single(-1.0) * x)); end
\mathsf{copysign}\left(-1 \cdot x, x\right)
Initial program 37.7%
Taylor expanded in x around -inf
lower-*.f3229.5%
Applied rewrites29.5%
lift-*.f32N/A
mul-1-negN/A
lower-neg.f3229.5%
Applied rewrites29.5%
lift-+.f32N/A
+-commutativeN/A
add-flipN/A
lower--.f32N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-neg.f32N/A
lift-neg.f32N/A
sqr-neg-revN/A
rem-sqrt-square-revN/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
lift-fabs.f32N/A
Applied rewrites29.5%
Taylor expanded in x around 0
lower-*.f3254.5%
Applied rewrites54.5%
(FPCore (x) :precision binary32 (let* ((t_0 (/ 1.0 (fabs x)))) (copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 t_0) t_0)))) x)))
float code(float x) {
float t_0 = 1.0f / fabsf(x);
return copysignf(log1pf((fabsf(x) + (fabsf(x) / (hypotf(1.0f, t_0) + t_0)))), x);
}
function code(x) t_0 = Float32(Float32(1.0) / abs(x)) return copysign(log1p(Float32(abs(x) + Float32(abs(x) / Float32(hypot(Float32(1.0), t_0) + t_0)))), x) end
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, t\_0\right) + t\_0}\right), x\right)
\end{array}
herbie shell --seed 2025212
(FPCore (x)
:name "Rust f32::asinh"
:precision binary32
:alt
(! :herbie-platform c (let* ((ax (fabs x)) (ix (/ 1 ax))) (copysign (log1p (+ ax (/ ax (+ (hypot 1 ix) ix)))) x)))
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))