| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 22916 |
(FPCore (x) :precision binary32 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
:precision binary32
(if (<= x -4.0)
(copysign (* (log (sqrt (/ -0.5 x))) 2.0) 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 <= -4.0f) {
tmp = copysignf((logf(sqrtf((-0.5f / x))) * 2.0f), 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(-4.0)) tmp = copysign(Float32(log(sqrt(Float32(Float32(-0.5) / x))) * Float32(2.0)), 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 -4:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\sqrt{\frac{-0.5}{x}}\right) \cdot 2, 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}
| Original | 20.4 |
|---|---|
| Target | 0.1 |
| Herbie | 0.4 |
if x < -4Initial program 16.6
Simplified0.1
[Start]16.6 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]16.6 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]0.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Taylor expanded in x around -inf 0.2
Simplified0.4
[Start]0.2 | \[ \mathsf{copysign}\left(\log \left(\left(\left|x\right| + -1 \cdot x\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
|---|---|
rem-square-sqrt [<=]32.0 | \[ \mathsf{copysign}\left(\log \left(\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + -1 \cdot x\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
fabs-sqr [=>]32.0 | \[ \mathsf{copysign}\left(\log \left(\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + -1 \cdot x\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
rem-square-sqrt [=>]0.4 | \[ \mathsf{copysign}\left(\log \left(\left(\color{blue}{x} + -1 \cdot x\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
mul-1-neg [=>]0.4 | \[ \mathsf{copysign}\left(\log \left(\left(x + \color{blue}{\left(-x\right)}\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
sub-neg [<=]0.4 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(x - x\right)} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
+-inverses [=>]0.4 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{0} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
neg-sub0 [<=]0.4 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(-0.5 \cdot \frac{1}{x}\right)}, x\right)
\] |
distribute-lft-neg-in [=>]0.4 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\left(-0.5\right) \cdot \frac{1}{x}\right)}, x\right)
\] |
associate-*r/ [=>]0.4 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left(-0.5\right) \cdot 1}{x}\right)}, x\right)
\] |
metadata-eval [=>]0.4 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5} \cdot 1}{x}\right), x\right)
\] |
metadata-eval [=>]0.4 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5}}{x}\right), x\right)
\] |
Applied egg-rr0.4
Simplified0.4
[Start]0.4 | \[ \mathsf{copysign}\left(\log \left(\sqrt{\frac{-0.5}{x}}\right) + \log \left(\sqrt{\frac{-0.5}{x}}\right), x\right)
\] |
|---|---|
count-2 [=>]0.4 | \[ \mathsf{copysign}\left(\color{blue}{2 \cdot \log \left(\sqrt{\frac{-0.5}{x}}\right)}, x\right)
\] |
*-commutative [=>]0.4 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(\sqrt{\frac{-0.5}{x}}\right) \cdot 2}, x\right)
\] |
if -4 < x < 0.0500000007Initial program 25.0
Applied egg-rr0.9
Applied egg-rr0.0
Simplified0.0
[Start]0.0 | \[ \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/ [=>]0.0 | \[ \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 [=>]0.0 | \[ \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 [=>]0.0 | \[ \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 0.4
Simplified0.4
[Start]0.4 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + 0.5 \cdot {x}^{2}}\right), x\right)
\] |
|---|---|
unpow2 [=>]0.4 | \[ \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 Initial program 15.4
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + 0, x\right)
\] |
|---|---|
+-rgt-identity [=>]0.3 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 22916 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 9896 |
| Alternative 3 | |
|---|---|
| Error | 0.6 |
| Cost | 6984 |
| Alternative 4 | |
|---|---|
| Error | 0.6 |
| Cost | 6792 |
| Alternative 5 | |
|---|---|
| Error | 0.7 |
| Cost | 6760 |
| Alternative 6 | |
|---|---|
| Error | 5.3 |
| Cost | 6664 |
| Alternative 7 | |
|---|---|
| Error | 1.0 |
| Cost | 6664 |
| Alternative 8 | |
|---|---|
| Error | 10.1 |
| Cost | 6564 |
| Alternative 9 | |
|---|---|
| Error | 12.2 |
| Cost | 6532 |
| Alternative 10 | |
|---|---|
| Error | 14.8 |
| Cost | 3264 |
herbie shell --seed 2023018
(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))