
(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
(let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
(if (<= t_0 -0.5)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= t_0 0.03999999910593033)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ x (hypot 1.0 x))) x)))))
float code(float x) {
float t_0 = copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
float tmp;
if (t_0 <= -0.5f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (t_0 <= 0.03999999910593033f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
}
return tmp;
}
function code(x) t_0 = copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x) tmp = Float32(0.0) if (t_0 <= Float32(-0.5)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (t_0 <= Float32(0.03999999910593033)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x); end return tmp end
function tmp_2 = code(x) t_0 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + single(1.0)))))); tmp = single(0.0); if (t_0 <= single(-0.5)) tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x))); elseif (t_0 <= single(0.03999999910593033)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); else tmp = sign(x) * abs(log((x + hypot(single(1.0), x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;t\_0 \leq 0.03999999910593033:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, 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.5Initial program 61.2%
+-commutative61.2%
hypot-1-def99.9%
Simplified99.9%
flip-+7.1%
clear-num7.1%
log-div7.1%
metadata-eval7.1%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt7.6%
pow27.6%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt7.6%
hypot-1-def7.6%
hypot-1-def7.6%
add-sqr-sqrt8.5%
+-commutative8.5%
Applied egg-rr9.0%
neg-sub09.0%
div-sub9.0%
fma-undefine8.5%
unpow28.5%
associate--r+9.1%
+-inverses9.1%
metadata-eval9.1%
*-rgt-identity9.1%
associate-/l*9.1%
metadata-eval9.1%
*-commutative9.1%
fma-undefine8.5%
unpow28.5%
associate--r+58.5%
+-inverses99.9%
metadata-eval99.9%
*-rgt-identity99.9%
associate-/l*99.9%
metadata-eval99.9%
*-commutative99.9%
neg-mul-199.9%
Simplified99.9%
if -0.5 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < 0.0399999991Initial program 16.5%
+-commutative16.5%
hypot-1-def16.5%
Simplified16.5%
add-log-exp16.6%
*-un-lft-identity16.6%
exp-prod15.9%
log-pow15.6%
add-sqr-sqrt8.0%
fabs-sqr8.0%
add-sqr-sqrt15.7%
exp-1-e15.7%
Applied egg-rr15.7%
Taylor expanded in x around 0 16.4%
log-E100.0%
metadata-eval100.0%
+-lft-identity100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-*l*100.0%
unpow2100.0%
unpow3100.0%
Simplified100.0%
if 0.0399999991 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) Initial program 65.0%
+-commutative65.0%
hypot-1-def99.9%
Simplified99.9%
*-un-lft-identity99.9%
*-commutative99.9%
log-prod99.9%
add-sqr-sqrt99.9%
fabs-sqr99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
+-rgt-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary32 (if (<= x 9.999999747378752e-5) (copysign (log1p (fabs x)) x) (copysign (log (+ x (hypot 1.0 x))) x)))
float code(float x) {
float tmp;
if (x <= 9.999999747378752e-5f) {
tmp = copysignf(log1pf(fabsf(x)), x);
} else {
tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(9.999999747378752e-5)) tmp = copysign(log1p(abs(x)), x); else tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), 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 < 9.99999975e-5Initial program 31.9%
+-commutative31.9%
hypot-1-def45.8%
Simplified45.8%
Taylor expanded in x around 0 25.3%
log1p-define78.6%
Simplified78.6%
if 9.99999975e-5 < x Initial program 65.5%
+-commutative65.5%
hypot-1-def99.2%
Simplified99.2%
*-un-lft-identity99.2%
*-commutative99.2%
log-prod99.2%
add-sqr-sqrt99.2%
fabs-sqr99.2%
add-sqr-sqrt99.2%
metadata-eval99.2%
Applied egg-rr99.2%
+-rgt-identity99.2%
Simplified99.2%
Final simplification83.5%
(FPCore (x) :precision binary32 (if (<= x 1.0) (copysign (log1p (fabs x)) x) (copysign (log (* x (+ 1.0 (/ x x)))) x)))
float code(float x) {
float tmp;
if (x <= 1.0f) {
tmp = copysignf(log1pf(fabsf(x)), x);
} else {
tmp = copysignf(logf((x * (1.0f + (x / x)))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(1.0)) tmp = copysign(log1p(abs(x)), x); else tmp = copysign(log(Float32(x * Float32(Float32(1.0) + Float32(x / x)))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\
\end{array}
\end{array}
if x < 1Initial program 32.7%
+-commutative32.7%
hypot-1-def46.4%
Simplified46.4%
Taylor expanded in x around 0 25.7%
log1p-define78.1%
Simplified78.1%
if 1 < x Initial program 64.5%
+-commutative64.5%
hypot-1-def99.9%
Simplified99.9%
Taylor expanded in x around inf 96.7%
rem-square-sqrt96.7%
fabs-sqr96.7%
rem-square-sqrt96.7%
Simplified96.7%
Final simplification82.3%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (- x)) x)
(if (<= x 1.0)
(copysign (* x (+ 1.0 (* -0.16666666666666666 (pow x 2.0)))) x)
(copysign (log (* x (+ 1.0 (/ x x)))) x))))
float code(float x) {
float tmp;
if (x <= -2.0f) {
tmp = copysignf(logf(-x), x);
} else if (x <= 1.0f) {
tmp = copysignf((x * (1.0f + (-0.16666666666666666f * powf(x, 2.0f)))), x);
} else {
tmp = copysignf(logf((x * (1.0f + (x / x)))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-2.0)) tmp = copysign(log(Float32(-x)), x); elseif (x <= Float32(1.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(-0.16666666666666666) * (x ^ Float32(2.0))))), x); else tmp = copysign(log(Float32(x * Float32(Float32(1.0) + Float32(x / x)))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-2.0)) tmp = sign(x) * abs(log(-x)); elseif (x <= single(1.0)) tmp = sign(x) * abs((x * (single(1.0) + (single(-0.16666666666666666) * (x ^ single(2.0)))))); else tmp = sign(x) * abs(log((x * (single(1.0) + (x / x))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + -0.16666666666666666 \cdot {x}^{2}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 60.6%
+-commutative60.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 43.7%
mul-1-neg43.7%
Simplified43.7%
if -2 < x < 1Initial program 17.8%
+-commutative17.8%
hypot-1-def17.8%
Simplified17.8%
add-log-exp17.9%
*-un-lft-identity17.9%
exp-prod17.2%
log-pow16.8%
add-sqr-sqrt8.6%
fabs-sqr8.6%
add-sqr-sqrt17.0%
exp-1-e17.0%
Applied egg-rr17.0%
Taylor expanded in x around 0 16.8%
+-commutative16.8%
log-E99.1%
metadata-eval99.1%
Simplified99.1%
if 1 < x Initial program 64.5%
+-commutative64.5%
hypot-1-def99.9%
Simplified99.9%
Taylor expanded in x around inf 96.7%
rem-square-sqrt96.7%
fabs-sqr96.7%
rem-square-sqrt96.7%
Simplified96.7%
Final simplification83.6%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (- x)) x)
(if (<= x 1.0)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (* x (+ 1.0 (/ x x)))) x))))
float code(float x) {
float tmp;
if (x <= -2.0f) {
tmp = copysignf(logf(-x), x);
} else if (x <= 1.0f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(logf((x * (1.0f + (x / x)))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-2.0)) tmp = copysign(log(Float32(-x)), x); elseif (x <= Float32(1.0)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log(Float32(x * Float32(Float32(1.0) + Float32(x / x)))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-2.0)) tmp = sign(x) * abs(log(-x)); elseif (x <= single(1.0)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); else tmp = sign(x) * abs(log((x * (single(1.0) + (x / x))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot \left(1 + \frac{x}{x}\right)\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 60.6%
+-commutative60.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 43.7%
mul-1-neg43.7%
Simplified43.7%
if -2 < x < 1Initial program 17.8%
+-commutative17.8%
hypot-1-def17.8%
Simplified17.8%
add-log-exp17.9%
*-un-lft-identity17.9%
exp-prod17.2%
log-pow16.8%
add-sqr-sqrt8.6%
fabs-sqr8.6%
add-sqr-sqrt17.0%
exp-1-e17.0%
Applied egg-rr17.0%
Taylor expanded in x around 0 16.8%
log-E99.1%
metadata-eval99.1%
+-lft-identity99.1%
distribute-rgt-in99.1%
*-lft-identity99.1%
associate-*l*99.1%
unpow299.1%
unpow399.1%
Simplified99.1%
if 1 < x Initial program 64.5%
+-commutative64.5%
hypot-1-def99.9%
Simplified99.9%
Taylor expanded in x around inf 96.7%
rem-square-sqrt96.7%
fabs-sqr96.7%
rem-square-sqrt96.7%
Simplified96.7%
Final simplification83.6%
(FPCore (x) :precision binary32 (if (<= x -2.0) (copysign (log (- x)) x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= -2.0f) {
tmp = copysignf(logf(-x), x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-2.0)) tmp = copysign(log(Float32(-x)), x); else tmp = copysign(log1p(x), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 60.6%
+-commutative60.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 43.7%
mul-1-neg43.7%
Simplified43.7%
if -2 < x Initial program 32.3%
+-commutative32.3%
hypot-1-def43.3%
Simplified43.3%
Taylor expanded in x around 0 24.5%
log1p-define80.1%
rem-square-sqrt49.3%
fabs-sqr49.3%
rem-square-sqrt80.0%
Simplified80.0%
Final simplification70.2%
(FPCore (x) :precision binary32 (if (<= x 1.0) (copysign x x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= 1.0f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(1.0)) tmp = copysign(x, x); else tmp = copysign(log1p(x), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\end{array}
if x < 1Initial program 32.7%
+-commutative32.7%
hypot-1-def46.4%
Simplified46.4%
add-log-exp15.3%
*-un-lft-identity15.3%
exp-prod14.8%
log-pow45.8%
add-sqr-sqrt5.6%
fabs-sqr5.6%
add-sqr-sqrt15.3%
exp-1-e15.3%
Applied egg-rr15.3%
Taylor expanded in x around 0 15.0%
log-E68.3%
metadata-eval68.3%
+-rgt-identity68.3%
Simplified68.3%
if 1 < x Initial program 64.5%
+-commutative64.5%
hypot-1-def99.9%
Simplified99.9%
Taylor expanded in x around 0 43.5%
log1p-define43.5%
rem-square-sqrt43.5%
fabs-sqr43.5%
rem-square-sqrt43.5%
Simplified43.5%
Final simplification62.7%
(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 39.9%
+-commutative39.9%
hypot-1-def58.5%
Simplified58.5%
add-log-exp14.7%
*-un-lft-identity14.7%
exp-prod14.4%
log-pow58.0%
add-sqr-sqrt27.0%
fabs-sqr27.0%
add-sqr-sqrt34.4%
exp-1-e34.4%
Applied egg-rr34.4%
Taylor expanded in x around 0 14.3%
log-E55.6%
metadata-eval55.6%
+-rgt-identity55.6%
Simplified55.6%
Final simplification55.6%
(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 2024059
(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))