Average Error: 38.0 → 25.9
Time: 3.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.00914210855056183 \cdot 10^{41}:\\ \;\;\;\;\frac{-1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 6.3927424461516727 \cdot 10^{128}:\\ \;\;\;\;\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 -2.00914210855056183 \cdot 10^{41}:\\
\;\;\;\;\frac{-1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\\

\mathbf{elif}\;x \le 6.3927424461516727 \cdot 10^{128}:\\
\;\;\;\;\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 r994700 = x;
        double r994701 = r994700 * r994700;
        double r994702 = y;
        double r994703 = r994702 * r994702;
        double r994704 = r994701 + r994703;
        double r994705 = z;
        double r994706 = r994705 * r994705;
        double r994707 = r994704 + r994706;
        double r994708 = 3.0;
        double r994709 = r994707 / r994708;
        double r994710 = sqrt(r994709);
        return r994710;
}

double f(double x, double y, double z) {
        double r994711 = x;
        double r994712 = -2.009142108550562e+41;
        bool r994713 = r994711 <= r994712;
        double r994714 = -1.0;
        double r994715 = 3.0;
        double r994716 = sqrt(r994715);
        double r994717 = cbrt(r994716);
        double r994718 = r994717 * r994717;
        double r994719 = r994714 / r994718;
        double r994720 = r994711 / r994717;
        double r994721 = r994719 * r994720;
        double r994722 = 6.392742446151673e+128;
        bool r994723 = r994711 <= r994722;
        double r994724 = r994711 * r994711;
        double r994725 = y;
        double r994726 = r994725 * r994725;
        double r994727 = r994724 + r994726;
        double r994728 = z;
        double r994729 = r994728 * r994728;
        double r994730 = r994727 + r994729;
        double r994731 = sqrt(r994730);
        double r994732 = 1.0;
        double r994733 = r994732 / r994715;
        double r994734 = sqrt(r994733);
        double r994735 = r994731 * r994734;
        double r994736 = 0.3333333333333333;
        double r994737 = sqrt(r994736);
        double r994738 = r994711 * r994737;
        double r994739 = r994723 ? r994735 : r994738;
        double r994740 = r994713 ? r994721 : r994739;
        return r994740;
}

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.0
Target26.0
Herbie25.9
\[\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 < -2.009142108550562e+41

    1. Initial program 50.3

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot x}}{\sqrt{3}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt23.1

      \[\leadsto \frac{-1 \cdot x}{\color{blue}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}}\]
    7. Applied times-frac23.1

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

    if -2.009142108550562e+41 < x < 6.392742446151673e+128

    1. Initial program 29.0

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

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

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

    if 6.392742446151673e+128 < x

    1. Initial program 58.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.00914210855056183 \cdot 10^{41}:\\ \;\;\;\;\frac{-1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 6.3927424461516727 \cdot 10^{128}:\\ \;\;\;\;\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 2020062 
(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)))