Average Error: 37.7 → 26.1
Time: 18.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.189641880819210225013444092263738436314 \cdot 10^{82}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;z \le 5.165075679522047093800465664025687976731 \cdot 10^{61}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -1.189641880819210225013444092263738436314 \cdot 10^{82}:\\
\;\;\;\;-z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r576422 = x;
        double r576423 = r576422 * r576422;
        double r576424 = y;
        double r576425 = r576424 * r576424;
        double r576426 = r576423 + r576425;
        double r576427 = z;
        double r576428 = r576427 * r576427;
        double r576429 = r576426 + r576428;
        double r576430 = 3.0;
        double r576431 = r576429 / r576430;
        double r576432 = sqrt(r576431);
        return r576432;
}

double f(double x, double y, double z) {
        double r576433 = z;
        double r576434 = -1.1896418808192102e+82;
        bool r576435 = r576433 <= r576434;
        double r576436 = 0.3333333333333333;
        double r576437 = sqrt(r576436);
        double r576438 = r576433 * r576437;
        double r576439 = -r576438;
        double r576440 = 5.165075679522047e+61;
        bool r576441 = r576433 <= r576440;
        double r576442 = x;
        double r576443 = y;
        double r576444 = r576443 * r576443;
        double r576445 = fma(r576442, r576442, r576444);
        double r576446 = fma(r576433, r576433, r576445);
        double r576447 = sqrt(r576446);
        double r576448 = 3.0;
        double r576449 = cbrt(r576448);
        double r576450 = r576449 * r576449;
        double r576451 = r576447 / r576450;
        double r576452 = r576447 / r576449;
        double r576453 = r576451 * r576452;
        double r576454 = sqrt(r576453);
        double r576455 = sqrt(r576448);
        double r576456 = r576433 / r576455;
        double r576457 = r576441 ? r576454 : r576456;
        double r576458 = r576435 ? r576439 : r576457;
        return r576458;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.7
Target25.6
Herbie26.1
\[\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 z < -1.1896418808192102e+82

    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. Taylor expanded around -inf 20.1

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    4. Simplified20.1

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

    if -1.1896418808192102e+82 < z < 5.165075679522047e+61

    1. Initial program 29.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified29.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-cube-cbrt29.2

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

      \[\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)}}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    6. Applied times-frac29.3

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

    if 5.165075679522047e+61 < z

    1. Initial program 51.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Simplified51.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-cube-cbrt51.2

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

      \[\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)}}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    6. Applied times-frac51.2

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3}}}}\]
    7. Using strategy rm
    8. Applied frac-times51.2

      \[\leadsto \sqrt{\color{blue}{\frac{\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)}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    9. Applied sqrt-div51.2

      \[\leadsto \color{blue}{\frac{\sqrt{\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{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    10. Simplified51.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.189641880819210225013444092263738436314 \cdot 10^{82}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;z \le 5.165075679522047093800465664025687976731 \cdot 10^{61}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \end{array}\]

Reproduce

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