Average Error: 37.2 → 26.2
Time: 13.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -4.636290233423019225578992902970977131599 \cdot 10^{86}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-y\right)\\ \mathbf{elif}\;y \le -6.50065769373261489118803575957100157732 \cdot 10^{70}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le -1.595389421696917498221625505629493011546 \cdot 10^{-66}:\\ \;\;\;\;\sqrt{\frac{1}{3} \cdot \mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}\\ \mathbf{elif}\;y \le 3.473733918617740311509637678395980100535 \cdot 10^{-147}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 9.09880737550489603575935437091842714316 \cdot 10^{60}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}{3} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot y\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -4.636290233423019225578992902970977131599 \cdot 10^{86}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-y\right)\\

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

\mathbf{elif}\;y \le -1.595389421696917498221625505629493011546 \cdot 10^{-66}:\\
\;\;\;\;\sqrt{\frac{1}{3} \cdot \mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}\\

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

\mathbf{elif}\;y \le 9.09880737550489603575935437091842714316 \cdot 10^{60}:\\
\;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}{3} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r631355 = x;
        double r631356 = r631355 * r631355;
        double r631357 = y;
        double r631358 = r631357 * r631357;
        double r631359 = r631356 + r631358;
        double r631360 = z;
        double r631361 = r631360 * r631360;
        double r631362 = r631359 + r631361;
        double r631363 = 3.0;
        double r631364 = r631362 / r631363;
        double r631365 = sqrt(r631364);
        return r631365;
}

double f(double x, double y, double z) {
        double r631366 = y;
        double r631367 = -4.636290233423019e+86;
        bool r631368 = r631366 <= r631367;
        double r631369 = 0.3333333333333333;
        double r631370 = sqrt(r631369);
        double r631371 = -r631366;
        double r631372 = r631370 * r631371;
        double r631373 = -6.500657693732615e+70;
        bool r631374 = r631366 <= r631373;
        double r631375 = z;
        double r631376 = 3.0;
        double r631377 = sqrt(r631376);
        double r631378 = r631375 / r631377;
        double r631379 = fabs(r631378);
        double r631380 = -1.5953894216969175e-66;
        bool r631381 = r631366 <= r631380;
        double r631382 = 1.0;
        double r631383 = r631382 / r631376;
        double r631384 = x;
        double r631385 = r631384 * r631384;
        double r631386 = fma(r631375, r631375, r631385);
        double r631387 = fma(r631366, r631366, r631386);
        double r631388 = r631383 * r631387;
        double r631389 = sqrt(r631388);
        double r631390 = 3.4737339186177403e-147;
        bool r631391 = r631366 <= r631390;
        double r631392 = 9.098807375504896e+60;
        bool r631393 = r631366 <= r631392;
        double r631394 = sqrt(r631387);
        double r631395 = r631394 / r631376;
        double r631396 = r631395 * r631394;
        double r631397 = sqrt(r631396);
        double r631398 = r631370 * r631366;
        double r631399 = r631393 ? r631397 : r631398;
        double r631400 = r631391 ? r631379 : r631399;
        double r631401 = r631381 ? r631389 : r631400;
        double r631402 = r631374 ? r631379 : r631401;
        double r631403 = r631368 ? r631372 : r631402;
        return r631403;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.2
Target25.0
Herbie26.2
\[\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 < -4.636290233423019e+86

    1. Initial program 52.8

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}{3}}}\]
    3. Taylor expanded around -inf 18.1

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

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

    if -4.636290233423019e+86 < y < -6.500657693732615e+70 or -1.5953894216969175e-66 < y < 3.4737339186177403e-147

    1. Initial program 29.9

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt30.0

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    5. Applied add-sqr-sqrt30.0

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    6. Applied times-frac30.0

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{\sqrt{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square30.0

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

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

    if -6.500657693732615e+70 < y < -1.5953894216969175e-66

    1. Initial program 25.5

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

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

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

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}}{1 \cdot 3}}\]
    6. Applied times-frac25.5

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}}\]
    7. Simplified25.5

      \[\leadsto \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}\]
    8. Simplified25.5

      \[\leadsto \sqrt{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)} \cdot \color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}{3}}}\]
    9. Using strategy rm
    10. Applied div-inv25.6

      \[\leadsto \sqrt{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)} \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)} \cdot \frac{1}{3}\right)}}\]
    11. Applied associate-*r*25.6

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}\right) \cdot \frac{1}{3}}}\]
    12. Simplified25.6

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

    if 3.4737339186177403e-147 < y < 9.098807375504896e+60

    1. Initial program 28.4

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

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

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}{\color{blue}{1 \cdot 3}}}\]
    5. Applied add-sqr-sqrt28.4

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

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}}\]
    7. Simplified28.4

      \[\leadsto \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}\]
    8. Simplified28.4

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

    if 9.098807375504896e+60 < y

    1. Initial program 50.0

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

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

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}{\color{blue}{1 \cdot 3}}}\]
    5. Applied add-sqr-sqrt50.0

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}}{1 \cdot 3}}\]
    6. Applied times-frac50.0

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}}\]
    7. Simplified50.0

      \[\leadsto \sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}} \cdot \frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, z \cdot z\right)\right)}}{3}}\]
    8. Simplified50.0

      \[\leadsto \sqrt{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)} \cdot \color{blue}{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}{3}}}\]
    9. Taylor expanded around inf 21.3

      \[\leadsto \color{blue}{y \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    10. Simplified21.3

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333148296162562473909929395} \cdot y}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification26.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.636290233423019225578992902970977131599 \cdot 10^{86}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-y\right)\\ \mathbf{elif}\;y \le -6.50065769373261489118803575957100157732 \cdot 10^{70}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le -1.595389421696917498221625505629493011546 \cdot 10^{-66}:\\ \;\;\;\;\sqrt{\frac{1}{3} \cdot \mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}\\ \mathbf{elif}\;y \le 3.473733918617740311509637678395980100535 \cdot 10^{-147}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 9.09880737550489603575935437091842714316 \cdot 10^{60}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}{3} \cdot \sqrt{\mathsf{fma}\left(y, y, \mathsf{fma}\left(z, z, x \cdot x\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot y\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(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)))