| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 71880 |
(FPCore (x) :precision binary64 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
:precision binary64
(let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
(if (<= t_0 -10.0)
(copysign (log (/ 1.0 (+ (* x -2.0) (/ -0.5 x)))) x)
(if (<= t_0 1e-8)
(copysign
(+
(fma -0.16666666666666666 (pow x 3.0) (* 0.075 (pow x 5.0)))
(expm1 (log1p x)))
x)
(copysign (log (+ x (hypot 1.0 x))) x)))))double code(double x) {
return copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
}
double code(double x) {
double t_0 = copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
double tmp;
if (t_0 <= -10.0) {
tmp = copysign(log((1.0 / ((x * -2.0) + (-0.5 / x)))), x);
} else if (t_0 <= 1e-8) {
tmp = copysign((fma(-0.16666666666666666, pow(x, 3.0), (0.075 * pow(x, 5.0))) + expm1(log1p(x))), x);
} else {
tmp = copysign(log((x + hypot(1.0, x))), x);
}
return tmp;
}
function code(x) return copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) end
function code(x) t_0 = copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) tmp = 0.0 if (t_0 <= -10.0) tmp = copysign(log(Float64(1.0 / Float64(Float64(x * -2.0) + Float64(-0.5 / x)))), x); elseif (t_0 <= 1e-8) tmp = copysign(Float64(fma(-0.16666666666666666, (x ^ 3.0), Float64(0.075 * (x ^ 5.0))) + expm1(log1p(x))), x); else tmp = copysign(log(Float64(x + hypot(1.0, x))), x); end return tmp end
code[x_] := N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]}, If[LessEqual[t$95$0, -10.0], N[With[{TMP1 = Abs[N[Log[N[(1.0 / N[(N[(x * -2.0), $MachinePrecision] + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 1e-8], N[With[{TMP1 = Abs[N[(N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision] + N[(0.075 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(Exp[N[Log[1 + x], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]]]
\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 -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 + \frac{-0.5}{x}}\right), x\right)\\
\mathbf{elif}\;t_0 \leq 10^{-8}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right) + \mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
| Original | 30.1% |
|---|---|
| Target | 99.9% |
| Herbie | 99.5% |
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -10Initial program 50.7%
Simplified99.8%
[Start]50.7 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]50.7 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]99.8 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr1.3%
[Start]99.8 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
+-commutative [=>]99.8 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\mathsf{hypot}\left(1, x\right) + \left|x\right|\right)}, x\right)
\] |
flip-+ [=>]0.6 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right) - \left|x\right| \cdot \left|x\right|}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right)}, x\right)
\] |
hypot-udef [=>]0.6 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{\sqrt{1 \cdot 1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right) - \left|x\right| \cdot \left|x\right|}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right), x\right)
\] |
hypot-udef [=>]0.6 | \[ \mathsf{copysign}\left(\log \left(\frac{\sqrt{1 \cdot 1 + x \cdot x} \cdot \color{blue}{\sqrt{1 \cdot 1 + x \cdot x}} - \left|x\right| \cdot \left|x\right|}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right), x\right)
\] |
add-sqr-sqrt [<=]0.6 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{\left(1 \cdot 1 + x \cdot x\right)} - \left|x\right| \cdot \left|x\right|}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right), x\right)
\] |
metadata-eval [=>]0.6 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(\color{blue}{1} + x \cdot x\right) - \left|x\right| \cdot \left|x\right|}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right), x\right)
\] |
sqr-abs [=>]0.6 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - \color{blue}{x \cdot x}}{\mathsf{hypot}\left(1, x\right) - \left|x\right|}\right), x\right)
\] |
add-sqr-sqrt [=>]0.0 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{\mathsf{hypot}\left(1, x\right) - \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}\right), x\right)
\] |
fabs-sqr [=>]0.0 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{\mathsf{hypot}\left(1, x\right) - \color{blue}{\sqrt{x} \cdot \sqrt{x}}}\right), x\right)
\] |
add-sqr-sqrt [<=]1.3 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{\mathsf{hypot}\left(1, x\right) - \color{blue}{x}}\right), x\right)
\] |
Taylor expanded in x around -inf 1.3%
Simplified1.3%
[Start]1.3 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{-2 \cdot x - 0.5 \cdot \frac{1}{x}}\right), x\right)
\] |
|---|---|
*-commutative [=>]1.3 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{\color{blue}{x \cdot -2} - 0.5 \cdot \frac{1}{x}}\right), x\right)
\] |
associate-*r/ [=>]1.3 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{x \cdot -2 - \color{blue}{\frac{0.5 \cdot 1}{x}}}\right), x\right)
\] |
metadata-eval [=>]1.3 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(1 + x \cdot x\right) - x \cdot x}{x \cdot -2 - \frac{\color{blue}{0.5}}{x}}\right), x\right)
\] |
Taylor expanded in x around 0 99.8%
if -10 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < 1e-8Initial program 8.1%
Simplified8.1%
[Start]8.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]8.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]8.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr8.0%
[Start]8.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
*-un-lft-identity [=>]8.1 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(1 \cdot \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right)
\] |
log-prod [=>]8.1 | \[ \mathsf{copysign}\left(\color{blue}{\log 1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
metadata-eval [=>]8.1 | \[ \mathsf{copysign}\left(\color{blue}{0} + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
add-sqr-sqrt [=>]3.2 | \[ \mathsf{copysign}\left(0 + \log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
fabs-sqr [=>]3.2 | \[ \mathsf{copysign}\left(0 + \log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
add-sqr-sqrt [<=]8.0 | \[ \mathsf{copysign}\left(0 + \log \left(\color{blue}{x} + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
Simplified8.0%
[Start]8.0 | \[ \mathsf{copysign}\left(0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
+-lft-identity [=>]8.0 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Taylor expanded in x around 0 99.4%
Applied egg-rr7.5%
[Start]99.4 | \[ \mathsf{copysign}\left(-0.16666666666666666 \cdot {x}^{3} + \left(0.075 \cdot {x}^{5} + x\right), x\right)
\] |
|---|---|
associate-+r+ [=>]99.4 | \[ \mathsf{copysign}\left(\color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right) + x}, x\right)
\] |
+-commutative [=>]99.4 | \[ \mathsf{copysign}\left(\color{blue}{x + \left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right)}, x\right)
\] |
expm1-log1p-u [=>]99.4 | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)} + \left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right), x\right)
\] |
expm1-udef [=>]8.0 | \[ \mathsf{copysign}\left(\color{blue}{\left(e^{\mathsf{log1p}\left(x\right)} - 1\right)} + \left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right), x\right)
\] |
associate-+l- [=>]7.5 | \[ \mathsf{copysign}\left(\color{blue}{e^{\mathsf{log1p}\left(x\right)} - \left(1 - \left(-0.16666666666666666 \cdot {x}^{3} + 0.075 \cdot {x}^{5}\right)\right)}, x\right)
\] |
fma-def [=>]7.5 | \[ \mathsf{copysign}\left(e^{\mathsf{log1p}\left(x\right)} - \left(1 - \color{blue}{\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right)}\right), x\right)
\] |
Simplified99.4%
[Start]7.5 | \[ \mathsf{copysign}\left(e^{\mathsf{log1p}\left(x\right)} - \left(1 - \mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right)\right), x\right)
\] |
|---|---|
associate--r- [=>]8.0 | \[ \mathsf{copysign}\left(\color{blue}{\left(e^{\mathsf{log1p}\left(x\right)} - 1\right) + \mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right)}, x\right)
\] |
+-commutative [=>]8.0 | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right) + \left(e^{\mathsf{log1p}\left(x\right)} - 1\right)}, x\right)
\] |
expm1-def [=>]99.4 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, 0.075 \cdot {x}^{5}\right) + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}, x\right)
\] |
if 1e-8 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) Initial program 50.9%
Simplified99.5%
[Start]50.9 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]50.9 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]99.5 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr99.5%
[Start]99.5 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
*-un-lft-identity [=>]99.5 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(1 \cdot \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)\right)}, x\right)
\] |
log-prod [=>]99.5 | \[ \mathsf{copysign}\left(\color{blue}{\log 1 + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
metadata-eval [=>]99.5 | \[ \mathsf{copysign}\left(\color{blue}{0} + \log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
add-sqr-sqrt [=>]99.5 | \[ \mathsf{copysign}\left(0 + \log \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
fabs-sqr [=>]99.5 | \[ \mathsf{copysign}\left(0 + \log \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
add-sqr-sqrt [<=]99.5 | \[ \mathsf{copysign}\left(0 + \log \left(\color{blue}{x} + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
Simplified99.5%
[Start]99.5 | \[ \mathsf{copysign}\left(0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
+-lft-identity [=>]99.5 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 71880 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 14024 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 13576 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 13576 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.3% |
| Cost | 13320 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 13320 |
| Alternative 7 | |
|---|---|
| Accuracy | 63.9% |
| Cost | 13124 |
| Alternative 8 | |
|---|---|
| Accuracy | 57.9% |
| Cost | 13060 |
| Alternative 9 | |
|---|---|
| Accuracy | 51.1% |
| Cost | 6528 |
herbie shell --seed 2023131
(FPCore (x)
:name "Rust f64::asinh"
:precision binary64
: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))