| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6528 |
\[\mathsf{hypot}\left(z, x\right)
\]

(FPCore (x y z) :precision binary64 (sqrt (+ (* x x) (+ (* y y) (* z z)))))
(FPCore (x y z) :precision binary64 (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) {
return hypot(z, x);
}
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) {
return Math.hypot(z, x);
}
def code(x, y, z): return math.sqrt(((x * x) + ((y * y) + (z * z))))
def code(x, y, z): return math.hypot(z, x)
function code(x, y, z) return sqrt(Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(z * z)))) end
function code(x, y, z) return hypot(z, x) end
function tmp = code(x, y, z) tmp = sqrt(((x * x) + ((y * y) + (z * z)))); end
function tmp = code(x, y, z) tmp = hypot(z, x); 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_] := N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)}
\mathsf{hypot}\left(z, x\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 44.6% |
|---|---|
| Target | 100.0% |
| Herbie | 99.3% |
Initial program 46.2%
Taylor expanded in y around 0 30.0%
Simplified65.0%
[Start]30.0% | \[ \sqrt{{z}^{2} + {x}^{2}}
\] |
|---|---|
unpow2 [=>]30.0% | \[ \sqrt{\color{blue}{z \cdot z} + {x}^{2}}
\] |
unpow2 [=>]30.0% | \[ \sqrt{z \cdot z + \color{blue}{x \cdot x}}
\] |
hypot-def [=>]65.0% | \[ \color{blue}{\mathsf{hypot}\left(z, x\right)}
\] |
Final simplification65.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6528 |
| Alternative 2 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 6924 |
| Alternative 3 | |
|---|---|
| Accuracy | 79.6% |
| Cost | 524 |
| Alternative 4 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 64 |
herbie shell --seed 2023269
(FPCore (x y z)
:name "bug366 (missed optimization)"
:precision binary64
:herbie-target
(hypot x (hypot y z))
(sqrt (+ (* x x) (+ (* y y) (* z z)))))