Average Error: 37.8 → 26.0
Time: 3.7s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{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 -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\

\mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r960121 = x;
        double r960122 = r960121 * r960121;
        double r960123 = y;
        double r960124 = r960123 * r960123;
        double r960125 = r960122 + r960124;
        double r960126 = z;
        double r960127 = r960126 * r960126;
        double r960128 = r960125 + r960127;
        double r960129 = 3.0;
        double r960130 = r960128 / r960129;
        double r960131 = sqrt(r960130);
        return r960131;
}

double f(double x, double y, double z) {
        double r960132 = x;
        double r960133 = -3.5794877859546974e+94;
        bool r960134 = r960132 <= r960133;
        double r960135 = -1.0;
        double r960136 = 0.3333333333333333;
        double r960137 = sqrt(r960136);
        double r960138 = r960132 * r960137;
        double r960139 = r960135 * r960138;
        double r960140 = 6.058132317483692e-184;
        bool r960141 = r960132 <= r960140;
        double r960142 = r960132 * r960132;
        double r960143 = y;
        double r960144 = r960143 * r960143;
        double r960145 = r960142 + r960144;
        double r960146 = z;
        double r960147 = r960146 * r960146;
        double r960148 = r960145 + r960147;
        double r960149 = sqrt(r960148);
        double r960150 = 1.0;
        double r960151 = 3.0;
        double r960152 = r960150 / r960151;
        double r960153 = sqrt(r960152);
        double r960154 = r960149 * r960153;
        double r960155 = 4.463507529461489e-156;
        bool r960156 = r960132 <= r960155;
        double r960157 = sqrt(r960151);
        double r960158 = cbrt(r960157);
        double r960159 = r960158 * r960158;
        double r960160 = r960150 / r960159;
        double r960161 = r960146 / r960158;
        double r960162 = r960160 * r960161;
        double r960163 = 1.3881517315915455e+99;
        bool r960164 = r960132 <= r960163;
        double r960165 = r960149 / r960157;
        double r960166 = r960132 / r960157;
        double r960167 = r960164 ? r960165 : r960166;
        double r960168 = r960156 ? r960162 : r960167;
        double r960169 = r960141 ? r960154 : r960168;
        double r960170 = r960134 ? r960139 : r960169;
        return r960170;
}

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.8
Target25.7
Herbie26.0
\[\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 5 regimes
  2. if x < -3.5794877859546974e+94

    1. Initial program 52.6

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

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

    if -3.5794877859546974e+94 < x < 6.058132317483692e-184

    1. Initial program 30.0

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

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

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

    if 6.058132317483692e-184 < x < 4.463507529461489e-156

    1. Initial program 32.0

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{z}}{\sqrt{3}}\]
    10. Using strategy rm
    11. Applied add-cube-cbrt46.4

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

      \[\leadsto \frac{\color{blue}{1 \cdot z}}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}\]
    13. Applied times-frac46.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}}\]

    if 4.463507529461489e-156 < x < 1.3881517315915455e+99

    1. Initial program 27.3

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

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

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

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

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

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

    if 1.3881517315915455e+99 < x

    1. Initial program 54.4

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]

Reproduce

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