Average Error: 37.4 → 25.3
Time: 19.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.360018800503746175981880130102650602316 \cdot 10^{121}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.129132419483062736989901465455124613453 \cdot 10^{141}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -6.360018800503746175981880130102650602316 \cdot 10^{121}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r38728249 = x;
        double r38728250 = r38728249 * r38728249;
        double r38728251 = y;
        double r38728252 = r38728251 * r38728251;
        double r38728253 = r38728250 + r38728252;
        double r38728254 = z;
        double r38728255 = r38728254 * r38728254;
        double r38728256 = r38728253 + r38728255;
        double r38728257 = 3.0;
        double r38728258 = r38728256 / r38728257;
        double r38728259 = sqrt(r38728258);
        return r38728259;
}

double f(double x, double y, double z) {
        double r38728260 = x;
        double r38728261 = -6.360018800503746e+121;
        bool r38728262 = r38728260 <= r38728261;
        double r38728263 = 0.3333333333333333;
        double r38728264 = sqrt(r38728263);
        double r38728265 = -r38728260;
        double r38728266 = r38728264 * r38728265;
        double r38728267 = 1.1291324194830627e+141;
        bool r38728268 = r38728260 <= r38728267;
        double r38728269 = z;
        double r38728270 = r38728269 * r38728269;
        double r38728271 = y;
        double r38728272 = r38728271 * r38728271;
        double r38728273 = r38728260 * r38728260;
        double r38728274 = r38728272 + r38728273;
        double r38728275 = r38728270 + r38728274;
        double r38728276 = sqrt(r38728275);
        double r38728277 = 3.0;
        double r38728278 = sqrt(r38728277);
        double r38728279 = r38728276 / r38728278;
        double r38728280 = r38728264 * r38728260;
        double r38728281 = r38728268 ? r38728279 : r38728280;
        double r38728282 = r38728262 ? r38728266 : r38728281;
        return r38728282;
}

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.4
Target25.2
Herbie25.3
\[\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 < -6.360018800503746e+121

    1. Initial program 57.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv57.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-prod57.2

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

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

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

    if -6.360018800503746e+121 < x < 1.1291324194830627e+141

    1. Initial program 28.8

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

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

    if 1.1291324194830627e+141 < x

    1. Initial program 61.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.360018800503746175981880130102650602316 \cdot 10^{121}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.129132419483062736989901465455124613453 \cdot 10^{141}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

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