Average Error: 38.1 → 25.9
Time: 13.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.88352274157357012 \cdot 10^{144}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \mathbf{elif}\;x \le 5.5672647142085938 \cdot 10^{147}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.88352274157357012 \cdot 10^{144}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r575508 = x;
        double r575509 = r575508 * r575508;
        double r575510 = y;
        double r575511 = r575510 * r575510;
        double r575512 = r575509 + r575511;
        double r575513 = z;
        double r575514 = r575513 * r575513;
        double r575515 = r575512 + r575514;
        double r575516 = 3.0;
        double r575517 = r575515 / r575516;
        double r575518 = sqrt(r575517);
        return r575518;
}

double f(double x, double y, double z) {
        double r575519 = x;
        double r575520 = -2.88352274157357e+144;
        bool r575521 = r575519 <= r575520;
        double r575522 = 1.0;
        double r575523 = 3.0;
        double r575524 = cbrt(r575523);
        double r575525 = r575524 * r575524;
        double r575526 = r575522 / r575525;
        double r575527 = sqrt(r575526);
        double r575528 = r575522 / r575524;
        double r575529 = sqrt(r575528);
        double r575530 = r575529 * r575519;
        double r575531 = -r575530;
        double r575532 = r575527 * r575531;
        double r575533 = 5.567264714208594e+147;
        bool r575534 = r575519 <= r575533;
        double r575535 = r575519 * r575519;
        double r575536 = y;
        double r575537 = r575536 * r575536;
        double r575538 = r575535 + r575537;
        double r575539 = z;
        double r575540 = r575539 * r575539;
        double r575541 = r575538 + r575540;
        double r575542 = sqrt(r575541);
        double r575543 = r575523 / r575542;
        double r575544 = r575542 / r575543;
        double r575545 = sqrt(r575544);
        double r575546 = 0.3333333333333333;
        double r575547 = sqrt(r575546);
        double r575548 = r575519 * r575547;
        double r575549 = r575534 ? r575545 : r575548;
        double r575550 = r575521 ? r575532 : r575549;
        return r575550;
}

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.1
Target25.6
Herbie25.9
\[\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 3 regimes
  2. if x < -2.88352274157357e+144

    1. Initial program 61.2

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\]
    4. Applied *-un-lft-identity61.2

      \[\leadsto \sqrt{\frac{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    5. Applied times-frac61.2

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

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

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)}\]
    8. Simplified14.5

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

    if -2.88352274157357e+144 < x < 5.567264714208594e+147

    1. Initial program 29.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt29.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}}}{3}}\]
    4. Applied associate-/l*29.8

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

    if 5.567264714208594e+147 < x

    1. Initial program 62.0

      \[\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.333333333333333315}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.88352274157357012 \cdot 10^{144}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \mathbf{elif}\;x \le 5.5672647142085938 \cdot 10^{147}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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