Average Error: 38.1 → 0.0
Time: 13.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\mathsf{hypot}\left(z, \mathsf{hypot}\left(y, x\right)\right)\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\mathsf{hypot}\left(z, \mathsf{hypot}\left(y, x\right)\right)
double f(double x, double y, double z) {
        double r449958 = x;
        double r449959 = r449958 * r449958;
        double r449960 = y;
        double r449961 = r449960 * r449960;
        double r449962 = r449959 + r449961;
        double r449963 = z;
        double r449964 = r449963 * r449963;
        double r449965 = r449962 + r449964;
        double r449966 = sqrt(r449965);
        return r449966;
}

double f(double x, double y, double z) {
        double r449967 = z;
        double r449968 = y;
        double r449969 = x;
        double r449970 = hypot(r449968, r449969);
        double r449971 = hypot(r449967, r449970);
        return r449971;
}

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

Original38.1
Target25.3
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 38.1

    \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
  2. Simplified38.1

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}\]
  3. Using strategy rm
  4. Applied fma-udef38.1

    \[\leadsto \sqrt{\color{blue}{z \cdot z + \mathsf{fma}\left(x, x, y \cdot y\right)}}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt38.1

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

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

    \[\leadsto \mathsf{hypot}\left(z, \sqrt{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, y \cdot y\right)}}\right)\]
  10. Applied sqrt-prod28.5

    \[\leadsto \mathsf{hypot}\left(z, \color{blue}{\sqrt{1} \cdot \sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}}\right)\]
  11. Simplified28.5

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

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

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

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(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))))