| Alternative 1 | |
|---|---|
| Error | 98.0% |
| Cost | 22916.00 |
(FPCore (x) :precision binary32 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
:precision binary32
(if (<= x -5.0)
(copysign (log (/ 1.0 (+ (* x -2.0) (/ -0.5 x)))) x)
(if (<= x 0.004999999888241291)
(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 <= -5.0f) {
tmp = copysignf(logf((1.0f / ((x * -2.0f) + (-0.5f / x)))), x);
} else if (x <= 0.004999999888241291f) {
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(-5.0)) tmp = copysign(log(Float32(Float32(1.0) / Float32(Float32(x * Float32(-2.0)) + Float32(Float32(-0.5) / x)))), x); elseif (x <= Float32(0.004999999888241291)) 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 -5:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 + \frac{-0.5}{x}}\right), x\right)\\
\mathbf{elif}\;x \leq 0.004999999888241291:\\
\;\;\;\;\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}
| Original | 36.5% |
|---|---|
| Target | 99.4% |
| Herbie | 98.6% |
if x < -5Initial program 49.2
Applied egg-rr98.9
Simplified98.9
[Start]98.9 | \[ \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 [=>]98.9 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{1}{x - \mathsf{hypot}\left(1, x\right)} \cdot \left(x \cdot \left(x - x\right) - 1\right)\right)}, x\right)
\] |
associate-*l/ [=>]98.9 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{1 \cdot \left(x \cdot \left(x - x\right) - 1\right)}{x - \mathsf{hypot}\left(1, x\right)}\right)}, x\right)
\] |
*-lft-identity [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{x \cdot \left(x - x\right) - 1}}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
+-inverses [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{x \cdot \color{blue}{0} - 1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
mul0-rgt [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{0} - 1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
metadata-eval [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-1}}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
metadata-eval [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{\frac{1}{-1}}}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
associate-/r* [<=]98.9 | \[ \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 [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{-\left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
neg-sub0 [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
associate--r- [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\left(0 - x\right) + \mathsf{hypot}\left(1, x\right)}}\right), x\right)
\] |
neg-sub0 [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\left(-x\right)} + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
mul-1-neg [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{-1 \cdot x} + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
+-commutative [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right) + -1 \cdot x}}\right), x\right)
\] |
mul-1-neg [=>]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) + \color{blue}{\left(-x\right)}}\right), x\right)
\] |
sub-neg [<=]98.9 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right) - x}}\right), x\right)
\] |
Taylor expanded in x around -inf 98.6
Simplified98.6
[Start]98.6 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{-2 \cdot x - 0.5 \cdot \frac{1}{x}}\right), x\right)
\] |
|---|---|
*-commutative [=>]98.6 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{x \cdot -2} - 0.5 \cdot \frac{1}{x}}\right), x\right)
\] |
associate-*r/ [=>]98.6 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 - \color{blue}{\frac{0.5 \cdot 1}{x}}}\right), x\right)
\] |
metadata-eval [=>]98.6 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 - \frac{\color{blue}{0.5}}{x}}\right), x\right)
\] |
if -5 < x < 0.00499999989Initial program 21.1
Applied egg-rr97.2
Applied egg-rr99.9
Simplified99.9
[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)
\] |
Taylor expanded in x around 0 98.7
Simplified98.7
[Start]98.7 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + 0.5 \cdot {x}^{2}}\right), x\right)
\] |
|---|---|
unpow2 [=>]98.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.00499999989 < x Initial program 51.7
Applied egg-rr98.6
Simplified98.6
[Start]98.6 | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + 0, x\right)
\] |
|---|---|
+-rgt-identity [=>]98.6 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification98.6
| Alternative 1 | |
|---|---|
| Error | 98.0% |
| Cost | 22916.00 |
| Alternative 2 | |
|---|---|
| Error | 97.0% |
| Cost | 9860.00 |
| Alternative 3 | |
|---|---|
| Error | 98.2% |
| Cost | 6984.00 |
| Alternative 4 | |
|---|---|
| Error | 98.1% |
| Cost | 6788.00 |
| Alternative 5 | |
|---|---|
| Error | 97.7% |
| Cost | 6760.00 |
| Alternative 6 | |
|---|---|
| Error | 83.5% |
| Cost | 6664.00 |
| Alternative 7 | |
|---|---|
| Error | 97.1% |
| Cost | 6664.00 |
| Alternative 8 | |
|---|---|
| Error | 97.3% |
| Cost | 6664.00 |
| Alternative 9 | |
|---|---|
| Error | 97.1% |
| Cost | 6664.00 |
| Alternative 10 | |
|---|---|
| Error | 68.1% |
| Cost | 6564.00 |
| Alternative 11 | |
|---|---|
| Error | 61.7% |
| Cost | 6532.00 |
| Alternative 12 | |
|---|---|
| Error | 53.3% |
| Cost | 3264.00 |
herbie shell --seed 2023093
(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))