Average Error: 37.3 → 25.7
Time: 13.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -5.008523466085166042269104572011026767694 \cdot 10^{110}:\\ \;\;\;\;\left|\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{y}{\sqrt{\sqrt{3}}}\right|\\ \mathbf{elif}\;y \le -1.232494092266792303298507831851883710859 \cdot 10^{-182}:\\ \;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le -1.792108602367511563107867303346475363755 \cdot 10^{-274}:\\ \;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 7.254479271513616272173912934899302783245 \cdot 10^{-209}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;y \le 6.697712028762041216512495239807927468844 \cdot 10^{-123}:\\ \;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 1.380374117965492703314427996253896487757 \cdot 10^{79}:\\ \;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{y}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -5.008523466085166042269104572011026767694 \cdot 10^{110}:\\
\;\;\;\;\left|\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{y}{\sqrt{\sqrt{3}}}\right|\\

\mathbf{elif}\;y \le -1.232494092266792303298507831851883710859 \cdot 10^{-182}:\\
\;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\

\mathbf{elif}\;y \le -1.792108602367511563107867303346475363755 \cdot 10^{-274}:\\
\;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\

\mathbf{elif}\;y \le 7.254479271513616272173912934899302783245 \cdot 10^{-209}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;y \le 6.697712028762041216512495239807927468844 \cdot 10^{-123}:\\
\;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\

\mathbf{elif}\;y \le 1.380374117965492703314427996253896487757 \cdot 10^{79}:\\
\;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\frac{y}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r537142 = x;
        double r537143 = r537142 * r537142;
        double r537144 = y;
        double r537145 = r537144 * r537144;
        double r537146 = r537143 + r537145;
        double r537147 = z;
        double r537148 = r537147 * r537147;
        double r537149 = r537146 + r537148;
        double r537150 = 3.0;
        double r537151 = r537149 / r537150;
        double r537152 = sqrt(r537151);
        return r537152;
}

