Average Error: 37.4 → 25.7
Time: 13.9s
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}:\\ \;\;\;\;-1 \cdot \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{\frac{6004799503160661}{18014398509481984}}\\ \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}:\\
\;\;\;\;-1 \cdot \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{\frac{6004799503160661}{18014398509481984}}\\

\end{array}
double f(double x, double y, double z) {
        double r760547 = x;
        double r760548 = r760547 * r760547;
        double r760549 = y;
        double r760550 = r760549 * r760549;
        double r760551 = r760548 + r760550;
        double r760552 = z;
        double r760553 = r760552 * r760552;
        double r760554 = r760551 + r760553;
        double r760555 = 3.0;
        double r760556 = r760554 / r760555;
        double r760557 = sqrt(r760556);
        return r760557;
}

double f(double x, double y, double z) {
        double r760558 = x;
        double r760559 = -1.472200864118953e+97;
        bool r760560 = r760558 <= r760559;
        double r760561 = -1.0;
        double r760562 = 3.0;
        double r760563 = sqrt(r760562);
        double r760564 = r760558 / r760563;
        double r760565 = r760561 * r760564;
        double r760566 = 9.739776979507706e+134;
        bool r760567 = r760558 <= r760566;
        double r760568 = r760558 * r760558;
        double r760569 = y;
        double r760570 = r760569 * r760569;
        double r760571 = r760568 + r760570;
        double r760572 = z;
        double r760573 = r760572 * r760572;
        double r760574 = r760571 + r760573;
        double r760575 = sqrt(r760574);
        double r760576 = 1.0;
        double r760577 = r760576 / r760562;
        double r760578 = sqrt(r760577);
        double r760579 = r760575 * r760578;
        double r760580 = 6004799503160661.0;
        double r760581 = 18014398509481984.0;
        double r760582 = r760580 / r760581;
        double r760583 = sqrt(r760582);
        double r760584 = r760558 * r760583;
        double r760585 = r760567 ? r760579 : r760584;
        double r760586 = r760560 ? r760565 : r760585;
        return r760586;
}

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} \cdot 1}}{\sqrt{3}}\]
    9. Taylor expanded around -inf 19.9

      \[\leadsto \color{blue}{-1 \cdot \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. Simplified15.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot \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{\frac{6004799503160661}{18014398509481984}}\\ \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)))