?

Average Error: 20.4 → 12.4
Time: 16.3s
Precision: binary32
Cost: 42696

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} t_0 := \sqrt{x \cdot x + 1}\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + t_0\right), x\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;t_1 \leq 2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{\left(t_0 + \left|x\right| \cdot 7\right) - \left|x\right| \cdot 6}{1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{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 (sqrt (+ (* x x) 1.0))) (t_1 (copysign (log (+ (fabs x) t_0)) x)))
   (if (<= t_1 (- INFINITY))
     (copysign (log (/ -0.5 x)) x)
     (if (<= t_1 2.0)
       (copysign (log (/ (- (+ t_0 (* (fabs x) 7.0)) (* (fabs x) 6.0)) 1.0)) x)
       (copysign (log (+ (fabs x) (+ x (/ 0.5 x)))) x)))))
float code(float x) {
	return copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
}
float code(float x) {
	float t_0 = sqrtf(((x * x) + 1.0f));
	float t_1 = copysignf(logf((fabsf(x) + t_0)), x);
	float tmp;
	if (t_1 <= -((float) INFINITY)) {
		tmp = copysignf(logf((-0.5f / x)), x);
	} else if (t_1 <= 2.0f) {
		tmp = copysignf(logf((((t_0 + (fabsf(x) * 7.0f)) - (fabsf(x) * 6.0f)) / 1.0f)), x);
	} else {
		tmp = copysignf(logf((fabsf(x) + (x + (0.5f / 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 = sqrt(Float32(Float32(x * x) + Float32(1.0)))
	t_1 = copysign(log(Float32(abs(x) + t_0)), x)
	tmp = Float32(0.0)
	if (t_1 <= Float32(-Float32(Inf)))
		tmp = copysign(log(Float32(Float32(-0.5) / x)), x);
	elseif (t_1 <= Float32(2.0))
		tmp = copysign(log(Float32(Float32(Float32(t_0 + Float32(abs(x) * Float32(7.0))) - Float32(abs(x) * Float32(6.0))) / Float32(1.0))), x);
	else
		tmp = copysign(log(Float32(abs(x) + Float32(x + Float32(Float32(0.5) / 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 = sqrt(((x * x) + single(1.0)));
	t_1 = sign(x) * abs(log((abs(x) + t_0)));
	tmp = single(0.0);
	if (t_1 <= -single(Inf))
		tmp = sign(x) * abs(log((single(-0.5) / x)));
	elseif (t_1 <= single(2.0))
		tmp = sign(x) * abs(log((((t_0 + (abs(x) * single(7.0))) - (abs(x) * single(6.0))) / single(1.0))));
	else
		tmp = sign(x) * abs(log((abs(x) + (x + (single(0.5) / 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 := \sqrt{x \cdot x + 1}\\
t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + t_0\right), x\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\

\mathbf{elif}\;t_1 \leq 2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{\left(t_0 + \left|x\right| \cdot 7\right) - \left|x\right| \cdot 6}{1}\right), x\right)\\

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


\end{array}

Error?

Target

Original20.4
Target0.1
Herbie12.4
\[\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.4

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

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

      [Start]0.4

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

      rational.json-simplify-39 [=>]0.4

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

      rational.json-simplify-71 [<=]0.4

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

      rational.json-simplify-20 [=>]0.4

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

      metadata-eval [=>]0.4

      \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \left(\left(-x\right) - \frac{\color{blue}{0.5}}{x}\right)\right), x\right) \]
    4. Taylor expanded in x around 0 0.0

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

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

    1. Initial program 19.7

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Applied egg-rr19.8

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(\sqrt{x \cdot x + 1} + \left(\left|x\right| \cdot 2\right) \cdot 2\right) - \left|x\right| \cdot 3\right)}, x\right) \]
    3. Applied egg-rr19.8

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

    if 2 < (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.4

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

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

      [Start]0.4

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

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

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

      rational.json-simplify-20 [=>]0.4

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

      metadata-eval [=>]0.4

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

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

Alternatives

Alternative 1
Error12.4
Cost42696
\[\begin{array}{l} t_0 := \sqrt{x \cdot x + 1}\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + t_0\right), x\right)\\ \mathbf{if}\;t_1 \leq -24:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;t_1 \leq 5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(t_0 + \left(\left|x\right| \cdot 2\right) \cdot 2\right) - \left|x\right| \cdot 3\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error12.4
Cost42632
\[\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 2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| \cdot 3 - \left(\left|x\right| \cdot 2 - \sqrt{1 + x \cdot x}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error12.4
Cost39496
\[\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 5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot \left(\left(x + x \cdot 3\right) - x \cdot 3\right) + 1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error12.4
Cost39304
\[\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 2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\frac{x}{\frac{1}{x}} + 1}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 5
Error12.4
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 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 6
Error13.1
Cost10056
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x} - \left(x - \left|x\right|\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(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 7
Error13.2
Cost9992
\[\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.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + 1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 8
Error13.1
Cost9992
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x} - \left(x - \left|x\right|\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| + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 9
Error13.3
Cost9864
\[\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(\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 10
Error17.5
Cost9796
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\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 11
Error18.9
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq -4.000000861221333 \cdot 10^{-39}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\frac{1}{\frac{-1}{\log \left(\frac{1}{x}\right)}}, x\right)\\ \end{array} \]
Alternative 12
Error18.9
Cost6628
\[\begin{array}{l} \mathbf{if}\;x \leq -4.000000861221333 \cdot 10^{-39}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{1}{x}\right), x\right)\\ \end{array} \]
Alternative 13
Error18.9
Cost6596
\[\begin{array}{l} \mathbf{if}\;x \leq -4.000000861221333 \cdot 10^{-39}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 14
Error23.2
Cost6564
\[\begin{array}{l} \mathbf{if}\;x \leq -4.000000861221333 \cdot 10^{-39}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 15
Error27.6
Cost6464
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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