Average Error: 38.5 → 25.7
Time: 12.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.344189575344254982519991103329315240932 \cdot 10^{116}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 1.038735686858710929062176730744016244556 \cdot 10^{130}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.344189575344254982519991103329315240932 \cdot 10^{116}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r629517 = x;
        double r629518 = r629517 * r629517;
        double r629519 = y;
        double r629520 = r629519 * r629519;
        double r629521 = r629518 + r629520;
        double r629522 = z;
        double r629523 = r629522 * r629522;
        double r629524 = r629521 + r629523;
        double r629525 = 3.0;
        double r629526 = r629524 / r629525;
        double r629527 = sqrt(r629526);
        return r629527;
}

double f(double x, double y, double z) {
        double r629528 = x;
        double r629529 = -2.344189575344255e+116;
        bool r629530 = r629528 <= r629529;
        double r629531 = -1.0;
        double r629532 = r629531 * r629528;
        double r629533 = 1.0;
        double r629534 = 3.0;
        double r629535 = r629533 / r629534;
        double r629536 = sqrt(r629535);
        double r629537 = r629532 * r629536;
        double r629538 = 1.0387356868587109e+130;
        bool r629539 = r629528 <= r629538;
        double r629540 = r629528 * r629528;
        double r629541 = y;
        double r629542 = r629541 * r629541;
        double r629543 = r629540 + r629542;
        double r629544 = z;
        double r629545 = r629544 * r629544;
        double r629546 = r629543 + r629545;
        double r629547 = r629546 / r629534;
        double r629548 = sqrt(r629547);
        double r629549 = sqrt(r629534);
        double r629550 = r629528 / r629549;
        double r629551 = r629539 ? r629548 : r629550;
        double r629552 = r629530 ? r629537 : r629551;
        return r629552;
}

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.5
Target26.1
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 < -2.344189575344255e+116

    1. Initial program 56.6

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

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

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

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

    if -2.344189575344255e+116 < x < 1.0387356868587109e+130

    1. Initial program 29.9

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

    if 1.0387356868587109e+130 < x

    1. Initial program 59.1

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied associate-/r*59.1

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

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

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

Reproduce

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