
(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 14 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 (/ 1.0 (- (hypot 1.0 x) x))) x)
(if (<= t_0 0.10000000149011612)
(copysign
(*
x
(+ 1.0 (* (pow x 2.0) (- (* (pow x 2.0) 0.075) 0.16666666666666666))))
x)
(copysign (log (+ (fabs 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((1.0f / (hypotf(1.0f, x) - x))), x);
} else if (t_0 <= 0.10000000149011612f) {
tmp = copysignf((x * (1.0f + (powf(x, 2.0f) * ((powf(x, 2.0f) * 0.075f) - 0.16666666666666666f)))), x);
} else {
tmp = copysignf(logf((fabsf(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(log(Float32(Float32(1.0) / Float32(hypot(Float32(1.0), x) - x))), x); elseif (t_0 <= Float32(0.10000000149011612)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32((x ^ Float32(2.0)) * Float32(Float32((x ^ Float32(2.0)) * Float32(0.075)) - Float32(0.16666666666666666))))), x); else tmp = copysign(log(Float32(abs(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(-1.0)) tmp = sign(x) * abs(log((single(1.0) / (hypot(single(1.0), x) - x)))); elseif (t_0 <= single(0.10000000149011612)) tmp = sign(x) * abs((x * (single(1.0) + ((x ^ single(2.0)) * (((x ^ single(2.0)) * single(0.075)) - single(0.16666666666666666)))))); else tmp = sign(x) * abs(log((abs(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 -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{elif}\;t\_0 \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \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) < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
if -1 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) < 0.100000001Initial program 24.7%
+-commutative24.7%
hypot-1-def24.7%
add-exp-log24.7%
add-sqr-sqrt13.7%
fabs-sqr13.7%
add-sqr-sqrt17.7%
Applied egg-rr17.7%
Taylor expanded in x around 0 100.0%
if 0.100000001 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) #s(literal 1 binary32))))) x) Initial program 53.9%
+-commutative53.9%
hypot-1-def98.5%
Simplified98.5%
Final simplification98.9%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ 1.0 (- (hypot 1.0 x) x))) x)
(if (<= x 0.10000000149011612)
(copysign
(*
x
(+ 1.0 (* (pow x 2.0) (- (* (pow x 2.0) 0.075) 0.16666666666666666))))
x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((1.0f / (hypotf(1.0f, x) - x))), x);
} else if (x <= 0.10000000149011612f) {
tmp = copysignf((x * (1.0f + (powf(x, 2.0f) * ((powf(x, 2.0f) * 0.075f) - 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(-1.0)) tmp = copysign(log(Float32(Float32(1.0) / Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= Float32(0.10000000149011612)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32((x ^ Float32(2.0)) * Float32(Float32((x ^ Float32(2.0)) * Float32(0.075)) - 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(-1.0)) tmp = sign(x) * abs(log((single(1.0) / (hypot(single(1.0), x) - x)))); elseif (x <= single(0.10000000149011612)) tmp = sign(x) * abs((x * (single(1.0) + ((x ^ single(2.0)) * (((x ^ single(2.0)) * single(0.075)) - 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 -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot 0.075 - 0.16666666666666666\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 < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
if -1 < x < 0.100000001Initial program 24.7%
+-commutative24.7%
hypot-1-def24.7%
add-exp-log24.7%
add-sqr-sqrt13.7%
fabs-sqr13.7%
add-sqr-sqrt17.7%
Applied egg-rr17.7%
Taylor expanded in x around 0 100.0%
if 0.100000001 < x Initial program 53.9%
Taylor expanded in x around 0 53.9%
rem-square-sqrt53.9%
fabs-sqr53.9%
metadata-eval53.9%
unpow253.9%
hypot-undefine98.5%
rem-square-sqrt98.5%
Simplified98.5%
Final simplification98.9%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ 1.0 (- (hypot 1.0 x) x))) x)
(if (<= x 0.03999999910593033)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((1.0f / (hypotf(1.0f, x) - x))), x);
} else if (x <= 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) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(1.0) / Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= 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) tmp = single(0.0); if (x <= single(-1.0)) tmp = sign(x) * abs(log((single(1.0) / (hypot(single(1.0), x) - x)))); elseif (x <= 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}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{elif}\;x \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 x < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
if -1 < x < 0.0399999991Initial program 23.0%
+-commutative23.0%
hypot-1-def23.0%
add-exp-log23.0%
add-sqr-sqrt11.7%
fabs-sqr11.7%
add-sqr-sqrt15.9%
Applied egg-rr15.9%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-*l*100.0%
unpow2100.0%
unpow3100.0%
Simplified100.0%
if 0.0399999991 < x Initial program 55.7%
Taylor expanded in x around 0 55.7%
rem-square-sqrt55.6%
fabs-sqr55.6%
metadata-eval55.6%
unpow255.6%
hypot-undefine98.3%
rem-square-sqrt98.3%
Simplified98.3%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= x 0.03999999910593033)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (x <= 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) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= 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) tmp = single(0.0); if (x <= single(-1.0)) tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x))); elseif (x <= 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}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;x \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 x < -1Initial program 44.1%
flip-+8.5%
clear-num8.5%
log-div8.5%
metadata-eval8.5%
+-commutative8.5%
hypot-1-def8.2%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt9.1%
Applied egg-rr9.4%
neg-sub09.4%
div-sub9.4%
*-rgt-identity9.4%
associate-/l*9.4%
*-rgt-identity9.4%
associate-/l*9.4%
fma-undefine9.5%
unpow29.5%
associate--r+9.5%
+-inverses9.5%
metadata-eval9.5%
metadata-eval9.5%
*-commutative9.5%
neg-mul-19.5%
neg-sub09.5%
fma-undefine9.5%
unpow29.5%
Simplified96.9%
if -1 < x < 0.0399999991Initial program 23.0%
+-commutative23.0%
hypot-1-def23.0%
add-exp-log23.0%
add-sqr-sqrt11.7%
fabs-sqr11.7%
add-sqr-sqrt15.9%
Applied egg-rr15.9%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-*l*100.0%
unpow2100.0%
unpow3100.0%
Simplified100.0%
if 0.0399999991 < x Initial program 55.7%
Taylor expanded in x around 0 55.7%
rem-square-sqrt55.6%
fabs-sqr55.6%
metadata-eval55.6%
unpow255.6%
hypot-undefine98.3%
rem-square-sqrt98.3%
Simplified98.3%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.03999999910593033)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 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) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= 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) tmp = single(0.0); if (x <= single(-1.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= 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}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \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 x < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in x around -inf 96.5%
if -1 < x < 0.0399999991Initial program 23.0%
+-commutative23.0%
hypot-1-def23.0%
add-exp-log23.0%
add-sqr-sqrt11.7%
fabs-sqr11.7%
add-sqr-sqrt15.9%
Applied egg-rr15.9%
Taylor expanded in x around 0 100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-*l*100.0%
unpow2100.0%
unpow3100.0%
Simplified100.0%
if 0.0399999991 < x Initial program 55.7%
Taylor expanded in x around 0 55.7%
rem-square-sqrt55.6%
fabs-sqr55.6%
metadata-eval55.6%
unpow255.6%
hypot-undefine98.3%
rem-square-sqrt98.3%
Simplified98.3%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.5)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (+ (log x) (log 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.5f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf((logf(x) + logf(2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.5)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(Float32(log(x) + log(Float32(2.0))), x); end return tmp end
function tmp_2 = code(x) tmp = single(0.0); if (x <= single(-1.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.5)) tmp = sign(x) * abs((x + (single(-0.16666666666666666) * (x ^ single(3.0))))); else tmp = sign(x) * abs((log(x) + log(single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log x + \log 2, x\right)\\
\end{array}
\end{array}
if x < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in x around -inf 96.5%
if -1 < x < 0.5Initial program 25.8%
+-commutative25.8%
hypot-1-def25.8%
add-exp-log25.9%
add-sqr-sqrt15.0%
fabs-sqr15.0%
add-sqr-sqrt19.0%
Applied egg-rr19.0%
Taylor expanded in x around 0 99.0%
distribute-rgt-in99.0%
*-lft-identity99.0%
associate-*l*99.0%
unpow299.0%
unpow399.0%
Simplified99.0%
if 0.5 < x Initial program 52.5%
+-commutative52.5%
hypot-1-def98.5%
add-exp-log95.3%
add-sqr-sqrt95.3%
fabs-sqr95.3%
add-sqr-sqrt95.3%
Applied egg-rr95.3%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
mul-1-neg97.4%
log-rec97.4%
remove-double-neg97.4%
Simplified97.4%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 0.5)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) x)
(copysign (log1p (+ -1.0 (* x 2.0))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.5f) {
tmp = copysignf((x + (-0.16666666666666666f * powf(x, 3.0f))), x);
} else {
tmp = copysignf(log1pf((-1.0f + (x * 2.0f))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.5)) tmp = copysign(Float32(x + Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), x); else tmp = copysign(log1p(Float32(Float32(-1.0) + Float32(x * Float32(2.0)))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in x around -inf 96.5%
if -1 < x < 0.5Initial program 25.8%
+-commutative25.8%
hypot-1-def25.8%
add-exp-log25.9%
add-sqr-sqrt15.0%
fabs-sqr15.0%
add-sqr-sqrt19.0%
Applied egg-rr19.0%
Taylor expanded in x around 0 99.0%
distribute-rgt-in99.0%
*-lft-identity99.0%
associate-*l*99.0%
unpow299.0%
unpow399.0%
Simplified99.0%
if 0.5 < x Initial program 52.5%
+-commutative52.5%
hypot-1-def98.5%
add-exp-log95.3%
add-sqr-sqrt95.3%
fabs-sqr95.3%
add-sqr-sqrt95.3%
Applied egg-rr95.3%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
mul-1-neg97.4%
log-rec97.4%
remove-double-neg97.4%
Simplified97.4%
log1p-expm1-u96.0%
expm1-undefine96.0%
sum-log96.8%
rem-exp-log96.8%
Applied egg-rr96.8%
Final simplification97.9%
(FPCore (x) :precision binary32 (if (<= x -1.0) (copysign (log (/ -0.5 x)) x) (if (<= x 0.5) (copysign x x) (copysign (log1p (+ -1.0 (* x 2.0))) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.5f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(log1pf((-1.0f + (x * 2.0f))), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.5)) tmp = copysign(x, x); else tmp = copysign(log1p(Float32(Float32(-1.0) + Float32(x * Float32(2.0)))), x); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in x around -inf 96.5%
if -1 < x < 0.5Initial program 25.8%
+-commutative25.8%
hypot-1-def25.8%
add-exp-log25.9%
add-sqr-sqrt15.0%
fabs-sqr15.0%
add-sqr-sqrt19.0%
Applied egg-rr19.0%
Taylor expanded in x around 0 96.7%
if 0.5 < x Initial program 52.5%
+-commutative52.5%
hypot-1-def98.5%
add-exp-log95.3%
add-sqr-sqrt95.3%
fabs-sqr95.3%
add-sqr-sqrt95.3%
Applied egg-rr95.3%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
mul-1-neg97.4%
log-rec97.4%
remove-double-neg97.4%
Simplified97.4%
log1p-expm1-u96.0%
expm1-undefine96.0%
sum-log96.8%
rem-exp-log96.8%
Applied egg-rr96.8%
Final simplification96.7%
(FPCore (x) :precision binary32 (if (<= x -1.0) (copysign (log (/ -0.5 x)) x) (if (<= x 0.5) (copysign x x) (copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 0.5f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(logf((x * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); elseif (x <= Float32(0.5)) 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(-1.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(0.5)) 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 -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\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 < -1Initial program 44.1%
+-commutative44.1%
hypot-1-def96.9%
flip-+8.3%
hypot-1-def8.2%
hypot-1-def8.2%
add-sqr-sqrt8.2%
+-commutative8.2%
hypot-1-def8.2%
+-commutative8.2%
div-sub8.3%
Applied egg-rr10.2%
div-sub11.4%
remove-double-neg11.4%
distribute-frac-neg211.4%
distribute-frac-neg11.4%
neg-sub011.4%
associate--r-11.4%
neg-sub011.4%
+-commutative11.4%
fma-undefine11.4%
unpow211.4%
+-commutative11.4%
associate-+l+40.3%
sub-neg40.3%
+-inverses97.0%
metadata-eval97.0%
neg-sub097.0%
associate--r-97.0%
neg-sub097.0%
+-commutative97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in x around -inf 96.5%
if -1 < x < 0.5Initial program 25.8%
+-commutative25.8%
hypot-1-def25.8%
add-exp-log25.9%
add-sqr-sqrt15.0%
fabs-sqr15.0%
add-sqr-sqrt19.0%
Applied egg-rr19.0%
Taylor expanded in x around 0 96.7%
if 0.5 < x Initial program 52.5%
Taylor expanded in x around inf 96.8%
rem-square-sqrt96.7%
fabs-sqr96.7%
rem-square-sqrt96.8%
*-inverses96.8%
metadata-eval96.8%
Simplified96.8%
(FPCore (x) :precision binary32 (if (<= x -5.0) (copysign (log (- x)) x) (if (<= x 0.5) (copysign x x) (copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -5.0f) {
tmp = copysignf(logf(-x), x);
} else if (x <= 0.5f) {
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(log(Float32(-x)), x); elseif (x <= Float32(0.5)) 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(-x)); elseif (x <= single(0.5)) 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(-x\right), x\right)\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\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 43.2%
Taylor expanded in x around -inf 44.6%
neg-mul-144.6%
Simplified44.6%
if -5 < x < 0.5Initial program 26.4%
+-commutative26.4%
hypot-1-def26.4%
add-exp-log26.4%
add-sqr-sqrt14.9%
fabs-sqr14.9%
add-sqr-sqrt18.8%
Applied egg-rr18.8%
Taylor expanded in x around 0 96.2%
if 0.5 < x Initial program 52.5%
Taylor expanded in x around inf 96.8%
rem-square-sqrt96.7%
fabs-sqr96.7%
rem-square-sqrt96.8%
*-inverses96.8%
metadata-eval96.8%
Simplified96.8%
(FPCore (x) :precision binary32 (if (<= x -1.0) (copysign (log (- x)) x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf(-x), x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.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 -1:\\
\;\;\;\;\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 < -1Initial program 44.1%
Taylor expanded in x around -inf 44.3%
neg-mul-144.3%
Simplified44.3%
if -1 < x Initial program 34.5%
Taylor expanded in x around 0 29.1%
log1p-define76.5%
rem-square-sqrt48.4%
fabs-sqr48.4%
rem-square-sqrt76.5%
Simplified76.5%
(FPCore (x) :precision binary32 (if (<= x 0.5) (copysign x x) (copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= 0.5f) {
tmp = copysignf(x, x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(0.5)) 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.5:\\
\;\;\;\;\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.5Initial program 31.7%
+-commutative31.7%
hypot-1-def48.7%
add-exp-log47.9%
add-sqr-sqrt10.2%
fabs-sqr10.2%
add-sqr-sqrt12.9%
Applied egg-rr12.9%
Taylor expanded in x around 0 69.2%
if 0.5 < x Initial program 52.5%
Taylor expanded in x around 0 44.4%
log1p-define44.4%
rem-square-sqrt44.4%
fabs-sqr44.4%
rem-square-sqrt44.4%
Simplified44.4%
(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.8%
+-commutative36.8%
hypot-1-def60.9%
add-exp-log59.6%
add-sqr-sqrt31.1%
fabs-sqr31.1%
add-sqr-sqrt33.2%
Applied egg-rr33.2%
Taylor expanded in x around 0 54.9%
(FPCore (x) :precision binary32 (copysign -1.0 x))
float code(float x) {
return copysignf(-1.0f, x);
}
function code(x) return copysign(Float32(-1.0), x) end
function tmp = code(x) tmp = sign(x) * abs(single(-1.0)); end
\begin{array}{l}
\\
\mathsf{copysign}\left(-1, x\right)
\end{array}
Initial program 36.8%
Taylor expanded in x around -inf 14.0%
distribute-lft-out14.0%
Simplified14.0%
Taylor expanded in x around 0 15.9%
associate-*r/15.9%
mul-1-neg15.9%
rem-square-sqrt8.3%
fabs-sqr8.3%
rem-square-sqrt15.9%
distribute-frac-neg15.9%
*-inverses15.9%
metadata-eval15.9%
Simplified15.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 2024138
(FPCore (x)
:name "Rust f32::asinh"
:precision binary32
:alt
(! :herbie-platform default (let* ((ax (fabs x)) (ix (/ 1 ax))) (copysign (log1p (+ ax (/ ax (+ (hypot 1 ix) ix)))) x)))
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))