| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13576 |
(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 (* x -2.0))) x)
(if (<= t_0 1e-11)
(copysign 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((x * -2.0)), x);
} else if (t_0 <= 1e-11) {
tmp = copysign(x, x);
} else {
tmp = copysign(log((x + hypot(1.0, 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 <= -10.0) {
tmp = Math.copySign(-Math.log((x * -2.0)), x);
} else if (t_0 <= 1e-11) {
tmp = Math.copySign(x, x);
} else {
tmp = Math.copySign(Math.log((x + Math.hypot(1.0, 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 <= -10.0: tmp = math.copysign(-math.log((x * -2.0)), x) elif t_0 <= 1e-11: tmp = math.copysign(x, x) else: tmp = math.copysign(math.log((x + math.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(Float64(-log(Float64(x * -2.0))), x); elseif (t_0 <= 1e-11) tmp = copysign(x, x); else tmp = copysign(log(Float64(x + hypot(1.0, 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 <= -10.0) tmp = sign(x) * abs(-log((x * -2.0))); elseif (t_0 <= 1e-11) tmp = sign(x) * abs(x); else tmp = sign(x) * abs(log((x + hypot(1.0, 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, -10.0], N[With[{TMP1 = Abs[(-N[Log[N[(x * -2.0), $MachinePrecision]], $MachinePrecision])], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 1e-11], N[With[{TMP1 = Abs[x], 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(x \cdot -2\right), x\right)\\
\mathbf{elif}\;t_0 \leq 10^{-11}:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
| Original | 45.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -10Initial program 31.5
Simplified0.0
[Start]31.5 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]31.5 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]0.0 | \[ \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.0
Simplified0.1
[Start]0.0 | \[ \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 [<=]64.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 [=>]64.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)
\] |
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ \mathsf{copysign}\left(0 - \log \left(x \cdot -2\right), x\right)
\] |
|---|---|
sub0-neg [=>]0.1 | \[ \mathsf{copysign}\left(\color{blue}{-\log \left(x \cdot -2\right)}, x\right)
\] |
if -10 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < 9.99999999999999939e-12Initial program 59.0
Simplified59.0
[Start]59.0 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]59.0 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]59.0 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Taylor expanded in x around 0 58.7
Simplified0.6
[Start]58.7 | \[ \mathsf{copysign}\left(0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right), x\right)
\] |
|---|---|
fma-def [=>]58.7 | \[ \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right)}, x\right)
\] |
unpow2 [=>]58.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{1 + \left|x\right|}, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
associate-/l* [=>]58.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \color{blue}{\frac{x}{\frac{1 + \left|x\right|}{x}}}, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
associate-/r/ [=>]58.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \color{blue}{\frac{x}{1 + \left|x\right|} \cdot x}, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
rem-square-sqrt [<=]61.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|} \cdot x, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
fabs-sqr [=>]61.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + \color{blue}{\sqrt{x} \cdot \sqrt{x}}} \cdot x, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
rem-square-sqrt [=>]58.8 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + \color{blue}{x}} \cdot x, \log \left(1 + \left|x\right|\right)\right), x\right)
\] |
log1p-def [=>]0.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + x} \cdot x, \color{blue}{\mathsf{log1p}\left(\left|x\right|\right)}\right), x\right)
\] |
rem-square-sqrt [<=]32.8 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + x} \cdot x, \mathsf{log1p}\left(\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)\right), x\right)
\] |
fabs-sqr [=>]32.8 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + x} \cdot x, \mathsf{log1p}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)\right), x\right)
\] |
rem-square-sqrt [=>]0.6 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \frac{x}{1 + x} \cdot x, \mathsf{log1p}\left(\color{blue}{x}\right)\right), x\right)
\] |
Taylor expanded in x around 0 0.7
Simplified0.7
[Start]0.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, {x}^{2}, \mathsf{log1p}\left(x\right)\right), x\right)
\] |
|---|---|
unpow2 [=>]0.7 | \[ \mathsf{copysign}\left(\mathsf{fma}\left(0.5, \color{blue}{x \cdot x}, \mathsf{log1p}\left(x\right)\right), x\right)
\] |
Taylor expanded in x around 0 0.6
if 9.99999999999999939e-12 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) Initial program 32.1
Simplified0.5
[Start]32.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]32.1 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{\color{blue}{1 + x \cdot x}}\right), x\right)
\] |
hypot-1-def [=>]0.5 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
Applied egg-rr0.5
Simplified0.5
[Start]0.5 | \[ \mathsf{copysign}\left(0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)
\] |
|---|---|
+-lft-identity [=>]0.5 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification0.5
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13576 |
| Alternative 2 | |
|---|---|
| Error | 11.1 |
| Cost | 13320 |
| Alternative 3 | |
|---|---|
| Error | 0.5 |
| Cost | 13320 |
| Alternative 4 | |
|---|---|
| Error | 0.5 |
| Cost | 13320 |
| Alternative 5 | |
|---|---|
| Error | 22.4 |
| Cost | 13124 |
| Alternative 6 | |
|---|---|
| Error | 27.4 |
| Cost | 12928 |
| Alternative 7 | |
|---|---|
| Error | 30.4 |
| Cost | 6528 |
herbie shell --seed 2023045
(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))