double f(double x, double y, double z) {
        double r537153 = y;
        double r537154 = -5.008523466085166e+110;
        bool r537155 = r537153 <= r537154;
        double r537156 = 1.0;
        double r537157 = 3.0;
        double r537158 = sqrt(r537157);
        double r537159 = sqrt(r537158);
        double r537160 = r537156 / r537159;
        double r537161 = r537153 / r537159;
        double r537162 = r537160 * r537161;
        double r537163 = fabs(r537162);
        double r537164 = -1.2324940922667923e-182;
        bool r537165 = r537153 <= r537164;
        double r537166 = z;
        double r537167 = x;
        double r537168 = r537153 * r537153;
        double r537169 = fma(r537167, r537167, r537168);
        double r537170 = fma(r537166, r537166, r537169);
        double r537171 = sqrt(r537170);
        double r537172 = r537171 / r537158;
        double r537173 = fabs(r537172);
        double r537174 = -1.7921086023675116e-274;
        bool r537175 = r537153 <= r537174;
        double r537176 = -r537166;
        double r537177 = r537176 / r537158;
        double r537178 = fabs(r537177);
        double r537179 = 7.254479271513616e-209;
        bool r537180 = r537153 <= r537179;
        double r537181 = r537156 / r537157;
        double r537182 = sqrt(r537181);
        double r537183 = r537171 * r537182;
        double r537184 = 6.697712028762041e-123;
        bool r537185 = r537153 <= r537184;
        double r537186 = 1.3803741179654927e+79;
        bool r537187 = r537153 <= r537186;
        double r537188 = cbrt(r537157);
        double r537189 = fabs(r537188);
        double r537190 = r537153 / r537189;
        double r537191 = sqrt(r537188);
        double r537192 = r537190 / r537191;
        double r537193 = fabs(r537192);
        double r537194 = r537187 ? r537173 : r537193;
        double r537195 = r537185 ? r537178 : r537194;
        double r537196 = r537180 ? r537183 : r537195;
        double r537197 = r537175 ? r537178 : r537196;
        double r537198 = r537165 ? r537173 : r537197;
        double r537199 = r537155 ? r537163 : r537198;
        return r537199;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.3
Target24.9
Herbie25.7
\[\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 y < -5.008523466085166e+110

    1. Initial program 56.0

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt56.0

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    5. Applied add-sqr-sqrt56.0

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    6. Applied times-frac56.0

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square56.0

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|}\]
    8. Taylor expanded around 0 18.6

      \[\leadsto \left|\frac{\color{blue}{y}}{\sqrt{3}}\right|\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt18.6

      \[\leadsto \left|\frac{y}{\sqrt{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\right|\]
    11. Applied sqrt-prod19.1

      \[\leadsto \left|\frac{y}{\color{blue}{\sqrt{\sqrt{3}} \cdot \sqrt{\sqrt{3}}}}\right|\]
    12. Applied *-un-lft-identity19.1

      \[\leadsto \left|\frac{\color{blue}{1 \cdot y}}{\sqrt{\sqrt{3}} \cdot \sqrt{\sqrt{3}}}\right|\]
    13. Applied times-frac18.6

      \[\leadsto \left|\color{blue}{\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{y}{\sqrt{\sqrt{3}}}}\right|\]

    if -5.008523466085166e+110 < y < -1.2324940922667923e-182 or 6.697712028762041e-123 < y < 1.3803741179654927e+79

    1. Initial program 27.2

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt27.4

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    5. Applied add-sqr-sqrt27.4

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    6. Applied times-frac27.3

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square27.3

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|}\]

    if -1.2324940922667923e-182 < y < -1.7921086023675116e-274 or 7.254479271513616e-209 < y < 6.697712028762041e-123

    1. Initial program 30.8

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt31.0

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    5. Applied add-sqr-sqrt31.0

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    6. Applied times-frac30.9

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square30.9

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|}\]
    8. Taylor expanded around -inf 31.0

      \[\leadsto \left|\frac{\color{blue}{-1 \cdot z}}{\sqrt{3}}\right|\]
    9. Simplified31.0

      \[\leadsto \left|\frac{\color{blue}{-z}}{\sqrt{3}}\right|\]

    if -1.7921086023675116e-274 < y < 7.254479271513616e-209

    1. Initial program 31.5

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied div-inv31.5

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right) \cdot \frac{1}{3}}}\]
    5. Applied sqrt-prod31.6

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

    if 1.3803741179654927e+79 < y

    1. Initial program 52.4

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

      \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt52.4

      \[\leadsto \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    5. Applied add-sqr-sqrt52.4

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    6. Applied times-frac52.4

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}}}\]
    7. Applied rem-sqrt-square52.4

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|}\]
    8. Taylor expanded around 0 20.3

      \[\leadsto \left|\frac{\color{blue}{y}}{\sqrt{3}}\right|\]
    9. Using strategy rm
    10. Applied add-cube-cbrt20.3

      \[\leadsto \left|\frac{y}{\sqrt{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\right|\]
    11. Applied sqrt-prod20.3

      \[\leadsto \left|\frac{y}{\color{blue}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \sqrt{\sqrt[3]{3}}}}\right|\]
    12. Applied associate-/r*20.3

      \[\leadsto \left|\color{blue}{\frac{\frac{y}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}}}}{\sqrt{\sqrt[3]{3}}}}\right|\]
    13. Simplified20.3

      \[\leadsto \left|\frac{\color{blue}{\frac{y}{\left|\sqrt[3]{3}\right|}}}{\sqrt{\sqrt[3]{3}}}\right|\]
  3. Recombined 5 regimes into one program.
  4. Final simplification25.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -5.008523466085166042269104572011026767694 \cdot 10^{110}:\\ \;\;\;\;\left|\frac{1}{\sqrt{\sqrt{3}}} \cdot \frac{y}{\sqrt{\sqrt{3}}}\right|\\ \mathbf{elif}\;y \le -1.232494092266792303298507831851883710859 \cdot 10^{-182}:\\ \;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le -1.792108602367511563107867303346475363755 \cdot 10^{-274}:\\ \;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 7.254479271513616272173912934899302783245 \cdot 10^{-209}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;y \le 6.697712028762041216512495239807927468844 \cdot 10^{-123}:\\ \;\;\;\;\left|\frac{-z}{\sqrt{3}}\right|\\ \mathbf{elif}\;y \le 1.380374117965492703314427996253896487757 \cdot 10^{79}:\\ \;\;\;\;\left|\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{y}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \end{array}\]

Reproduce

herbie shell --seed 2019208 +o rules:numerics
(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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3)))