Average Error: 37.8 → 26.7
Time: 14.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.394319598461054288703127888846215955555 \cdot 10^{128}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -3.312387562883202246132015611465101507388 \cdot 10^{-69}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -4.600250752436584514345487829187327804588 \cdot 10^{-119}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -5.00023236585558363592745395119684668536 \cdot 10^{-234}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 6.773085673229095399749744186557323924016 \cdot 10^{-289}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.099626361391999452940357963962436180571 \cdot 10^{-36}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.815593598445295857255478843989935605406 \cdot 10^{65}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.776008856932964701291342974326440851158 \cdot 10^{76}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -4.394319598461054288703127888846215955555 \cdot 10^{128}:\\
\;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\

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

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

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

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

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

\mathbf{elif}\;x \le 3.815593598445295857255478843989935605406 \cdot 10^{65}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r549872 = x;
        double r549873 = r549872 * r549872;
        double r549874 = y;
        double r549875 = r549874 * r549874;
        double r549876 = r549873 + r549875;
        double r549877 = z;
        double r549878 = r549877 * r549877;
        double r549879 = r549876 + r549878;
        double r549880 = 3.0;
        double r549881 = r549879 / r549880;
        double r549882 = sqrt(r549881);
        return r549882;
}

double f(double x, double y, double z) {
        double r549883 = x;
        double r549884 = -4.394319598461054e+128;
        bool r549885 = r549883 <= r549884;
        double r549886 = -r549883;
        double r549887 = 3.0;
        double r549888 = sqrt(r549887);
        double r549889 = r549886 / r549888;
        double r549890 = fabs(r549889);
        double r549891 = -3.312387562883202e-69;
        bool r549892 = r549883 <= r549891;
        double r549893 = r549883 * r549883;
        double r549894 = y;
        double r549895 = r549894 * r549894;
        double r549896 = r549893 + r549895;
        double r549897 = z;
        double r549898 = r549897 * r549897;
        double r549899 = r549896 + r549898;
        double r549900 = sqrt(r549899);
        double r549901 = 1.0;
        double r549902 = r549901 / r549887;
        double r549903 = sqrt(r549902);
        double r549904 = r549900 * r549903;
        double r549905 = -4.6002507524365845e-119;
        bool r549906 = r549883 <= r549905;
        double r549907 = r549897 / r549888;
        double r549908 = fabs(r549907);
        double r549909 = -5.0002323658555836e-234;
        bool r549910 = r549883 <= r549909;
        double r549911 = r549900 / r549888;
        double r549912 = fabs(r549911);
        double r549913 = 6.773085673229095e-289;
        bool r549914 = r549883 <= r549913;
        double r549915 = 1.0996263613919995e-36;
        bool r549916 = r549883 <= r549915;
        double r549917 = 3.815593598445296e+65;
        bool r549918 = r549883 <= r549917;
        double r549919 = 1.7760088569329647e+76;
        bool r549920 = r549883 <= r549919;
        double r549921 = r549920 ? r549912 : r549890;
        double r549922 = r549918 ? r549908 : r549921;
        double r549923 = r549916 ? r549904 : r549922;
        double r549924 = r549914 ? r549908 : r549923;
        double r549925 = r549910 ? r549912 : r549924;
        double r549926 = r549906 ? r549908 : r549925;
        double r549927 = r549892 ? r549904 : r549926;
        double r549928 = r549885 ? r549890 : r549927;
        return r549928;
}

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
Herbie26.7
\[\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 4 regimes
  2. if x < -4.394319598461054e+128 or 1.7760088569329647e+76 < x

    1. Initial program 54.6

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

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

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

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

    if -4.394319598461054e+128 < x < -3.312387562883202e-69 or 6.773085673229095e-289 < x < 1.0996263613919995e-36

    1. Initial program 29.2

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

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

    if -3.312387562883202e-69 < x < -4.6002507524365845e-119 or -5.0002323658555836e-234 < x < 6.773085673229095e-289 or 1.0996263613919995e-36 < x < 3.815593598445296e+65

    1. Initial program 28.5

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

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

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

    if -4.6002507524365845e-119 < x < -5.0002323658555836e-234 or 3.815593598445296e+65 < x < 1.7760088569329647e+76

    1. Initial program 29.8

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

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

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification26.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.394319598461054288703127888846215955555 \cdot 10^{128}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -3.312387562883202246132015611465101507388 \cdot 10^{-69}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -4.600250752436584514345487829187327804588 \cdot 10^{-119}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -5.00023236585558363592745395119684668536 \cdot 10^{-234}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 6.773085673229095399749744186557323924016 \cdot 10^{-289}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.099626361391999452940357963962436180571 \cdot 10^{-36}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.815593598445295857255478843989935605406 \cdot 10^{65}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.776008856932964701291342974326440851158 \cdot 10^{76}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

herbie shell --seed 2019212 
(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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3)))