| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 23044 |
(FPCore (x) :precision binary32 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x) :precision binary32 (if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) -4.5) (copysign (log (/ -0.5 x)) x) (copysign (log1p (fma x (/ x (+ 1.0 (hypot 1.0 x))) x)) x)))
float code(float x) {
return copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x);
}
float code(float x) {
float tmp;
if (copysignf(logf((fabsf(x) + sqrtf(((x * x) + 1.0f)))), x) <= -4.5f) {
tmp = copysignf(logf((-0.5f / x)), x);
} else {
tmp = copysignf(log1pf(fmaf(x, (x / (1.0f + hypotf(1.0f, x))), 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 (copysign(log(Float32(abs(x) + sqrt(Float32(Float32(x * x) + Float32(1.0))))), x) <= Float32(-4.5)) tmp = copysign(log(Float32(Float32(-0.5) / x)), x); else tmp = copysign(log1p(fma(x, Float32(x / Float32(Float32(1.0) + hypot(Float32(1.0), x))), 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}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -4.5:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\mathsf{fma}\left(x, \frac{x}{1 + \mathsf{hypot}\left(1, x\right)}, x\right)\right), x\right)\\
\end{array}
| Original | 20.4 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < -4.5Initial program 16.7
Simplified0.2
[Start]16.7 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]16.7 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]0.2 | \[ \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.1
[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.1 | \[ \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.1 | \[ \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.1 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(x - x\right)} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
+-inverses [=>]0.1 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{0} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
neg-sub0 [<=]0.1 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(-0.5 \cdot \frac{1}{x}\right)}, x\right)
\] |
distribute-lft-neg-in [=>]0.1 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\left(-0.5\right) \cdot \frac{1}{x}\right)}, x\right)
\] |
associate-*r/ [=>]0.1 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left(-0.5\right) \cdot 1}{x}\right)}, x\right)
\] |
metadata-eval [=>]0.1 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5} \cdot 1}{x}\right), x\right)
\] |
metadata-eval [=>]0.1 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5}}{x}\right), x\right)
\] |
if -4.5 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) Initial program 21.5
Applied egg-rr0.7
Applied egg-rr5.3
Simplified5.3
[Start]5.3 | \[ \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/ [=>]5.3 | \[ \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 [=>]5.3 | \[ \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 [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{\color{blue}{x \cdot x}}{1 + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr16.3
Simplified0.1
[Start]16.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(\frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}} + \left(x + 1\right)\right) - 1\right), x\right)
\] |
|---|---|
associate--l+ [=>]16.1 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{\frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}} + \left(\left(x + 1\right) - 1\right)}\right), x\right)
\] |
+-commutative [=>]16.1 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{\left(\left(x + 1\right) - 1\right) + \frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}}}\right), x\right)
\] |
associate--l+ [=>]0.1 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{\left(x + \left(1 - 1\right)\right)} + \frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}}\right), x\right)
\] |
metadata-eval [=>]0.1 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + \color{blue}{0}\right) + \frac{x}{\frac{1 + \mathsf{hypot}\left(1, x\right)}{x}}\right), x\right)
\] |
associate-/l* [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \color{blue}{\frac{x \cdot x}{1 + \mathsf{hypot}\left(1, x\right)}}\right), x\right)
\] |
metadata-eval [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{\left(2 + -1\right)} + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
associate-+r+ [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{2 + \left(-1 + \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
metadata-eval [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \left(\color{blue}{\left(0 - 1\right)} + \mathsf{hypot}\left(1, x\right)\right)}\right), x\right)
\] |
associate--r- [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \color{blue}{\left(0 - \left(1 - \mathsf{hypot}\left(1, x\right)\right)\right)}}\right), x\right)
\] |
neg-sub0 [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \color{blue}{\left(-\left(1 - \mathsf{hypot}\left(1, x\right)\right)\right)}}\right), x\right)
\] |
neg-mul-1 [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \color{blue}{-1 \cdot \left(1 - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
sub-neg [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + -1 \cdot \color{blue}{\left(1 + \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}}\right), x\right)
\] |
distribute-lft-in [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \color{blue}{\left(-1 \cdot 1 + -1 \cdot \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}}\right), x\right)
\] |
metadata-eval [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{2 + \left(\color{blue}{-1} + -1 \cdot \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}\right), x\right)
\] |
associate-+r+ [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{\left(2 + -1\right) + -1 \cdot \left(-\mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
metadata-eval [=>]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{1} + -1 \cdot \left(-\mathsf{hypot}\left(1, x\right)\right)}\right), x\right)
\] |
metadata-eval [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{-1 \cdot -1} + -1 \cdot \left(-\mathsf{hypot}\left(1, x\right)\right)}\right), x\right)
\] |
distribute-lft-in [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{-1 \cdot \left(-1 + \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}}\right), x\right)
\] |
metadata-eval [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{\frac{1}{-1}} \cdot \left(-1 + \left(-\mathsf{hypot}\left(1, x\right)\right)\right)}\right), x\right)
\] |
sub-neg [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\frac{1}{-1} \cdot \color{blue}{\left(-1 - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
associate-/r/ [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \frac{x \cdot x}{\color{blue}{\frac{1}{\frac{-1}{-1 - \mathsf{hypot}\left(1, x\right)}}}}\right), x\right)
\] |
associate-/l* [<=]5.3 | \[ \mathsf{copysign}\left(\mathsf{log1p}\left(\left(x + 0\right) + \color{blue}{\frac{\left(x \cdot x\right) \cdot \frac{-1}{-1 - \mathsf{hypot}\left(1, x\right)}}{1}}\right), x\right)
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 23044 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 10020 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 9896 |
| Alternative 4 | |
|---|---|
| Error | 0.2 |
| Cost | 9896 |
| Alternative 5 | |
|---|---|
| Error | 0.6 |
| Cost | 9892 |
| Alternative 6 | |
|---|---|
| Error | 0.5 |
| Cost | 6984 |
| Alternative 7 | |
|---|---|
| Error | 0.5 |
| Cost | 6792 |
| Alternative 8 | |
|---|---|
| Error | 0.6 |
| Cost | 6760 |
| Alternative 9 | |
|---|---|
| Error | 5.2 |
| Cost | 6664 |
| Alternative 10 | |
|---|---|
| Error | 0.9 |
| Cost | 6664 |
| Alternative 11 | |
|---|---|
| Error | 10.0 |
| Cost | 6564 |
| Alternative 12 | |
|---|---|
| Error | 12.1 |
| Cost | 6532 |
| Alternative 13 | |
|---|---|
| Error | 14.8 |
| Cost | 3264 |
herbie shell --seed 2023066
(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))