Average Error: 38.5 → 25.7
Time: 15.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.800436619407530802706838305298910062354 \cdot 10^{135}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\\ \mathbf{else}:\\ \;\;\;\;x \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}\;x \le -2.800436619407530802706838305298910062354 \cdot 10^{135}:\\
\;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r546916 = x;
        double r546917 = r546916 * r546916;
        double r546918 = y;
        double r546919 = r546918 * r546918;
        double r546920 = r546917 + r546919;
        double r546921 = z;
        double r546922 = r546921 * r546921;
        double r546923 = r546920 + r546922;
        double r546924 = 3.0;
        double r546925 = r546923 / r546924;
        double r546926 = sqrt(r546925);
        return r546926;
}

double f(double x, double y, double z) {
        double r546927 = x;
        double r546928 = -2.8004366194075308e+135;
        bool r546929 = r546927 <= r546928;
        double r546930 = -r546927;
        double r546931 = 0.3333333333333333;
        double r546932 = sqrt(r546931);
        double r546933 = r546930 * r546932;
        double r546934 = 2.2733836340085665e+132;
        bool r546935 = r546927 <= r546934;
        double r546936 = r546927 * r546927;
        double r546937 = y;
        double r546938 = r546937 * r546937;
        double r546939 = r546936 + r546938;
        double r546940 = z;
        double r546941 = r546940 * r546940;
        double r546942 = r546939 + r546941;
        double r546943 = sqrt(r546942);
        double r546944 = 3.0;
        double r546945 = r546944 / r546943;
        double r546946 = r546943 / r546945;
        double r546947 = sqrt(r546946);
        double r546948 = r546927 * r546932;
        double r546949 = r546935 ? r546947 : r546948;
        double r546950 = r546929 ? r546933 : r546949;
        return r546950;
}

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.5
Target26.0
Herbie25.7
\[\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 x < -2.8004366194075308e+135

    1. Initial program 60.9

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

      \[\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}}}{3}}\]
    4. Applied associate-/l*60.9

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    6. Simplified16.2

      \[\leadsto \color{blue}{\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if -2.8004366194075308e+135 < x < 2.2733836340085665e+132

    1. Initial program 29.6

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

      \[\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}}}{3}}\]
    4. Applied associate-/l*29.7

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

    if 2.2733836340085665e+132 < x

    1. Initial program 59.6

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.7

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

Reproduce

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

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.3333333333333333) z)))

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