Average Error: 37.7 → 25.1
Time: 20.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{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 -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r43153827 = x;
        double r43153828 = r43153827 * r43153827;
        double r43153829 = y;
        double r43153830 = r43153829 * r43153829;
        double r43153831 = r43153828 + r43153830;
        double r43153832 = z;
        double r43153833 = r43153832 * r43153832;
        double r43153834 = r43153831 + r43153833;
        double r43153835 = 3.0;
        double r43153836 = r43153834 / r43153835;
        double r43153837 = sqrt(r43153836);
        return r43153837;
}

double f(double x, double y, double z) {
        double r43153838 = x;
        double r43153839 = -8.656892189523162e+102;
        bool r43153840 = r43153838 <= r43153839;
        double r43153841 = 0.3333333333333333;
        double r43153842 = sqrt(r43153841);
        double r43153843 = -r43153838;
        double r43153844 = r43153842 * r43153843;
        double r43153845 = 4.471707363468376e+118;
        bool r43153846 = r43153838 <= r43153845;
        double r43153847 = z;
        double r43153848 = r43153847 * r43153847;
        double r43153849 = y;
        double r43153850 = r43153849 * r43153849;
        double r43153851 = r43153838 * r43153838;
        double r43153852 = r43153850 + r43153851;
        double r43153853 = r43153848 + r43153852;
        double r43153854 = 3.0;
        double r43153855 = r43153853 / r43153854;
        double r43153856 = sqrt(r43153855);
        double r43153857 = sqrt(r43153854);
        double r43153858 = r43153838 / r43153857;
        double r43153859 = r43153846 ? r43153856 : r43153858;
        double r43153860 = r43153840 ? r43153844 : r43153859;
        return r43153860;
}

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.5
Herbie25.1
\[\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 < -8.656892189523162e+102

    1. Initial program 55.3

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

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

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

    if -8.656892189523162e+102 < x < 4.471707363468376e+118

    1. Initial program 28.6

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

    if 4.471707363468376e+118 < x

    1. Initial program 57.1

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

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

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

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

Reproduce

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