Average Error: 38.2 → 26.1
Time: 16.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.917725958087788011890119017695135051486 \cdot 10^{80}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \le 8.320790080049101987450207216852360941277 \cdot 10^{126}:\\ \;\;\;\;\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -3.917725958087788011890119017695135051486 \cdot 10^{80}:\\
\;\;\;\;\frac{-z}{\sqrt{3}}\\

\mathbf{elif}\;z \le 8.320790080049101987450207216852360941277 \cdot 10^{126}:\\
\;\;\;\;\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\end{array}
double f(double x, double y, double z) {
        double r36607371 = x;
        double r36607372 = r36607371 * r36607371;
        double r36607373 = y;
        double r36607374 = r36607373 * r36607373;
        double r36607375 = r36607372 + r36607374;
        double r36607376 = z;
        double r36607377 = r36607376 * r36607376;
        double r36607378 = r36607375 + r36607377;
        double r36607379 = 3.0;
        double r36607380 = r36607378 / r36607379;
        double r36607381 = sqrt(r36607380);
        return r36607381;
}

double f(double x, double y, double z) {
        double r36607382 = z;
        double r36607383 = -3.917725958087788e+80;
        bool r36607384 = r36607382 <= r36607383;
        double r36607385 = -r36607382;
        double r36607386 = 3.0;
        double r36607387 = sqrt(r36607386);
        double r36607388 = r36607385 / r36607387;
        double r36607389 = 8.320790080049102e+126;
        bool r36607390 = r36607382 <= r36607389;
        double r36607391 = y;
        double r36607392 = r36607391 * r36607391;
        double r36607393 = x;
        double r36607394 = r36607393 * r36607393;
        double r36607395 = r36607382 * r36607382;
        double r36607396 = r36607394 + r36607395;
        double r36607397 = r36607392 + r36607396;
        double r36607398 = sqrt(r36607397);
        double r36607399 = r36607398 / r36607387;
        double r36607400 = 0.3333333333333333;
        double r36607401 = sqrt(r36607400);
        double r36607402 = r36607382 * r36607401;
        double r36607403 = r36607390 ? r36607399 : r36607402;
        double r36607404 = r36607384 ? r36607388 : r36607403;
        return r36607404;
}

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.2
Target25.9
Herbie26.1
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -3.917725958087788e+80

    1. Initial program 53.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv53.2

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}}\]
    4. Applied sqrt-prod53.2

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}}\]
    5. Using strategy rm
    6. Applied sqrt-div53.3

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3}}}\]
    7. Applied associate-*r/53.2

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{1}}{\sqrt{3}}}\]
    8. Simplified53.2

      \[\leadsto \frac{\color{blue}{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}}{\sqrt{3}}\]
    9. Taylor expanded around -inf 20.0

      \[\leadsto \frac{\color{blue}{-1 \cdot z}}{\sqrt{3}}\]
    10. Simplified20.0

      \[\leadsto \frac{\color{blue}{-z}}{\sqrt{3}}\]

    if -3.917725958087788e+80 < z < 8.320790080049102e+126

    1. Initial program 29.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv29.8

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}}\]
    4. Applied sqrt-prod29.9

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}}\]
    5. Using strategy rm
    6. Applied sqrt-div30.1

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3}}}\]
    7. Applied associate-*r/29.9

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{1}}{\sqrt{3}}}\]
    8. Simplified29.9

      \[\leadsto \frac{\color{blue}{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}}{\sqrt{3}}\]

    if 8.320790080049102e+126 < z

    1. Initial program 58.3

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Taylor expanded around 0 16.3

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.917725958087788011890119017695135051486 \cdot 10^{80}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \le 8.320790080049101987450207216852360941277 \cdot 10^{126}:\\ \;\;\;\;\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :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)))