| Alternative 1 | |
|---|---|
| Accuracy | 74.5% |
| Cost | 6660 |
\[\begin{array}{l}
\mathbf{if}\;z \leq 1.02 \cdot 10^{+70}:\\
\;\;\;\;\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 (hypot (hypot z y) 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(hypot(z, y), 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(Math.hypot(z, y), x);
}
def code(x, y, z): return math.sqrt((((x * x) + (y * y)) + (z * z)))
def code(x, y, z): return math.hypot(math.hypot(z, y), x)
function code(x, y, z) return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))) end
function code(x, y, z) return hypot(hypot(z, y), 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(hypot(z, y), x); end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := N[Sqrt[N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\mathsf{hypot}\left(\mathsf{hypot}\left(z, y\right), x\right)
Results
| Original | 41.7% |
|---|---|
| Target | 61.1% |
| Herbie | 100.0% |
Initial program 41.7%
Applied egg-rr100.0%
[Start]41.7 | \[ \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\] |
|---|---|
associate-+l+ [=>]41.7 | \[ \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}
\] |
+-commutative [=>]41.7 | \[ \sqrt{\color{blue}{\left(y \cdot y + z \cdot z\right) + x \cdot x}}
\] |
add-sqr-sqrt [=>]41.7 | \[ \sqrt{\color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}} + x \cdot x}
\] |
hypot-def [=>]56.1 | \[ \color{blue}{\mathsf{hypot}\left(\sqrt{y \cdot y + z \cdot z}, x\right)}
\] |
hypot-def [=>]100.0 | \[ \mathsf{hypot}\left(\color{blue}{\mathsf{hypot}\left(y, z\right)}, x\right)
\] |
Simplified100.0%
[Start]100.0 | \[ \mathsf{hypot}\left(\mathsf{hypot}\left(y, z\right), x\right)
\] |
|---|---|
hypot-def [<=]56.1 | \[ \mathsf{hypot}\left(\color{blue}{\sqrt{y \cdot y + z \cdot z}}, x\right)
\] |
+-commutative [<=]56.1 | \[ \mathsf{hypot}\left(\sqrt{\color{blue}{z \cdot z + y \cdot y}}, x\right)
\] |
hypot-def [=>]100.0 | \[ \mathsf{hypot}\left(\color{blue}{\mathsf{hypot}\left(z, y\right)}, x\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 74.5% |
| Cost | 6660 |
| Alternative 2 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 6528 |
| Alternative 3 | |
|---|---|
| Accuracy | 30.4% |
| Cost | 260 |
| Alternative 4 | |
|---|---|
| Accuracy | 19.1% |
| Cost | 64 |
herbie shell --seed 2023151
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:precision binary64
:herbie-target
(if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))
(sqrt (+ (+ (* x x) (* y y)) (* z z))))