?

Average Accuracy: 36.8% → 99.4%
Time: 9.9s
Precision: binary32
Cost: 9896

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\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
 (if (<= x -0.5)
   (copysign (log (/ 1.0 (- (hypot 1.0 x) x))) x)
   (if (<= x 0.05000000074505806)
     (copysign (log1p (+ x (/ (* x x) (+ 2.0 (* (* x x) 0.5))))) 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 tmp;
	if (x <= -0.5f) {
		tmp = copysignf(logf((1.0f / (hypotf(1.0f, x) - x))), x);
	} else if (x <= 0.05000000074505806f) {
		tmp = copysignf(log1pf((x + ((x * x) / (2.0f + ((x * x) * 0.5f))))), 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)
	tmp = Float32(0.0)
	if (x <= Float32(-0.5))
		tmp = copysign(log(Float32(Float32(1.0) / Float32(hypot(Float32(1.0), x) - x))), x);
	elseif (x <= Float32(0.05000000074505806))
		tmp = copysign(log1p(Float32(x + Float32(Float32(x * x) / Float32(Float32(2.0) + Float32(Float32(x * x) * Float32(0.5)))))), x);
	else
		tmp = copysign(log(Float32(x + hypot(Float32(1.0), x))), x);
	end
	return tmp
end
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\begin{array}{l}
\mathbf{if}\;x \leq -0.5:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\

\mathbf{elif}\;x \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\right), x\right)\\

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


\end{array}

Error?

Target

Original36.8%
Target99.6%
Herbie99.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 x < -0.5

    1. Initial program 51.8%

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

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

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

      [Start]99.4

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

      *-commutative [=>]99.4

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

      +-inverses [=>]99.4

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

      mul0-lft [=>]99.4

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

      metadata-eval [=>]99.4

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

      associate-*r/ [=>]99.4

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

      metadata-eval [=>]99.4

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

      metadata-eval [<=]99.4

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

      associate-/r* [<=]99.4

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

      neg-mul-1 [<=]99.4

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

      neg-sub0 [=>]99.4

      \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right) \]

      associate--r- [=>]99.4

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

      neg-sub0 [<=]99.4

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

      mul-1-neg [<=]99.4

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

      +-commutative [<=]99.4

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

      mul-1-neg [=>]99.4

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

      sub-neg [<=]99.4

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

    if -0.5 < x < 0.0500000007

    1. Initial program 20.8%

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) - 1\right)\right)}, x\right) \]
    3. Applied egg-rr99.9%

      \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(x + \color{blue}{\left(x \cdot x + 0\right) \cdot \frac{1}{1 + \mathsf{hypot}\left(1, x\right)}}\right), x\right) \]
    4. Simplified99.9%

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

      [Start]99.9

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(x \cdot x + 0\right) \cdot \frac{1}{1 + \mathsf{hypot}\left(1, x\right)}\right), x\right) \]

      associate-*r/ [=>]99.9

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \color{blue}{\frac{\left(x \cdot x + 0\right) \cdot 1}{1 + \mathsf{hypot}\left(1, x\right)}}\right), x\right) \]

      +-rgt-identity [=>]99.9

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{\color{blue}{\left(x \cdot x\right)} \cdot 1}{1 + \mathsf{hypot}\left(1, x\right)}\right), x\right) \]

      *-rgt-identity [=>]99.9

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{\color{blue}{x \cdot x}}{1 + \mathsf{hypot}\left(1, x\right)}\right), x\right) \]
    5. Taylor expanded in x around 0 99.7%

      \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{\color{blue}{2 + 0.5 \cdot {x}^{2}}}\right), x\right) \]
    6. Simplified99.7%

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

      [Start]99.7

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + 0.5 \cdot {x}^{2}}\right), x\right) \]

      unpow2 [=>]99.7

      \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + 0.5 \cdot \color{blue}{\left(x \cdot x\right)}}\right), x\right) \]

    if 0.0500000007 < x

    1. Initial program 52.7%

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

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

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

      [Start]99.0

      \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + 0, x\right) \]

      +-rgt-identity [=>]99.0

      \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\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
Accuracy98.1%
Cost22916
\[\begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right), x\right)\\ \end{array} \]
Alternative 2
Accuracy98.9%
Cost9896
\[\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.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.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
Accuracy99.5%
Cost9896
\[\begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\ \mathbf{elif}\;x \leq 0.05000000074505806:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
Alternative 4
Accuracy98.4%
Cost7048
\[\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(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(1 + x \cdot \frac{x}{x + \left(1 + \frac{0.5}{x}\right)}\right)\right), x\right)\\ \end{array} \]
Alternative 5
Accuracy98.4%
Cost6984
\[\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(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\ \end{array} \]
Alternative 6
Accuracy98.2%
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 {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\ \end{array} \]
Alternative 7
Accuracy97.8%
Cost6760
\[\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 {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 8
Accuracy83.6%
Cost6664
\[\begin{array}{l} \mathbf{if}\;x \leq -4:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 9
Accuracy97.1%
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, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 10
Accuracy68.8%
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 11
Accuracy62.5%
Cost6532
\[\begin{array}{l} \mathbf{if}\;x \leq 1.600000023841858:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 12
Accuracy54.5%
Cost3264
\[\mathsf{copysign}\left(x, x\right) \]

Error

Reproduce?

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