Average Error: 38.2 → 25.4
Time: 10.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.51459440820440755 \cdot 10^{142}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 5.8594097784833193 \cdot 10^{97}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{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 -7.51459440820440755 \cdot 10^{142}:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r1488192 = x;
        double r1488193 = r1488192 * r1488192;
        double r1488194 = y;
        double r1488195 = r1488194 * r1488194;
        double r1488196 = r1488193 + r1488195;
        double r1488197 = z;
        double r1488198 = r1488197 * r1488197;
        double r1488199 = r1488196 + r1488198;
        double r1488200 = 3.0;
        double r1488201 = r1488199 / r1488200;
        double r1488202 = sqrt(r1488201);
        return r1488202;
}

double f(double x, double y, double z) {
        double r1488203 = x;
        double r1488204 = -7.514594408204408e+142;
        bool r1488205 = r1488203 <= r1488204;
        double r1488206 = 3.0;
        double r1488207 = sqrt(r1488206);
        double r1488208 = r1488203 / r1488207;
        double r1488209 = -r1488208;
        double r1488210 = 5.859409778483319e+97;
        bool r1488211 = r1488203 <= r1488210;
        double r1488212 = r1488203 * r1488203;
        double r1488213 = y;
        double r1488214 = r1488213 * r1488213;
        double r1488215 = r1488212 + r1488214;
        double r1488216 = z;
        double r1488217 = r1488216 * r1488216;
        double r1488218 = r1488215 + r1488217;
        double r1488219 = sqrt(r1488218);
        double r1488220 = 1.0;
        double r1488221 = r1488220 / r1488206;
        double r1488222 = sqrt(r1488221);
        double r1488223 = r1488219 * r1488222;
        double r1488224 = 0.3333333333333333;
        double r1488225 = sqrt(r1488224);
        double r1488226 = r1488203 * r1488225;
        double r1488227 = r1488211 ? r1488223 : r1488226;
        double r1488228 = r1488205 ? r1488209 : r1488227;
        return r1488228;
}

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.2
Target26.1
Herbie25.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 < -7.514594408204408e+142

    1. Initial program 61.4

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

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

      \[\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. Taylor expanded around -inf 14.1

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

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

    if -7.514594408204408e+142 < x < 5.859409778483319e+97

    1. Initial program 29.2

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

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

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

    if 5.859409778483319e+97 < x

    1. Initial program 54.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.51459440820440755 \cdot 10^{142}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 5.8594097784833193 \cdot 10^{97}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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