Average Error: 37.7 → 25.5
Time: 41.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\ \;\;\;\;\left(-\sqrt{\sqrt{0.3333333333333333148296162562473909929395}} \cdot x\right) \cdot \sqrt{\sqrt{0.3333333333333333148296162562473909929395}}\\ \mathbf{elif}\;x \le 9.445373192608023995102518569819932542768 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)}}{\sqrt[3]{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 -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\
\;\;\;\;\left(-\sqrt{\sqrt{0.3333333333333333148296162562473909929395}} \cdot x\right) \cdot \sqrt{\sqrt{0.3333333333333333148296162562473909929395}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r37852987 = x;
        double r37852988 = r37852987 * r37852987;
        double r37852989 = y;
        double r37852990 = r37852989 * r37852989;
        double r37852991 = r37852988 + r37852990;
        double r37852992 = z;
        double r37852993 = r37852992 * r37852992;
        double r37852994 = r37852991 + r37852993;
        double r37852995 = 3.0;
        double r37852996 = r37852994 / r37852995;
        double r37852997 = sqrt(r37852996);
        return r37852997;
}

double f(double x, double y, double z) {
        double r37852998 = x;
        double r37852999 = -2.114597052343944e+96;
        bool r37853000 = r37852998 <= r37852999;
        double r37853001 = 0.3333333333333333;
        double r37853002 = sqrt(r37853001);
        double r37853003 = sqrt(r37853002);
        double r37853004 = r37853003 * r37852998;
        double r37853005 = -r37853004;
        double r37853006 = r37853005 * r37853003;
        double r37853007 = 9.445373192608024e+93;
        bool r37853008 = r37852998 <= r37853007;
        double r37853009 = y;
        double r37853010 = z;
        double r37853011 = r37853010 * r37853010;
        double r37853012 = fma(r37853009, r37853009, r37853011);
        double r37853013 = fma(r37852998, r37852998, r37853012);
        double r37853014 = sqrt(r37853013);
        double r37853015 = 3.0;
        double r37853016 = cbrt(r37853015);
        double r37853017 = r37853016 * r37853016;
        double r37853018 = r37853014 / r37853017;
        double r37853019 = r37853014 / r37853016;
        double r37853020 = r37853018 * r37853019;
        double r37853021 = sqrt(r37853020);
        double r37853022 = r37853002 * r37852998;
        double r37853023 = r37853008 ? r37853021 : r37853022;
        double r37853024 = r37853000 ? r37853006 : r37853023;
        return r37853024;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.7
Target26.0
Herbie25.5
\[\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 < -2.114597052343944e+96

    1. Initial program 54.0

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt18.1

      \[\leadsto \left(-x\right) \cdot \sqrt{\color{blue}{\sqrt{0.3333333333333333148296162562473909929395} \cdot \sqrt{0.3333333333333333148296162562473909929395}}}\]
    11. Applied sqrt-prod18.1

      \[\leadsto \left(-x\right) \cdot \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333148296162562473909929395}} \cdot \sqrt{\sqrt{0.3333333333333333148296162562473909929395}}\right)}\]
    12. Applied associate-*r*18.0

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

    if -2.114597052343944e+96 < x < 9.445373192608024e+93

    1. Initial program 29.3

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

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

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

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

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

    if 9.445373192608024e+93 < x

    1. Initial program 53.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\ \;\;\;\;\left(-\sqrt{\sqrt{0.3333333333333333148296162562473909929395}} \cdot x\right) \cdot \sqrt{\sqrt{0.3333333333333333148296162562473909929395}}\\ \mathbf{elif}\;x \le 9.445373192608023995102518569819932542768 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)}}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019200 +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)))