Rust f32::asinh

Percentage Accurate: 37.8% → 98.1%
Time: 8.8s
Alternatives: 14
Speedup: 4.0×

Specification

?
\[\begin{array}{l} \\ \sinh^{-1} x \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 37.8% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 98.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|x\right| + 1\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_2 := \log \left(\frac{1}{x}\right)\\ t_3 := 1 + \left(\log 2 - t_2\right)\\ t_4 := \frac{1}{{t_3}^{2}}\\ \mathbf{if}\;t_1 \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_1 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) + \mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_0} + \frac{3}{{t_0}^{2}}\right), 0.5 \cdot \frac{{x}^{2}}{t_0}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log 2 + \left(\left(0.25 \cdot \frac{1}{{x}^{2}} + \frac{t_3 \cdot \left(-0.041666666666666664 \cdot \left(2.25 \cdot \frac{1}{t_3} + 0.75 \cdot t_4\right) + t_4 \cdot 0.03125\right)}{{x}^{4}}\right) - t_2\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (+ (fabs x) 1.0))
        (t_1 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
        (t_2 (log (/ 1.0 x)))
        (t_3 (+ 1.0 (- (log 2.0) t_2)))
        (t_4 (/ 1.0 (pow t_3 2.0))))
   (if (<= t_1 -1.0)
     (copysign (log (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_1 0.019999999552965164)
       (copysign
        (+
         (log1p (fabs x))
         (fma
          -0.041666666666666664
          (* (pow x 4.0) (+ (/ 3.0 t_0) (/ 3.0 (pow t_0 2.0))))
          (* 0.5 (/ (pow x 2.0) t_0))))
        x)
       (copysign
        (+
         (log 2.0)
         (-
          (+
           (* 0.25 (/ 1.0 (pow x 2.0)))
           (/
            (*
             t_3
             (+
              (* -0.041666666666666664 (+ (* 2.25 (/ 1.0 t_3)) (* 0.75 t_4)))
              (* t_4 0.03125)))
            (pow x 4.0)))
          t_2))
        x)))))
float code(float x) {
	float t_0 = fabsf(x) + 1.0f;
	float t_1 = copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
	float t_2 = logf((1.0f / x));
	float t_3 = 1.0f + (logf(2.0f) - t_2);
	float t_4 = 1.0f / powf(t_3, 2.0f);
	float tmp;
	if (t_1 <= -1.0f) {
		tmp = copysignf(logf((fabsf(x) + hypotf(1.0f, x))), x);
	} else if (t_1 <= 0.019999999552965164f) {
		tmp = copysignf((log1pf(fabsf(x)) + fmaf(-0.041666666666666664f, (powf(x, 4.0f) * ((3.0f / t_0) + (3.0f / powf(t_0, 2.0f)))), (0.5f * (powf(x, 2.0f) / t_0)))), x);
	} else {
		tmp = copysignf((logf(2.0f) + (((0.25f * (1.0f / powf(x, 2.0f))) + ((t_3 * ((-0.041666666666666664f * ((2.25f * (1.0f / t_3)) + (0.75f * t_4))) + (t_4 * 0.03125f))) / powf(x, 4.0f))) - t_2)), x);
	}
	return tmp;
}
function code(x)
	t_0 = Float32(abs(x) + Float32(1.0))
	t_1 = copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x)
	t_2 = log(Float32(Float32(1.0) / x))
	t_3 = Float32(Float32(1.0) + Float32(log(Float32(2.0)) - t_2))
	t_4 = Float32(Float32(1.0) / (t_3 ^ Float32(2.0)))
	tmp = Float32(0.0)
	if (t_1 <= Float32(-1.0))
		tmp = copysign(log(Float32(abs(x) + hypot(Float32(1.0), x))), x);
	elseif (t_1 <= Float32(0.019999999552965164))
		tmp = copysign(Float32(log1p(abs(x)) + fma(Float32(-0.041666666666666664), Float32((x ^ Float32(4.0)) * Float32(Float32(Float32(3.0) / t_0) + Float32(Float32(3.0) / (t_0 ^ Float32(2.0))))), Float32(Float32(0.5) * Float32((x ^ Float32(2.0)) / t_0)))), x);
	else
		tmp = copysign(Float32(log(Float32(2.0)) + Float32(Float32(Float32(Float32(0.25) * Float32(Float32(1.0) / (x ^ Float32(2.0)))) + Float32(Float32(t_3 * Float32(Float32(Float32(-0.041666666666666664) * Float32(Float32(Float32(2.25) * Float32(Float32(1.0) / t_3)) + Float32(Float32(0.75) * t_4))) + Float32(t_4 * Float32(0.03125)))) / (x ^ Float32(4.0)))) - t_2)), x);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|x\right| + 1\\
