?

Average Error: 20.7 → 0.1
Time: 1.4min
Precision: binary32
Cost: 82152

?

\[\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 := \left|x\right| - -1\\ t_2 := {t_1}^{2}\\ t_3 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\ \mathbf{if}\;t_0 \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(t_3, x\right)\\ \mathbf{elif}\;t_0 \leq 0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_1} + \frac{3}{t_2}\right), \mathsf{fma}\left(0.001388888888888889, \left(\frac{45}{t_1} + \left(\frac{30}{{t_1}^{3}} + \frac{45}{t_2}\right)\right) \cdot {x}^{6}, \mathsf{fma}\left(0.5, \frac{x \cdot x}{t_1}, \mathsf{log1p}\left(\left|x\right|\right)\right)\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(1 + \left(-1 - \left(-t_3\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 (- (fabs x) -1.0))
        (t_2 (pow t_1 2.0))
        (t_3 (log (+ (fabs x) (hypot 1.0 x)))))
   (if (<= t_0 -0.20000000298023224)
     (copysign t_3 x)
     (if (<= t_0 0.20000000298023224)
       (copysign
        (fma
         -0.041666666666666664
         (* (pow x 4.0) (+ (/ 3.0 t_1) (/ 3.0 t_2)))
         (fma
          0.001388888888888889
          (*
           (+ (/ 45.0 t_1) (+ (/ 30.0 (pow t_1 3.0)) (/ 45.0 t_2)))
           (pow x 6.0))
          (fma 0.5 (/ (* x x) t_1) (log1p (fabs x)))))
        x)
       (copysign (+ 1.0 (- -1.0 (- t_3))) 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 = fabsf(x) - -1.0f;
	float t_2 = powf(t_1, 2.0f);
	float t_3 = logf((fabsf(x) + hypotf(1.0f, x)));
	float tmp;
	if (t_0 <= -0.20000000298023224f) {
		tmp = copysignf(t_3, x);
	} else if (t_0 <= 0.20000000298023224f) {
		tmp = copysignf(fmaf(-0.041666666666666664f, (powf(x, 4.0f) * ((3.0f / t_1) + (3.0f / t_2))), fmaf(0.001388888888888889f, (((45.0f / t_1) + ((30.0f / powf(t_1, 3.0f)) + (45.0f / t_2))) * powf(x, 6.0f)), fmaf(0.5f, ((x * x) / t_1), log1pf(fabsf(x))))), x);
	} else {
		tmp = copysignf((1.0f + (-1.0f - -t_3)), 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(abs(x) - Float32(-1.0))
	t_2 = t_1 ^ Float32(2.0)
	t_3 = log(Float32(abs(x) + hypot(Float32(1.0), x)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(-0.20000000298023224))
		tmp = copysign(t_3, x);
	elseif (t_0 <= Float32(0.20000000298023224))
		tmp = copysign(fma(Float32(-0.041666666666666664), Float32((x ^ Float32(4.0)) * Float32(Float32(Float32(3.0) / t_1) + Float32(Float32(3.0) / t_2))), fma(Float32(0.001388888888888889), Float32(Float32(Float32(Float32(45.0) / t_1) + Float32(Float32(Float32(30.0) / (t_1 ^ Float32(3.0))) + Float32(Float32(45.0) / t_2))) * (x ^ Float32(6.0))), fma(Float32(0.5), Float32(Float32(x * x) / t_1), log1p(abs(x))))), x);
	else
		tmp = copysign(Float32(Float32(1.0) + Float32(Float32(-1.0) - Float32(-t_3))), x);
	end
	return 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 := \left|x\right| - -1\\
t_2 := {t_1}^{2}\\
t_3 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\
\mathbf{if}\;t_0 \leq -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(t_3, x\right)\\

\mathbf{elif}\;t_0 \leq 0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{t_1} + \frac{3}{t_2}\right), \mathsf{fma}\left(0.001388888888888889, \left(\frac{45}{t_1} + \left(\frac{30}{{t_1}^{3}} + \frac{45}{t_2}\right)\right) \cdot {x}^{6}, \mathsf{fma}\left(0.5, \frac{x \cdot x}{t_1}, \mathsf{log1p}\left(\left|x\right|\right)\right)\right)\right), x\right)\\

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


\end{array}

Error?

Target

Original20.7
Target0.1
Herbie0.1
\[\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) < -0.200000003

    1. Initial program 16.3

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

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

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

    1. Initial program 25.6

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

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
      Proof
    3. Taylor expanded in x around 0 25.3

      \[\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.001388888888888889 \cdot \left(\left(45 \cdot \frac{1}{1 + \left|x\right|} + \left(30 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{3}} + 45 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) \cdot {x}^{6}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right)\right)}, x\right) \]
    4. Simplified0.0

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

    if 0.200000003 < (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. Applied egg-rr16.0

      \[\leadsto \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{\left({x}^{2} + 4\right) - 3}}\right), x\right) \]
    3. Applied egg-rr0.3

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\frac{\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right) \cdot 37}{37}}, x\right) \]
    4. Applied egg-rr0.3

      \[\leadsto \mathsf{copysign}\left(\color{blue}{1 + \left(-1 - \left(-\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)\right)}, x\right) \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.2
Cost52748
\[\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\\ t_2 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\ \mathbf{if}\;t_0 \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(t_2, x\right)\\ \mathbf{elif}\;t_0 \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(-0.041666666666666664 \cdot \frac{{x}^{4} \cdot \left(\frac{-3}{-1 - \left|x\right|} + 3\right)}{1 + \left|x\right|} + \left(0.5 \cdot \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{x}{\frac{t_1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{2}}{t_1}\\ \end{array} + \mathsf{log1p}\left(\left|x\right|\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(1 + \left(-1 - \left(-t_2\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error0.2
Cost49512
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\ \mathbf{if}\;t_0 \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(t_1, x\right)\\ \mathbf{elif}\;t_0 \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(-0.041666666666666664 \cdot \frac{{x}^{4} \cdot \left(\frac{-3}{-1 - \left|x\right|} + 3\right)}{1 + \left|x\right|} + \left(0.5 \cdot \left(x \cdot \frac{x}{\left|x\right| - -1}\right) + \mathsf{log1p}\left(\left|x\right|\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(1 + \left(-1 - \left(-t_1\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost42572
\[\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\\ t_2 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\ \mathbf{if}\;t_0 \leq -0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(t_2, x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(0.5, \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{x}{\frac{t_1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{t_1}\\ \end{array}, \mathsf{log1p}\left(\left|x\right|\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(1 + \left(-1 - \left(-t_2\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error0.2
Cost39368
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\\ \mathbf{if}\;t_0 \leq -0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(t_1, x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) - \frac{x \cdot x}{\frac{\left|x\right| - -1}{-0.5}}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(1 + \left(-1 - \left(-t_1\right)\right), x\right)\\ \end{array} \]
Alternative 5
Error0.5
Cost39144
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{if}\;t_0 \leq -0.0005000000237487257:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 1.9999999494757503 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error1.3
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(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(\frac{0.5}{x} + x\right)\right), x\right)\\ \end{array} \]
Alternative 7
Error1.2
Cost9992
\[\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.5:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(\frac{0.5}{x} + x\right)\right), x\right)\\ \end{array} \]
Alternative 8
Error1.4
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 0.5:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 9
Error5.6
Cost9732
\[\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(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \end{array} \]
Alternative 10
Error18.9
Cost6628
\[\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(-\log \left(\frac{1}{x}\right), x\right)\\ \end{array} \]
Alternative 11
Error18.9
Cost6596
\[\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(\log x, x\right)\\ \end{array} \]
Alternative 12
Error23.3
Cost6564
\[\begin{array}{l} \mathbf{if}\;x \leq -4.0000000204422544 \cdot 10^{-38}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 13
Error27.7
Cost6464
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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