Average Error: 38.2 → 25.4
Time: 13.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.51459440820440755 \cdot 10^{142}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 5.8594097784833193 \cdot 10^{97}:\\ \;\;\;\;\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 -7.51459440820440755 \cdot 10^{142}:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

\mathbf{elif}\;x \le 5.8594097784833193 \cdot 10^{97}:\\
\;\;\;\;\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 r913380 = x;
        double r913381 = r913380 * r913380;
        double r913382 = y;
        double r913383 = r913382 * r913382;
        double r913384 = r913381 + r913383;
        double r913385 = z;
        double r913386 = r913385 * r913385;
        double r913387 = r913384 + r913386;
        double r913388 = 3.0;
        double r913389 = r913387 / r913388;
        double r913390 = sqrt(r913389);
        return r913390;
}

double f(double x, double y, double z) {
        double r913391 = x;
        double r913392 = -7.514594408204408e+142;
        bool r913393 = r913391 <= r913392;
        double r913394 = 3.0;
        double r913395 = sqrt(r913394);
        double r913396 = r913391 / r913395;
        double r913397 = -r913396;
        double r913398 = 5.859409778483319e+97;
        bool r913399 = r913391 <= r913398;
        double r913400 = r913391 * r913391;
        double r913401 = y;
        double r913402 = r913401 * r913401;
        double r913403 = r913400 + r913402;
        double r913404 = z;
        double r913405 = r913404 * r913404;
        double r913406 = r913403 + r913405;
        double r913407 = sqrt(r913406);
        double r913408 = 1.0;
        double r913409 = r913408 / r913394;
        double r913410 = sqrt(r913409);
        double r913411 = r913407 * r913410;
        double r913412 = r913391 * r913410;
        double r913413 = r913399 ? r913411 : r913412;
        double r913414 = r913393 ? r913397 : r913413;
        return r913414;
}

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.2
Target26.1
Herbie25.4
\[\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 < -7.514594408204408e+142

    1. Initial program 61.4

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

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

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

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

    if -7.514594408204408e+142 < x < 5.859409778483319e+97

    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.2

      \[\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 5.859409778483319e+97 < x

    1. Initial program 54.9

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv54.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-prod54.9

      \[\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 19.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.51459440820440755 \cdot 10^{142}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 5.8594097784833193 \cdot 10^{97}:\\ \;\;\;\;\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 2020047 
(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)))