Average Error: 37.6 → 25.6
Time: 5.7s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.653486872877025328162949610044300723903 \cdot 10^{103}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le 4.548512359051216215734424553488962080637 \cdot 10^{125}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.653486872877025328162949610044300723903 \cdot 10^{103}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x}{\sqrt{3}}\\

\end{array}
double f(double x, double y, double z) {
        double r1044415 = x;
        double r1044416 = r1044415 * r1044415;
        double r1044417 = y;
        double r1044418 = r1044417 * r1044417;
        double r1044419 = r1044416 + r1044418;
        double r1044420 = z;
        double r1044421 = r1044420 * r1044420;
        double r1044422 = r1044419 + r1044421;
        double r1044423 = 3.0;
        double r1044424 = r1044422 / r1044423;
        double r1044425 = sqrt(r1044424);
        return r1044425;
}

double f(double x, double y, double z) {
        double r1044426 = x;
        double r1044427 = -1.6534868728770253e+103;
        bool r1044428 = r1044426 <= r1044427;
        double r1044429 = 1.0;
        double r1044430 = 3.0;
        double r1044431 = cbrt(r1044430);
        double r1044432 = r1044431 * r1044431;
        double r1044433 = r1044429 / r1044432;
        double r1044434 = sqrt(r1044433);
        double r1044435 = -1.0;
        double r1044436 = r1044429 / r1044431;
        double r1044437 = sqrt(r1044436);
        double r1044438 = r1044437 * r1044426;
        double r1044439 = r1044435 * r1044438;
        double r1044440 = r1044434 * r1044439;
        double r1044441 = 4.548512359051216e+125;
        bool r1044442 = r1044426 <= r1044441;
        double r1044443 = r1044426 * r1044426;
        double r1044444 = y;
        double r1044445 = r1044444 * r1044444;
        double r1044446 = r1044443 + r1044445;
        double r1044447 = z;
        double r1044448 = r1044447 * r1044447;
        double r1044449 = r1044446 + r1044448;
        double r1044450 = sqrt(r1044449);
        double r1044451 = r1044450 / r1044430;
        double r1044452 = r1044450 * r1044451;
        double r1044453 = sqrt(r1044452);
        double r1044454 = sqrt(r1044430);
        double r1044455 = r1044426 / r1044454;
        double r1044456 = r1044442 ? r1044453 : r1044455;
        double r1044457 = r1044428 ? r1044440 : r1044456;
        return r1044457;
}

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.3
Herbie25.6
\[\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 3 regimes
  2. if x < -1.6534868728770253e+103

    1. Initial program 54.4

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

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

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

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

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

      \[\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)}\]

    if -1.6534868728770253e+103 < x < 4.548512359051216e+125

    1. Initial program 29.2

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{1 \cdot 3}}}\]
    4. Applied add-sqr-sqrt29.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}}}{1 \cdot 3}}\]
    5. Applied times-frac29.2

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

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

    if 4.548512359051216e+125 < x

    1. Initial program 58.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.653486872877025328162949610044300723903 \cdot 10^{103}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le 4.548512359051216215734424553488962080637 \cdot 10^{125}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]

Reproduce

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