Average Error: 35.7 → 24.2
Time: 18.7s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}
\begin{array}{l}
\mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\

\mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r40339130 = x;
        double r40339131 = r40339130 * r40339130;
        double r40339132 = y;
        double r40339133 = r40339132 * r40339132;
        double r40339134 = r40339131 + r40339133;
        double r40339135 = z;
        double r40339136 = r40339135 * r40339135;
        double r40339137 = r40339134 + r40339136;
        double r40339138 = 3.0;
        double r40339139 = r40339137 / r40339138;
        double r40339140 = sqrt(r40339139);
        return r40339140;
}

double f(double x, double y, double z) {
        double r40339141 = x;
        double r40339142 = -1.3226326560428921e+154;
        bool r40339143 = r40339141 <= r40339142;
        double r40339144 = 0.3333333333333333;
        double r40339145 = sqrt(r40339144);
        double r40339146 = -r40339141;
        double r40339147 = r40339145 * r40339146;
        double r40339148 = 1.2721613999661422e+154;
        bool r40339149 = r40339141 <= r40339148;
        double r40339150 = z;
        double r40339151 = r40339150 * r40339150;
        double r40339152 = y;
        double r40339153 = r40339152 * r40339152;
        double r40339154 = r40339141 * r40339141;
        double r40339155 = r40339153 + r40339154;
        double r40339156 = r40339151 + r40339155;
        double r40339157 = 3.0;
        double r40339158 = r40339156 / r40339157;
        double r40339159 = sqrt(r40339158);
        double r40339160 = r40339145 * r40339141;
        double r40339161 = r40339149 ? r40339159 : r40339160;
        double r40339162 = r40339143 ? r40339147 : r40339161;
        return r40339162;
}

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

Original35.7
Target24.6
Herbie24.2
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.3226326560428921e+154

    1. Initial program 59.3

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

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

      \[\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}}}{1 \cdot 3.0}}\]
    5. Applied times-frac59.3

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3.0}}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt59.3

      \[\leadsto \sqrt{\frac{\sqrt{\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}}}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3.0}}\]
    8. Applied sqrt-prod59.3

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3.0}}\]
    9. Taylor expanded around -inf 14.7

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
    10. Simplified14.7

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x}\]

    if -1.3226326560428921e+154 < x < 1.2721613999661422e+154

    1. Initial program 27.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]

    if 1.2721613999661422e+154 < x

    1. Initial program 59.3

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.2721613999661422 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

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