Average Error: 38.1 → 26.0
Time: 14.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -8.482917924797483679712647688226368282521 \cdot 10^{119}:\\ \;\;\;\;y \cdot \left(-\sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;y \le -1.641898882548598243013797171058025073649 \cdot 10^{-140}:\\ \;\;\;\;\left|\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 1.905941665788049680441607306162017688087 \cdot 10^{-142}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 3.650529274743424126022624456719780516428 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left({y}^{2} + z \cdot z\right) + x \cdot x} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-y}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -8.482917924797483679712647688226368282521 \cdot 10^{119}:\\
\;\;\;\;y \cdot \left(-\sqrt{0.3333333333333333148296162562473909929395}\right)\\

\mathbf{elif}\;y \le -1.641898882548598243013797171058025073649 \cdot 10^{-140}:\\
\;\;\;\;\left|\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\right|\\

\mathbf{elif}\;y \le 1.905941665788049680441607306162017688087 \cdot 10^{-142}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{-y}{\sqrt{3}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r567376 = x;
        double r567377 = r567376 * r567376;
        double r567378 = y;
        double r567379 = r567378 * r567378;
        double r567380 = r567377 + r567379;
        double r567381 = z;
        double r567382 = r567381 * r567381;
        double r567383 = r567380 + r567382;
        double r567384 = 3.0;
        double r567385 = r567383 / r567384;
        double r567386 = sqrt(r567385);
        return r567386;
}

double f(double x, double y, double z) {
        double r567387 = y;
        double r567388 = -8.482917924797484e+119;
        bool r567389 = r567387 <= r567388;
        double r567390 = 0.3333333333333333;
        double r567391 = sqrt(r567390);
        double r567392 = -r567391;
        double r567393 = r567387 * r567392;
        double r567394 = -1.6418988825485982e-140;
        bool r567395 = r567387 <= r567394;
        double r567396 = z;
        double r567397 = r567396 * r567396;
        double r567398 = x;
        double r567399 = r567398 * r567398;
        double r567400 = r567397 + r567399;
        double r567401 = r567387 * r567387;
        double r567402 = r567400 + r567401;
        double r567403 = sqrt(r567402);
        double r567404 = 3.0;
        double r567405 = sqrt(r567404);
        double r567406 = r567403 / r567405;
        double r567407 = fabs(r567406);
        double r567408 = 1.9059416657880497e-142;
        bool r567409 = r567387 <= r567408;
        double r567410 = r567396 / r567405;
        double r567411 = fabs(r567410);
        double r567412 = 3.650529274743424e+93;
        bool r567413 = r567387 <= r567412;
        double r567414 = 2.0;
        double r567415 = pow(r567387, r567414);
        double r567416 = r567415 + r567397;
        double r567417 = r567416 + r567399;
        double r567418 = sqrt(r567417);
        double r567419 = 1.0;
        double r567420 = r567419 / r567404;
        double r567421 = sqrt(r567420);
        double r567422 = r567418 * r567421;
        double r567423 = -r567387;
        double r567424 = r567423 / r567405;
        double r567425 = fabs(r567424);
        double r567426 = r567413 ? r567422 : r567425;
        double r567427 = r567409 ? r567411 : r567426;
        double r567428 = r567395 ? r567407 : r567427;
        double r567429 = r567389 ? r567393 : r567428;
        return r567429;
}

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.1
Target25.4
Herbie26.0
\[\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 5 regimes
  2. if y < -8.482917924797484e+119

    1. Initial program 58.3

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified58.3

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{\sqrt{\left({y}^{2} + z \cdot z\right) + x \cdot x}}} \cdot \sqrt{\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{3}}\]
    9. Simplified58.4

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    11. Simplified18.5

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

    if -8.482917924797484e+119 < y < -1.6418988825485982e-140

    1. Initial program 28.5

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified28.5

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt28.6

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

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

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

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

    if -1.6418988825485982e-140 < y < 1.9059416657880497e-142

    1. Initial program 31.4

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified31.4

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt31.6

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}} \cdot \frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square31.5

      \[\leadsto \color{blue}{\left|\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}\right|}\]
    8. Taylor expanded around 0 31.3

      \[\leadsto \left|\frac{\color{blue}{z}}{\sqrt{3}}\right|\]

    if 1.9059416657880497e-142 < y < 3.650529274743424e+93

    1. Initial program 27.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified27.8

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied div-inv27.9

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

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

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

    if 3.650529274743424e+93 < y

    1. Initial program 53.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified53.8

      \[\leadsto \color{blue}{\sqrt{\frac{y \cdot y + \left(x \cdot x + z \cdot z\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt53.9

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}} \cdot \frac{\sqrt{y \cdot y + \left(x \cdot x + z \cdot z\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square53.8

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

      \[\leadsto \left|\frac{\color{blue}{-1 \cdot y}}{\sqrt{3}}\right|\]
    9. Simplified19.2

      \[\leadsto \left|\frac{\color{blue}{-y}}{\sqrt{3}}\right|\]
  3. Recombined 5 regimes into one program.
  4. Final simplification26.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.482917924797483679712647688226368282521 \cdot 10^{119}:\\ \;\;\;\;y \cdot \left(-\sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;y \le -1.641898882548598243013797171058025073649 \cdot 10^{-140}:\\ \;\;\;\;\left|\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 1.905941665788049680441607306162017688087 \cdot 10^{-142}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 3.650529274743424126022624456719780516428 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left({y}^{2} + z \cdot z\right) + x \cdot x} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-y}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

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