Average Error: 38.2 → 25.5
Time: 14.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.942680527553483193495594945411872245454 \cdot 10^{151}:\\ \;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;y \le 6.557174003264763770996525885584065399587 \cdot 10^{116}:\\ \;\;\;\;\sqrt{\frac{1}{3} \cdot \left(\left(z \cdot z + x \cdot x\right) + y \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot y\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -2.942680527553483193495594945411872245454 \cdot 10^{151}:\\
\;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r663599 = x;
        double r663600 = r663599 * r663599;
        double r663601 = y;
        double r663602 = r663601 * r663601;
        double r663603 = r663600 + r663602;
        double r663604 = z;
        double r663605 = r663604 * r663604;
        double r663606 = r663603 + r663605;
        double r663607 = 3.0;
        double r663608 = r663606 / r663607;
        double r663609 = sqrt(r663608);
        return r663609;
}

double f(double x, double y, double z) {
        double r663610 = y;
        double r663611 = -2.942680527553483e+151;
        bool r663612 = r663610 <= r663611;
        double r663613 = -r663610;
        double r663614 = 0.3333333333333333;
        double r663615 = sqrt(r663614);
        double r663616 = r663613 * r663615;
        double r663617 = 6.557174003264764e+116;
        bool r663618 = r663610 <= r663617;
        double r663619 = 1.0;
        double r663620 = 3.0;
        double r663621 = r663619 / r663620;
        double r663622 = z;
        double r663623 = r663622 * r663622;
        double r663624 = x;
        double r663625 = r663624 * r663624;
        double r663626 = r663623 + r663625;
        double r663627 = r663610 * r663610;
        double r663628 = r663626 + r663627;
        double r663629 = r663621 * r663628;
        double r663630 = sqrt(r663629);
        double r663631 = r663615 * r663610;
        double r663632 = r663618 ? r663630 : r663631;
        double r663633 = r663612 ? r663616 : r663632;
        return r663633;
}

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
Target25.9
Herbie25.5
\[\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 y < -2.942680527553483e+151

    1. Initial program 63.1

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    4. Simplified13.6

      \[\leadsto \color{blue}{\left(-y\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if -2.942680527553483e+151 < y < 6.557174003264764e+116

    1. Initial program 29.7

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

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

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

    if 6.557174003264764e+116 < y

    1. Initial program 56.2

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

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

      \[\leadsto \color{blue}{y \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
    4. Simplified16.4

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

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

Reproduce

herbie shell --seed 2019174 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

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