Average Error: 37.7 → 15.7
Time: 11.7s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 9.5571349373151974 \cdot 10^{307}:\\ \;\;\;\;\left|\frac{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \cdot x + y \cdot y \le 9.5571349373151974 \cdot 10^{307}:\\
\;\;\;\;\left|\frac{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}{\sqrt{3}}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r1049756 = x;
        double r1049757 = r1049756 * r1049756;
        double r1049758 = y;
        double r1049759 = r1049758 * r1049758;
        double r1049760 = r1049757 + r1049759;
        double r1049761 = z;
        double r1049762 = r1049761 * r1049761;
        double r1049763 = r1049760 + r1049762;
        double r1049764 = 3.0;
        double r1049765 = r1049763 / r1049764;
        double r1049766 = sqrt(r1049765);
        return r1049766;
}

double f(double x, double y, double z) {
        double r1049767 = x;
        double r1049768 = r1049767 * r1049767;
        double r1049769 = y;
        double r1049770 = r1049769 * r1049769;
        double r1049771 = r1049768 + r1049770;
        double r1049772 = 9.557134937315197e+307;
        bool r1049773 = r1049771 <= r1049772;
        double r1049774 = sqrt(r1049771);
        double r1049775 = z;
        double r1049776 = hypot(r1049774, r1049775);
        double r1049777 = 3.0;
        double r1049778 = sqrt(r1049777);
        double r1049779 = r1049776 / r1049778;
        double r1049780 = fabs(r1049779);
        double r1049781 = -r1049767;
        double r1049782 = r1049781 / r1049778;
        double r1049783 = fabs(r1049782);
        double r1049784 = r1049773 ? r1049780 : r1049783;
        return r1049784;
}

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.7
Target25.8
Herbie15.7
\[\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 2 regimes
  2. if (+ (* x x) (* y y)) < 9.557134937315197e+307

    1. Initial program 17.1

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

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

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

      \[\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. Applied rem-sqrt-square17.3

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt17.3

      \[\leadsto \left|\frac{\sqrt{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} + z \cdot z}}{\sqrt{3}}\right|\]
    9. Applied hypot-def1.4

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

    if 9.557134937315197e+307 < (+ (* x x) (* y y))

    1. Initial program 64.0

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

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

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

      \[\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. Applied rem-sqrt-square64.0

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

      \[\leadsto \left|\frac{\color{blue}{-1 \cdot x}}{\sqrt{3}}\right|\]
    8. Simplified34.0

      \[\leadsto \left|\frac{\color{blue}{-x}}{\sqrt{3}}\right|\]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x + y \cdot y \le 9.5571349373151974 \cdot 10^{307}:\\ \;\;\;\;\left|\frac{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-x}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

herbie shell --seed 2020045 +o rules:numerics
(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)))