
(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
\begin{array}{l}
\\
\sinh^{-1} x
\end{array}
Sampling outcomes in binary32 precision:
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
\begin{array}{l}
\\
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\end{array}
(FPCore (x)
:precision binary32
(let* ((t_0 (pow (+ x 1.0) 2.0)))
(if (<=
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)
-0.20000000298023224)
(copysign (log (/ -1.0 (- x (hypot 1.0 x)))) x)
(copysign
(fma
(pow x 2.0)
(fma
(pow x 2.0)
(fma
0.001388888888888889
(*
(pow x 2.0)
(+ (/ 45.0 (+ x 1.0)) (+ (/ 45.0 t_0) (/ 30.0 (pow (+ x 1.0) 3.0)))))
(+ (/ -0.125 (+ x 1.0)) (/ -0.125 t_0)))
(/ 0.5 (+ x 1.0)))
(log1p x))
x))))
float code(float x) {
float t_0 = powf((x + 1.0f), 2.0f);
float tmp;
if (copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x) <= -0.20000000298023224f) {
tmp = copysignf(logf((-1.0f / (x - hypotf(1.0f, x)))), x);
} else {
tmp = copysignf(fmaf(powf(x, 2.0f), fmaf(powf(x, 2.0f), fmaf(0.001388888888888889f, (powf(x, 2.0f) * ((45.0f / (x + 1.0f)) + ((45.0f / t_0) + (30.0f / powf((x + 1.0f), 3.0f))))), ((-0.125f / (x + 1.0f)) + (-0.125f / t_0))), (0.5f / (x + 1.0f))), log1pf(x)), x);
}
return tmp;
}
function code(x) t_0 = Float32(x + Float32(1.0)) ^ Float32(2.0) tmp = Float32(0.0) if (copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x) <= Float32(-0.20000000298023224)) tmp = copysign(log(Float32(Float32(-1.0) / Float32(x - hypot(Float32(1.0), x)))), x); else tmp = copysign(fma((x ^ Float32(2.0)), fma((x ^ Float32(2.0)), fma(Float32(0.001388888888888889), Float32((x ^ Float32(2.0)) * Float32(Float32(Float32(45.0) / Float32(x + Float32(1.0))) + Float32(Float32(Float32(45.0) / t_0) + Float32(Float32(30.0) / (Float32(x + Float32(1.0)) ^ Float32(3.0)))))), Float32(Float32(Float32(-0.125) / Float32(x + Float32(1.0))) + Float32(Float32(-0.125) / t_0))), Float32(Float32(0.5) / Float32(x + Float32(1.0)))), log1p(x)), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(x + 1\right)}^{2}\\
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left({x}^{2}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left(0.001388888888888889, {x}^{2} \cdot \left(\frac{45}{x + 1} + \left(\frac{45}{t\_0} + \frac{30}{{\left(x + 1\right)}^{3}}\right)\right), \frac{-0.125}{x + 1} + \frac{-0.125}{t\_0}\right), \frac{0.5}{x + 1}\right), \mathsf{log1p}\left(x\right)\right), x\right)\\
\end{array}
\end{array}
if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < -0.200000003Initial program 57.4%
+-commutative57.4%
hypot-1-def99.8%
flip-+14.9%
hypot-1-def14.9%
hypot-1-def14.9%
add-sqr-sqrt14.9%
+-commutative14.9%
hypot-1-def14.9%
+-commutative14.9%
div-sub15.1%
Applied egg-rr17.4%
div-sub20.9%
remove-double-neg20.9%
remove-double-neg20.9%
fma-undefine20.8%
unpow220.8%
associate--r+54.6%
+-inverses99.8%
metadata-eval99.8%
Simplified99.8%
if -0.200000003 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) Initial program 34.0%
Taylor expanded in x around 0 17.3%
Simplified67.4%
Final simplification74.1%
(FPCore (x) :precision binary32 (copysign (log1p (fabs x)) x))
float code(float x) {
return copysignf(log1pf(fabsf(x)), x);
}
function code(x) return copysign(log1p(abs(x)), x) end
\begin{array}{l}
\\
\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)
\end{array}
Initial program 38.8%
Taylor expanded in x around 0 30.8%
log1p-define69.7%
Simplified69.7%
Final simplification69.7%
(FPCore (x)
:precision binary32
(if (<= x -5.0)
(copysign (log (/ -0.5 x)) x)
(copysign
(*
x
(+
1.0
(* (pow x 2.0) (- (* x (- (* x -0.05) 0.125)) 0.16666666666666666))))
x)))
float code(float x) {
float tmp;
if (x <= -5.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else {
tmp = copysignf((x * (1.0f + (powf(x, 2.0f) * ((x * ((x * -0.05f) - 0.125f)) - 0.16666666666666666f)))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-5.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); else tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32((x ^ Float32(2.0)) * Float32(Float32(x * Float32(Float32(x * Float32(-0.05)) - Float32(0.125))) - Float32(0.16666666666666666))))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-5.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); else tmp = sign(x) * abs((x * (single(1.0) + ((x ^ single(2.0)) * ((x * ((x * single(-0.05)) - single(0.125))) - single(0.16666666666666666)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left(x \cdot \left(x \cdot -0.05 - 0.125\right) - 0.16666666666666666\right)\right), x\right)\\
\end{array}
\end{array}
if x < -5Initial program 54.2%
Taylor expanded in x around -inf 99.1%
mul-1-neg99.1%
*-commutative99.1%
distribute-rgt-neg-in99.1%
mul-1-neg99.1%
unsub-neg99.1%
sub-neg99.1%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt12.5%
associate-*r/12.5%
metadata-eval12.5%
distribute-neg-frac12.5%
metadata-eval12.5%
Simplified12.5%
Taylor expanded in x around 0 97.6%
if -5 < x Initial program 35.2%
+-commutative35.2%
hypot-1-def49.7%
flip-+16.7%
hypot-1-def16.7%
hypot-1-def16.6%
add-sqr-sqrt16.6%
+-commutative16.6%
hypot-1-def16.6%
+-commutative16.6%
div-sub16.6%
Applied egg-rr16.4%
div-sub16.7%
remove-double-neg16.7%
remove-double-neg16.7%
fma-undefine16.7%
unpow216.7%
associate--r+16.8%
+-inverses16.8%
metadata-eval16.8%
Simplified16.8%
Taylor expanded in x around 0 20.7%
Taylor expanded in x around 0 66.2%
Final simplification72.2%
(FPCore (x) :precision binary32 (copysign (log1p x) x))
float code(float x) {
return copysignf(log1pf(x), x);
}
function code(x) return copysign(log1p(x), x) end
\begin{array}{l}
\\
\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)
\end{array}
Initial program 38.8%
Taylor expanded in x around 0 30.8%
log1p-define69.7%
rem-square-sqrt37.0%
fabs-sqr37.0%
rem-square-sqrt61.1%
Simplified61.1%
Final simplification61.1%
(FPCore (x) :precision binary32 (copysign x x))
float code(float x) {
return copysignf(x, x);
}
function code(x) return copysign(x, x) end
function tmp = code(x) tmp = sign(x) * abs(x); end
\begin{array}{l}
\\
\mathsf{copysign}\left(x, x\right)
\end{array}
Initial program 38.8%
Taylor expanded in x around 0 20.2%
+-commutative20.2%
fma-define20.2%
rem-square-sqrt10.3%
fabs-sqr10.3%
rem-square-sqrt20.3%
Simplified20.3%
Taylor expanded in x around 0 55.8%
distribute-rgt-in55.8%
*-lft-identity55.8%
associate-*l*55.8%
unpow255.8%
unpow355.8%
Simplified55.8%
Taylor expanded in x around 0 56.1%
Final simplification56.1%
(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}
\\
\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}
\end{array}
herbie shell --seed 2024066
(FPCore (x)
:name "Rust f32::asinh"
:precision binary32
:alt
(copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))) x)
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))