Average Error: 38.4 → 25.0
Time: 4.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 2.31575969133539379 \cdot 10^{-234}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 6.707815176943637 \cdot 10^{92}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 3.85879325329768613 \cdot 10^{129}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 2.26629948981050773 \cdot 10^{307}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \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 \cdot x + y \cdot y \le 2.31575969133539379 \cdot 10^{-234}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

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

\mathbf{elif}\;x \cdot x + y \cdot y \le 3.85879325329768613 \cdot 10^{129}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r835827 = x;
        double r835828 = r835827 * r835827;
        double r835829 = y;
        double r835830 = r835829 * r835829;
        double r835831 = r835828 + r835830;
        double r835832 = z;
        double r835833 = r835832 * r835832;
        double r835834 = r835831 + r835833;
        double r835835 = 3.0;
        double r835836 = r835834 / r835835;
        double r835837 = sqrt(r835836);
        return r835837;
}

double f(double x, double y, double z) {
        double r835838 = x;
        double r835839 = r835838 * r835838;
        double r835840 = y;
        double r835841 = r835840 * r835840;
        double r835842 = r835839 + r835841;
        double r835843 = 2.3157596913353938e-234;
        bool r835844 = r835842 <= r835843;
        double r835845 = z;
        double r835846 = 3.0;
        double r835847 = sqrt(r835846);
        double r835848 = r835845 / r835847;
        double r835849 = fabs(r835848);
        double r835850 = 6.707815176943637e+92;
        bool r835851 = r835842 <= r835850;
        double r835852 = r835845 * r835845;
        double r835853 = r835842 + r835852;
        double r835854 = sqrt(r835853);
        double r835855 = 1.0;
        double r835856 = r835855 / r835846;
        double r835857 = sqrt(r835856);
        double r835858 = r835854 * r835857;
        double r835859 = 3.858793253297686e+129;
        bool r835860 = r835842 <= r835859;
        double r835861 = 2.2662994898105077e+307;
        bool r835862 = r835842 <= r835861;
        double r835863 = r835854 / r835847;
        double r835864 = fabs(r835863);
        double r835865 = -1.0;
        double r835866 = r835838 / r835847;
        double r835867 = r835865 * r835866;
        double r835868 = fabs(r835867);
        double r835869 = r835862 ? r835864 : r835868;
        double r835870 = r835860 ? r835849 : r835869;
        double r835871 = r835851 ? r835858 : r835870;
        double r835872 = r835844 ? r835849 : r835871;
        return r835872;
}

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.4
Target26.0
Herbie25.0
\[\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 x) (* y y)) < 2.3157596913353938e-234 or 6.707815176943637e+92 < (+ (* x x) (* y y)) < 3.858793253297686e+129

    1. Initial program 23.9

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

      \[\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-sqrt24.0

      \[\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-frac24.0

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

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

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

    if 2.3157596913353938e-234 < (+ (* x x) (* y y)) < 6.707815176943637e+92

    1. Initial program 15.6

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}}\]
    4. Applied sqrt-prod15.7

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

    if 3.858793253297686e+129 < (+ (* x x) (* y y)) < 2.2662994898105077e+307

    1. Initial program 17.3

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

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

    if 2.2662994898105077e+307 < (+ (* x x) (* y y))

    1. Initial program 63.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 2.31575969133539379 \cdot 10^{-234}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 6.707815176943637 \cdot 10^{92}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 3.85879325329768613 \cdot 10^{129}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \cdot x + y \cdot y \le 2.26629948981050773 \cdot 10^{307}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

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