Average Error: 37.8 → 27.7
Time: 4.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.79874432463715116 \cdot 10^{107}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -1.7101058514616343 \cdot 10^{23}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -5.778603750163605 \cdot 10^{-226}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;x \le 4.3684950057415883 \cdot 10^{-21}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 4.8685464842898213 \cdot 10^{107}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.79874432463715116 \cdot 10^{107}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \le -1.7101058514616343 \cdot 10^{23}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \le -5.778603750163605 \cdot 10^{-226}:\\
\;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\

\mathbf{elif}\;x \le 4.3684950057415883 \cdot 10^{-21}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \le 4.8685464842898213 \cdot 10^{107}:\\
\;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\

\mathbf{else}:\\
\;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\

\end{array}
double f(double x, double y, double z) {
        double r814943 = x;
        double r814944 = r814943 * r814943;
        double r814945 = y;
        double r814946 = r814945 * r814945;
        double r814947 = r814944 + r814946;
        double r814948 = z;
        double r814949 = r814948 * r814948;
        double r814950 = r814947 + r814949;
        double r814951 = 3.0;
        double r814952 = r814950 / r814951;
        double r814953 = sqrt(r814952);
        return r814953;
}

double f(double x, double y, double z) {
        double r814954 = x;
        double r814955 = -1.798744324637151e+107;
        bool r814956 = r814954 <= r814955;
        double r814957 = -1.0;
        double r814958 = 3.0;
        double r814959 = sqrt(r814958);
        double r814960 = r814954 / r814959;
        double r814961 = r814957 * r814960;
        double r814962 = fabs(r814961);
        double r814963 = -1.7101058514616343e+23;
        bool r814964 = r814954 <= r814963;
        double r814965 = z;
        double r814966 = r814965 / r814959;
        double r814967 = fabs(r814966);
        double r814968 = -5.778603750163605e-226;
        bool r814969 = r814954 <= r814968;
        double r814970 = 0.3333333333333333;
        double r814971 = r814954 * r814954;
        double r814972 = y;
        double r814973 = r814972 * r814972;
        double r814974 = r814971 + r814973;
        double r814975 = r814965 * r814965;
        double r814976 = r814974 + r814975;
        double r814977 = r814970 * r814976;
        double r814978 = sqrt(r814977);
        double r814979 = 4.368495005741588e-21;
        bool r814980 = r814954 <= r814979;
        double r814981 = 4.868546484289821e+107;
        bool r814982 = r814954 <= r814981;
        double r814983 = 1.0;
        double r814984 = sqrt(r814959);
        double r814985 = r814983 / r814984;
        double r814986 = r814954 / r814984;
        double r814987 = r814985 * r814986;
        double r814988 = r814957 * r814987;
        double r814989 = fabs(r814988);
        double r814990 = r814982 ? r814978 : r814989;
        double r814991 = r814980 ? r814967 : r814990;
        double r814992 = r814969 ? r814978 : r814991;
        double r814993 = r814964 ? r814967 : r814992;
        double r814994 = r814956 ? r814962 : r814993;
        return r814994;
}

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.8
Target25.5
Herbie27.7
\[\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 4 regimes
  2. if x < -1.798744324637151e+107

    1. Initial program 55.4

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt55.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-sqrt55.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-frac55.4

      \[\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-square55.4

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

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\right|\]

    if -1.798744324637151e+107 < x < -1.7101058514616343e+23 or -5.778603750163605e-226 < x < 4.368495005741588e-21

    1. Initial program 29.7

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

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

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

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

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

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

    if -1.7101058514616343e+23 < x < -5.778603750163605e-226 or 4.368495005741588e-21 < x < 4.868546484289821e+107

    1. Initial program 28.7

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

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot {x}^{2} + \left(0.333333333333333315 \cdot {y}^{2} + 0.333333333333333315 \cdot {z}^{2}\right)}}\]
    3. Simplified28.7

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

    if 4.868546484289821e+107 < x

    1. Initial program 55.5

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

      \[\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-sqrt55.6

      \[\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-frac55.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-square55.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 -inf 17.8

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.79874432463715116 \cdot 10^{107}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -1.7101058514616343 \cdot 10^{23}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -5.778603750163605 \cdot 10^{-226}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;x \le 4.3684950057415883 \cdot 10^{-21}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 4.8685464842898213 \cdot 10^{107}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{x}{\sqrt{\sqrt{3}}}\right)\right|\\ \end{array}\]

Reproduce

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