Average Error: 37.8 → 27.2
Time: 5.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\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{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\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 -2.016424411749676 \cdot 10^{133}:\\
\;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\

\mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\
\;\;\;\;\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{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

\mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\
\;\;\;\;\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 r959243 = x;
        double r959244 = r959243 * r959243;
        double r959245 = y;
        double r959246 = r959245 * r959245;
        double r959247 = r959244 + r959246;
        double r959248 = z;
        double r959249 = r959248 * r959248;
        double r959250 = r959247 + r959249;
        double r959251 = 3.0;
        double r959252 = r959250 / r959251;
        double r959253 = sqrt(r959252);
        return r959253;
}

double f(double x, double y, double z) {
        double r959254 = x;
        double r959255 = -2.016424411749676e+133;
        bool r959256 = r959254 <= r959255;
        double r959257 = -1.0;
        double r959258 = 3.0;
        double r959259 = sqrt(r959258);
        double r959260 = r959254 / r959259;
        double r959261 = r959257 * r959260;
        double r959262 = 1.4232710093281964e-37;
        bool r959263 = r959254 <= r959262;
        double r959264 = r959254 * r959254;
        double r959265 = y;
        double r959266 = r959265 * r959265;
        double r959267 = r959264 + r959266;
        double r959268 = z;
        double r959269 = r959268 * r959268;
        double r959270 = r959267 + r959269;
        double r959271 = sqrt(r959270);
        double r959272 = r959271 / r959258;
        double r959273 = r959271 * r959272;
        double r959274 = sqrt(r959273);
        double r959275 = 5.4695075101521495e+42;
        bool r959276 = r959254 <= r959275;
        double r959277 = 0.3333333333333333;
        double r959278 = sqrt(r959277);
        double r959279 = r959268 * r959278;
        double r959280 = 1.199826361110612e+75;
        bool r959281 = r959254 <= r959280;
        double r959282 = r959254 * r959278;
        double r959283 = r959281 ? r959274 : r959282;
        double r959284 = r959276 ? r959279 : r959283;
        double r959285 = r959263 ? r959274 : r959284;
        double r959286 = r959256 ? r959261 : r959285;
        return r959286;
}

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.7
Herbie27.2
\[\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 4 regimes
  2. if x < -2.016424411749676e+133

    1. Initial program 59.7

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\]

    if -2.016424411749676e+133 < x < 1.4232710093281964e-37 or 5.4695075101521495e+42 < x < 1.199826361110612e+75

    1. Initial program 29.4

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

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

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

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

      \[\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.4232710093281964e-37 < x < 5.4695075101521495e+42

    1. Initial program 27.8

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

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

    if 1.199826361110612e+75 < x

    1. Initial program 52.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\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{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\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 2020049 
(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)))