
(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
(if (<= x -0.20000000298023224)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= x 0.10000000149011612)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
x)
(copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
float tmp;
if (x <= -0.20000000298023224f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (x <= 0.10000000149011612f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 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(-0.20000000298023224)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (x <= Float32(0.10000000149011612)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * 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(-0.20000000298023224)) tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x))); elseif (x <= single(0.10000000149011612)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * 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 -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \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 < -0.200000003Initial program 51.1%
+-commutative51.1%
hypot-1-def99.8%
Simplified99.8%
flip-+10.9%
frac-2neg10.9%
log-div10.9%
Applied egg-rr14.7%
sub-neg14.7%
fma-undefine14.7%
unpow214.7%
distribute-neg-in14.7%
metadata-eval14.7%
associate-+r+47.7%
sub-neg47.7%
+-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
neg-sub099.8%
neg-sub099.8%
associate--r-99.8%
neg-sub099.8%
+-commutative99.8%
sub-neg99.8%
Simplified99.8%
if -0.200000003 < x < 0.100000001Initial program 17.5%
+-commutative17.5%
hypot-1-def17.5%
Simplified17.5%
Taylor expanded in x around 0 17.5%
rem-square-sqrt7.9%
fabs-sqr7.9%
metadata-eval7.9%
unpow27.9%
hypot-undefine7.9%
rem-square-sqrt17.8%
Simplified17.8%
Taylor expanded in x around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
unpow2100.0%
Applied egg-rr100.0%
if 0.100000001 < x Initial program 50.5%
+-commutative50.5%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around 0 50.5%
rem-square-sqrt50.5%
fabs-sqr50.5%
metadata-eval50.5%
unpow250.5%
hypot-undefine98.5%
rem-square-sqrt98.6%
Simplified98.6%
Final simplification99.5%
(FPCore (x) :precision binary32 (if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) -0.5) (copysign (- (log (- (hypot 1.0 x) 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) <= -0.5f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - 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(-0.5)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - 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 -0.5:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - 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) #s(literal 1 binary32))))) x) < -0.5Initial program 48.3%
+-commutative48.3%
hypot-1-def100.0%
Simplified100.0%
flip-+5.7%
frac-2neg5.7%
log-div5.7%
Applied egg-rr9.8%
sub-neg9.8%
fma-undefine9.8%
unpow29.8%
distribute-neg-in9.8%
metadata-eval9.8%
associate-+r+44.7%
sub-neg44.7%
+-inverses100.0%
metadata-eval100.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) Initial program 31.4%
+-commutative31.4%
hypot-1-def49.2%
Simplified49.2%
add-sqr-sqrt49.1%
pow249.1%
log-pow49.2%
add-sqr-sqrt41.3%
fabs-sqr41.3%
add-sqr-sqrt49.3%
Applied egg-rr49.3%
log1p-expm1-u49.3%
log1p-undefine49.2%
expm1-undefine49.2%
*-commutative49.2%
exp-to-pow49.2%
pow249.2%
add-sqr-sqrt49.4%
Applied egg-rr49.4%
log1p-define49.4%
associate--l+98.6%
Simplified98.6%
Final simplification98.9%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (- (log (* x -2.0))) x)
(if (<= x 0.10000000149011612)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 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((x * -2.0f)), x);
} else if (x <= 0.10000000149011612f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 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(Float32(-log(Float32(x * Float32(-2.0)))), x); elseif (x <= Float32(0.10000000149011612)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * 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((x * single(-2.0)))); elseif (x <= single(0.10000000149011612)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * 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(x \cdot -2\right), x\right)\\
\mathbf{elif}\;x \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \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 47.6%
+-commutative47.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.6%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
metadata-eval-0.0%
unpow2-0.0%
hypot-undefine-0.0%
rem-square-sqrt10.5%
Simplified10.5%
Taylor expanded in x around -inf 98.4%
clear-num98.4%
log-rec98.5%
div-inv98.5%
metadata-eval98.5%
Applied egg-rr98.5%
if -1 < x < 0.100000001Initial program 20.8%
+-commutative20.8%
hypot-1-def20.8%
Simplified20.8%
Taylor expanded in x around 0 20.8%
rem-square-sqrt7.6%
fabs-sqr7.6%
metadata-eval7.6%
unpow27.6%
hypot-undefine7.6%
rem-square-sqrt21.1%
Simplified21.1%
Taylor expanded in x around 0 98.5%
unpow298.5%
Applied egg-rr98.5%
unpow298.5%
Applied egg-rr98.5%
if 0.100000001 < x Initial program 50.5%
+-commutative50.5%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around 0 50.5%
rem-square-sqrt50.5%
fabs-sqr50.5%
metadata-eval50.5%
unpow250.5%
hypot-undefine98.5%
rem-square-sqrt98.6%
Simplified98.6%
Final simplification98.5%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (- (log (* x -2.0))) x)
(if (<= x 1.0)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
x)
(copysign (log (/ 0.5 x)) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(-logf((x * -2.0f)), x);
} else if (x <= 1.0f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 0.075f) - 0.16666666666666666f)))), x);
} else {
tmp = copysignf(logf((0.5f / x)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-1.0)) tmp = copysign(Float32(-log(Float32(x * Float32(-2.0)))), x); elseif (x <= Float32(1.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * Float32(0.075)) - Float32(0.16666666666666666))))), x); else tmp = copysign(log(Float32(Float32(0.5) / 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((x * single(-2.0)))); elseif (x <= single(1.0)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * single(0.075)) - single(0.16666666666666666)))))); else tmp = sign(x) * abs(log((single(0.5) / x))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(x \cdot -2\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 47.6%
+-commutative47.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.6%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
metadata-eval-0.0%
unpow2-0.0%
hypot-undefine-0.0%
rem-square-sqrt10.5%
Simplified10.5%
Taylor expanded in x around -inf 98.4%
clear-num98.4%
log-rec98.5%
div-inv98.5%
metadata-eval98.5%
Applied egg-rr98.5%
if -1 < x < 1Initial program 22.1%
+-commutative22.1%
hypot-1-def22.1%
Simplified22.1%
Taylor expanded in x around 0 22.1%
rem-square-sqrt9.1%
fabs-sqr9.1%
metadata-eval9.1%
unpow29.1%
hypot-undefine9.0%
rem-square-sqrt22.3%
Simplified22.3%
Taylor expanded in x around 0 97.9%
unpow297.9%
Applied egg-rr97.9%
unpow297.9%
Applied egg-rr97.9%
if 1 < x Initial program 49.1%
+-commutative49.1%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around 0 49.1%
rem-square-sqrt49.1%
fabs-sqr49.1%
metadata-eval49.1%
unpow249.1%
hypot-undefine98.5%
rem-square-sqrt98.6%
Simplified98.6%
Taylor expanded in x around -inf -0.0%
frac-2neg-0.0%
div-inv-0.0%
metadata-eval-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod45.7%
sqr-neg45.7%
sqrt-prod96.6%
add-sqr-sqrt96.6%
Applied egg-rr96.6%
associate-*r/96.6%
metadata-eval96.6%
Simplified96.6%
Final simplification97.7%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 1.0)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
x)
(copysign (log (/ 0.5 x)) x))))
float code(float x) {
float tmp;
if (x <= -1.0f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else if (x <= 1.0f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 0.075f) - 0.16666666666666666f)))), x);
} else {
tmp = copysignf(logf((0.5f / 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(1.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * Float32(0.075)) - Float32(0.16666666666666666))))), x); else tmp = copysign(log(Float32(Float32(0.5) / 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(1.0)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * single(0.075)) - single(0.16666666666666666)))))); else tmp = sign(x) * abs(log((single(0.5) / 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 1:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 47.6%
+-commutative47.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.6%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
metadata-eval-0.0%
unpow2-0.0%
hypot-undefine-0.0%
rem-square-sqrt10.5%
Simplified10.5%
Taylor expanded in x around -inf 98.4%
if -1 < x < 1Initial program 22.1%
+-commutative22.1%
hypot-1-def22.1%
Simplified22.1%
Taylor expanded in x around 0 22.1%
rem-square-sqrt9.1%
fabs-sqr9.1%
metadata-eval9.1%
unpow29.1%
hypot-undefine9.0%
rem-square-sqrt22.3%
Simplified22.3%
Taylor expanded in x around 0 97.9%
unpow297.9%
Applied egg-rr97.9%
unpow297.9%
Applied egg-rr97.9%
if 1 < x Initial program 49.1%
+-commutative49.1%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around 0 49.1%
rem-square-sqrt49.1%
fabs-sqr49.1%
metadata-eval49.1%
unpow249.1%
hypot-undefine98.5%
rem-square-sqrt98.6%
Simplified98.6%
Taylor expanded in x around -inf -0.0%
frac-2neg-0.0%
div-inv-0.0%
metadata-eval-0.0%
add-sqr-sqrt-0.0%
sqrt-unprod45.7%
sqr-neg45.7%
sqrt-prod96.6%
add-sqr-sqrt96.6%
Applied egg-rr96.6%
associate-*r/96.6%
metadata-eval96.6%
Simplified96.6%
Final simplification97.7%
(FPCore (x)
:precision binary32
(if (<= x -1.0)
(copysign (log (/ -0.5 x)) x)
(if (<= x 1.0)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
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 <= 1.0f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 0.075f) - 0.16666666666666666f)))), 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(1.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * Float32(0.075)) - 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(-1.0)) tmp = sign(x) * abs(log((single(-0.5) / x))); elseif (x <= single(1.0)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * single(0.075)) - 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 -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 47.6%
+-commutative47.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 47.6%
rem-square-sqrt-0.0%
fabs-sqr-0.0%
metadata-eval-0.0%
unpow2-0.0%
hypot-undefine-0.0%
rem-square-sqrt10.5%
Simplified10.5%
Taylor expanded in x around -inf 98.4%
if -1 < x < 1Initial program 22.1%
+-commutative22.1%
hypot-1-def22.1%
Simplified22.1%
Taylor expanded in x around 0 22.1%
rem-square-sqrt9.1%
fabs-sqr9.1%
metadata-eval9.1%
unpow29.1%
hypot-undefine9.0%
rem-square-sqrt22.3%
Simplified22.3%
Taylor expanded in x around 0 97.9%
unpow297.9%
Applied egg-rr97.9%
unpow297.9%
Applied egg-rr97.9%
if 1 < x Initial program 49.1%
+-commutative49.1%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around inf 95.3%
+-commutative95.3%
rem-square-sqrt95.3%
fabs-sqr95.3%
rem-square-sqrt95.3%
*-inverses95.3%
metadata-eval95.3%
Simplified95.3%
Final simplification97.3%
(FPCore (x)
:precision binary32
(if (<= x -50.0)
(copysign (log (- x)) x)
(if (<= x 1.0)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
x)
(copysign (log (* x 2.0)) x))))
float code(float x) {
float tmp;
if (x <= -50.0f) {
tmp = copysignf(logf(-x), x);
} else if (x <= 1.0f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 0.075f) - 0.16666666666666666f)))), x);
} else {
tmp = copysignf(logf((x * 2.0f)), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(-50.0)) tmp = copysign(log(Float32(-x)), x); elseif (x <= Float32(1.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * Float32(0.075)) - 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(-50.0)) tmp = sign(x) * abs(log(-x)); elseif (x <= single(1.0)) tmp = sign(x) * abs((x * (single(1.0) + ((x * x) * (((x * x) * single(0.075)) - 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 -50:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot 2\right), x\right)\\
\end{array}
\end{array}
if x < -50Initial program 46.8%
+-commutative46.8%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 45.5%
mul-1-neg45.5%
Simplified45.5%
if -50 < x < 1Initial program 22.7%
+-commutative22.7%
hypot-1-def22.7%
Simplified22.7%
Taylor expanded in x around 0 22.7%
rem-square-sqrt9.0%
fabs-sqr9.0%
metadata-eval9.0%
unpow29.0%
hypot-undefine9.0%
rem-square-sqrt22.9%
Simplified22.9%
Taylor expanded in x around 0 97.4%
unpow297.4%
Applied egg-rr97.4%
unpow297.4%
Applied egg-rr97.4%
if 1 < x Initial program 49.1%
+-commutative49.1%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around inf 95.3%
+-commutative95.3%
rem-square-sqrt95.3%
fabs-sqr95.3%
rem-square-sqrt95.3%
*-inverses95.3%
metadata-eval95.3%
Simplified95.3%
Final simplification83.6%
(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 47.6%
+-commutative47.6%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 45.1%
mul-1-neg45.1%
Simplified45.1%
if -1 < x Initial program 31.7%
+-commutative31.7%
hypot-1-def49.5%
Simplified49.5%
Taylor expanded in x around 0 26.6%
log1p-define75.6%
rem-square-sqrt44.3%
fabs-sqr44.3%
rem-square-sqrt75.5%
Simplified75.5%
(FPCore (x)
:precision binary32
(if (<= x 2.0)
(copysign
(* x (+ 1.0 (* (* x x) (- (* (* x x) 0.075) 0.16666666666666666))))
x)
(copysign (log1p x) x)))
float code(float x) {
float tmp;
if (x <= 2.0f) {
tmp = copysignf((x * (1.0f + ((x * x) * (((x * x) * 0.075f) - 0.16666666666666666f)))), x);
} else {
tmp = copysignf(log1pf(x), x);
}
return tmp;
}
function code(x) tmp = Float32(0.0) if (x <= Float32(2.0)) tmp = copysign(Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(Float32(x * x) * Float32(0.075)) - Float32(0.16666666666666666))))), 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(x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot 0.075 - 0.16666666666666666\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\end{array}
if x < 2Initial program 31.4%
+-commutative31.4%
hypot-1-def49.7%
Simplified49.7%
Taylor expanded in x around 0 31.4%
rem-square-sqrt6.4%
fabs-sqr6.4%
metadata-eval6.4%
unpow26.4%
hypot-undefine6.4%
rem-square-sqrt18.6%
Simplified18.6%
Taylor expanded in x around 0 65.9%
unpow265.9%
Applied egg-rr65.9%
unpow265.9%
Applied egg-rr65.9%
if 2 < x Initial program 48.3%
+-commutative48.3%
hypot-1-def98.6%
Simplified98.6%
Taylor expanded in x around 0 44.7%
log1p-define44.7%
rem-square-sqrt44.7%
fabs-sqr44.7%
rem-square-sqrt44.7%
Simplified44.7%
Final simplification60.3%
(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 35.8%
+-commutative35.8%
hypot-1-def62.5%
Simplified62.5%
Taylor expanded in x around 0 35.8%
rem-square-sqrt17.4%
fabs-sqr17.4%
metadata-eval17.4%
unpow217.4%
hypot-undefine30.5%
rem-square-sqrt39.5%
Simplified39.5%
Taylor expanded in x around 0 51.0%
(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 2024188
(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))