Average Error: 38.1 → 27.1
Time: 5.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.67483720172885296 \cdot 10^{150}:\\ \;\;\;\;-1 \cdot \left(z \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;z \le -1.6807596291604125 \cdot 10^{-146}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\sqrt[3]{3}}}\\ \mathbf{elif}\;z \le -4.89753850018684267 \cdot 10^{-237}:\\ \;\;\;\;y \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;z \le 4.98293636143277424 \cdot 10^{94}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -1.67483720172885296 \cdot 10^{150}:\\
\;\;\;\;-1 \cdot \left(z \cdot \sqrt{0.333333333333333315}\right)\\

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

\mathbf{elif}\;z \le -4.89753850018684267 \cdot 10^{-237}:\\
\;\;\;\;y \cdot \sqrt{0.333333333333333315}\\

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

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

\end{array}
double f(double x, double y, double z) {
        double r933313 = x;
        double r933314 = r933313 * r933313;
        double r933315 = y;
        double r933316 = r933315 * r933315;
        double r933317 = r933314 + r933316;
        double r933318 = z;
        double r933319 = r933318 * r933318;
        double r933320 = r933317 + r933319;
        double r933321 = 3.0;
        double r933322 = r933320 / r933321;
        double r933323 = sqrt(r933322);
        return r933323;
}

double f(double x, double y, double z) {
        double r933324 = z;
        double r933325 = -1.674837201728853e+150;
        bool r933326 = r933324 <= r933325;
        double r933327 = -1.0;
        double r933328 = 0.3333333333333333;
        double r933329 = sqrt(r933328);
        double r933330 = r933324 * r933329;
        double r933331 = r933327 * r933330;
        double r933332 = -1.6807596291604125e-146;
        bool r933333 = r933324 <= r933332;
        double r933334 = 1.0;
        double r933335 = 3.0;
        double r933336 = cbrt(r933335);
        double r933337 = r933336 * r933336;
        double r933338 = r933334 / r933337;
        double r933339 = x;
        double r933340 = y;
        double r933341 = r933340 * r933340;
        double r933342 = fma(r933339, r933339, r933341);
        double r933343 = fma(r933324, r933324, r933342);
        double r933344 = r933343 / r933336;
        double r933345 = r933338 * r933344;
        double r933346 = sqrt(r933345);
        double r933347 = -4.8975385001868427e-237;
        bool r933348 = r933324 <= r933347;
        double r933349 = r933340 * r933329;
        double r933350 = 4.982936361432774e+94;
        bool r933351 = r933324 <= r933350;
        double r933352 = r933339 * r933339;
        double r933353 = r933352 + r933341;
        double r933354 = r933324 * r933324;
        double r933355 = r933353 + r933354;
        double r933356 = sqrt(r933355);
        double r933357 = r933356 / r933335;
        double r933358 = r933356 * r933357;
        double r933359 = sqrt(r933358);
        double r933360 = r933351 ? r933359 : r933330;
        double r933361 = r933348 ? r933349 : r933360;
        double r933362 = r933333 ? r933346 : r933361;
        double r933363 = r933326 ? r933331 : r933362;
        return r933363;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original38.1
Target25.9
Herbie27.1
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 5 regimes
  2. if z < -1.674837201728853e+150

    1. Initial program 63.0

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

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

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

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

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

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

    if -1.674837201728853e+150 < z < -1.6807596291604125e-146

    1. Initial program 27.9

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    4. Applied *-un-lft-identity27.9

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

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

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

    if -1.6807596291604125e-146 < z < -4.8975385001868427e-237

    1. Initial program 30.2

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \sqrt{0.333333333333333315}}\]

    if -4.8975385001868427e-237 < z < 4.982936361432774e+94

    1. Initial program 30.4

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

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

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

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

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

    if 4.982936361432774e+94 < z

    1. Initial program 53.2

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.333333333333333315}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification27.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.67483720172885296 \cdot 10^{150}:\\ \;\;\;\;-1 \cdot \left(z \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;z \le -1.6807596291604125 \cdot 10^{-146}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{\sqrt[3]{3}}}\\ \mathbf{elif}\;z \le -4.89753850018684267 \cdot 10^{-237}:\\ \;\;\;\;y \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;z \le 4.98293636143277424 \cdot 10^{94}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

herbie shell --seed 2020081 +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.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)))