Average Error: 37.9 → 25.6
Time: 4.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 7.6875795344769699 \cdot 10^{110}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r772914 = x;
        double r772915 = r772914 * r772914;
        double r772916 = y;
        double r772917 = r772916 * r772916;
        double r772918 = r772915 + r772917;
        double r772919 = z;
        double r772920 = r772919 * r772919;
        double r772921 = r772918 + r772920;
        double r772922 = 3.0;
        double r772923 = r772921 / r772922;
        double r772924 = sqrt(r772923);
        return r772924;
}

double f(double x, double y, double z) {
        double r772925 = x;
        double r772926 = -3.694047169561497e+135;
        bool r772927 = r772925 <= r772926;
        double r772928 = -1.0;
        double r772929 = 0.3333333333333333;
        double r772930 = sqrt(r772929);
        double r772931 = r772925 * r772930;
        double r772932 = r772928 * r772931;
        double r772933 = 7.68757953447697e+110;
        bool r772934 = r772925 <= r772933;
        double r772935 = r772925 * r772925;
        double r772936 = y;
        double r772937 = r772936 * r772936;
        double r772938 = r772935 + r772937;
        double r772939 = z;
        double r772940 = r772939 * r772939;
        double r772941 = r772938 + r772940;
        double r772942 = sqrt(r772941);
        double r772943 = 1.0;
        double r772944 = 3.0;
        double r772945 = r772943 / r772944;
        double r772946 = sqrt(r772945);
        double r772947 = r772942 * r772946;
        double r772948 = r772934 ? r772947 : r772931;
        double r772949 = r772927 ? r772932 : r772948;
        return r772949;
}

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.9
Target26.0
Herbie25.6
\[\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 x < -3.694047169561497e+135

    1. Initial program 60.2

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

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

    if -3.694047169561497e+135 < x < 7.68757953447697e+110

    1. Initial program 29.1

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

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

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

    if 7.68757953447697e+110 < x

    1. Initial program 56.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 7.6875795344769699 \cdot 10^{110}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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