Average Error: 38.1 → 25.9
Time: 5.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.89558649116172909 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\ \;\;\;\;\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 -1.89558649116172909 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

\mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\
\;\;\;\;\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 r958966 = x;
        double r958967 = r958966 * r958966;
        double r958968 = y;
        double r958969 = r958968 * r958968;
        double r958970 = r958967 + r958969;
        double r958971 = z;
        double r958972 = r958971 * r958971;
        double r958973 = r958970 + r958972;
        double r958974 = 3.0;
        double r958975 = r958973 / r958974;
        double r958976 = sqrt(r958975);
        return r958976;
}

double f(double x, double y, double z) {
        double r958977 = x;
        double r958978 = -1.895586491161729e+137;
        bool r958979 = r958977 <= r958978;
        double r958980 = -1.0;
        double r958981 = 0.3333333333333333;
        double r958982 = sqrt(r958981);
        double r958983 = r958977 * r958982;
        double r958984 = r958980 * r958983;
        double r958985 = 7.792733426685086e+150;
        bool r958986 = r958977 <= r958985;
        double r958987 = r958977 * r958977;
        double r958988 = y;
        double r958989 = r958988 * r958988;
        double r958990 = r958987 + r958989;
        double r958991 = z;
        double r958992 = r958991 * r958991;
        double r958993 = r958990 + r958992;
        double r958994 = 3.0;
        double r958995 = r958993 / r958994;
        double r958996 = sqrt(r958995);
        double r958997 = sqrt(r958994);
        double r958998 = r958977 / r958997;
        double r958999 = r958986 ? r958996 : r958998;
        double r959000 = r958979 ? r958984 : r958999;
        return r959000;
}

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.1
Target25.6
Herbie25.9
\[\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 < -1.895586491161729e+137

    1. Initial program 60.9

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Taylor expanded around -inf 16.0

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

    if -1.895586491161729e+137 < x < 7.792733426685086e+150

    1. Initial program 29.5

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

    if 7.792733426685086e+150 < x

    1. Initial program 63.3

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.89558649116172909 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\ \;\;\;\;\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 2020027 
(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)))