| Alternative 1 | |
|---|---|
| Error | 12.1 |
| Cost | 6792 |
\[\begin{array}{l}
\mathbf{if}\;z \leq -1.22 \cdot 10^{+129}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{hypot}\left(y, x\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (sqrt (+ (* x x) (+ (* y y) (* z z)))))
(FPCore (x y z) :precision binary64 (if (<= (* z z) 2e+14) (hypot y x) (if (<= (* z z) 5e+247) (hypot z y) (hypot z x))))
double code(double x, double y, double z) {
return sqrt(((x * x) + ((y * y) + (z * z))));
}
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2e+14) {
tmp = hypot(y, x);
} else if ((z * z) <= 5e+247) {
tmp = hypot(z, y);
} else {
tmp = hypot(z, x);
}
return tmp;
}
public static double code(double x, double y, double z) {
return Math.sqrt(((x * x) + ((y * y) + (z * z))));
}
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2e+14) {
tmp = Math.hypot(y, x);
} else if ((z * z) <= 5e+247) {
tmp = Math.hypot(z, y);
} else {
tmp = Math.hypot(z, x);
}
return tmp;
}
def code(x, y, z): return math.sqrt(((x * x) + ((y * y) + (z * z))))
def code(x, y, z): tmp = 0 if (z * z) <= 2e+14: tmp = math.hypot(y, x) elif (z * z) <= 5e+247: tmp = math.hypot(z, y) else: tmp = math.hypot(z, x) return tmp
function code(x, y, z) return sqrt(Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(z * z)))) end
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 2e+14) tmp = hypot(y, x); elseif (Float64(z * z) <= 5e+247) tmp = hypot(z, y); else tmp = hypot(z, x); end return tmp end
function tmp = code(x, y, z) tmp = sqrt(((x * x) + ((y * y) + (z * z)))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 2e+14) tmp = hypot(y, x); elseif ((z * z) <= 5e+247) tmp = hypot(z, y); else tmp = hypot(z, x); end tmp_2 = tmp; end
code[x_, y_, z_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+14], N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 5e+247], N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision], N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]]]
\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{hypot}\left(y, x\right)\\
\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+247}:\\
\;\;\;\;\mathsf{hypot}\left(z, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(z, x\right)\\
\end{array}
Results
| Original | 38.5 |
|---|---|
| Target | 0 |
| Herbie | 8.8 |
if (*.f64 z z) < 2e14Initial program 30.5
Taylor expanded in z around 0 35.0
Simplified5.1
if 2e14 < (*.f64 z z) < 5.00000000000000023e247Initial program 29.9
Simplified29.9
Taylor expanded in x around 0 34.0
Simplified19.0
if 5.00000000000000023e247 < (*.f64 z z) Initial program 57.8
Simplified57.8
Taylor expanded in y around 0 57.9
Simplified8.2
| Alternative 1 | |
|---|---|
| Error | 12.1 |
| Cost | 6792 |
| Alternative 2 | |
|---|---|
| Error | 8.7 |
| Cost | 6792 |
| Alternative 3 | |
|---|---|
| Error | 36.8 |
| Cost | 920 |
| Alternative 4 | |
|---|---|
| Error | 36.8 |
| Cost | 920 |
| Alternative 5 | |
|---|---|
| Error | 36.7 |
| Cost | 724 |
| Alternative 6 | |
|---|---|
| Error | 44.3 |
| Cost | 460 |
| Alternative 7 | |
|---|---|
| Error | 44.6 |
| Cost | 196 |
| Alternative 8 | |
|---|---|
| Error | 52.2 |
| Cost | 64 |
herbie shell --seed 2023033
(FPCore (x y z)
:name "bug366 (missed optimization)"
:precision binary64
:herbie-target
(hypot x (hypot y z))
(sqrt (+ (* x x) (+ (* y y) (* z z)))))