Average Error: 37.8 → 26.0
Time: 15.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.717333272640103545901465763102229690483 \cdot 10^{89}:\\ \;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;y \le 2.673911141236909644899525953792608723737 \cdot 10^{-195}:\\ \;\;\;\;\sqrt{x \cdot x + \left(z \cdot z + y \cdot y\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;y \le 3.267479005742163364041445759339258528358 \cdot 10^{-158}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \mathbf{elif}\;y \le 1.902370008063671102963145796212009492267 \cdot 10^{138}:\\ \;\;\;\;\sqrt{x \cdot x + \left(z \cdot z + y \cdot y\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot y\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -1.717333272640103545901465763102229690483 \cdot 10^{89}:\\
\;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;y \le 2.673911141236909644899525953792608723737 \cdot 10^{-195}:\\
\;\;\;\;\sqrt{x \cdot x + \left(z \cdot z + y \cdot y\right)} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;y \le 3.267479005742163364041445759339258528358 \cdot 10^{-158}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r767952 = x;
        double r767953 = r767952 * r767952;
        double r767954 = y;
        double r767955 = r767954 * r767954;
        double r767956 = r767953 + r767955;
        double r767957 = z;
        double r767958 = r767957 * r767957;
        double r767959 = r767956 + r767958;
        double r767960 = 3.0;
        double r767961 = r767959 / r767960;
        double r767962 = sqrt(r767961);
        return r767962;
}

double f(double x, double y, double z) {
        double r767963 = y;
        double r767964 = -1.7173332726401035e+89;
        bool r767965 = r767963 <= r767964;
        double r767966 = -r767963;
        double r767967 = 0.3333333333333333;
        double r767968 = sqrt(r767967);
        double r767969 = r767966 * r767968;
        double r767970 = 2.6739111412369096e-195;
        bool r767971 = r767963 <= r767970;
        double r767972 = x;
        double r767973 = r767972 * r767972;
        double r767974 = z;
        double r767975 = r767974 * r767974;
        double r767976 = r767963 * r767963;
        double r767977 = r767975 + r767976;
        double r767978 = r767973 + r767977;
        double r767979 = sqrt(r767978);
        double r767980 = 1.0;
        double r767981 = 3.0;
        double r767982 = r767980 / r767981;
        double r767983 = sqrt(r767982);
        double r767984 = r767979 * r767983;
        double r767985 = 3.2674790057421634e-158;
        bool r767986 = r767963 <= r767985;
        double r767987 = r767968 * r767974;
        double r767988 = 1.902370008063671e+138;
        bool r767989 = r767963 <= r767988;
        double r767990 = r767968 * r767963;
        double r767991 = r767989 ? r767984 : r767990;
        double r767992 = r767986 ? r767987 : r767991;
        double r767993 = r767971 ? r767984 : r767992;
        double r767994 = r767965 ? r767969 : r767993;
        return r767994;
}

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

Original37.8
Target25.8
Herbie26.0
\[\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 4 regimes
  2. if y < -1.7173332726401035e+89

    1. Initial program 53.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified53.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    4. Simplified19.4

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

    if -1.7173332726401035e+89 < y < 2.6739111412369096e-195 or 3.2674790057421634e-158 < y < 1.902370008063671e+138

    1. Initial program 28.9

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified28.9

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied div-inv28.9

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

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

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

    if 2.6739111412369096e-195 < y < 3.2674790057421634e-158

    1. Initial program 33.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified33.2

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    4. Simplified48.1

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333148296162562473909929395} \cdot z}\]

    if 1.902370008063671e+138 < y

    1. Initial program 60.7

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified60.7

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt60.7

      \[\leadsto \sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    5. Applied add-sqr-sqrt60.7

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)} \cdot \sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    6. Applied times-frac60.7

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

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

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

      \[\leadsto \color{blue}{y \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    10. Simplified14.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.717333272640103545901465763102229690483 \cdot 10^{89}:\\ \;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;y \le 2.673911141236909644899525953792608723737 \cdot 10^{-195}:\\ \;\;\;\;\sqrt{x \cdot x + \left(z \cdot z + y \cdot y\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;y \le 3.267479005742163364041445759339258528358 \cdot 10^{-158}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \mathbf{elif}\;y \le 1.902370008063671102963145796212009492267 \cdot 10^{138}:\\ \;\;\;\;\sqrt{x \cdot x + \left(z \cdot z + y \cdot y\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot y\\ \end{array}\]

Reproduce

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