Average Error: 38.7 → 25.7
Time: 9.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.4467202670789784 \cdot 10^{138}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le 1.0960437794666031 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.4467202670789784 \cdot 10^{138}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r979252 = x;
        double r979253 = r979252 * r979252;
        double r979254 = y;
        double r979255 = r979254 * r979254;
        double r979256 = r979253 + r979255;
        double r979257 = z;
        double r979258 = r979257 * r979257;
        double r979259 = r979256 + r979258;
        double r979260 = 3.0;
        double r979261 = r979259 / r979260;
        double r979262 = sqrt(r979261);
        return r979262;
}

double f(double x, double y, double z) {
        double r979263 = x;
        double r979264 = -1.4467202670789784e+138;
        bool r979265 = r979263 <= r979264;
        double r979266 = 1.0;
        double r979267 = 3.0;
        double r979268 = cbrt(r979267);
        double r979269 = r979268 * r979268;
        double r979270 = r979266 / r979269;
        double r979271 = sqrt(r979270);
        double r979272 = -1.0;
        double r979273 = r979266 / r979268;
        double r979274 = sqrt(r979273);
        double r979275 = r979274 * r979263;
        double r979276 = r979272 * r979275;
        double r979277 = r979271 * r979276;
        double r979278 = 1.096043779466603e+127;
        bool r979279 = r979263 <= r979278;
        double r979280 = r979263 * r979263;
        double r979281 = y;
        double r979282 = r979281 * r979281;
        double r979283 = r979280 + r979282;
        double r979284 = z;
        double r979285 = r979284 * r979284;
        double r979286 = r979283 + r979285;
        double r979287 = r979286 / r979267;
        double r979288 = sqrt(r979287);
        double r979289 = r979271 * r979275;
        double r979290 = r979279 ? r979288 : r979289;
        double r979291 = r979265 ? r979277 : r979290;
        return r979291;
}

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.7
Target26.3
Herbie25.7
\[\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 < -1.4467202670789784e+138

    1. Initial program 61.0

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    4. Applied *-un-lft-identity61.0

      \[\leadsto \sqrt{\frac{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    5. Applied times-frac61.0

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

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

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

    if -1.4467202670789784e+138 < x < 1.096043779466603e+127

    1. Initial program 29.8

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

    if 1.096043779466603e+127 < x

    1. Initial program 58.4

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    4. Applied *-un-lft-identity58.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.4467202670789784 \cdot 10^{138}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le 1.0960437794666031 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020025 +o rules:numerics
(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)))