
(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 10 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 -1.0)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= t_0 0.05000000074505806)
(copysign
(+ x (+ (* -0.16666666666666666 (pow x 3.0)) (* 0.075 (pow x 5.0))))
x)
(copysign (log1p (+ -1.0 (+ 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 <= -1.0f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (t_0 <= 0.05000000074505806f) {
tmp = copysignf((x + ((-0.16666666666666666f * powf(x, 3.0f)) + (0.075f * powf(x, 5.0f)))), x);
} else {
tmp = copysignf(log1pf((-1.0f + (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(-1.0)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (t_0 <= Float32(0.05000000074505806)) tmp = copysign(Float32(x + Float32(Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0))) + Float32(Float32(0.075) * (x ^ Float32(5.0))))), x); else tmp = copysign(log1p(Float32(Float32(-1.0) + Float32(x + hypot(Float32(1.0), x)))), x); end return 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 -1:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;t_0 \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(x + \left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + \left(x + \mathsf{hypot}\left(1, x\right)\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) < -1Initial program 56.9%
flip-+8.8%
clear-num8.8%
log-rec8.8%
+-commutative8.8%
hypot-1-def8.7%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt9.9%
sqr-abs9.9%
add-sqr-sqrt11.1%
+-commutative11.1%
Applied egg-rr11.1%
div-inv11.1%
log-prod-0.0%
Applied egg-rr-0.0%
+-commutative-0.0%
fma-udef-0.0%
associate-+r--0.0%
+-commutative-0.0%
associate-+l--0.0%
+-inverses-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
+-inverses-0.0%
associate-+l--0.0%
+-commutative-0.0%
associate-+r--0.0%
fma-udef-0.0%
Simplified100.0%
if -1 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < 0.0500000007Initial program 24.3%
*-un-lft-identity24.3%
*-commutative24.3%
log-prod24.3%
add-sqr-sqrt8.1%
fabs-sqr8.1%
add-sqr-sqrt24.5%
+-commutative24.5%
hypot-1-def24.5%
metadata-eval24.5%
Applied egg-rr24.5%
Taylor expanded in x around 0 100.0%
if 0.0500000007 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) Initial program 57.7%
log1p-expm1-u57.7%
expm1-udef57.7%
add-exp-log57.7%
add-sqr-sqrt57.7%
fabs-sqr57.7%
add-sqr-sqrt57.7%
+-commutative57.7%
hypot-1-def99.9%
Applied egg-rr99.9%
Final simplification100.0%
(FPCore (x)
:precision binary32
(if (<= x -0.05000000074505806)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= x 0.05000000074505806)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log1p (+ -1.0 (+ x (hypot 1.0 x)))) x))))
float code(float x) {
float tmp;
if (x <= -0.05000000074505806f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (x <= 0.05000000074505806f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(log1pf((-1.0f + (x + hypotf(1.0f, x)))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-0.05000000074505806)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= Float32(0.05000000074505806)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log1p(Float32(Float32(-1.0) + Float32(x + hypot(Float32(1.0), x)))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;x \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + \left(x + \mathsf{hypot}\left(1, x\right)\right)\right), x\right)\\
\end{array}
\end{array}
if x < -0.0500000007Initial program 58.0%
flip-+11.3%
clear-num11.3%
log-rec11.3%
+-commutative11.3%
hypot-1-def11.2%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt12.5%
sqr-abs12.5%
add-sqr-sqrt13.6%
+-commutative13.6%
Applied egg-rr13.6%
div-inv13.6%
log-prod-0.0%
Applied egg-rr-0.0%
+-commutative-0.0%
fma-udef-0.0%
associate-+r--0.0%
+-commutative-0.0%
associate-+l--0.0%
+-inverses-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
+-inverses-0.0%
associate-+l--0.0%
+-commutative-0.0%
associate-+r--0.0%
fma-udef-0.0%
Simplified99.8%
if -0.0500000007 < x < 0.0500000007Initial program 23.3%
*-un-lft-identity23.3%
*-commutative23.3%
log-prod23.3%
add-sqr-sqrt8.2%
fabs-sqr8.2%
add-sqr-sqrt23.4%
+-commutative23.4%
hypot-1-def23.4%
metadata-eval23.4%
Applied egg-rr23.4%
Taylor expanded in x around 0 100.0%
if 0.0500000007 < x Initial program 57.7%
log1p-expm1-u57.7%
expm1-udef57.7%
add-exp-log57.7%
add-sqr-sqrt57.7%
fabs-sqr57.7%
add-sqr-sqrt57.7%
+-commutative57.7%
hypot-1-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary32
(if (<= x -0.05000000074505806)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= x 0.800000011920929)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ (* x 2.0) (/ 0.5 x))) x))))
float code(float x) {
float tmp;
if (x <= -0.05000000074505806f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (x <= 0.800000011920929f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(logf(((x * 2.0f) + (0.5f / x))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-0.05000000074505806)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= Float32(0.800000011920929)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log(Float32(Float32(x * Float32(2.0)) + Float32(Float32(0.5) / x))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-0.05000000074505806)) tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x))); elseif (x <= single(0.800000011920929)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); else tmp = sign(x) * abs(log(((x * single(2.0)) + (single(0.5) / x)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;x \leq 0.800000011920929:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2 + \frac{0.5}{x}\right), x\right)\\
\end{array}
\end{array}
if x < -0.0500000007Initial program 58.0%
flip-+11.3%
clear-num11.3%
log-rec11.3%
+-commutative11.3%
hypot-1-def11.2%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt12.5%
sqr-abs12.5%
add-sqr-sqrt13.6%
+-commutative13.6%
Applied egg-rr13.6%
div-inv13.6%
log-prod-0.0%
Applied egg-rr-0.0%
+-commutative-0.0%
fma-udef-0.0%
associate-+r--0.0%
+-commutative-0.0%
associate-+l--0.0%
+-inverses-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
metadata-eval-0.0%
+-inverses-0.0%
associate-+l--0.0%
+-commutative-0.0%
associate-+r--0.0%
fma-udef-0.0%
Simplified99.8%
if -0.0500000007 < x < 0.800000012Initial program 23.8%
*-un-lft-identity23.8%
*-commutative23.8%
log-prod23.8%
add-sqr-sqrt8.9%
fabs-sqr8.9%
add-sqr-sqrt24.0%
+-commutative24.0%
hypot-1-def24.0%
metadata-eval24.0%
Applied egg-rr24.0%
Taylor expanded in x around 0 99.5%
if 0.800000012 < x Initial program 57.1%
*-un-lft-identity57.1%
*-commutative57.1%
log-prod57.1%
add-sqr-sqrt57.0%
fabs-sqr57.0%
add-sqr-sqrt57.1%
+-commutative57.1%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.0%
Taylor expanded in x around 0 99.0%
Final simplification99.5%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.800000011920929)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ (* x 2.0) (/ 0.5 x))) x))))
float code(float x) {
float tmp;
if (x <= -2.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.800000011920929f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(logf(((x * 2.0f) + (0.5f / 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.800000011920929)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log(Float32(Float32(x * Float32(2.0)) + Float32(Float32(0.5) / 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.800000011920929)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); else tmp = sign(x) * abs(log(((x * single(2.0)) + (single(0.5) / 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.800000011920929:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2 + \frac{0.5}{x}\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 56.9%
*-un-lft-identity56.9%
*-commutative56.9%
log-prod56.9%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.3%
+-commutative14.3%
hypot-1-def14.3%
metadata-eval14.3%
Applied egg-rr14.3%
Taylor expanded in x around -inf 96.7%
if -2 < x < 0.800000012Initial program 24.9%
*-un-lft-identity24.9%
*-commutative24.9%
log-prod24.9%
add-sqr-sqrt8.8%
fabs-sqr8.8%
add-sqr-sqrt25.1%
+-commutative25.1%
hypot-1-def25.1%
metadata-eval25.1%
Applied egg-rr25.1%
Taylor expanded in x around 0 99.3%
if 0.800000012 < x Initial program 57.1%
*-un-lft-identity57.1%
*-commutative57.1%
log-prod57.1%
add-sqr-sqrt57.0%
fabs-sqr57.0%
add-sqr-sqrt57.1%
+-commutative57.1%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.0%
Taylor expanded in x around 0 99.0%
Final simplification98.6%
(FPCore (x)
:precision binary32
(if (<= x -2.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 1.0)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) 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 <= 1.0f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), 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(1.0)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), 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(1.0)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); 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 1:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -2Initial program 56.9%
*-un-lft-identity56.9%
*-commutative56.9%
log-prod56.9%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.3%
+-commutative14.3%
hypot-1-def14.3%
metadata-eval14.3%
Applied egg-rr14.3%
Taylor expanded in x around -inf 96.7%
if -2 < x < 1Initial program 25.4%
*-un-lft-identity25.4%
*-commutative25.4%
log-prod25.4%
add-sqr-sqrt9.5%
fabs-sqr9.5%
add-sqr-sqrt25.6%
+-commutative25.6%
hypot-1-def25.6%
metadata-eval25.6%
Applied egg-rr25.6%
Taylor expanded in x around 0 98.9%
if 1 < x Initial program 56.4%
*-un-lft-identity56.4%
*-commutative56.4%
log-prod56.4%
add-sqr-sqrt56.3%
fabs-sqr56.3%
add-sqr-sqrt56.4%
+-commutative56.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification98.2%
(FPCore (x) :precision binary32 (if (<= x -5.0) (copysign (- (log (/ -1.0 x))) x) (if (<= x 1.0) (copysign x x) (copysign (- (log (/ 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -5.0f) {
tmp = copysignf(-logf((-1.0f / x)), x);
} else if (x <= 1.0f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(-logf((1.0f / x)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-5.0)) tmp = copysign(Float32(-log(Float32(Float32(-1.0) / x))), x); elseif (x <= Float32(1.0)) tmp = copysign(x, x); else tmp = copysign(Float32(-log(Float32(Float32(1.0) / x))), 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(-1.0) / x))); elseif (x <= single(1.0)) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(-log((single(1.0) / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{1}{x}\right), x\right)\\
\end{array}
\end{array}
if x < -5Initial program 56.3%
Taylor expanded in x around -inf 43.7%
if -5 < x < 1Initial program 26.0%
*-un-lft-identity26.0%
*-commutative26.0%
log-prod26.0%
add-sqr-sqrt9.4%
fabs-sqr9.4%
add-sqr-sqrt26.1%
+-commutative26.1%
hypot-1-def26.1%
metadata-eval26.1%
Applied egg-rr26.1%
Taylor expanded in x around 0 96.1%
if 1 < x Initial program 56.4%
Taylor expanded in x around inf 43.9%
Final simplification71.2%
(FPCore (x) :precision binary32 (if (<= x -5.0) (copysign (- (log (/ -1.0 x))) x) (if (<= x 1.0) (copysign x x) (copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -5.0f) {
tmp = copysignf(-logf((-1.0f / x)), x);
} else if (x <= 1.0f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-5.0)) tmp = copysign(Float32(-log(Float32(Float32(-1.0) / x))), x); elseif (x <= Float32(1.0)) 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(-5.0)) tmp = sign(x) * abs(-log((single(-1.0) / x))); elseif (x <= single(1.0)) 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 -5:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\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 < -5Initial program 56.3%
Taylor expanded in x around -inf 43.7%
if -5 < x < 1Initial program 26.0%
*-un-lft-identity26.0%
*-commutative26.0%
log-prod26.0%
add-sqr-sqrt9.4%
fabs-sqr9.4%
add-sqr-sqrt26.1%
+-commutative26.1%
hypot-1-def26.1%
metadata-eval26.1%
Applied egg-rr26.1%
Taylor expanded in x around 0 96.1%
if 1 < x Initial program 56.4%
*-un-lft-identity56.4%
*-commutative56.4%
log-prod56.4%
add-sqr-sqrt56.3%
fabs-sqr56.3%
add-sqr-sqrt56.4%
+-commutative56.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification84.0%
(FPCore (x) :precision binary32 (if (<= x -2.0) (copysign (log (/ -0.5 x)) x) (if (<= x 1.0) (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 <= 1.0f) {
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(1.0)) 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(1.0)) 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 1:\\
\;\;\;\;\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 56.9%
*-un-lft-identity56.9%
*-commutative56.9%
log-prod56.9%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt14.3%
+-commutative14.3%
hypot-1-def14.3%
metadata-eval14.3%
Applied egg-rr14.3%
Taylor expanded in x around -inf 96.7%
if -2 < x < 1Initial program 25.4%
*-un-lft-identity25.4%
*-commutative25.4%
log-prod25.4%
add-sqr-sqrt9.5%
fabs-sqr9.5%
add-sqr-sqrt25.6%
+-commutative25.6%
hypot-1-def25.6%
metadata-eval25.6%
Applied egg-rr25.6%
Taylor expanded in x around 0 96.6%
if 1 < x Initial program 56.4%
*-un-lft-identity56.4%
*-commutative56.4%
log-prod56.4%
add-sqr-sqrt56.3%
fabs-sqr56.3%
add-sqr-sqrt56.4%
+-commutative56.4%
hypot-1-def100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification97.1%
(FPCore (x) :precision binary32 (if (<= x -5.0) (copysign (- (log (/ -1.0 x))) x) (copysign x x)))
float code(float x) {
float tmp;
if (x <= -5.0f) {
tmp = copysignf(-logf((-1.0f / x)), x);
} else {
tmp = copysignf(x, x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-5.0)) tmp = copysign(Float32(-log(Float32(Float32(-1.0) / x))), x); else tmp = copysign(x, 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(-1.0) / x))); else tmp = sign(x) * abs(x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\end{array}
\end{array}
if x < -5Initial program 56.3%
Taylor expanded in x around -inf 43.7%
if -5 < x Initial program 35.4%
*-un-lft-identity35.4%
*-commutative35.4%
log-prod35.4%
add-sqr-sqrt23.9%
fabs-sqr23.9%
add-sqr-sqrt35.5%
+-commutative35.5%
hypot-1-def49.0%
metadata-eval49.0%
Applied egg-rr49.0%
Taylor expanded in x around 0 70.0%
Final simplification63.6%
(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 40.4%
*-un-lft-identity40.4%
*-commutative40.4%
log-prod40.4%
add-sqr-sqrt18.1%
fabs-sqr18.1%
add-sqr-sqrt30.1%
+-commutative30.1%
hypot-1-def40.3%
metadata-eval40.3%
Applied egg-rr40.3%
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 2023279
(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))