
(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 7 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.009999999776482582)
(copysign (+ x (* (pow x 3.0) -0.16666666666666666)) 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.009999999776482582f) {
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) 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.009999999776482582)) 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) 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.009999999776482582)) 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}
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.009999999776482582:\\
\;\;\;\;\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 (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < -0.5Initial program 59.1%
flip-+10.2%
frac-2neg10.2%
log-div10.2%
Applied egg-rr15.2%
neg-sub015.2%
associate--r-15.2%
neg-sub015.2%
+-commutative15.2%
fma-undefine15.7%
unpow215.7%
+-commutative15.7%
associate-+l+56.2%
sub-neg56.2%
+-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
neg-sub0100.0%
neg-sub0100.0%
associate--r-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
if -0.5 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < 0.00999999978Initial program 18.4%
*-un-lft-identity18.4%
*-commutative18.4%
log-prod18.4%
*-un-lft-identity18.4%
*-un-lft-identity18.4%
add-sqr-sqrt9.8%
fabs-sqr9.8%
add-sqr-sqrt18.5%
+-commutative18.5%
hypot-1-def18.5%
metadata-eval18.5%
Applied egg-rr18.5%
+-rgt-identity18.5%
Simplified18.5%
Taylor expanded in x around 0 100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
*-commutative100.0%
associate-*r*100.0%
unpow2100.0%
cube-mult100.0%
Simplified100.0%
if 0.00999999978 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) Initial program 58.9%
*-un-lft-identity58.9%
*-commutative58.9%
log-prod58.9%
*-un-lft-identity58.9%
*-un-lft-identity58.9%
add-sqr-sqrt58.8%
fabs-sqr58.8%
add-sqr-sqrt58.9%
+-commutative58.9%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-rgt-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.009999999776482582)
(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 <= -2.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.009999999776482582f) {
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(-2.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.009999999776482582)) 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(-2.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.009999999776482582)) 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 -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.009999999776482582:\\
\;\;\;\;\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 < -2Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.7%
+-commutative14.7%
hypot-1-def14.7%
metadata-eval14.7%
Applied egg-rr14.7%
+-rgt-identity14.7%
Simplified14.7%
Taylor expanded in x around -inf 96.6%
if -2 < x < 0.00999999978Initial program 19.0%
*-un-lft-identity19.0%
*-commutative19.0%
log-prod19.0%
*-un-lft-identity19.0%
*-un-lft-identity19.0%
add-sqr-sqrt9.7%
fabs-sqr9.7%
add-sqr-sqrt19.1%
+-commutative19.1%
hypot-1-def19.1%
metadata-eval19.1%
Applied egg-rr19.1%
+-rgt-identity19.1%
Simplified19.1%
Taylor expanded in x around 0 99.5%
distribute-lft-in99.5%
*-rgt-identity99.5%
*-commutative99.5%
associate-*r*99.5%
unpow299.5%
cube-mult99.5%
Simplified99.5%
if 0.00999999978 < x Initial program 58.9%
*-un-lft-identity58.9%
*-commutative58.9%
log-prod58.9%
*-un-lft-identity58.9%
*-un-lft-identity58.9%
add-sqr-sqrt58.8%
fabs-sqr58.8%
add-sqr-sqrt58.9%
+-commutative58.9%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-rgt-identity100.0%
Simplified100.0%
Final simplification98.9%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.10000000149011612)
(copysign (+ x (* (pow x 3.0) -0.16666666666666666)) x)
(copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -2.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 * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-2.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 * Float32(2.0))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-2.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 * single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\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 \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.7%
+-commutative14.7%
hypot-1-def14.7%
metadata-eval14.7%
Applied egg-rr14.7%
+-rgt-identity14.7%
Simplified14.7%
Taylor expanded in x around -inf 96.6%
if -2 < x < 0.100000001Initial program 19.5%
*-un-lft-identity19.5%
*-commutative19.5%
log-prod19.5%
*-un-lft-identity19.5%
*-un-lft-identity19.5%
add-sqr-sqrt10.3%
fabs-sqr10.3%
add-sqr-sqrt19.6%
+-commutative19.6%
hypot-1-def19.7%
metadata-eval19.7%
Applied egg-rr19.7%
+-rgt-identity19.7%
Simplified19.7%
Taylor expanded in x around 0 99.3%
distribute-lft-in99.4%
*-rgt-identity99.4%
*-commutative99.4%
associate-*r*99.4%
unpow299.4%
cube-mult99.4%
Simplified99.4%
if 0.100000001 < x Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt58.4%
fabs-sqr58.4%
add-sqr-sqrt58.4%
+-commutative58.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification98.6%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.10000000149011612)
(copysign x x)
(copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -2.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.10000000149011612f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-2.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.10000000149011612)) tmp = copysign(x, x); else tmp = copysign(log(Float32(x * Float32(2.0))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-2.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.10000000149011612)) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(log((x * single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.7%
+-commutative14.7%
hypot-1-def14.7%
metadata-eval14.7%
Applied egg-rr14.7%
+-rgt-identity14.7%
Simplified14.7%
Taylor expanded in x around -inf 96.6%
if -2 < x < 0.100000001Initial program 19.5%
Taylor expanded in x around 0 18.0%
log1p-define95.7%
rem-square-sqrt44.5%
fabs-sqr44.5%
rem-square-sqrt95.4%
Simplified95.4%
Taylor expanded in x around 0 98.7%
if 0.100000001 < x Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt58.4%
fabs-sqr58.4%
add-sqr-sqrt58.4%
+-commutative58.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification98.3%
(FPCore (x) :precision binary32 (if (<= x 0.10000000149011612) (copysign x x) (copysign (log (* x 2.0)) x)))
float code(float x) {
float tmp;
if (x <= 0.10000000149011612f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.10000000149011612)) tmp = copysign(x, x); else tmp = copysign(log(Float32(x * Float32(2.0))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(0.10000000149011612)) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(log((x * single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < 0.100000001Initial program 32.2%
Taylor expanded in x around 0 26.2%
log1p-define78.6%
rem-square-sqrt30.0%
fabs-sqr30.0%
rem-square-sqrt64.3%
Simplified64.3%
Taylor expanded in x around 0 70.5%
if 0.100000001 < x Initial program 58.4%
*-un-lft-identity58.4%
*-commutative58.4%
log-prod58.4%
*-un-lft-identity58.4%
*-un-lft-identity58.4%
add-sqr-sqrt58.4%
fabs-sqr58.4%
add-sqr-sqrt58.4%
+-commutative58.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-rgt-identity100.0%
Simplified100.0%
Taylor expanded in x around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification77.5%
(FPCore (x) :precision binary32 (if (<= x -1.0) (copysign -2.0 x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(-2.0f, x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(Float32(-2.0), 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(-2, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 59.1%
flip-+10.2%
frac-2neg10.2%
log-div10.2%
Applied egg-rr15.2%
neg-sub015.2%
associate--r-15.2%
neg-sub015.2%
+-commutative15.2%
fma-undefine15.7%
unpow215.7%
+-commutative15.7%
associate-+l+56.2%
sub-neg56.2%
+-inverses100.0%
metadata-eval100.0%
metadata-eval100.0%
neg-sub0100.0%
neg-sub0100.0%
associate--r-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Applied egg-rr22.7%
if -1 < x Initial program 31.9%
Taylor expanded in x around 0 26.5%
log1p-define79.1%
rem-square-sqrt44.6%
fabs-sqr44.6%
rem-square-sqrt79.1%
Simplified79.1%
Final simplification65.0%
(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.7%
Taylor expanded in x around 0 30.7%
log1p-define70.1%
rem-square-sqrt33.5%
fabs-sqr33.5%
rem-square-sqrt59.4%
Simplified59.4%
Taylor expanded in x around 0 55.9%
Final simplification55.9%
(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 2024110
(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))