| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 36168 |
(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)))
(if (<= t_0 -0.20000000298023224)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= t_0 0.10000000149011612)
(copysign
(fma
(fma 0.075 (pow x 5.0) (* -0.16666666666666666 (pow x 3.0)))
1.0
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 tmp;
if (t_0 <= -0.20000000298023224f) {
tmp = copysignf(-logf((hypotf(1.0f, x) - x)), x);
} else if (t_0 <= 0.10000000149011612f) {
tmp = copysignf(fmaf(fmaf(0.075f, powf(x, 5.0f), (-0.16666666666666666f * powf(x, 3.0f))), 1.0f, 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) tmp = Float32(0.0) if (t_0 <= Float32(-0.20000000298023224)) tmp = copysign(Float32(-log(Float32(hypot(Float32(1.0), x) - x))), x); elseif (t_0 <= Float32(0.10000000149011612)) tmp = copysign(fma(fma(Float32(0.075), (x ^ Float32(5.0)), Float32(Float32(-0.16666666666666666) * (x ^ Float32(3.0)))), Float32(1.0), 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)\\
\mathbf{if}\;t_0 \leq -0.20000000298023224:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;t_0 \leq 0.10000000149011612:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.075, {x}^{5}, -0.16666666666666666 \cdot {x}^{3}\right), 1, x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
| Original | 36.1% |
|---|---|
| Target | 99.6% |
| Herbie | 99.6% |
if (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < -0.200000003Initial program 52.7%
Applied egg-rr12.6%
[Start]52.7 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
flip-+ [=>]10.0 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left|x\right| \cdot \left|x\right| - \sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}{\left|x\right| - \sqrt{x \cdot x + 1}}\right)}, x\right)
\] |
frac-2neg [=>]10.0 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{-\left(\left|x\right| \cdot \left|x\right| - \sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}\right)}{-\left(\left|x\right| - \sqrt{x \cdot x + 1}\right)}\right)}, x\right)
\] |
log-div [=>]10.0 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(-\left(\left|x\right| \cdot \left|x\right| - \sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}\right)\right) - \log \left(-\left(\left|x\right| - \sqrt{x \cdot x + 1}\right)\right)}, x\right)
\] |
sqr-abs [=>]10.0 | \[ \mathsf{copysign}\left(\log \left(-\left(\color{blue}{x \cdot x} - \sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}\right)\right) - \log \left(-\left(\left|x\right| - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
add-sqr-sqrt [<=]9.7 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \color{blue}{\left(x \cdot x + 1\right)}\right)\right) - \log \left(-\left(\left|x\right| - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
fma-def [=>]9.7 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \color{blue}{\mathsf{fma}\left(x, x, 1\right)}\right)\right) - \log \left(-\left(\left|x\right| - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
add-sqr-sqrt [=>]-0.0 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right) - \log \left(-\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
fabs-sqr [=>]-0.0 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right) - \log \left(-\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
add-sqr-sqrt [<=]12.6 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right) - \log \left(-\left(\color{blue}{x} - \sqrt{x \cdot x + 1}\right)\right), x\right)
\] |
+-commutative [=>]12.6 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right) - \log \left(-\left(x - \sqrt{\color{blue}{1 + x \cdot x}}\right)\right), x\right)
\] |
Simplified99.1%
[Start]12.6 | \[ \mathsf{copysign}\left(\log \left(-\left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
|---|---|
neg-mul-1 [=>]12.6 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(-1 \cdot \left(x \cdot x - \mathsf{fma}\left(x, x, 1\right)\right)\right)} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
fma-udef [=>]12.6 | \[ \mathsf{copysign}\left(\log \left(-1 \cdot \left(x \cdot x - \color{blue}{\left(x \cdot x + 1\right)}\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
associate--r+ [=>]52.7 | \[ \mathsf{copysign}\left(\log \left(-1 \cdot \color{blue}{\left(\left(x \cdot x - x \cdot x\right) - 1\right)}\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
+-inverses [=>]99.1 | \[ \mathsf{copysign}\left(\log \left(-1 \cdot \left(\color{blue}{0} - 1\right)\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
metadata-eval [=>]99.1 | \[ \mathsf{copysign}\left(\log \left(-1 \cdot \color{blue}{-1}\right) - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
metadata-eval [=>]99.1 | \[ \mathsf{copysign}\left(\log \color{blue}{1} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
metadata-eval [=>]99.1 | \[ \mathsf{copysign}\left(\color{blue}{0} - \log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right), x\right)
\] |
neg-sub0 [<=]99.1 | \[ \mathsf{copysign}\left(\color{blue}{-\log \left(-\left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right)
\] |
neg-sub0 [=>]99.1 | \[ \mathsf{copysign}\left(-\log \color{blue}{\left(0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right)
\] |
associate--r- [=>]99.1 | \[ \mathsf{copysign}\left(-\log \color{blue}{\left(\left(0 - x\right) + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
neg-sub0 [<=]99.1 | \[ \mathsf{copysign}\left(-\log \left(\color{blue}{\left(-x\right)} + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
+-commutative [<=]99.1 | \[ \mathsf{copysign}\left(-\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left(-x\right)\right)}, x\right)
\] |
sub-neg [<=]99.1 | \[ \mathsf{copysign}\left(-\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right)
\] |
if -0.200000003 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) < 0.100000001Initial program 20.3%
Simplified20.4%
[Start]20.3 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]20.3 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]20.4 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr20.6%
[Start]20.4 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
expm1-log1p-u [=>]20.4 | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)\right)}, x\right)
\] |
expm1-udef [=>]20.3 | \[ \mathsf{copysign}\left(\color{blue}{e^{\mathsf{log1p}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1}, x\right)
\] |
log1p-udef [=>]20.3 | \[ \mathsf{copysign}\left(e^{\color{blue}{\log \left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}} - 1, x\right)
\] |
add-exp-log [<=]20.3 | \[ \mathsf{copysign}\left(\color{blue}{\left(1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)} - 1, x\right)
\] |
*-un-lft-identity [=>]20.3 | \[ \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(1 \cdot \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}\right) - 1, x\right)
\] |
*-un-lft-identity [<=]20.3 | \[ \mathsf{copysign}\left(\left(1 + \log \color{blue}{\left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)}\right) - 1, x\right)
\] |
add-sqr-sqrt [=>]10.2 | \[ \mathsf{copysign}\left(\left(1 + \log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right)
\] |
fabs-sqr [=>]10.2 | \[ \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right)
\] |
add-sqr-sqrt [<=]20.6 | \[ \mathsf{copysign}\left(\left(1 + \log \left(\color{blue}{x} + \mathsf{hypot}\left(1, x\right)\right)\right) - 1, x\right)
\] |
Taylor expanded in x around 0 99.9%
Applied egg-rr100.0%
[Start]99.9 | \[ \mathsf{copysign}\left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + x\right), x\right)
\] |
|---|---|
*-un-lft-identity [=>]99.9 | \[ \mathsf{copysign}\left(\color{blue}{1 \cdot \left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + x\right)\right)}, x\right)
\] |
associate-+r+ [=>]100.0 | \[ \mathsf{copysign}\left(1 \cdot \color{blue}{\left(\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right) + x\right)}, x\right)
\] |
distribute-rgt-in [=>]100.0 | \[ \mathsf{copysign}\left(\color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right) \cdot 1 + x \cdot 1}, x\right)
\] |
*-commutative [<=]100.0 | \[ \mathsf{copysign}\left(\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right) \cdot 1 + \color{blue}{1 \cdot x}, x\right)
\] |
*-un-lft-identity [<=]100.0 | \[ \mathsf{copysign}\left(\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right) \cdot 1 + \color{blue}{x}, x\right)
\] |
fma-def [=>]100.0 | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}, 1, x\right)}, x\right)
\] |
+-commutative [=>]100.0 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(\color{blue}{0.075 \cdot {x}^{5} + -0.16666666666666666 \cdot {x}^{3}}, 1, x\right), x\right)
\] |
fma-def [=>]100.0 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(0.075, {x}^{5}, -0.16666666666666666 \cdot {x}^{3}\right)}, 1, x\right), x\right)
\] |
if 0.100000001 < (copysign.f32 (log.f32 (+.f32 (fabs.f32 x) (sqrt.f32 (+.f32 (*.f32 x x) 1)))) x) Initial program 49.3%
Applied egg-rr99.3%
[Start]49.3 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
*-un-lft-identity [=>]49.3 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(1 \cdot \left(\left|x\right| + \sqrt{x \cdot x + 1}\right)\right)}, x\right)
\] |
*-commutative [=>]49.3 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\left(\left|x\right| + \sqrt{x \cdot x + 1}\right) \cdot 1\right)}, x\right)
\] |
log-prod [=>]49.3 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right) + \log 1}, x\right)
\] |
add-sqr-sqrt [=>]49.3 | \[ \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 [=>]49.3 | \[ \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 [<=]49.3 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{x} + \sqrt{x \cdot x + 1}\right) + \log 1, x\right)
\] |
+-commutative [=>]49.3 | \[ \mathsf{copysign}\left(\log \left(x + \sqrt{\color{blue}{1 + x \cdot x}}\right) + \log 1, x\right)
\] |
hypot-1-def [=>]99.3 | \[ \mathsf{copysign}\left(\log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) + \log 1, x\right)
\] |
metadata-eval [=>]99.3 | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + \color{blue}{0}, x\right)
\] |
Simplified99.3%
[Start]99.3 | \[ \mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + 0, x\right)
\] |
|---|---|
+-rgt-identity [=>]99.3 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 36168 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 9992 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 9896 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 9896 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 6792 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 6792 |
| Alternative 7 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 6760 |
| Alternative 8 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 6664 |
| Alternative 9 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 6664 |
| Alternative 10 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 6664 |
| Alternative 11 | |
|---|---|
| Accuracy | 68.8% |
| Cost | 6564 |
| Alternative 12 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 6532 |
| Alternative 13 | |
|---|---|
| Accuracy | 54.1% |
| Cost | 3264 |
herbie shell --seed 2023151
(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))