Average Error: 20.4 → 0.1
Time: 5.8s
Precision: binary32
Cost: 39528
\[\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 -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, 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 -0.20000000298023224)
     (copysign (- (log (- (hypot 1.0 x) x))) x)
     (if (<= t_0 0.019999999552965164)
       (copysign
        (+
         (* -0.16666666666666666 (pow x 3.0))
         (+ (* 0.075 (pow x 5.0)) (+ x (* -0.044642857142857144 (pow x 7.0)))))
        x)
       (copysign (log (+ x (hypot 1.0 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 <= -0.20000000298023224f) {
		tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
	} else if (t_0 <= 0.019999999552965164f) {
		tmp = copysignf(((-0.16666666666666666f * powf(x, 3.0f)) + ((0.075f * powf(x, 5.0f)) + (x + (-0.044642857142857144f * powf(x, 7.0f))))), x);
	} else {
		tmp = copysignf(logf((x + hypotf(1.0f, 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(-0.20000000298023224))
		tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x);
	elseif (t_0 <= Float32(0.019999999552965164))
		tmp = copysign(Float32(Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0))) + Float32(Float32(Float32(0.075) * (x ^ Float32(5.0))) + Float32(x + Float32(Float32(-0.044642857142857144) * (x ^ Float32(7.0)))))), x);
	else
		tmp = copysign(log(Float32(x + hypot(Float32(1.0), 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(-0.20000000298023224))
		tmp = sign(x) * abs(-log((hypot(single(1.0), x) - x)));
	elseif (t_0 <= single(0.019999999552965164))
		tmp = sign(x) * abs(((single(-0.16666666666666666) * (x ^ single(3.0))) + ((single(0.075) * (x ^ single(5.0))) + (x + (single(-0.044642857142857144) * (x ^ single(7.0)))))));
	else
		tmp = sign(x) * abs(log((x + hypot(single(1.0), 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 -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\

\mathbf{elif}\;t_0 \leq 0.019999999552965164:\\
\;\;\;\;\mathsf{copysign}\left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right), x\right)\\

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


\end{array}

Error

Target

Original20.4
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 15.8

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

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
      Proof
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (hypot.f32 1 x))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (Rewrite<= hypot-1-def_binary32 (sqrt.f32 (+.f32 1 (*.f32 x x)))))) x): 64 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 (*.f32 x x) 1))))) x): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr29.1

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

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right)}, x\right) \]
      Proof
      (/.f32 1 (-.f32 (hypot.f32 1 x) x)): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (Rewrite=> sub-neg_binary32 (+.f32 (hypot.f32 1 x) (neg.f32 x)))): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (+.f32 (Rewrite<= remove-double-neg_binary32 (neg.f32 (neg.f32 (hypot.f32 1 x)))) (neg.f32 x))): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (Rewrite<= distribute-neg-in_binary32 (neg.f32 (+.f32 (neg.f32 (hypot.f32 1 x)) x)))): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (neg.f32 (Rewrite<= +-commutative_binary32 (+.f32 x (neg.f32 (hypot.f32 1 x)))))): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (neg.f32 (Rewrite<= sub-neg_binary32 (-.f32 x (hypot.f32 1 x))))): 0 points increase in error, 0 points decrease in error
      (/.f32 1 (Rewrite=> neg-mul-1_binary32 (*.f32 -1 (-.f32 x (hypot.f32 1 x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r*_binary32 (/.f32 (/.f32 1 -1) (-.f32 x (hypot.f32 1 x)))): 0 points increase in error, 0 points decrease in error
      (/.f32 (Rewrite=> metadata-eval -1) (-.f32 x (hypot.f32 1 x))): 0 points increase in error, 0 points decrease in error
      (/.f32 (Rewrite<= metadata-eval (-.f32 0 1)) (-.f32 x (hypot.f32 1 x))): 0 points increase in error, 0 points decrease in error
      (/.f32 (-.f32 (Rewrite<= +-inverses_binary32 (-.f32 (*.f32 x x) (*.f32 x x))) 1) (-.f32 x (hypot.f32 1 x))): 36 points increase in error, 0 points decrease in error
      (/.f32 (Rewrite<= associate--r+_binary32 (-.f32 (*.f32 x x) (+.f32 (*.f32 x x) 1))) (-.f32 x (hypot.f32 1 x))): 0 points increase in error, 29 points decrease in error
      (/.f32 (-.f32 (*.f32 x x) (Rewrite<= +-commutative_binary32 (+.f32 1 (*.f32 x x)))) (-.f32 x (hypot.f32 1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> div-sub_binary32 (-.f32 (/.f32 (*.f32 x x) (-.f32 x (hypot.f32 1 x))) (/.f32 (+.f32 1 (*.f32 x x)) (-.f32 x (hypot.f32 1 x))))): 4 points increase in error, 4 points decrease in error
    5. Applied egg-rr0.3

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right) \]
      Proof
      (neg.f32 (log.f32 (-.f32 (hypot.f32 1 x) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-lft-identity_binary32 (+.f32 0 (neg.f32 (log.f32 (-.f32 (hypot.f32 1 x) x))))): 0 points increase in error, 0 points decrease in error

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

    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
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (hypot.f32 1 x))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (Rewrite<= hypot-1-def_binary32 (sqrt.f32 (+.f32 1 (*.f32 x x)))))) x): 64 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 (*.f32 x x) 1))))) x): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr25.5

      \[\leadsto \mathsf{copysign}\left(\color{blue}{0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
    4. Simplified25.5

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      Proof
      (log.f32 (+.f32 x (hypot.f32 1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-lft-identity_binary32 (+.f32 0 (log.f32 (+.f32 x (hypot.f32 1 x))))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in x around 0 0.0

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(-0.044642857142857144 \cdot {x}^{7} + x\right)\right)}, x\right) \]

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

    1. Initial program 15.0

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

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
      Proof
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (hypot.f32 1 x))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (Rewrite<= hypot-1-def_binary32 (sqrt.f32 (+.f32 1 (*.f32 x x)))))) x): 64 points increase in error, 0 points decrease in error
      (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 (*.f32 x x) 1))))) x): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.3

      \[\leadsto \mathsf{copysign}\left(\color{blue}{0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
    4. Simplified0.3

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      Proof
      (log.f32 (+.f32 x (hypot.f32 1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-lft-identity_binary32 (+.f32 0 (log.f32 (+.f32 x (hypot.f32 1 x))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -0.20000000298023224:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + \left(x + -0.044642857142857144 \cdot {x}^{7}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost35944
\[\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 -0.10000000149011612:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;t_0 \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error0.3
Cost9896
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 - \frac{0.5}{x}}\right), x\right)\\ \mathbf{elif}\;x \leq 0.019999999552965164:\\ \;\;\;\;\mathsf{copysign}\left(-0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right) + \left(x + 0.075 \cdot {x}^{5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost7016
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 - \frac{0.5}{x}}\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(-0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right) + \left(x + 0.075 \cdot {x}^{5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error0.6
Cost6792
\[\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(x + -0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 5
Error0.5
Cost6792
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 - \frac{0.5}{x}}\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(x + \frac{0.5}{x}\right)\right), x\right)\\ \end{array} \]
Alternative 6
Error4.9
Cost6664
\[\begin{array}{l} \mathbf{if}\;x \leq -10:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 7
Error0.7
Cost6664
\[\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(x + -0.16666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 8
Error9.9
Cost6564
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 9
Error12.0
Cost6532
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 10
Error14.5
Cost3264
\[\mathsf{copysign}\left(x, x\right) \]

Error

Reproduce

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