| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 59752 |

(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))
(t_1 (pow (+ x 1.0) 2.0)))
(if (<= t_0 -0.4000000059604645)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= t_0 0.20000000298023224)
(copysign
(fma
(* -0.041666666666666664 (+ (/ 3.0 (+ x 1.0)) (/ 3.0 t_1)))
(pow x 4.0)
(fma
(*
0.001388888888888889
(+
(/ 45.0 t_1)
(+ (/ 45.0 (+ x 1.0)) (/ 30.0 (pow (+ x 1.0) 3.0)))))
(pow x 6.0)
(fma 0.5 (/ (* x x) (+ x 1.0)) (log1p x))))
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 t_1 = powf((x + 1.0f), 2.0f);
float tmp;
if (t_0 <= -0.4000000059604645f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (t_0 <= 0.20000000298023224f) {
tmp = copysignf(fmaf((-0.041666666666666664f * ((3.0f / (x + 1.0f)) + (3.0f / t_1))), powf(x, 4.0f), fmaf((0.001388888888888889f * ((45.0f / t_1) + ((45.0f / (x + 1.0f)) + (30.0f / powf((x + 1.0f), 3.0f))))), powf(x, 6.0f), fmaf(0.5f, ((x * x) / (x + 1.0f)), log1pf(x)))), 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) t_1 = Float32(x + Float32(1.0)) ^ Float32(2.0) tmp = Float32(0.0) if (t_0 <= Float32(-0.4000000059604645)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (t_0 <= Float32(0.20000000298023224)) tmp = copysign(fma(Float32(Float32(-0.041666666666666664) * Float32(Float32(Float32(3.0) / Float32(x + Float32(1.0))) + Float32(Float32(3.0) / t_1))), (x ^ Float32(4.0)), fma(Float32(Float32(0.001388888888888889) * Float32(Float32(Float32(45.0) / t_1) + Float32(Float32(Float32(45.0) / Float32(x + Float32(1.0))) + Float32(Float32(30.0) / (Float32(x + Float32(1.0)) ^ Float32(3.0)))))), (x ^ Float32(6.0)), fma(Float32(0.5), Float32(Float32(x * x) / Float32(x + Float32(1.0))), log1p(x)))), 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}
t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
t_1 := {\left(x + 1\right)}^{2}\\
\mathbf{if}\;t_0 \leq -0.4000000059604645:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;t_0 \leq 0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(-0.041666666666666664 \cdot \left(\frac{3}{x + 1} + \frac{3}{t_1}\right), {x}^{4}, \mathsf{fma}\left(0.001388888888888889 \cdot \left(\frac{45}{t_1} + \left(\frac{45}{x + 1} + \frac{30}{{\left(x + 1\right)}^{3}}\right)\right), {x}^{6}, \mathsf{fma}\left(0.5, \frac{x \cdot x}{x + 1}, \mathsf{log1p}\left(x\right)\right)\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 37.6% |
|---|---|
| Target | 99.5% |
| Herbie | 99.4% |
if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < -0.400000006Initial program 61.6%
Applied egg-rr17.5%
[Start]61.6% | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]61.6% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\sqrt{x \cdot x + 1} + \left|x\right|\right)}, x\right)
\] |
add-sqr-sqrt [=>]-0.0% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right)
\] |
fabs-sqr [=>]-0.0% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right)
\] |
add-sqr-sqrt [<=]16.0% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \color{blue}{x}\right), x\right)
\] |
flip-+ [=>]13.0% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1} - x \cdot x}{\sqrt{x \cdot x + 1} - x}\right)}, x\right)
\] |
log-div [=>]13.1% | \[ \mathsf{copysign}\left(\color{blue}{\log \left(\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1} - x \cdot x\right) - \log \left(\sqrt{x \cdot x + 1} - x\right)}, x\right)
\] |
add-sqr-sqrt [<=]17.5% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(x \cdot x + 1\right)} - x \cdot x\right) - \log \left(\sqrt{x \cdot x + 1} - x\right), x\right)
\] |
fma-def [=>]17.5% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\mathsf{fma}\left(x, x, 1\right)} - x \cdot x\right) - \log \left(\sqrt{x \cdot x + 1} - x\right), x\right)
\] |
+-commutative [=>]17.5% | \[ \mathsf{copysign}\left(\log \left(\mathsf{fma}\left(x, x, 1\right) - x \cdot x\right) - \log \left(\sqrt{\color{blue}{1 + x \cdot x}} - x\right), x\right)
\] |
hypot-1-def [=>]17.5% | \[ \mathsf{copysign}\left(\log \left(\mathsf{fma}\left(x, x, 1\right) - x \cdot x\right) - \log \left(\color{blue}{\mathsf{hypot}\left(1, x\right)} - x\right), x\right)
\] |
Simplified99.9%
[Start]17.5% | \[ \mathsf{copysign}\left(\log \left(\mathsf{fma}\left(x, x, 1\right) - x \cdot x\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
|---|---|
fma-udef [=>]17.4% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(x \cdot x + 1\right)} - x \cdot x\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
+-commutative [<=]17.4% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(1 + x \cdot x\right)} - x \cdot x\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
associate--l+ [=>]59.0% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(1 + \left(x \cdot x - x \cdot x\right)\right)} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
+-inverses [=>]99.9% | \[ \mathsf{copysign}\left(\log \left(1 + \color{blue}{0}\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{copysign}\left(\log \color{blue}{1} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
metadata-eval [=>]99.9% | \[ \mathsf{copysign}\left(\color{blue}{0} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
neg-sub0 [<=]99.9% | \[ \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right)
\] |
if -0.400000006 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < 0.200000003Initial program 22.0%
Taylor expanded in x around 0 22.9%
Simplified99.9%
[Start]22.9% | \[ \mathsf{copysign}\left(-0.041666666666666664 \cdot \left(\left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right) \cdot {x}^{4}\right) + \left(0.001388888888888889 \cdot \left(\left(45 \cdot \frac{1}{1 + \left|x\right|} + \left(30 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{3}} + 45 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) \cdot {x}^{6}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right)\right), x\right)
\] |
|---|---|
associate-*r* [=>]22.9% | \[ \mathsf{copysign}\left(\color{blue}{\left(-0.041666666666666664 \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) \cdot {x}^{4}} + \left(0.001388888888888889 \cdot \left(\left(45 \cdot \frac{1}{1 + \left|x\right|} + \left(30 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{3}} + 45 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) \cdot {x}^{6}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right)\right), x\right)
\] |
fma-def [=>]22.9% | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left(-0.041666666666666664 \cdot \left(3 \cdot \frac{1}{1 + \left|x\right|} + 3 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right), {x}^{4}, 0.001388888888888889 \cdot \left(\left(45 \cdot \frac{1}{1 + \left|x\right|} + \left(30 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{3}} + 45 \cdot \frac{1}{{\left(1 + \left|x\right|\right)}^{2}}\right)\right) \cdot {x}^{6}\right) + \left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)\right)\right)}, x\right)
\] |
if 0.200000003 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) Initial program 56.7%
Applied egg-rr98.4%
[Start]56.7% | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
*-un-lft-identity [=>]56.7% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(1 \cdot \left(\left|x\right| + \sqrt{x \cdot x + 1}\right)\right)}, x\right)
\] |
*-commutative [=>]56.7% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\left(\left|x\right| + \sqrt{x \cdot x + 1}\right) \cdot 1\right)}, x\right)
\] |
log-prod [=>]56.7% | \[ \mathsf{copysign}\left(\color{blue}{\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right) + \log 1}, x\right)
\] |
add-sqr-sqrt [=>]56.7% | \[ \mathsf{copysign}\left(\log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \sqrt{x \cdot x + 1}\right) + \log 1, x\right)
\] |
fabs-sqr [=>]56.7% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \sqrt{x \cdot x + 1}\right) + \log 1, x\right)
\] |
add-sqr-sqrt [<=]56.7% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{x} + \sqrt{x \cdot x + 1}\right) + \log 1, x\right)
\] |
+-commutative [=>]56.7% | \[ \mathsf{copysign}\left(\log \left(x + \sqrt{\color{blue}{1 + x \cdot x}}\right) + \log 1, x\right)
\] |
hypot-1-def [=>]98.4% | \[ \mathsf{copysign}\left(\log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) + \log 1, x\right)
\] |
metadata-eval [=>]98.4% | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + \color{blue}{0}, x\right)
\] |
Simplified98.4%
[Start]98.4% | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + 0, x\right)
\] |
|---|---|
+-rgt-identity [=>]98.4% | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 59752 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 46216 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 39208 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 10056 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 10024 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 9896 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 9896 |
| Alternative 8 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 9796 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 6888 |
| Alternative 10 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 6792 |
| Alternative 11 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 6792 |
| Alternative 12 | |
|---|---|
| Accuracy | 83.4% |
| Cost | 6664 |
| Alternative 13 | |
|---|---|
| Accuracy | 75.4% |
| Cost | 6596 |
| Alternative 14 | |
|---|---|
| Accuracy | 62.4% |
| Cost | 6532 |
| Alternative 15 | |
|---|---|
| Accuracy | 54.2% |
| Cost | 3392 |
herbie shell --seed 2023263
(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))