Average Error: 37.8 → 26.0
Time: 15.4s
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 r728865 = x;
        double r728866 = r728865 * r728865;
        double r728867 = y;
        double r728868 = r728867 * r728867;
        double r728869 = r728866 + r728868;
        double r728870 = z;
        double r728871 = r728870 * r728870;
        double r728872 = r728869 + r728871;
        double r728873 = 3.0;
        double r728874 = r728872 / r728873;
        double r728875 = sqrt(r728874);
        return r728875;
}

double f(double x, double y, double z) {
        double r728876 = y;
        double r728877 = -1.7173332726401035e+89;
        bool r728878 = r728876 <= r728877;
        double r728879 = -r728876;
        double r728880 = 0.3333333333333333;
        double r728881 = sqrt(r728880);
        double r728882 = r728879 * r728881;
        double r728883 = 2.6739111412369096e-195;
        bool r728884 = r728876 <= r728883;
        double r728885 = x;
        double r728886 = r728885 * r728885;
        double r728887 = z;
        double r728888 = r728887 * r728887;
        double r728889 = r728876 * r728876;
        double r728890 = r728888 + r728889;
        double r728891 = r728886 + r728890;
        double r728892 = sqrt(r728891);
        double r728893 = 1.0;
        double r728894 = 3.0;
        double r728895 = r728893 / r728894;
        double r728896 = sqrt(r728895);
        double r728897 = r728892 * r728896;
        double r728898 = 3.2674790057421634e-158;
        bool r728899 = r728876 <= r728898;
        double r728900 = r728881 * r728887;
        double r728901 = 1.902370008063671e+138;
        bool r728902 = r728876 <= r728901;
        double r728903 = r728881 * r728876;
        double r728904 = r728902 ? r728897 : r728903;
        double r728905 = r728899 ? r728900 : r728904;
        double r728906 = r728884 ? r728897 : r728905;
        double r728907 = r728878 ? r728882 : r728906;
        return r728907;
}

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. Taylor expanded around inf 14.9

      \[\leadsto \color{blue}{y \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    4. 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)))