| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 13576.00 |
(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 (/ -0.5 x)) x)
(if (<= t_0 0.0)
(copysign (+ x (* -0.16666666666666666 (pow x 3.0))) 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((-0.5 / x)), x);
} else if (t_0 <= 0.0) {
tmp = copysign((x + (-0.16666666666666666 * pow(x, 3.0))), 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((-0.5 / x)), x);
} else if (t_0 <= 0.0) {
tmp = Math.copySign((x + (-0.16666666666666666 * Math.pow(x, 3.0))), 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((-0.5 / x)), x) elif t_0 <= 0.0: tmp = math.copysign((x + (-0.16666666666666666 * math.pow(x, 3.0))), 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(log(Float64(-0.5 / x)), x); elseif (t_0 <= 0.0) tmp = copysign(Float64(x + Float64(-0.16666666666666666 * (x ^ 3.0))), 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((-0.5 / x))); elseif (t_0 <= 0.0) tmp = sign(x) * abs((x + (-0.16666666666666666 * (x ^ 3.0)))); 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[(-0.5 / x), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 0.0], 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[(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{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
| Original | 29.5% |
|---|---|
| Target | 99.9% |
| Herbie | 99.0% |
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -10Initial program 48.9
Simplified99.8
[Start]48.9 | \[ \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\] |
|---|---|
+-commutative [=>]48.9 | \[ \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)
\] |
Taylor expanded in x around -inf 99.8
Simplified99.9
[Start]99.8 | \[ \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 [<=]0.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 [=>]0.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 [=>]99.9 | \[ \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 [=>]99.9 | \[ \mathsf{copysign}\left(\log \left(\left(x + \color{blue}{\left(-x\right)}\right) - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
sub-neg [<=]99.9 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(x - x\right)} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
+-inverses [=>]99.9 | \[ \mathsf{copysign}\left(\log \left(\color{blue}{0} - 0.5 \cdot \frac{1}{x}\right), x\right)
\] |
neg-sub0 [<=]99.9 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(-0.5 \cdot \frac{1}{x}\right)}, x\right)
\] |
distribute-lft-neg-in [=>]99.9 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\left(-0.5\right) \cdot \frac{1}{x}\right)}, x\right)
\] |
associate-*r/ [=>]99.9 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left(-0.5\right) \cdot 1}{x}\right)}, x\right)
\] |
metadata-eval [=>]99.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5} \cdot 1}{x}\right), x\right)
\] |
metadata-eval [=>]99.9 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-0.5}}{x}\right), x\right)
\] |
if -10 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -0.0Initial program 7.7
Applied egg-rr7.7
Simplified7.7
[Start]7.7 | \[ \mathsf{copysign}\left(\log \left(\left(\left(x \cdot x\right) \cdot 0 - 1\right) \cdot \frac{1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
|---|---|
associate-*r/ [=>]7.7 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{\left(\left(x \cdot x\right) \cdot 0 - 1\right) \cdot 1}{x - \mathsf{hypot}\left(1, x\right)}\right)}, x\right)
\] |
mul0-rgt [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{\left(\color{blue}{0} - 1\right) \cdot 1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
metadata-eval [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-1} \cdot 1}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
metadata-eval [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{-1}}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
metadata-eval [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{\color{blue}{\frac{1}{-1}}}{x - \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
associate-/r* [<=]7.7 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(\frac{1}{-1 \cdot \left(x - \mathsf{hypot}\left(1, x\right)\right)}\right)}, x\right)
\] |
neg-mul-1 [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{-\left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
neg-sub0 [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{0 - \left(x - \mathsf{hypot}\left(1, x\right)\right)}}\right), x\right)
\] |
associate--r- [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\left(0 - x\right) + \mathsf{hypot}\left(1, x\right)}}\right), x\right)
\] |
neg-sub0 [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\left(-x\right)} + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
mul-1-neg [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{-1 \cdot x} + \mathsf{hypot}\left(1, x\right)}\right), x\right)
\] |
+-commutative [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right) + -1 \cdot x}}\right), x\right)
\] |
mul-1-neg [=>]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) + \color{blue}{\left(-x\right)}}\right), x\right)
\] |
sub-neg [<=]7.7 | \[ \mathsf{copysign}\left(\log \left(\frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right) - x}}\right), x\right)
\] |
Taylor expanded in x around 0 99.2
if -0.0 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) Initial program 50.9
Applied egg-rr97.7
Simplified97.7
[Start]97.7 | \[ \mathsf{copysign}\left(\log \left(\mathsf{hypot}\left(1, x\right) + x\right) + 0, x\right)
\] |
|---|---|
+-rgt-identity [=>]97.7 | \[ \mathsf{copysign}\left(\color{blue}{\log \left(\mathsf{hypot}\left(1, x\right) + x\right)}, x\right)
\] |
+-commutative [=>]97.7 | \[ \mathsf{copysign}\left(\log \color{blue}{\left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right)
\] |
Final simplification99.0
| Alternative 1 | |
|---|---|
| Error | 99.4% |
| Cost | 13576.00 |
| Alternative 2 | |
|---|---|
| Error | 99.3% |
| Cost | 13512.00 |
| Alternative 3 | |
|---|---|
| Error | 99.0% |
| Cost | 13448.00 |
| Alternative 4 | |
|---|---|
| Error | 81.7% |
| Cost | 13320.00 |
| Alternative 5 | |
|---|---|
| Error | 99.0% |
| Cost | 13320.00 |
| Alternative 6 | |
|---|---|
| Error | 64.3% |
| Cost | 13124.00 |
| Alternative 7 | |
|---|---|
| Error | 57.9% |
| Cost | 13060.00 |
| Alternative 8 | |
|---|---|
| Error | 51.8% |
| Cost | 6528.00 |
herbie shell --seed 2023093
(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))