Average Error: 34.8 → 23.6
Time: 14.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.1364581299832128 \cdot 10^{+139}:\\ \;\;\;\;-\frac{z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \le 6.472584579521452 \cdot 10^{+153}:\\ \;\;\;\;\sqrt{\left(y \cdot y + x \cdot x\right) + z \cdot z} \cdot \sqrt{\frac{1}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3.0}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}
\begin{array}{l}
\mathbf{if}\;z \le -1.1364581299832128 \cdot 10^{+139}:\\
\;\;\;\;-\frac{z}{\sqrt{3.0}}\\

\mathbf{elif}\;z \le 6.472584579521452 \cdot 10^{+153}:\\
\;\;\;\;\sqrt{\left(y \cdot y + x \cdot x\right) + z \cdot z} \cdot \sqrt{\frac{1}{3.0}}\\

\mathbf{else}:\\
\;\;\;\;\frac{z}{\sqrt{3.0}}\\

\end{array}
double f(double x, double y, double z) {
        double r42302816 = x;
        double r42302817 = r42302816 * r42302816;
        double r42302818 = y;
        double r42302819 = r42302818 * r42302818;
        double r42302820 = r42302817 + r42302819;
        double r42302821 = z;
        double r42302822 = r42302821 * r42302821;
        double r42302823 = r42302820 + r42302822;
        double r42302824 = 3.0;
        double r42302825 = r42302823 / r42302824;
        double r42302826 = sqrt(r42302825);
        return r42302826;
}

double f(double x, double y, double z) {
        double r42302827 = z;
        double r42302828 = -1.1364581299832128e+139;
        bool r42302829 = r42302827 <= r42302828;
        double r42302830 = 3.0;
        double r42302831 = sqrt(r42302830);
        double r42302832 = r42302827 / r42302831;
        double r42302833 = -r42302832;
        double r42302834 = 6.472584579521452e+153;
        bool r42302835 = r42302827 <= r42302834;
        double r42302836 = y;
        double r42302837 = r42302836 * r42302836;
        double r42302838 = x;
        double r42302839 = r42302838 * r42302838;
        double r42302840 = r42302837 + r42302839;
        double r42302841 = r42302827 * r42302827;
        double r42302842 = r42302840 + r42302841;
        double r42302843 = sqrt(r42302842);
        double r42302844 = 1.0;
        double r42302845 = r42302844 / r42302830;
        double r42302846 = sqrt(r42302845);
        double r42302847 = r42302843 * r42302846;
        double r42302848 = r42302835 ? r42302847 : r42302832;
        double r42302849 = r42302829 ? r42302833 : r42302848;
        return r42302849;
}

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

Original34.8
Target23.7
Herbie23.6
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -1.1364581299832128e+139

    1. Initial program 56.5

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

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

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3.0}}}\]
    5. Using strategy rm
    6. Applied sqrt-div56.5

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3.0}}}\]
    7. Applied associate-*r/56.5

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{1}}{\sqrt{3.0}}}\]
    8. Simplified56.5

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

      \[\leadsto \frac{\color{blue}{-1 \cdot z}}{\sqrt{3.0}}\]
    10. Simplified15.3

      \[\leadsto \frac{\color{blue}{-z}}{\sqrt{3.0}}\]

    if -1.1364581299832128e+139 < z < 6.472584579521452e+153

    1. Initial program 26.6

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

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

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

    if 6.472584579521452e+153 < z

    1. Initial program 59.2

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

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

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3.0}}}\]
    5. Using strategy rm
    6. Applied sqrt-div59.2

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3.0}}}\]
    7. Applied associate-*r/59.2

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{1}}{\sqrt{3.0}}}\]
    8. Simplified59.2

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

      \[\leadsto \frac{\color{blue}{z}}{\sqrt{3.0}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification23.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.1364581299832128 \cdot 10^{+139}:\\ \;\;\;\;-\frac{z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \le 6.472584579521452 \cdot 10^{+153}:\\ \;\;\;\;\sqrt{\left(y \cdot y + x \cdot x\right) + z \cdot z} \cdot \sqrt{\frac{1}{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3.0}}\\ \end{array}\]

Reproduce

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