Average Error: 38.7 → 26.0
Time: 4.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.78746078478264228 \cdot 10^{99}:\\ \;\;\;\;\left|\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\right|\\ \mathbf{elif}\;z \le -6.0707960974712676 \cdot 10^{-210}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le 2.3864141824080956 \cdot 10^{-275}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 2.7516587340071538 \cdot 10^{118}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{z}{\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}\;z \le -5.78746078478264228 \cdot 10^{99}:\\
\;\;\;\;\left|\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\right|\\

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

\mathbf{elif}\;z \le 2.3864141824080956 \cdot 10^{-275}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r699560 = x;
        double r699561 = r699560 * r699560;
        double r699562 = y;
        double r699563 = r699562 * r699562;
        double r699564 = r699561 + r699563;
        double r699565 = z;
        double r699566 = r699565 * r699565;
        double r699567 = r699564 + r699566;
        double r699568 = 3.0;
        double r699569 = r699567 / r699568;
        double r699570 = sqrt(r699569);
        return r699570;
}

double f(double x, double y, double z) {
        double r699571 = z;
        double r699572 = -5.787460784782642e+99;
        bool r699573 = r699571 <= r699572;
        double r699574 = 1.0;
        double r699575 = 3.0;
        double r699576 = sqrt(r699575);
        double r699577 = cbrt(r699576);
        double r699578 = r699577 * r699577;
        double r699579 = r699574 / r699578;
        double r699580 = r699571 / r699577;
        double r699581 = r699579 * r699580;
        double r699582 = fabs(r699581);
        double r699583 = -6.0707960974712676e-210;
        bool r699584 = r699571 <= r699583;
        double r699585 = x;
        double r699586 = r699585 * r699585;
        double r699587 = y;
        double r699588 = r699587 * r699587;
        double r699589 = r699586 + r699588;
        double r699590 = r699571 * r699571;
        double r699591 = r699589 + r699590;
        double r699592 = sqrt(r699591);
        double r699593 = r699574 / r699575;
        double r699594 = sqrt(r699593);
        double r699595 = r699592 * r699594;
        double r699596 = 2.3864141824080956e-275;
        bool r699597 = r699571 <= r699596;
        double r699598 = -1.0;
        double r699599 = r699585 / r699576;
        double r699600 = r699598 * r699599;
        double r699601 = fabs(r699600);
        double r699602 = 2.751658734007154e+118;
        bool r699603 = r699571 <= r699602;
        double r699604 = cbrt(r699575);
        double r699605 = fabs(r699604);
        double r699606 = r699571 / r699605;
        double r699607 = sqrt(r699604);
        double r699608 = r699606 / r699607;
        double r699609 = fabs(r699608);
        double r699610 = r699603 ? r699595 : r699609;
        double r699611 = r699597 ? r699601 : r699610;
        double r699612 = r699584 ? r699595 : r699611;
        double r699613 = r699573 ? r699582 : r699612;
        return r699613;
}

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

Original38.7
Target26.3
Herbie26.0
\[\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 4 regimes
  2. if z < -5.787460784782642e+99

    1. Initial program 54.7

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

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

      \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac54.7

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}\]
    6. Applied rem-sqrt-square54.7

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
    7. Taylor expanded around 0 19.3

      \[\leadsto \left|\frac{\color{blue}{z}}{\sqrt{3}}\right|\]
    8. Using strategy rm
    9. Applied add-cube-cbrt19.3

      \[\leadsto \left|\frac{z}{\color{blue}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}}\right|\]
    10. Applied *-un-lft-identity19.3

      \[\leadsto \left|\frac{\color{blue}{1 \cdot z}}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}\right|\]
    11. Applied times-frac19.4

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

    if -5.787460784782642e+99 < z < -6.0707960974712676e-210 or 2.3864141824080956e-275 < z < 2.751658734007154e+118

    1. Initial program 29.6

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

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

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

    if -6.0707960974712676e-210 < z < 2.3864141824080956e-275

    1. Initial program 34.1

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

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

      \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac34.1

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

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

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

    if 2.751658734007154e+118 < z

    1. Initial program 57.1

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

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

      \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac57.2

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}\]
    6. Applied rem-sqrt-square57.2

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
    7. Taylor expanded around 0 16.8

      \[\leadsto \left|\frac{\color{blue}{z}}{\sqrt{3}}\right|\]
    8. Using strategy rm
    9. Applied add-cube-cbrt16.8

      \[\leadsto \left|\frac{z}{\sqrt{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\right|\]
    10. Applied sqrt-prod16.8

      \[\leadsto \left|\frac{z}{\color{blue}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \sqrt{\sqrt[3]{3}}}}\right|\]
    11. Applied associate-/r*16.7

      \[\leadsto \left|\color{blue}{\frac{\frac{z}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}}}}{\sqrt{\sqrt[3]{3}}}}\right|\]
    12. Simplified16.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.78746078478264228 \cdot 10^{99}:\\ \;\;\;\;\left|\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\right|\\ \mathbf{elif}\;z \le -6.0707960974712676 \cdot 10^{-210}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le 2.3864141824080956 \cdot 10^{-275}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 2.7516587340071538 \cdot 10^{118}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \end{array}\]

Reproduce

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