Average Error: 37.3 → 0.0
Time: 10.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right)\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right)
double f(double x, double y, double z) {
        double r430834 = x;
        double r430835 = r430834 * r430834;
        double r430836 = y;
        double r430837 = r430836 * r430836;
        double r430838 = r430835 + r430837;
        double r430839 = z;
        double r430840 = r430839 * r430839;
        double r430841 = r430838 + r430840;
        double r430842 = sqrt(r430841);
        return r430842;
}

double f(double x, double y, double z) {
        double r430843 = x;
        double r430844 = y;
        double r430845 = hypot(r430843, r430844);
        double r430846 = z;
        double r430847 = hypot(r430845, r430846);
        return r430847;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.3
Target24.7
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Derivation

  1. Initial program 37.3

    \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt37.3

    \[\leadsto \sqrt{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} + z \cdot z}\]
  4. Applied hypot-def27.9

    \[\leadsto \color{blue}{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}\]
  5. Using strategy rm
  6. Applied *-un-lft-identity27.9

    \[\leadsto \mathsf{hypot}\left(\sqrt{\color{blue}{1 \cdot \left(x \cdot x + y \cdot y\right)}}, z\right)\]
  7. Applied sqrt-prod27.9

    \[\leadsto \mathsf{hypot}\left(\color{blue}{\sqrt{1} \cdot \sqrt{x \cdot x + y \cdot y}}, z\right)\]
  8. Simplified27.9

    \[\leadsto \mathsf{hypot}\left(\color{blue}{1} \cdot \sqrt{x \cdot x + y \cdot y}, z\right)\]
  9. Simplified0.0

    \[\leadsto \mathsf{hypot}\left(1 \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}, z\right)\]
  10. Final simplification0.0

    \[\leadsto \mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right)\]

Reproduce

herbie shell --seed 2019303 +o rules:numerics
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))