Average Error: 37.9 → 25.8
Time: 16.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.1005165876387523 \cdot 10^{94}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -1.6711070948620834 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le 9.1360964630422332 \cdot 10^{-17}:\\ \;\;\;\;\left|\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 1.6350700005414168 \cdot 10^{108}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 9.3247667101326216 \cdot 10^{129}:\\ \;\;\;\;\left|\frac{1}{\frac{\sqrt{3}}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;z \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}\;z \le -1.1005165876387523 \cdot 10^{94}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

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

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

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r681534 = x;
        double r681535 = r681534 * r681534;
        double r681536 = y;
        double r681537 = r681536 * r681536;
        double r681538 = r681535 + r681537;
        double r681539 = z;
        double r681540 = r681539 * r681539;
        double r681541 = r681538 + r681540;
        double r681542 = 3.0;
        double r681543 = r681541 / r681542;
        double r681544 = sqrt(r681543);
        return r681544;
}

double f(double x, double y, double z) {
        double r681545 = z;
        double r681546 = -1.1005165876387523e+94;
        bool r681547 = r681545 <= r681546;
        double r681548 = 3.0;
        double r681549 = sqrt(r681548);
        double r681550 = r681545 / r681549;
        double r681551 = fabs(r681550);
        double r681552 = -1.6711070948620834e-161;
        bool r681553 = r681545 <= r681552;
        double r681554 = x;
        double r681555 = r681554 * r681554;
        double r681556 = y;
        double r681557 = r681556 * r681556;
        double r681558 = r681555 + r681557;
        double r681559 = r681545 * r681545;
        double r681560 = r681558 + r681559;
        double r681561 = sqrt(r681560);
        double r681562 = 1.0;
        double r681563 = r681562 / r681548;
        double r681564 = sqrt(r681563);
        double r681565 = r681561 * r681564;
        double r681566 = 9.136096463042233e-17;
        bool r681567 = r681545 <= r681566;
        double r681568 = r681554 / r681549;
        double r681569 = fabs(r681568);
        double r681570 = 1.6350700005414168e+108;
        bool r681571 = r681545 <= r681570;
        double r681572 = r681561 / r681549;
        double r681573 = fabs(r681572);
        double r681574 = 9.324766710132622e+129;
        bool r681575 = r681545 <= r681574;
        double r681576 = r681549 / r681554;
        double r681577 = r681562 / r681576;
        double r681578 = fabs(r681577);
        double r681579 = 0.3333333333333333;
        double r681580 = sqrt(r681579);
        double r681581 = r681545 * r681580;
        double r681582 = r681575 ? r681578 : r681581;
        double r681583 = r681571 ? r681573 : r681582;
        double r681584 = r681567 ? r681569 : r681583;
        double r681585 = r681553 ? r681565 : r681584;
        double r681586 = r681547 ? r681551 : r681585;
        return r681586;
}

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.9
Target25.2
Herbie25.8
\[\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 6 regimes
  2. if z < -1.1005165876387523e+94

    1. Initial program 54.0

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

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

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

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

    if -1.1005165876387523e+94 < z < -1.6711070948620834e-161

    1. Initial program 27.7

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv27.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-prod27.9

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

    if -1.6711070948620834e-161 < z < 9.136096463042233e-17

    1. Initial program 31.3

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

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

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

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

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

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

    if 9.136096463042233e-17 < z < 1.6350700005414168e+108

    1. Initial program 25.7

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

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

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

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

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

    if 1.6350700005414168e+108 < z < 9.324766710132622e+129

    1. Initial program 24.5

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

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

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

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

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

      \[\leadsto \left|\frac{\color{blue}{x}}{\sqrt{3}}\right|\]
    8. Using strategy rm
    9. Applied clear-num47.5

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

    if 9.324766710132622e+129 < z

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.333333333333333315}}\]
  3. Recombined 6 regimes into one program.
  4. Final simplification25.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.1005165876387523 \cdot 10^{94}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -1.6711070948620834 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;z \le 9.1360964630422332 \cdot 10^{-17}:\\ \;\;\;\;\left|\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 1.6350700005414168 \cdot 10^{108}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 9.3247667101326216 \cdot 10^{129}:\\ \;\;\;\;\left|\frac{1}{\frac{\sqrt{3}}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

herbie shell --seed 2019198 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))