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

(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 -0.02)
(copysign (- (log (- (hypot 1.0 x) x))) x)
(if (<= t_0 1e-8)
(copysign (- x (* 0.16666666666666666 (pow x 3.0))) x)
(copysign (log (+ (/ 0.5 x) (+ x 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 <= -0.02) {
tmp = copysign(-log((hypot(1.0, x) - x)), x);
} else if (t_0 <= 1e-8) {
tmp = copysign((x - (0.16666666666666666 * pow(x, 3.0))), x);
} else {
tmp = copysign(log(((0.5 / x) + (x + x))), x);
}
return tmp;
}
public static double code(double x) {
return Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
}
public static double code(double x) {
double t_0 = Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
double tmp;
if (t_0 <= -0.02) {
tmp = Math.copySign(-Math.log((Math.hypot(1.0, x) - x)), x);
} else if (t_0 <= 1e-8) {
tmp = Math.copySign((x - (0.16666666666666666 * Math.pow(x, 3.0))), x);
} else {
tmp = Math.copySign(Math.log(((0.5 / x) + (x + x))), x);
}
return tmp;
}
def code(x): return math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
def code(x): t_0 = math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x) tmp = 0 if t_0 <= -0.02: tmp = math.copysign(-math.log((math.hypot(1.0, x) - x)), x) elif t_0 <= 1e-8: tmp = math.copysign((x - (0.16666666666666666 * math.pow(x, 3.0))), x) else: tmp = math.copysign(math.log(((0.5 / x) + (x + 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 <= -0.02) tmp = copysign(Float64(-log(Float64(hypot(1.0, x) - x))), x); elseif (t_0 <= 1e-8) tmp = copysign(Float64(x - Float64(0.16666666666666666 * (x ^ 3.0))), x); else tmp = copysign(log(Float64(Float64(0.5 / x) + Float64(x + x))), x); end return tmp end
function tmp = code(x) tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0))))); end
function tmp_2 = code(x) t_0 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0))))); tmp = 0.0; if (t_0 <= -0.02) tmp = sign(x) * abs(-log((hypot(1.0, x) - x))); elseif (t_0 <= 1e-8) tmp = sign(x) * abs((x - (0.16666666666666666 * (x ^ 3.0)))); else tmp = sign(x) * abs(log(((0.5 / x) + (x + x)))); end tmp_2 = 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, -0.02], N[With[{TMP1 = Abs[(-N[Log[N[(N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision])], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 1e-8], N[With[{TMP1 = Abs[N[(x - N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[Log[N[(N[(0.5 / x), $MachinePrecision] + N[(x + x), $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 -0.02:\\
\;\;\;\;\mathsf{copysign}\left(-\log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)\\
\mathbf{elif}\;t_0 \leq 10^{-8}:\\
\;\;\;\;\mathsf{copysign}\left(x - 0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 28.8% |
|---|---|
| Target | 100.0% |
| Herbie | 99.4% |
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -0.0200000000000000004Initial program 57.0%
Applied egg-rr6.8%
[Start]57.0% | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]57.0% | \[ \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 [<=]7.5% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \color{blue}{x}\right), x\right)
\] |
flip-+ [=>]6.1% | \[ \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 [=>]6.0% | \[ \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 [<=]6.4% | \[ \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 [=>]6.8% | \[ \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 [=>]6.8% | \[ \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 [=>]6.8% | \[ \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]6.8% | \[ \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 [=>]6.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 [<=]6.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+ [=>]55.6% | \[ \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.0200000000000000004 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < 1e-8Initial program 7.3%
Applied egg-rr7.3%
[Start]7.3% | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]7.3% | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\sqrt{x \cdot x + 1} + \left|x\right|\right)}, x\right)
\] |
add-sqr-sqrt [=>]3.5% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right), x\right)
\] |
fabs-sqr [=>]3.5% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right), x\right)
\] |
add-sqr-sqrt [<=]7.3% | \[ \mathsf{copysign}\left(\log \left(\sqrt{x \cdot x + 1} + \color{blue}{x}\right), x\right)
\] |
flip-+ [=>]7.3% | \[ \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 [=>]7.3% | \[ \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 [<=]7.3% | \[ \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 [=>]7.3% | \[ \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 [=>]7.3% | \[ \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 [=>]7.3% | \[ \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)
\] |
Simplified7.3%
[Start]7.3% | \[ \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 [=>]7.3% | \[ \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 [<=]7.3% | \[ \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+ [=>]7.3% | \[ \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 [=>]7.3% | \[ \mathsf{copysign}\left(\log \left(1 + \color{blue}{0}\right) - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
metadata-eval [=>]7.3% | \[ \mathsf{copysign}\left(\log \color{blue}{1} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
metadata-eval [=>]7.3% | \[ \mathsf{copysign}\left(\color{blue}{0} - \log \left(\mathsf{hypot}\left(1, x\right) - x\right), x\right)
\] |
neg-sub0 [<=]7.3% | \[ \mathsf{copysign}\left(\color{blue}{-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)}, x\right)
\] |
Taylor expanded in x around 0 100.0%
if 1e-8 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) Initial program 42.5%
Taylor expanded in x around inf 100.0%
Simplified100.0%
[Start]100.0% | \[ \mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)
\] |
|---|---|
associate-*r/ [=>]100.0% | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\frac{0.5 \cdot 1}{x}} + \left(\left|x\right| + x\right)\right), x\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{0.5}}{x} + \left(\left|x\right| + x\right)\right), x\right)
\] |
rem-square-sqrt [<=]100.0% | \[ \mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right| + x\right)\right), x\right)
\] |
fabs-sqr [=>]100.0% | \[ \mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} + x\right)\right), x\right)
\] |
rem-square-sqrt [=>]100.0% | \[ \mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\color{blue}{x} + x\right)\right), x\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 65672 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 13576 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 13576 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 13576 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 13320 |
| Alternative 6 | |
|---|---|
| Accuracy | 59.3% |
| Cost | 13188 |
| Alternative 7 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 13188 |
| Alternative 8 | |
|---|---|
| Accuracy | 59.3% |
| Cost | 13060 |
| Alternative 9 | |
|---|---|
| Accuracy | 53.0% |
| Cost | 6528 |
herbie shell --seed 2023269
(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))