
(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 8 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
(if (<= x -50.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.10000000149011612)
(copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -50.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.10000000149011612f) {
tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
} else {
tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-50.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.10000000149011612)) tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x); else tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-50.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.10000000149011612)) tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666)))); else tmp = sign(x) * abs(log((x + hypot(single(1.0), x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -50:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
\end{array}
if x < -50Initial program 50.3%
Taylor expanded in x around -inf 98.5%
associate--l+98.5%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt8.8%
sub-neg8.8%
associate-+r+99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 -0.0%
mul-1-neg-0.0%
sub-neg-0.0%
log-div99.6%
Simplified99.6%
if -50 < x < 0.100000001Initial program 23.4%
Taylor expanded in x around 0 22.7%
+-commutative22.7%
fma-def22.7%
unpow222.7%
associate-/l*22.7%
rem-square-sqrt10.9%
fabs-sqr10.9%
rem-square-sqrt21.9%
log1p-def97.0%
rem-square-sqrt45.0%
fabs-sqr45.0%
rem-square-sqrt98.0%
Simplified98.0%
Taylor expanded in x around 0 98.8%
*-commutative98.8%
Simplified98.8%
if 0.100000001 < x Initial program 46.4%
*-un-lft-identity46.4%
*-commutative46.4%
log-prod46.4%
add-sqr-sqrt46.4%
fabs-sqr46.4%
add-sqr-sqrt46.4%
+-commutative46.4%
hypot-1-def99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-rgt-identity99.8%
Simplified99.8%
Final simplification99.3%
(FPCore (x) :precision binary32 (if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) -5.0) (copysign (log (/ -0.5 x)) x) (copysign (log1p (+ x (+ (hypot 1.0 x) -1.0))) x)))
float code(float x) {
float tmp;
if (copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x) <= -5.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else {
tmp = copysignf(log1pf((x + (hypotf(1.0f, x) + -1.0f))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x) <= Float32(-5.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); else tmp = copysign(log1p(Float32(x + Float32(hypot(Float32(1.0), x) + Float32(-1.0)))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -5:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right), x\right)\\
\end{array}
\end{array}
if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < -5Initial program 50.3%
Taylor expanded in x around -inf 98.5%
associate--l+98.5%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt8.8%
sub-neg8.8%
associate-+r+99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 -0.0%
mul-1-neg-0.0%
sub-neg-0.0%
log-div99.6%
Simplified99.6%
if -5 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) Initial program 31.8%
log1p-expm1-u31.8%
expm1-udef31.8%
add-exp-log31.8%
add-sqr-sqrt23.8%
fabs-sqr23.8%
add-sqr-sqrt32.0%
+-commutative32.0%
hypot-1-def51.4%
Applied egg-rr51.4%
associate--l+97.9%
+-commutative97.9%
sub-neg97.9%
metadata-eval97.9%
Applied egg-rr97.9%
Final simplification98.3%
(FPCore (x)
:precision binary32
(if (<= x -50.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.4000000059604645)
(copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
(copysign (log (+ (/ 0.5 x) (+ x x))) x))))
float code(float x) {
float tmp;
if (x <= -50.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.4000000059604645f) {
tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
} else {
tmp = copysignf(logf(((0.5f / x) + (x + x))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-50.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.4000000059604645)) tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x); else tmp = copysign(log(Float32(Float32(Float32(0.5) / x) + Float32(x + x))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-50.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.4000000059604645)) tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666)))); else tmp = sign(x) * abs(log(((single(0.5) / x) + (x + x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -50:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\
\end{array}
\end{array}
if x < -50Initial program 50.3%
Taylor expanded in x around -inf 98.5%
associate--l+98.5%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt8.8%
sub-neg8.8%
associate-+r+99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 -0.0%
mul-1-neg-0.0%
sub-neg-0.0%
log-div99.6%
Simplified99.6%
if -50 < x < 0.400000006Initial program 24.0%
Taylor expanded in x around 0 22.9%
+-commutative22.9%
fma-def22.9%
unpow222.9%
associate-/l*22.9%
rem-square-sqrt11.3%
fabs-sqr11.3%
rem-square-sqrt22.2%
log1p-def96.6%
rem-square-sqrt45.1%
fabs-sqr45.1%
rem-square-sqrt97.6%
Simplified97.6%
Taylor expanded in x around 0 98.5%
*-commutative98.5%
Simplified98.5%
if 0.400000006 < x Initial program 45.7%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
+-commutative99.4%
associate-+l+99.4%
rem-square-sqrt99.4%
fabs-sqr99.4%
rem-square-sqrt99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.0%
(FPCore (x)
:precision binary32
(if (<= x -50.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.4000000059604645)
(copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
(copysign (log (+ x x)) x))))
float code(float x) {
float tmp;
if (x <= -50.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.4000000059604645f) {
tmp = copysignf((x + (powf(x, 3.0f) * -0.16666666666666666f)), x);
} else {
tmp = copysignf(logf((x + x)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-50.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.4000000059604645)) tmp = copysign(Float32(x + Float32((x ^ Float32(3.0)) * Float32(-0.16666666666666666))), x); else tmp = copysign(log(Float32(x + x)), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-50.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.4000000059604645)) tmp = sign(x) * abs((x + ((x ^ single(3.0)) * single(-0.16666666666666666)))); else tmp = sign(x) * abs(log((x + x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -50:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(x + {x}^{3} \cdot -0.16666666666666666, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\end{array}
if x < -50Initial program 50.3%
Taylor expanded in x around -inf 98.5%
associate--l+98.5%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt8.8%
sub-neg8.8%
associate-+r+99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 -0.0%
mul-1-neg-0.0%
sub-neg-0.0%
log-div99.6%
Simplified99.6%
if -50 < x < 0.400000006Initial program 24.0%
Taylor expanded in x around 0 22.9%
+-commutative22.9%
fma-def22.9%
unpow222.9%
associate-/l*22.9%
rem-square-sqrt11.3%
fabs-sqr11.3%
rem-square-sqrt22.2%
log1p-def96.6%
rem-square-sqrt45.1%
fabs-sqr45.1%
rem-square-sqrt97.6%
Simplified97.6%
Taylor expanded in x around 0 98.5%
*-commutative98.5%
Simplified98.5%
if 0.400000006 < x Initial program 45.7%
Taylor expanded in x around inf 98.5%
rem-square-sqrt98.5%
fabs-sqr98.5%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification98.8%
(FPCore (x) :precision binary32 (if (<= x -50.0) (copysign (log (/ -0.5 x)) x) (if (<= x 0.4000000059604645) (copysign x x) (copysign (log (+ x x)) x))))
float code(float x) {
float tmp;
if (x <= -50.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.4000000059604645f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x + x)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-50.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.4000000059604645)) tmp = copysign(x, x); else tmp = copysign(log(Float32(x + x)), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-50.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.4000000059604645)) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(log((x + x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -50:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\end{array}
if x < -50Initial program 50.3%
Taylor expanded in x around -inf 98.5%
associate--l+98.5%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
rem-square-sqrt8.8%
sub-neg8.8%
associate-+r+99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
metadata-eval99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 -0.0%
mul-1-neg-0.0%
sub-neg-0.0%
log-div99.6%
Simplified99.6%
if -50 < x < 0.400000006Initial program 24.0%
log1p-expm1-u24.0%
expm1-udef24.0%
add-exp-log24.0%
add-sqr-sqrt11.4%
fabs-sqr11.4%
add-sqr-sqrt24.4%
+-commutative24.4%
hypot-1-def24.2%
Applied egg-rr24.2%
associate--l+96.8%
+-commutative96.8%
sub-neg96.8%
metadata-eval96.8%
Applied egg-rr96.8%
Taylor expanded in x around 0 96.7%
if 0.400000006 < x Initial program 45.7%
Taylor expanded in x around inf 98.5%
rem-square-sqrt98.5%
fabs-sqr98.5%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification97.9%
(FPCore (x) :precision binary32 (if (<= x 0.4000000059604645) (copysign x x) (copysign (log (+ x x)) x)))
float code(float x) {
float tmp;
if (x <= 0.4000000059604645f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x + x)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.4000000059604645)) tmp = copysign(x, x); else tmp = copysign(log(Float32(x + x)), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(0.4000000059604645)) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(log((x + x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\end{array}
if x < 0.400000006Initial program 33.0%
log1p-expm1-u33.0%
expm1-udef33.0%
add-exp-log33.0%
add-sqr-sqrt7.5%
fabs-sqr7.5%
add-sqr-sqrt19.0%
+-commutative19.0%
hypot-1-def18.9%
Applied egg-rr18.9%
associate--l+66.6%
+-commutative66.6%
sub-neg66.6%
metadata-eval66.6%
Applied egg-rr66.6%
Taylor expanded in x around 0 67.3%
if 0.400000006 < x Initial program 45.7%
Taylor expanded in x around inf 98.5%
rem-square-sqrt98.5%
fabs-sqr98.5%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification75.7%
(FPCore (x) :precision binary32 (if (<= x 0.4000000059604645) (copysign x x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= 0.4000000059604645f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.4000000059604645)) tmp = copysign(x, x); else tmp = copysign(log1p(x), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\end{array}
if x < 0.400000006Initial program 33.0%
log1p-expm1-u33.0%
expm1-udef33.0%
add-exp-log33.0%
add-sqr-sqrt7.5%
fabs-sqr7.5%
add-sqr-sqrt19.0%
+-commutative19.0%
hypot-1-def18.9%
Applied egg-rr18.9%
associate--l+66.6%
+-commutative66.6%
sub-neg66.6%
metadata-eval66.6%
Applied egg-rr66.6%
Taylor expanded in x around 0 67.3%
if 0.400000006 < x Initial program 45.7%
Taylor expanded in x around 0 44.5%
log1p-def44.5%
rem-square-sqrt44.5%
fabs-sqr44.5%
rem-square-sqrt44.5%
Simplified44.5%
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 36.4%
log1p-expm1-u36.4%
expm1-udef36.4%
add-exp-log36.4%
add-sqr-sqrt17.8%
fabs-sqr17.8%
add-sqr-sqrt26.2%
+-commutative26.2%
hypot-1-def40.8%
Applied egg-rr40.8%
associate--l+75.6%
+-commutative75.6%
sub-neg75.6%
metadata-eval75.6%
Applied egg-rr75.6%
Taylor expanded in x around 0 52.1%
Final simplification52.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 2023292
(FPCore (x)
:name "Rust f32::asinh"
:precision binary32
:herbie-target
(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))