Average Error: 35.7 → 24.2
Time: 18.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}
\begin{array}{l}
\mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\

\mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot x\\

\end{array}
double f(double x, double y, double z) {
        double r39812292 = x;
        double r39812293 = r39812292 * r39812292;
        double r39812294 = y;
        double r39812295 = r39812294 * r39812294;
        double r39812296 = r39812293 + r39812295;
        double r39812297 = z;
        double r39812298 = r39812297 * r39812297;
        double r39812299 = r39812296 + r39812298;
        double r39812300 = 3.0;
        double r39812301 = r39812299 / r39812300;
        double r39812302 = sqrt(r39812301);
        return r39812302;
}

double f(double x, double y, double z) {
        double r39812303 = x;
        double r39812304 = -1.3226326560428921e+154;
        bool r39812305 = r39812303 <= r39812304;
        double r39812306 = 0.3333333333333333;
        double r39812307 = sqrt(r39812306);
        double r39812308 = -r39812303;
        double r39812309 = r39812307 * r39812308;
        double r39812310 = 1.2721613999661422e+154;
        bool r39812311 = r39812303 <= r39812310;
        double r39812312 = z;
        double r39812313 = r39812312 * r39812312;
        double r39812314 = y;
        double r39812315 = r39812314 * r39812314;
        double r39812316 = r39812303 * r39812303;
        double r39812317 = r39812315 + r39812316;
        double r39812318 = r39812313 + r39812317;
        double r39812319 = 3.0;
        double r39812320 = r39812318 / r39812319;
        double r39812321 = sqrt(r39812320);
        double r39812322 = r39812307 * r39812303;
        double r39812323 = r39812311 ? r39812321 : r39812322;
        double r39812324 = r39812305 ? r39812309 : r39812323;
        return r39812324;
}

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

Original35.7
Target24.6
Herbie24.2
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.3226326560428921e+154

    1. Initial program 59.3

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity59.3

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

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}{1 \cdot 3.0}}\]
    5. Applied times-frac59.3

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
    10. Simplified14.7

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x}\]

    if -1.3226326560428921e+154 < x < 1.2721613999661422e+154

    1. Initial program 27.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]

    if 1.2721613999661422e+154 < x

    1. Initial program 59.3

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Taylor expanded around inf 14.0

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 
(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)))