Average Error: 38.1 → 0.0
Time: 13.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right)\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right)
double f(double x, double y, double z) {
        double r421264 = x;
        double r421265 = r421264 * r421264;
        double r421266 = y;
        double r421267 = r421266 * r421266;
        double r421268 = r421265 + r421267;
        double r421269 = z;
        double r421270 = r421269 * r421269;
        double r421271 = r421268 + r421270;
        double r421272 = sqrt(r421271);
        return r421272;
}

double f(double x, double y, double z) {
        double r421273 = z;
        double r421274 = x;
        double r421275 = y;
        double r421276 = hypot(r421274, r421275);
        double r421277 = hypot(r421273, r421276);
        return r421277;
}

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 fma-udef28.5

    \[\leadsto \mathsf{hypot}\left(z, \sqrt{\color{blue}{x \cdot x + y \cdot y}}\right)\]
  10. Applied hypot-def0.0

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

    \[\leadsto \mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\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))))