t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
t_2 := \log \left(\frac{1}{x}\right)\\
t_3 := 1 + \left(\log 2 - t_2\right)\\
t_4 := \frac{1}{{t_3}^{2}}\\
\mathbf{if}\;t_1 \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_1 \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) + \mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_0} + \frac{3}{{t_0}^{2}}\right), 0.5 \cdot \frac{{x}^{2}}{t_0}\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log 2 + \left(\left(0.25 \cdot \frac{1}{{x}^{2}} + \frac{t_3 \cdot \left(-0.041666666666666664 \cdot \left(2.25 \cdot \frac{1}{t_3} + 0.75 \cdot t_4\right) + t_4 \cdot 0.03125\right)}{{x}^{4}}\right) - t_2\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 97.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \left|x\right| + 1\\ \mathbf{if}\;t_0 \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) + \mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_1} + \frac{3}{{t_1}^{2}}\right), 0.5 \cdot \frac{{x}^{2}}{t_1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
        (t_1 (+ (fabs x) 1.0)))
   (if (<= t_0 -1.0)
     (copysign (log (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_0 0.019999999552965164)
       (copysign
        (+
         (log1p (fabs x))
         (fma
          -0.041666666666666664
          (* (pow x 4.0) (+ (/ 3.0 t_1) (/ 3.0 (pow t_1 2.0))))
          (* 0.5 (/ (pow x 2.0) t_1))))
        x)
       (copysign (* 0.3333333333333333 (* 3.0 (+ (log 2.0) (log x)))) x)))))
