Average Error: 37.5 → 23.9
Time: 3.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 3.8686438432293343 \cdot 10^{-231}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 1.671275639876674 \cdot 10^{302}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \cdot x + y \cdot y \le 3.8686438432293343 \cdot 10^{-231}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \cdot x + y \cdot y \le 1.671275639876674 \cdot 10^{302}:\\
\;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r1050849 = x;
        double r1050850 = r1050849 * r1050849;
        double r1050851 = y;
        double r1050852 = r1050851 * r1050851;
        double r1050853 = r1050850 + r1050852;
        double r1050854 = z;
        double r1050855 = r1050854 * r1050854;
        double r1050856 = r1050853 + r1050855;
        double r1050857 = 3.0;
        double r1050858 = r1050856 / r1050857;
        double r1050859 = sqrt(r1050858);
        return r1050859;
}

double f(double x, double y, double z) {
        double r1050860 = x;
        double r1050861 = r1050860 * r1050860;
        double r1050862 = y;
        double r1050863 = r1050862 * r1050862;
        double r1050864 = r1050861 + r1050863;
        double r1050865 = 3.868643843229334e-231;
        bool r1050866 = r1050864 <= r1050865;
        double r1050867 = z;
        double r1050868 = 3.0;
        double r1050869 = sqrt(r1050868);
        double r1050870 = r1050867 / r1050869;
        double r1050871 = fabs(r1050870);
        double r1050872 = 1.6712756398766739e+302;
        bool r1050873 = r1050864 <= r1050872;
        double r1050874 = 0.3333333333333333;
        double r1050875 = 2.0;
        double r1050876 = pow(r1050860, r1050875);
        double r1050877 = pow(r1050862, r1050875);
        double r1050878 = pow(r1050867, r1050875);
        double r1050879 = r1050877 + r1050878;
        double r1050880 = r1050876 + r1050879;
        double r1050881 = r1050874 * r1050880;
        double r1050882 = sqrt(r1050881);
        double r1050883 = -1.0;
        double r1050884 = r1050860 / r1050869;
        double r1050885 = r1050883 * r1050884;
        double r1050886 = fabs(r1050885);
        double r1050887 = r1050873 ? r1050882 : r1050886;
        double r1050888 = r1050866 ? r1050871 : r1050887;
        return r1050888;
}

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.5
Target25.6
Herbie23.9
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (+ (* x x) (* y y)) < 3.868643843229334e-231

    1. Initial program 25.5

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

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

      \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac25.7

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

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

      \[\leadsto \left|\frac{\color{blue}{z}}{\sqrt{3}}\right|\]

    if 3.868643843229334e-231 < (+ (* x x) (* y y)) < 1.6712756398766739e+302

    1. Initial program 15.6

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

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot {x}^{2} + \left(0.333333333333333315 \cdot {y}^{2} + 0.333333333333333315 \cdot {z}^{2}\right)}}\]
    3. Simplified15.6

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}}\]

    if 1.6712756398766739e+302 < (+ (* x x) (* y y))

    1. Initial program 63.3

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied add-sqr-sqrt63.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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac63.3

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

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

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\right|\]
  3. Recombined 3 regimes into one program.
  4. Final simplification23.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 3.8686438432293343 \cdot 10^{-231}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 1.671275639876674 \cdot 10^{302}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

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