Average Error: 37.6 → 25.5
Time: 17.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -1.300826073826069390206779020116460497933 \cdot 10^{-184}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 2.963930732093339184027916604821132221056 \cdot 10^{-286}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 4.808010570528259607557562930705767404361 \cdot 10^{-173}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.157422220345378975630750006632647108073 \cdot 10^{-141}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.681133737755100120774954244284973127491 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\
\;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\

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

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

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

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r547511 = x;
        double r547512 = r547511 * r547511;
        double r547513 = y;
        double r547514 = r547513 * r547513;
        double r547515 = r547512 + r547514;
        double r547516 = z;
        double r547517 = r547516 * r547516;
        double r547518 = r547515 + r547517;
        double r547519 = 3.0;
        double r547520 = r547518 / r547519;
        double r547521 = sqrt(r547520);
        return r547521;
}

double f(double x, double y, double z) {
        double r547522 = x;
        double r547523 = -4.839580010133739e+89;
        bool r547524 = r547522 <= r547523;
        double r547525 = 3.0;
        double r547526 = sqrt(r547525);
        double r547527 = r547522 / r547526;
        double r547528 = -r547527;
        double r547529 = fabs(r547528);
        double r547530 = -1.3008260738260694e-184;
        bool r547531 = r547522 <= r547530;
        double r547532 = r547522 * r547522;
        double r547533 = y;
        double r547534 = r547533 * r547533;
        double r547535 = r547532 + r547534;
        double r547536 = z;
        double r547537 = r547536 * r547536;
        double r547538 = r547535 + r547537;
        double r547539 = sqrt(r547538);
        double r547540 = r547539 / r547526;
        double r547541 = fabs(r547540);
        double r547542 = 2.963930732093339e-286;
        bool r547543 = r547522 <= r547542;
        double r547544 = r547536 / r547526;
        double r547545 = fabs(r547544);
        double r547546 = 4.8080105705282596e-173;
        bool r547547 = r547522 <= r547546;
        double r547548 = 1.0;
        double r547549 = r547548 / r547525;
        double r547550 = sqrt(r547549);
        double r547551 = r547539 * r547550;
        double r547552 = 3.157422220345379e-141;
        bool r547553 = r547522 <= r547552;
        double r547554 = 1.6811337377551001e+93;
        bool r547555 = r547522 <= r547554;
        double r547556 = 0.3333333333333333;
        double r547557 = sqrt(r547556);
        double r547558 = r547522 * r547557;
        double r547559 = r547555 ? r547551 : r547558;
        double r547560 = r547553 ? r547545 : r547559;
        double r547561 = r547547 ? r547551 : r547560;
        double r547562 = r547543 ? r547545 : r547561;
        double r547563 = r547531 ? r547541 : r547562;
        double r547564 = r547524 ? r547529 : r547563;
        return r547564;
}

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.6
Target25.5
Herbie25.5
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 5 regimes
  2. if x < -4.839580010133739e+89

    1. Initial program 52.1

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt52.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-sqrt52.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-frac52.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-square52.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 -inf 19.7

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

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

    if -4.839580010133739e+89 < x < -1.3008260738260694e-184

    1. Initial program 27.0

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

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

    if -1.3008260738260694e-184 < x < 2.963930732093339e-286 or 4.8080105705282596e-173 < x < 3.157422220345379e-141

    1. Initial program 32.5

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

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

      \[\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-frac32.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-square32.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 0 31.2

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

    if 2.963930732093339e-286 < x < 4.8080105705282596e-173 or 3.157422220345379e-141 < x < 1.6811337377551001e+93

    1. Initial program 29.1

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

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

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

    if 1.6811337377551001e+93 < x

    1. Initial program 54.1

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification25.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -1.300826073826069390206779020116460497933 \cdot 10^{-184}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 2.963930732093339184027916604821132221056 \cdot 10^{-286}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 4.808010570528259607557562930705767404361 \cdot 10^{-173}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 3.157422220345378975630750006632647108073 \cdot 10^{-141}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.681133737755100120774954244284973127491 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

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