Average Error: 38.5 → 25.7
Time: 5.3s
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}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\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{\frac{1}{3}}\\ \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}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\

\mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\
\;\;\;\;\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{\frac{1}{3}}\\

\end{array}
double f(double x, double y, double z) {
        double r842896 = x;
        double r842897 = r842896 * r842896;
        double r842898 = y;
        double r842899 = r842898 * r842898;
        double r842900 = r842897 + r842899;
        double r842901 = z;
        double r842902 = r842901 * r842901;
        double r842903 = r842900 + r842902;
        double r842904 = 3.0;
        double r842905 = r842903 / r842904;
        double r842906 = sqrt(r842905);
        return r842906;
}

double f(double x, double y, double z) {
        double r842907 = x;
        double r842908 = -2.8004366194075308e+135;
        bool r842909 = r842907 <= r842908;
        double r842910 = -1.0;
        double r842911 = 0.3333333333333333;
        double r842912 = sqrt(r842911);
        double r842913 = r842907 * r842912;
        double r842914 = r842910 * r842913;
        double r842915 = 2.2733836340085665e+132;
        bool r842916 = r842907 <= r842915;
        double r842917 = r842907 * r842907;
        double r842918 = y;
        double r842919 = r842918 * r842918;
        double r842920 = r842917 + r842919;
        double r842921 = z;
        double r842922 = r842921 * r842921;
        double r842923 = r842920 + r842922;
        double r842924 = sqrt(r842923);
        double r842925 = 3.0;
        double r842926 = r842924 / r842925;
        double r842927 = r842924 * r842926;
        double r842928 = sqrt(r842927);
        double r842929 = 1.0;
        double r842930 = r842929 / r842925;
        double r842931 = sqrt(r842930);
        double r842932 = r842907 * r842931;
        double r842933 = r842916 ? r842928 : r842932;
        double r842934 = r842909 ? r842914 : r842933;
        return r842934;
}

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

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

    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 *-un-lft-identity29.6

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

      \[\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.7

      \[\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 2.2733836340085665e+132 < x

    1. Initial program 59.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.800436619407530802706838305298910062354 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\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{\frac{1}{3}}\\ \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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

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