Average Error: 37.4 → 25.7
Time: 18.2s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r593345 = x;
        double r593346 = r593345 * r593345;
        double r593347 = y;
        double r593348 = r593347 * r593347;
        double r593349 = r593346 + r593348;
        double r593350 = z;
        double r593351 = r593350 * r593350;
        double r593352 = r593349 + r593351;
        double r593353 = 3.0;
        double r593354 = r593352 / r593353;
        double r593355 = sqrt(r593354);
        return r593355;
}

double f(double x, double y, double z) {
        double r593356 = x;
        double r593357 = -1.472200864118953e+97;
        bool r593358 = r593356 <= r593357;
        double r593359 = 3.0;
        double r593360 = sqrt(r593359);
        double r593361 = r593356 / r593360;
        double r593362 = -r593361;
        double r593363 = 9.739776979507706e+134;
        bool r593364 = r593356 <= r593363;
        double r593365 = r593356 * r593356;
        double r593366 = y;
        double r593367 = r593366 * r593366;
        double r593368 = r593365 + r593367;
        double r593369 = z;
        double r593370 = r593369 * r593369;
        double r593371 = r593368 + r593370;
        double r593372 = sqrt(r593371);
        double r593373 = 1.0;
        double r593374 = r593373 / r593359;
        double r593375 = sqrt(r593374);
        double r593376 = r593372 * r593375;
        double r593377 = 0.3333333333333333;
        double r593378 = sqrt(r593377);
        double r593379 = r593356 * r593378;
        double r593380 = r593364 ? r593376 : r593379;
        double r593381 = r593358 ? r593362 : r593380;
        return r593381;
}

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.4
Target24.9
Herbie25.7
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.472200864118953e+97

    1. Initial program 55.7

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

      \[\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-sqrt55.8

      \[\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-frac55.8

      \[\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. Taylor expanded around -inf 19.9

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\]
    7. Simplified19.9

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

    if -1.472200864118953e+97 < x < 9.739776979507706e+134

    1. Initial program 28.9

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

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

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

    if 9.739776979507706e+134 < x

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

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