?

Average Error: 20.2 → 12.9
Time: 3.5s
Precision: binary32
Cost: 56104

?

\[\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)\\ t_1 := 1 + \left|x\right|\\ \mathbf{if}\;t_0 \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| + \frac{1}{x} \cdot -0.5\right) - x\right), x\right)\\ \mathbf{elif}\;t_0 \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(\left(\log t_1 + 0.5 \cdot \frac{{x}^{2}}{t_1}\right) + \left(3 \cdot \frac{1}{t_1} + 3 \cdot \frac{1}{{t_1}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\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} \]
(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))
        (t_1 (+ 1.0 (fabs x))))
   (if (<= t_0 -1.0)
     (copysign (log (- (+ (fabs x) (* (/ 1.0 x) -0.5)) x)) x)
     (if (<= t_0 1.0)
       (copysign
        (+
         (+ (log t_1) (* 0.5 (/ (pow x 2.0) t_1)))
         (*
          (+ (* 3.0 (/ 1.0 t_1)) (* 3.0 (/ 1.0 (pow t_1 2.0))))
          (* -0.041666666666666664 (pow x 4.0))))
        x)
       (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 t_1 = 1.0f + fabsf(x);
	float tmp;
	if (t_0 <= -1.0f) {
		tmp = copysignf(logf(((fabsf(x) + ((1.0f / x) * -0.5f)) - x)), x);
	} else if (t_0 <= 1.0f) {
		tmp = copysignf(((logf(t_1) + (0.5f * (powf(x, 2.0f) / t_1))) + (((3.0f * (1.0f / t_1)) + (3.0f * (1.0f / powf(t_1, 2.0f)))) * (-0.041666666666666664f * powf(x, 4.0f)))), x);
	} 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)
	t_1 = Float32(Float32(1.0) + abs(x))
	tmp = Float32(0.0)
	if (t_0 <= Float32(-1.0))
		tmp = copysign(log(Float32(Float32(abs(x) + Float32(Float32(Float32(1.0) / x) * Float32(-0.5))) - x)), x);
	elseif (t_0 <= Float32(1.0))
		tmp = copysign(Float32(Float32(log(t_1) + Float32(Float32(0.5) * Float32((x ^ Float32(2.0)) / t_1))) + Float32(Float32(Float32(Float32(3.0) * Float32(Float32(1.0) / t_1)) + Float32(Float32(3.0) * Float32(Float32(1.0) / (t_1 ^ Float32(2.0))))) * Float32(Float32(-0.041666666666666664) * (x ^ Float32(4.0))))), x);
	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))))));
	t_1 = single(1.0) + abs(x);
	tmp = single(0.0);
	if (t_0 <= single(-1.0))
		tmp = sign(x) * abs(log(((abs(x) + ((single(1.0) / x) * single(-0.5))) - x)));
	elseif (t_0 <= single(1.0))
		tmp = sign(x) * abs(((log(t_1) + (single(0.5) * ((x ^ single(2.0)) / t_1))) + (((single(3.0) * (single(1.0) / t_1)) + (single(3.0) * (single(1.0) / (t_1 ^ single(2.0))))) * (single(-0.041666666666666664) * (x ^ single(4.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)\\
t_1 := 1 + \left|x\right|\\
\mathbf{if}\;t_0 \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| + \frac{1}{x} \cdot -0.5\right) - x\right), x\right)\\

\mathbf{elif}\;t_0 \leq 1:\\
\;\;\;\;\mathsf{copysign}\left(\left(\log t_1 + 0.5 \cdot \frac{{x}^{2}}{t_1}\right) + \left(3 \cdot \frac{1}{t_1} + 3 \cdot \frac{1}{{t_1}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\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}

Error?

Target

Original20.2
Target0.1
Herbie12.9
\[\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) < -1

    1. Initial program 15.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.5

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

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

      [Start]0.5

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

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

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

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

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

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

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

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

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

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

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

      rational.json-simplify-41 [<=]0.5

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

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

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

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

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

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

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

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

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

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

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

      metadata-eval [=>]0.5

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

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

    1. Initial program 24.7

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-0.041666666666666664 \cdot \left(\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot {x}^{4}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right)}, x\right) \]
    3. Simplified24.7

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(\log \left(1 + \left|x\right|\right) + 0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|}\right) + \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\right)}, x\right) \]
      Proof

      [Start]24.7

      \[ \mathsf{copysign}\left(-0.041666666666666664 \cdot \left(\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot {x}^{4}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right), x\right) \]

      rational.json-simplify-1 [=>]24.7

      \[ \mathsf{copysign}\left(\color{blue}{\left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right) + -0.041666666666666664 \cdot \left(\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot {x}^{4}\right)}, x\right) \]

      rational.json-simplify-1 [=>]24.7

      \[ \mathsf{copysign}\left(\color{blue}{\left(\log \left(1 + \left|x\right|\right) + 0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|}\right)} + -0.041666666666666664 \cdot \left(\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot {x}^{4}\right), x\right) \]

      rational.json-simplify-31 [=>]24.7

      \[ \mathsf{copysign}\left(\left(\log \left(1 + \left|x\right|\right) + 0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|}\right) + \color{blue}{\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\right)}, x\right) \]

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

    1. Initial program 16.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 \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.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| + \frac{1}{x} \cdot -0.5\right) - x\right), x\right)\\ \mathbf{elif}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(\left(\log \left(1 + \left|x\right|\right) + 0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|}\right) + \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot \left(-0.041666666666666664 \cdot {x}^{4}\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
Error12.8
Cost39240
\[\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(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;t_0 \leq 1:\\ \;\;\;\;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} \]
Alternative 2
Error13.5
Cost10056
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.4000000059604645:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + 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} \]
Alternative 3
Error13.5
Cost10056
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| + \frac{1}{x} \cdot -0.5\right) - x\right), x\right)\\ \mathbf{elif}\;x \leq 0.4000000059604645:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + 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} \]
Alternative 4
Error13.6
Cost9864
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\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 5
Error17.7
Cost9796
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + 1\right), x\right)\\ \end{array} \]
Alternative 6
Error19.2
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq -4.0000000204422544 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(-1 \cdot \log \left(\frac{1}{x}\right), x\right)\\ \end{array} \]
Alternative 7
Error20.9
Cost6596
\[\begin{array}{l} \mathbf{if}\;x \leq -0.10000000149011612:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\frac{\left|x\right|}{x}, x\right)\\ \end{array} \]
Alternative 8
Error23.4
Cost6528
\[\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right) \]
Alternative 9
Error27.7
Cost6496
\[\mathsf{copysign}\left(\log \left(-x\right), x\right) \]

Error

Reproduce?

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