Average Error: 37.4 → 25.7
Time: 17.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r570475 = x;
        double r570476 = r570475 * r570475;
        double r570477 = y;
        double r570478 = r570477 * r570477;
        double r570479 = r570476 + r570478;
        double r570480 = z;
        double r570481 = r570480 * r570480;
        double r570482 = r570479 + r570481;
        double r570483 = 3.0;
        double r570484 = r570482 / r570483;
        double r570485 = sqrt(r570484);
        return r570485;
}

double f(double x, double y, double z) {
        double r570486 = x;
        double r570487 = -1.472200864118953e+97;
        bool r570488 = r570486 <= r570487;
        double r570489 = 3.0;
        double r570490 = sqrt(r570489);
        double r570491 = r570486 / r570490;
        double r570492 = -r570491;
        double r570493 = 9.739776979507706e+134;
        bool r570494 = r570486 <= r570493;
        double r570495 = r570486 * r570486;
        double r570496 = y;
        double r570497 = r570496 * r570496;
        double r570498 = r570495 + r570497;
        double r570499 = z;
        double r570500 = r570499 * r570499;
        double r570501 = r570498 + r570500;
        double r570502 = sqrt(r570501);
        double r570503 = 1.0;
        double r570504 = r570503 / r570489;
        double r570505 = sqrt(r570504);
        double r570506 = r570502 * r570505;
        double r570507 = 0.3333333333333333;
        double r570508 = sqrt(r570507);
        double r570509 = r570486 * r570508;
        double r570510 = r570494 ? r570506 : r570509;
        double r570511 = r570488 ? r570492 : r570510;
        return r570511;
}

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
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 3 regimes
  2. if x < -1.472200864118953e+97

    1. Initial program 55.7

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

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

      \[\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-div55.8

      \[\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/55.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\]
    10. Simplified19.9

      \[\leadsto \color{blue}{-\frac{x}{\sqrt{3}}}\]

    if -1.472200864118953e+97 < x < 9.739776979507706e+134

    1. Initial program 28.9

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

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

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

    if 9.739776979507706e+134 < x

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

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