Average Error: 37.9 → 25.6
Time: 3.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.60009329042165313 \cdot 10^{97}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 1.41036131757970017 \cdot 10^{125}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{\frac{1}{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -6.60009329042165313 \cdot 10^{97}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

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

\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{\frac{1}{3}}\\

\end{array}
double f(double x, double y, double z) {
        double r1369375 = x;
        double r1369376 = r1369375 * r1369375;
        double r1369377 = y;
        double r1369378 = r1369377 * r1369377;
        double r1369379 = r1369376 + r1369378;
        double r1369380 = z;
        double r1369381 = r1369380 * r1369380;
        double r1369382 = r1369379 + r1369381;
        double r1369383 = 3.0;
        double r1369384 = r1369382 / r1369383;
        double r1369385 = sqrt(r1369384);
        return r1369385;
}

double f(double x, double y, double z) {
        double r1369386 = x;
        double r1369387 = -6.600093290421653e+97;
        bool r1369388 = r1369386 <= r1369387;
        double r1369389 = -1.0;
        double r1369390 = r1369389 * r1369386;
        double r1369391 = 1.0;
        double r1369392 = 3.0;
        double r1369393 = r1369391 / r1369392;
        double r1369394 = sqrt(r1369393);
        double r1369395 = r1369390 * r1369394;
        double r1369396 = 1.4103613175797002e+125;
        bool r1369397 = r1369386 <= r1369396;
        double r1369398 = r1369386 * r1369386;
        double r1369399 = y;
        double r1369400 = r1369399 * r1369399;
        double r1369401 = r1369398 + r1369400;
        double r1369402 = z;
        double r1369403 = r1369402 * r1369402;
        double r1369404 = r1369401 + r1369403;
        double r1369405 = sqrt(r1369404);
        double r1369406 = r1369405 * r1369394;
        double r1369407 = r1369386 * r1369394;
        double r1369408 = r1369397 ? r1369406 : r1369407;
        double r1369409 = r1369388 ? r1369395 : r1369408;
        return r1369409;
}

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
Target25.9
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 < -6.600093290421653e+97

    1. Initial program 54.3

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

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

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

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

    if -6.600093290421653e+97 < x < 1.4103613175797002e+125

    1. Initial program 29.2

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

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

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

    if 1.4103613175797002e+125 < 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 div-inv58.4

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

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

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

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

Reproduce

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