Average Error: 37.4 → 25.3
Time: 18.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.360018800503746175981880130102650602316 \cdot 10^{121}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.129132419483062736989901465455124613453 \cdot 10^{141}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{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 -6.360018800503746175981880130102650602316 \cdot 10^{121}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot \left(-x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r41703745 = x;
        double r41703746 = r41703745 * r41703745;
        double r41703747 = y;
        double r41703748 = r41703747 * r41703747;
        double r41703749 = r41703746 + r41703748;
        double r41703750 = z;
        double r41703751 = r41703750 * r41703750;
        double r41703752 = r41703749 + r41703751;
        double r41703753 = 3.0;
        double r41703754 = r41703752 / r41703753;
        double r41703755 = sqrt(r41703754);
        return r41703755;
}

double f(double x, double y, double z) {
        double r41703756 = x;
        double r41703757 = -6.360018800503746e+121;
        bool r41703758 = r41703756 <= r41703757;
        double r41703759 = 0.3333333333333333;
        double r41703760 = sqrt(r41703759);
        double r41703761 = -r41703756;
        double r41703762 = r41703760 * r41703761;
        double r41703763 = 1.1291324194830627e+141;
        bool r41703764 = r41703756 <= r41703763;
        double r41703765 = z;
        double r41703766 = r41703765 * r41703765;
        double r41703767 = y;
        double r41703768 = r41703767 * r41703767;
        double r41703769 = r41703756 * r41703756;
        double r41703770 = r41703768 + r41703769;
        double r41703771 = r41703766 + r41703770;
        double r41703772 = sqrt(r41703771);
        double r41703773 = 3.0;
        double r41703774 = sqrt(r41703773);
        double r41703775 = r41703772 / r41703774;
        double r41703776 = r41703760 * r41703756;
        double r41703777 = r41703764 ? r41703775 : r41703776;
        double r41703778 = r41703758 ? r41703762 : r41703777;
        return r41703778;
}

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.4
Target25.2
Herbie25.3
\[\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 < -6.360018800503746e+121

    1. Initial program 57.2

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

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

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

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

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333148296162562473909929395} \cdot x}\]

    if -6.360018800503746e+121 < x < 1.1291324194830627e+141

    1. Initial program 28.8

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

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

    if 1.1291324194830627e+141 < x

    1. Initial program 61.3

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

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

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

Reproduce

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