Average Error: 38.4 → 26.4
Time: 12.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.35612836383285588 \cdot 10^{108}:\\ \;\;\;\;-x \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.35612836383285588 \cdot 10^{108}:\\
\;\;\;\;-x \cdot \sqrt{0.333333333333333315}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r1041867 = x;
        double r1041868 = r1041867 * r1041867;
        double r1041869 = y;
        double r1041870 = r1041869 * r1041869;
        double r1041871 = r1041868 + r1041870;
        double r1041872 = z;
        double r1041873 = r1041872 * r1041872;
        double r1041874 = r1041871 + r1041873;
        double r1041875 = 3.0;
        double r1041876 = r1041874 / r1041875;
        double r1041877 = sqrt(r1041876);
        return r1041877;
}

double f(double x, double y, double z) {
        double r1041878 = x;
        double r1041879 = -1.356128363832856e+108;
        bool r1041880 = r1041878 <= r1041879;
        double r1041881 = 0.3333333333333333;
        double r1041882 = sqrt(r1041881);
        double r1041883 = r1041878 * r1041882;
        double r1041884 = -r1041883;
        double r1041885 = 1.0479353069555717e+77;
        bool r1041886 = r1041878 <= r1041885;
        double r1041887 = r1041878 * r1041878;
        double r1041888 = y;
        double r1041889 = r1041888 * r1041888;
        double r1041890 = r1041887 + r1041889;
        double r1041891 = z;
        double r1041892 = r1041891 * r1041891;
        double r1041893 = r1041890 + r1041892;
        double r1041894 = sqrt(r1041893);
        double r1041895 = 3.0;
        double r1041896 = r1041894 / r1041895;
        double r1041897 = r1041894 * r1041896;
        double r1041898 = sqrt(r1041897);
        double r1041899 = r1041886 ? r1041898 : r1041883;
        double r1041900 = r1041880 ? r1041884 : r1041899;
        return r1041900;
}

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.4
Target25.9
Herbie26.4
\[\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 < -1.356128363832856e+108

    1. Initial program 55.4

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)}\]
    3. Simplified18.6

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

    if -1.356128363832856e+108 < x < 1.0479353069555717e+77

    1. Initial program 29.9

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

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

      \[\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}}}\]
    6. Simplified29.9

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

    if 1.0479353069555717e+77 < x

    1. Initial program 53.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.35612836383285588 \cdot 10^{108}:\\ \;\;\;\;-x \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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