Average Error: 38.0 → 27.5
Time: 4.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.00914210855056183 \cdot 10^{41}:\\ \;\;\;\;\left|-1 \cdot \frac{\frac{x}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \mathbf{elif}\;x \le -3.3197380773614497 \cdot 10^{-280}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.31567698948686265 \cdot 10^{-169}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 3.0918938969591369 \cdot 10^{-47}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.13019308291360447 \cdot 10^{74}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\right)\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.00914210855056183 \cdot 10^{41}:\\
\;\;\;\;\left|-1 \cdot \frac{\frac{x}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\

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

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

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

\mathbf{elif}\;x \le 3.13019308291360447 \cdot 10^{74}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\right)\right|\\

\end{array}
double f(double x, double y, double z) {
        double r901617 = x;
        double r901618 = r901617 * r901617;
        double r901619 = y;
        double r901620 = r901619 * r901619;
        double r901621 = r901618 + r901620;
        double r901622 = z;
        double r901623 = r901622 * r901622;
        double r901624 = r901621 + r901623;
        double r901625 = 3.0;
        double r901626 = r901624 / r901625;
        double r901627 = sqrt(r901626);
        return r901627;
}

double f(double x, double y, double z) {
        double r901628 = x;
        double r901629 = -2.009142108550562e+41;
        bool r901630 = r901628 <= r901629;
        double r901631 = -1.0;
        double r901632 = 3.0;
        double r901633 = cbrt(r901632);
        double r901634 = fabs(r901633);
        double r901635 = r901628 / r901634;
        double r901636 = sqrt(r901633);
        double r901637 = r901635 / r901636;
        double r901638 = r901631 * r901637;
        double r901639 = fabs(r901638);
        double r901640 = -3.3197380773614497e-280;
        bool r901641 = r901628 <= r901640;
        double r901642 = r901628 * r901628;
        double r901643 = y;
        double r901644 = r901643 * r901643;
        double r901645 = r901642 + r901644;
        double r901646 = z;
        double r901647 = r901646 * r901646;
        double r901648 = r901645 + r901647;
        double r901649 = sqrt(r901648);
        double r901650 = 1.0;
        double r901651 = r901650 / r901632;
        double r901652 = sqrt(r901651);
        double r901653 = r901649 * r901652;
        double r901654 = 4.3156769894868627e-169;
        bool r901655 = r901628 <= r901654;
        double r901656 = sqrt(r901632);
        double r901657 = r901646 / r901656;
        double r901658 = fabs(r901657);
        double r901659 = 3.091893896959137e-47;
        bool r901660 = r901628 <= r901659;
        double r901661 = 3.1301930829136045e+74;
        bool r901662 = r901628 <= r901661;
        double r901663 = cbrt(r901656);
        double r901664 = r901663 * r901663;
        double r901665 = r901650 / r901664;
        double r901666 = r901628 / r901663;
        double r901667 = r901665 * r901666;
        double r901668 = r901631 * r901667;
        double r901669 = fabs(r901668);
        double r901670 = r901662 ? r901658 : r901669;
        double r901671 = r901660 ? r901653 : r901670;
        double r901672 = r901655 ? r901658 : r901671;
        double r901673 = r901641 ? r901653 : r901672;
        double r901674 = r901630 ? r901639 : r901673;
        return r901674;
}

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.0
Target26.0
Herbie27.5
\[\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 x < -2.009142108550562e+41

    1. Initial program 50.3

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

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

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

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

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

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\right|\]
    8. Using strategy rm
    9. Applied add-cube-cbrt23.0

      \[\leadsto \left|-1 \cdot \frac{x}{\sqrt{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\right|\]
    10. Applied sqrt-prod23.0

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

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

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

    if -2.009142108550562e+41 < x < -3.3197380773614497e-280 or 4.3156769894868627e-169 < x < 3.091893896959137e-47

    1. Initial program 28.7

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

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

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

    if -3.3197380773614497e-280 < x < 4.3156769894868627e-169 or 3.091893896959137e-47 < x < 3.1301930829136045e+74

    1. Initial program 30.1

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt30.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-sqrt30.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-frac30.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-square30.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 35.4

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

    if 3.1301930829136045e+74 < x

    1. Initial program 50.9

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

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

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

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

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

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

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

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

      \[\leadsto \left|-1 \cdot \color{blue}{\left(\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\right)}\right|\]
  3. Recombined 4 regimes into one program.
  4. Final simplification27.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.00914210855056183 \cdot 10^{41}:\\ \;\;\;\;\left|-1 \cdot \frac{\frac{x}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \mathbf{elif}\;x \le -3.3197380773614497 \cdot 10^{-280}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.31567698948686265 \cdot 10^{-169}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 3.0918938969591369 \cdot 10^{-47}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.13019308291360447 \cdot 10^{74}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \left(\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{x}{\sqrt[3]{\sqrt{3}}}\right)\right|\\ \end{array}\]

Reproduce

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