Average Error: 38.0 → 26.0
Time: 22.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.98369446481531483 \cdot 10^{143}:\\ \;\;\;\;\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 -1.53786150967003364 \cdot 10^{-273}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.119152176003768 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \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 -3.98369446481531483 \cdot 10^{143}:\\
\;\;\;\;\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 -1.53786150967003364 \cdot 10^{-273}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r600397 = x;
        double r600398 = r600397 * r600397;
        double r600399 = y;
        double r600400 = r600399 * r600399;
        double r600401 = r600398 + r600400;
        double r600402 = z;
        double r600403 = r600402 * r600402;
        double r600404 = r600401 + r600403;
        double r600405 = 3.0;
        double r600406 = r600404 / r600405;
        double r600407 = sqrt(r600406);
        return r600407;
}

double f(double x, double y, double z) {
        double r600408 = x;
        double r600409 = -3.983694464815315e+143;
        bool r600410 = r600408 <= r600409;
        double r600411 = 1.0;
        double r600412 = 3.0;
        double r600413 = cbrt(r600412);
        double r600414 = r600413 * r600413;
        double r600415 = r600411 / r600414;
        double r600416 = sqrt(r600415);
        double r600417 = r600411 / r600413;
        double r600418 = sqrt(r600417);
        double r600419 = r600418 * r600408;
        double r600420 = -r600419;
        double r600421 = r600416 * r600420;
        double r600422 = -1.5378615096700336e-273;
        bool r600423 = r600408 <= r600422;
        double r600424 = r600408 * r600408;
        double r600425 = y;
        double r600426 = r600425 * r600425;
        double r600427 = r600424 + r600426;
        double r600428 = z;
        double r600429 = r600428 * r600428;
        double r600430 = r600427 + r600429;
        double r600431 = sqrt(r600430);
        double r600432 = r600411 / r600412;
        double r600433 = sqrt(r600432);
        double r600434 = r600431 * r600433;
        double r600435 = -1.7754786637459033e-299;
        bool r600436 = r600408 <= r600435;
        double r600437 = 0.3333333333333333;
        double r600438 = sqrt(r600437);
        double r600439 = r600428 * r600438;
        double r600440 = 1.119152176003768e+99;
        bool r600441 = r600408 <= r600440;
        double r600442 = r600408 * r600438;
        double r600443 = r600441 ? r600434 : r600442;
        double r600444 = r600436 ? r600439 : r600443;
        double r600445 = r600423 ? r600434 : r600444;
        double r600446 = r600410 ? r600421 : r600445;
        return r600446;
}

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
Target25.7
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 x < -3.983694464815315e+143

    1. Initial program 61.8

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

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

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

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

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

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

      \[\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 -3.983694464815315e+143 < x < -1.5378615096700336e-273 or -1.7754786637459033e-299 < x < 1.119152176003768e+99

    1. Initial program 29.3

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

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

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

    if -1.5378615096700336e-273 < x < -1.7754786637459033e-299

    1. Initial program 32.3

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.333333333333333315}}\]

    if 1.119152176003768e+99 < x

    1. Initial program 54.6

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.333333333333333315}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification26.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.98369446481531483 \cdot 10^{143}:\\ \;\;\;\;\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 -1.53786150967003364 \cdot 10^{-273}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.119152176003768 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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