Average Error: 38.5 → 27.4
Time: 4.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.187041864145105 \cdot 10^{125}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -1182.041878556847:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le -2.5746552440525236 \cdot 10^{-243}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\ \mathbf{elif}\;z \le 2.3757984146179946 \cdot 10^{152}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -2.187041864145105 \cdot 10^{125}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{elif}\;z \le -1182.041878556847:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;z \le -2.5746552440525236 \cdot 10^{-243}:\\
\;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r820901 = x;
        double r820902 = r820901 * r820901;
        double r820903 = y;
        double r820904 = r820903 * r820903;
        double r820905 = r820902 + r820904;
        double r820906 = z;
        double r820907 = r820906 * r820906;
        double r820908 = r820905 + r820907;
        double r820909 = 3.0;
        double r820910 = r820908 / r820909;
        double r820911 = sqrt(r820910);
        return r820911;
}

double f(double x, double y, double z) {
        double r820912 = z;
        double r820913 = -2.187041864145105e+125;
        bool r820914 = r820912 <= r820913;
        double r820915 = 3.0;
        double r820916 = sqrt(r820915);
        double r820917 = r820912 / r820916;
        double r820918 = fabs(r820917);
        double r820919 = -1182.041878556847;
        bool r820920 = r820912 <= r820919;
        double r820921 = x;
        double r820922 = r820921 * r820921;
        double r820923 = y;
        double r820924 = r820923 * r820923;
        double r820925 = r820922 + r820924;
        double r820926 = r820912 * r820912;
        double r820927 = r820925 + r820926;
        double r820928 = sqrt(r820927);
        double r820929 = 1.0;
        double r820930 = r820929 / r820915;
        double r820931 = sqrt(r820930);
        double r820932 = r820928 * r820931;
        double r820933 = -2.5746552440525236e-243;
        bool r820934 = r820912 <= r820933;
        double r820935 = -1.0;
        double r820936 = sqrt(r820916);
        double r820937 = r820929 / r820936;
        double r820938 = r820921 / r820936;
        double r820939 = r820937 * r820938;
        double r820940 = r820935 * r820939;
        double r820941 = fabs(r820940);
        double r820942 = 2.3757984146179946e+152;
        bool r820943 = r820912 <= r820942;
        double r820944 = r820943 ? r820932 : r820918;
        double r820945 = r820934 ? r820941 : r820944;
        double r820946 = r820920 ? r820932 : r820945;
        double r820947 = r820914 ? r820918 : r820946;
        return r820947;
}

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.5
Target26.3
Herbie27.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 z < -2.187041864145105e+125 or 2.3757984146179946e+152 < z

    1. Initial program 60.5

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

      \[\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-sqrt60.5

      \[\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-frac60.5

      \[\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. Applied rem-sqrt-square60.5

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

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

    if -2.187041864145105e+125 < z < -1182.041878556847 or -2.5746552440525236e-243 < z < 2.3757984146179946e+152

    1. Initial program 30.1

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

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

    if -1182.041878556847 < z < -2.5746552440525236e-243

    1. Initial program 29.5

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

      \[\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-sqrt29.7

      \[\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-frac29.7

      \[\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. Applied rem-sqrt-square29.6

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

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\right|\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt35.2

      \[\leadsto \left|-1 \cdot \frac{x}{\sqrt{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\right|\]
    10. Applied sqrt-prod35.6

      \[\leadsto \left|-1 \cdot \frac{x}{\color{blue}{\sqrt{\sqrt{3}} \cdot \sqrt{\sqrt{3}}}}\right|\]
    11. Applied *-un-lft-identity35.6

      \[\leadsto \left|-1 \cdot \frac{\color{blue}{1 \cdot x}}{\sqrt{\sqrt{3}} \cdot \sqrt{\sqrt{3}}}\right|\]
    12. Applied times-frac35.2

      \[\leadsto \left|-1 \cdot \color{blue}{\left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)}\right|\]
  3. Recombined 3 regimes into one program.
  4. Final simplification27.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.187041864145105 \cdot 10^{125}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -1182.041878556847:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le -2.5746552440525236 \cdot 10^{-243}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\ \mathbf{elif}\;z \le 2.3757984146179946 \cdot 10^{152}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

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