Average Error: 37.2 → 25.9
Time: 17.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r567966 = x;
        double r567967 = r567966 * r567966;
        double r567968 = y;
        double r567969 = r567968 * r567968;
        double r567970 = r567967 + r567969;
        double r567971 = z;
        double r567972 = r567971 * r567971;
        double r567973 = r567970 + r567972;
        double r567974 = 3.0;
        double r567975 = r567973 / r567974;
        double r567976 = sqrt(r567975);
        return r567976;
}

double f(double x, double y, double z) {
        double r567977 = x;
        double r567978 = -7.0606062487436015e+50;
        bool r567979 = r567977 <= r567978;
        double r567980 = 0.3333333333333333;
        double r567981 = sqrt(r567980);
        double r567982 = -r567977;
        double r567983 = r567981 * r567982;
        double r567984 = 7.898403675517638e+123;
        bool r567985 = r567977 <= r567984;
        double r567986 = z;
        double r567987 = r567986 * r567986;
        double r567988 = y;
        double r567989 = r567988 * r567988;
        double r567990 = r567977 * r567977;
        double r567991 = r567989 + r567990;
        double r567992 = r567987 + r567991;
        double r567993 = 3.0;
        double r567994 = r567992 / r567993;
        double r567995 = sqrt(r567994);
        double r567996 = r567981 * r567977;
        double r567997 = r567985 ? r567995 : r567996;
        double r567998 = r567979 ? r567983 : r567997;
        return r567998;
}

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.2
Target25.0
Herbie25.9
\[\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 < -7.0606062487436015e+50

    1. Initial program 47.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    3. Simplified22.0

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

    if -7.0606062487436015e+50 < x < 7.898403675517638e+123

    1. Initial program 29.2

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

    if 7.898403675517638e+123 < x

    1. Initial program 58.2

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

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

      \[\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}}}{1 \cdot 3}}\]
    5. Applied times-frac58.2

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

      \[\leadsto \sqrt{\color{blue}{\sqrt{z \cdot z + \left({y}^{2} + x \cdot x\right)}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\]
    7. Simplified58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]

Reproduce

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