?

Average Error: 20.5 → 12.7
Time: 16.7s
Precision: binary32
Cost: 39240

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\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 -\infty:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 4:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
(FPCore (x)
 :precision binary32
 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
 :precision binary32
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 (- INFINITY))
     (copysign (log (+ (fabs x) (- x))) x)
     (if (<= t_0 4.0)
       t_0
       (copysign (log (+ (* 0.5 (/ 1.0 x)) (+ (fabs x) x))) x)))))
float code(float x) {
	return copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
}
float code(float x) {
	float t_0 = copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
	float tmp;
	if (t_0 <= -((float) INFINITY)) {
		tmp = copysignf(logf((fabsf(x) + -x)), x);
	} else if (t_0 <= 4.0f) {
		tmp = t_0;
	} else {
		tmp = copysignf(logf(((0.5f * (1.0f / x)) + (fabsf(x) + x))), x);
	}
	return tmp;
}
function code(x)
	return copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x)
end
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(-Float32(Inf)))
		tmp = copysign(log(Float32(abs(x) + Float32(-x))), x);
	elseif (t_0 <= Float32(4.0))
		tmp = t_0;
	else
		tmp = copysign(log(Float32(Float32(Float32(0.5) * Float32(Float32(1.0) / x)) + Float32(abs(x) + x))), x);
	end
	return tmp
end
function tmp = code(x)
	tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + single(1.0))))));
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(Inf))
		tmp = sign(x) * abs(log((abs(x) + -x)));
	elseif (t_0 <= single(4.0))
		tmp = t_0;
	else
		tmp = sign(x) * abs(log(((single(0.5) * (single(1.0) / x)) + (abs(x) + x))));
	end
	tmp_2 = tmp;
end
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\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 -\infty:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 4:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original20.5
Target0.1
Herbie12.7
\[\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, \frac{1}{\left|x\right|}\right) + \frac{1}{\left|x\right|}}\right), x\right) \]

Derivation?

  1. Split input into 3 regimes
  2. if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < -inf.0

    1. Initial program 32.0

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Taylor expanded in x around -inf 0.5

      \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{-1 \cdot x}\right), x\right) \]
    3. Simplified0.5

      \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\left(-x\right)}\right), x\right) \]
      Proof

      [Start]0.5

      \[ \mathsf{copysign}\left(\log \left(\left|x\right| + -1 \cdot x\right), x\right) \]

      rational.json-simplify-2 [=>]0.5

      \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{x \cdot -1}\right), x\right) \]

      rational.json-simplify-9 [=>]0.5

      \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\left(-x\right)}\right), x\right) \]

    if -inf.0 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < 4

    1. Initial program 19.8

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]

    if 4 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x)

    1. Initial program 16.6

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Taylor expanded in x around inf 0.3

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -\infty:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{elif}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 4:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error14.8
Cost10020
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{1}{x}\\ \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| + \left(-x\right)\right) - t_0\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(t_0 + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error14.9
Cost9988
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(0.5 \cdot \frac{1}{x} + x\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error14.9
Cost9988
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error14.9
Cost9828
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\left(0 - \left(-1 - \log \left(\frac{0.5}{x}\right)\right)\right) - 1, x\right)\\ \end{array} \]
Alternative 5
Error17.7
Cost9796
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - -1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 6
Error19.0
Cost9732
\[\begin{array}{l} \mathbf{if}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 7
Error19.0
Cost6820
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(-\left(\left(0 - \left(-1 - \log \left(\frac{-1}{x}\right)\right)\right) - 1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\left(0 - \left(-1 - \log \left(\frac{0.5}{x}\right)\right)\right) - 1, x\right)\\ \end{array} \]
Alternative 8
Error19.0
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\left(0 - \left(-1 - \log \left(\frac{0.5}{x}\right)\right)\right) - 1, x\right)\\ \end{array} \]
Alternative 9
Error19.0
Cost6628
\[\begin{array}{l} \mathbf{if}\;x \leq -2.0000000102211272 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 10
Error23.3
Cost6528
\[\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right) \]
Alternative 11
Error27.6
Cost6464
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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