| Alternative 1 | |
|---|---|
| Error | 20.8 |
| Cost | 13056 |
\[\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right)
\]
(FPCore (x y z) :precision binary64 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z) :precision binary64 (/ (hypot z (hypot y x)) (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(z, hypot(y, x)) / 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(z, Math.hypot(y, x)) / 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(z, math.hypot(y, x)) / 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(z, hypot(y, x)) / 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(z, hypot(y, x)) / 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[z ^ 2 + N[Sqrt[y ^ 2 + x ^ 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(z, \mathsf{hypot}\left(y, x\right)\right)}{\sqrt{3}}
Results
| Original | 37.3 |
|---|---|
| Target | 25.5 |
| Herbie | 0.4 |
Initial program 37.3
Applied egg-rr0.9
Simplified0.4
[Start]0.9 | \[ \mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right) \cdot \frac{1}{\sqrt{3}}
\] |
|---|---|
associate-*r/ [=>]0.4 | \[ \color{blue}{\frac{\mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right) \cdot 1}{\sqrt{3}}}
\] |
*-rgt-identity [=>]0.4 | \[ \frac{\color{blue}{\mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right)}}{\sqrt{3}}
\] |
hypot-def [<=]28.4 | \[ \frac{\mathsf{hypot}\left(z, \color{blue}{\sqrt{x \cdot x + y \cdot y}}\right)}{\sqrt{3}}
\] |
unpow2 [<=]28.4 | \[ \frac{\mathsf{hypot}\left(z, \sqrt{\color{blue}{{x}^{2}} + y \cdot y}\right)}{\sqrt{3}}
\] |
unpow2 [<=]28.4 | \[ \frac{\mathsf{hypot}\left(z, \sqrt{{x}^{2} + \color{blue}{{y}^{2}}}\right)}{\sqrt{3}}
\] |
+-commutative [<=]28.4 | \[ \frac{\mathsf{hypot}\left(z, \sqrt{\color{blue}{{y}^{2} + {x}^{2}}}\right)}{\sqrt{3}}
\] |
unpow2 [=>]28.4 | \[ \frac{\mathsf{hypot}\left(z, \sqrt{\color{blue}{y \cdot y} + {x}^{2}}\right)}{\sqrt{3}}
\] |
unpow2 [=>]28.4 | \[ \frac{\mathsf{hypot}\left(z, \sqrt{y \cdot y + \color{blue}{x \cdot x}}\right)}{\sqrt{3}}
\] |
hypot-def [=>]0.4 | \[ \frac{\mathsf{hypot}\left(z, \color{blue}{\mathsf{hypot}\left(y, x\right)}\right)}{\sqrt{3}}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 20.8 |
| Cost | 13056 |
| Alternative 2 | |
|---|---|
| Error | 42.9 |
| Cost | 7496 |
| Alternative 3 | |
|---|---|
| Error | 45.2 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 45.8 |
| Cost | 7053 |
| Alternative 5 | |
|---|---|
| Error | 45.8 |
| Cost | 7053 |
| Alternative 6 | |
|---|---|
| Error | 45.8 |
| Cost | 7052 |
| Alternative 7 | |
|---|---|
| Error | 52.5 |
| Cost | 6592 |
herbie shell --seed 2023018
(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)))