| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 19520 |
\[\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}
\]

(FPCore (x y z) :precision binary64 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z) :precision binary64 (/ (hypot x (hypot z y)) (sqrt 3.0)))
double code(double x, double y, double z) {
return sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
double code(double x, double y, double z) {
return hypot(x, hypot(z, y)) / sqrt(3.0);
}
public static double code(double x, double y, double z) {
return Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
public static double code(double x, double y, double z) {
return Math.hypot(x, Math.hypot(z, y)) / Math.sqrt(3.0);
}
def code(x, y, z): return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
def code(x, y, z): return math.hypot(x, math.hypot(z, y)) / math.sqrt(3.0)
function code(x, y, z) return sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0)) end
function code(x, y, z) return Float64(hypot(x, hypot(z, y)) / sqrt(3.0)) end
function tmp = code(x, y, z) tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0)); end
function tmp = code(x, y, z) tmp = hypot(x, hypot(z, y)) / sqrt(3.0); end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := N[(N[Sqrt[x ^ 2 + N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 44.2% |
|---|---|
| Target | 61.3% |
| Herbie | 99.4% |
Initial program 49.2%
Applied egg-rr98.6%
[Start]49.2% | \[ \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\] |
|---|---|
sqrt-div [=>]49.1% | \[ \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}
\] |
div-inv [=>]48.8% | \[ \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{1}{\sqrt{3}}}
\] |
associate-+l+ [=>]48.8% | \[ \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}}
\] |
add-sqr-sqrt [=>]48.8% | \[ \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}}} \cdot \frac{1}{\sqrt{3}}
\] |
hypot-def [=>]62.8% | \[ \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot y + z \cdot z}\right)} \cdot \frac{1}{\sqrt{3}}
\] |
hypot-def [=>]98.6% | \[ \mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(y, z\right)}\right) \cdot \frac{1}{\sqrt{3}}
\] |
Simplified99.4%
[Start]98.6% | \[ \mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \frac{1}{\sqrt{3}}
\] |
|---|---|
associate-*r/ [=>]99.4% | \[ \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot 1}{\sqrt{3}}}
\] |
*-rgt-identity [=>]99.4% | \[ \frac{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}}{\sqrt{3}}
\] |
hypot-def [<=]63.2% | \[ \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}}
\] |
+-commutative [<=]63.2% | \[ \frac{\mathsf{hypot}\left(x, \sqrt{\color{blue}{z \cdot z + y \cdot y}}\right)}{\sqrt{3}}
\] |
hypot-def [=>]99.4% | \[ \frac{\mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(z, y\right)}\right)}{\sqrt{3}}
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 19520 |
| Alternative 2 | |
|---|---|
| Accuracy | 37.7% |
| Cost | 13188 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 13056 |
| Alternative 4 | |
|---|---|
| Accuracy | 36.1% |
| Cost | 7496 |
| Alternative 5 | |
|---|---|
| Accuracy | 30.7% |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Accuracy | 18.4% |
| Cost | 6592 |
| Alternative 7 | |
|---|---|
| Accuracy | 18.4% |
| Cost | 6592 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
:precision binary64
:herbie-target
(if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))
(sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))