float code(float x) {
	float t_0 = copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
	float t_1 = fabsf(x) + 1.0f;
	float tmp;
	if (t_0 <= -1.0f) {
		tmp = copysignf(logf((fabsf(x) + hypotf(1.0f, x))), x);
	} else if (t_0 <= 0.019999999552965164f) {
		tmp = copysignf((log1pf(fabsf(x)) + fmaf(-0.041666666666666664f, (powf(x, 4.0f) * ((3.0f / t_1) + (3.0f / powf(t_1, 2.0f)))), (0.5f * (powf(x, 2.0f) / t_1)))), x);
	} else {
		tmp = copysignf((0.3333333333333333f * (3.0f * (logf(2.0f) + logf(x)))), x);
	}
	return tmp;
}
function code(x)
	t_0 = copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x)
	t_1 = Float32(abs(x) + Float32(1.0))
	tmp = Float32(0.0)
	if (t_0 <= Float32(-1.0))
		tmp = copysign(log(Float32(abs(x) + hypot(Float32(1.0), x))), x);
	elseif (t_0 <= Float32(0.019999999552965164))
		tmp = copysign(Float32(log1p(abs(x)) + fma(Float32(-0.041666666666666664), Float32((x ^ Float32(4.0)) * Float32(Float32(Float32(3.0) / t_1) + Float32(Float32(3.0) / (t_1 ^ Float32(2.0))))), Float32(Float32(0.5) * Float32((x ^ Float32(2.0)) / t_1)))), x);
	else
		tmp = copysign(Float32(Float32(0.3333333333333333) * Float32(Float32(3.0) * Float32(log(Float32(2.0)) + log(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)\\
t_1 := \left|x\right| + 1\\
\mathbf{if}\;t_0 \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) + \mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_1} + \frac{3}{{t_1}^{2}}\right), 0.5 \cdot \frac{{x}^{2}}{t_1}\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 97.5% accurate, 0.3× speedup?

\[\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(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{{x}^{2}}{x + 1}, \mathsf{log1p}\left(x\right)\right) + \left(\frac{3}{x + 1} + \frac{3}{{\left(x + 1\right)}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\ \end{array} \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 (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_0 0.019999999552965164)
       (copysign
        (+
         (fma 0.5 (/ (pow x 2.0) (+ x 1.0)) (log1p x))
         (*
          (+ (/ 3.0 (+ x 1.0)) (/ 3.0 (pow (+ x 1.0) 2.0)))
          (* -0.041666666666666664 (pow x 4.0))))
        x)
       (copysign (* 0.3333333333333333 (* 3.0 (+ (log 2.0) (log 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((fabsf(x) + hypotf(1.0f, x))), x);
	} else if (t_0 <= 0.019999999552965164f) {
		tmp = copysignf((fmaf(0.5f, (powf(x, 2.0f) / (x + 1.0f)), log1pf(x)) + (((3.0f / (x + 1.0f)) + (3.0f / powf((x + 1.0f), 2.0f))) * (-0.041666666666666664f * powf(x, 4.0f)))), x);
	} else {
		tmp = copysignf((0.3333333333333333f * (3.0f * (logf(2.0f) + logf(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(abs(x) + hypot(Float32(1.0), x))), x);
	elseif (t_0 <= Float32(0.019999999552965164))
		tmp = copysign(Float32(fma(Float32(0.5), Float32((x ^ Float32(2.0)) / Float32(x + Float32(1.0))), log1p(x)) + Float32(Float32(Float32(Float32(3.0) / Float32(x + Float32(1.0))) + Float32(Float32(3.0) / (Float32(x + Float32(1.0)) ^ Float32(2.0)))) * Float32(Float32(-0.041666666666666664) * (x ^ Float32(4.0))))), x);
	else
		tmp = copysign(Float32(Float32(0.3333333333333333) * Float32(Float32(3.0) * Float32(log(Float32(2.0)) + log(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(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{{x}^{2}}{x + 1}, \mathsf{log1p}\left(x\right)\right) + \left(\frac{3}{x + 1} + \frac{3}{{\left(x + 1\right)}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 97.8% accurate, 0.3× speedup?

\[\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.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{{x}^{2}}{x + 1}, \mathsf{log1p}\left(x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 -0.019999999552965164)
     (copysign (log (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_0 0.019999999552965164)
       (copysign (fma 0.5 (/ (pow x 2.0) (+ x 1.0)) (log1p x)) x)
       (copysign (* 0.3333333333333333 (* 3.0 (+ (log 2.0) (log 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.019999999552965164f) {
		tmp = copysignf(logf((fabsf(x) + hypotf(1.0f, x))), x);
	} else if (t_0 <= 0.019999999552965164f) {
		tmp = copysignf(fmaf(0.5f, (powf(x, 2.0f) / (x + 1.0f)), log1pf(x)), x);
	} else {
		tmp = copysignf((0.3333333333333333f * (3.0f * (logf(2.0f) + logf(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.019999999552965164))
		tmp = copysign(log(Float32(abs(x) + hypot(Float32(1.0), x))), x);
	elseif (t_0 <= Float32(0.019999999552965164))
		tmp = copysign(fma(Float32(0.5), Float32((x ^ Float32(2.0)) / Float32(x + Float32(1.0))), log1p(x)), x);
	else
		tmp = copysign(Float32(Float32(0.3333333333333333) * Float32(Float32(3.0) * Float32(log(Float32(2.0)) + log(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 -0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{{x}^{2}}{x + 1}, \mathsf{log1p}\left(x\right)\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \left(\log 2 + \log x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 99.3% accurate, 0.4× speedup?

\[\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.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.0010000000474974513:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 -0.019999999552965164)
     (copysign (log (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_0 0.0010000000474974513)
       (copysign x 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.019999999552965164f) {
		tmp = copysignf(logf((fabsf(x) + hypotf(1.0f, x))), x);
	} else if (t_0 <= 0.0010000000474974513f) {
		tmp = copysignf(x, 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.019999999552965164))
		tmp = copysign(log(Float32(abs(x) + hypot(Float32(1.0), x))), x);
	elseif (t_0 <= Float32(0.0010000000474974513))
		tmp = copysign(x, 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.019999999552965164))
		tmp = sign(x) * abs(log((abs(x) + hypot(single(1.0), x))));
	elseif (t_0 <= single(0.0010000000474974513))
		tmp = sign(x) * abs(x);
	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.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 0.0010000000474974513:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 99.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right)\right), x\right)\\ \mathbf{elif}\;x \leq 0.0010000000474974513:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -0.019999999552965164)
   (copysign
    (* 0.3333333333333333 (* 3.0 (log (/ 1.0 (- (hypot 1.0 x) x)))))
    x)
   (if (<= x 0.0010000000474974513)
     (copysign x x)
     (copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
	float tmp;
	if (x <= -0.019999999552965164f) {
		tmp = copysignf((0.3333333333333333f * (3.0f * logf((1.0f / (hypotf(1.0f, x) - x))))), x);
	} else if (x <= 0.0010000000474974513f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(logf((x + hypotf(1.0f, x))), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(-0.019999999552965164))
		tmp = copysign(Float32(Float32(0.3333333333333333) * Float32(Float32(3.0) * log(Float32(Float32(1.0) / Float32(hypot(Float32(1.0), x) - x))))), x);
	elseif (x <= Float32(0.0010000000474974513))
		tmp = copysign(x, 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.019999999552965164))
		tmp = sign(x) * abs((single(0.3333333333333333) * (single(3.0) * log((single(1.0) / (hypot(single(1.0), x) - x))))));
	elseif (x <= single(0.0010000000474974513))
		tmp = sign(x) * abs(x);
	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.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(0.3333333333333333 \cdot \left(3 \cdot \log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right)\right), x\right)\\

\mathbf{elif}\;x \leq 0.0010000000474974513:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 98.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - x\right) + \frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.0010000000474974513:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -1.0)
   (copysign (log (+ (- (fabs x) x) (/ -0.5 x))) x)
   (if (<= x 0.0010000000474974513)
     (copysign x x)
     (copysign (log (+ x (hypot 1.0 x))) x))))
float code(float x) {
	float tmp;
	if (x <= -1.0f) {
		tmp = copysignf(logf(((fabsf(x) - x) + (-0.5f / x))), x);
	} else if (x <= 0.0010000000474974513f) {
		tmp = copysignf(x, 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(abs(x) - x) + Float32(Float32(-0.5) / x))), x);
	elseif (x <= Float32(0.0010000000474974513))
		tmp = copysign(x, 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(((abs(x) - x) + (single(-0.5) / x))));
	elseif (x <= single(0.0010000000474974513))
		tmp = sign(x) * abs(x);
	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(\left(\left|x\right| - x\right) + \frac{-0.5}{x}\right), x\right)\\

\mathbf{elif}\;x \leq 0.0010000000474974513:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 98.5% accurate, 1.3× speedup?

\[\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.0010000000474974513:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -1.0)
   (copysign (log (/ -0.5 x)) x)
   (if (<= x 0.0010000000474974513)
     (copysign x 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.0010000000474974513f) {
		tmp = copysignf(x, 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.0010000000474974513))
		tmp = copysign(x, 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.0010000000474974513))
		tmp = sign(x) * abs(x);
	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.0010000000474974513:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 97.3% accurate, 1.9× speedup?

\[\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.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -1.0)
   (copysign (log (/ -0.5 x)) x)
   (if (<= x 0.019999999552965164)
     (copysign x x)
     (copysign (log (+ (/ 0.5 x) (+ x x))) x))))
float code(float x) {
	float tmp;
	if (x <= -1.0f) {
		tmp = copysignf(logf((-0.5f / x)), x);
	} else if (x <= 0.019999999552965164f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(logf(((0.5f / x) + (x + 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.019999999552965164))
		tmp = copysign(x, x);
	else
		tmp = copysign(log(Float32(Float32(Float32(0.5) / x) + Float32(x + 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.019999999552965164))
		tmp = sign(x) * abs(x);
	else
		tmp = sign(x) * abs(log(((single(0.5) / x) + (x + 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.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 96.9% accurate, 2.0× speedup?

\[\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.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x -1.0)
   (copysign (log (/ -0.5 x)) x)
   (if (<= x 0.019999999552965164) (copysign x x) (copysign (log (+ x x)) x))))
float code(float x) {
	float tmp;
	if (x <= -1.0f) {
		tmp = copysignf(logf((-0.5f / x)), x);
	} else if (x <= 0.019999999552965164f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(logf((x + 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.019999999552965164))
		tmp = copysign(x, x);
	else
		tmp = copysign(log(Float32(x + 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.019999999552965164))
		tmp = sign(x) * abs(x);
	else
		tmp = sign(x) * abs(log((x + 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.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 62.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + 1\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 0.019999999552965164) (copysign x x) (copysign (log (+ x 1.0)) x)))
float code(float x) {
	float tmp;
	if (x <= 0.019999999552965164f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(logf((x + 1.0f)), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(0.019999999552965164))
		tmp = copysign(x, x);
	else
		tmp = copysign(log(Float32(x + Float32(1.0))), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(0.019999999552965164))
		tmp = sign(x) * abs(x);
	else
		tmp = sign(x) * abs(log((x + single(1.0))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + 1\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 75.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 0.019999999552965164) (copysign x x) (copysign (log (+ x x)) x)))
float code(float x) {
	float tmp;
	if (x <= 0.019999999552965164f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(logf((x + x)), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(0.019999999552965164))
		tmp = copysign(x, x);
	else
		tmp = copysign(log(Float32(x + x)), x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = single(0.0);
	if (x <= single(0.019999999552965164))
		tmp = sign(x) * abs(x);
	else
		tmp = sign(x) * abs(log((x + x)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 62.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary32
 (if (<= x 0.019999999552965164) (copysign x x) (copysign (log1p x) x)))
float code(float x) {
	float tmp;
	if (x <= 0.019999999552965164f) {
		tmp = copysignf(x, x);
	} else {
		tmp = copysignf(log1pf(x), x);
	}
	return tmp;
}
function code(x)
	tmp = Float32(0.0)
	if (x <= Float32(0.019999999552965164))
		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.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 14: 54.7% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \mathsf{copysign}\left(x, x\right) \end{array} \]
(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}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Developer target: 99.6% accurate, 0.6× speedup?

\[\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} \]
(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}

Reproduce

?
herbie shell --seed 2023343 
(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))