?

Average Error: 20.6 → 12.6
Time: 8.9s
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 5:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{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 5.0) t_0 (copysign (log (+ (/ 0.5 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 <= 5.0f) {
		tmp = t_0;
	} else {
		tmp = copysignf(logf(((0.5f / 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(5.0))
		tmp = t_0;
	else
		tmp = copysign(log(Float32(Float32(Float32(0.5) / 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(5.0))
		tmp = t_0;
	else
		tmp = sign(x) * abs(log(((single(0.5) / 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 5:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original20.6
Target0.2
Herbie12.6
\[\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.6

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

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

      [Start]0.6

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

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

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

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

      \[ \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) < 5

    1. Initial program 19.6

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

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

    1. Initial program 17.2

      \[\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. Taylor expanded in x around 0 0.3

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

    \[\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 5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error13.4
Cost9992
\[\begin{array}{l} \mathbf{if}\;x \leq -5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(\frac{-0.5}{x} - x\right)\right), x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - -1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error13.5
Cost9924
\[\begin{array}{l} \mathbf{if}\;x \leq -5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(\frac{-0.5}{x} - x\right)\right), x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - -1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 3
Error13.6
Cost9864
\[\begin{array}{l} \mathbf{if}\;x \leq -5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(-x\right)\right), x\right)\\ \mathbf{elif}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - -1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 4
Error19.2
Cost9796
\[\begin{array}{l} \mathbf{if}\;x \leq -4.0000000204422544 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 5
Error17.7
Cost9796
\[\begin{array}{l} \mathbf{if}\;x \leq 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - -1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 6
Error19.1
Cost6628
\[\begin{array}{l} \mathbf{if}\;x \leq -4.0000000204422544 \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 7
Error23.4
Cost6528
\[\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right) \]
Alternative 8
Error27.7
Cost6464
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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