Average Error: 37.6 → 25.6
Time: 15.2s
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}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{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}:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r643588 = x;
        double r643589 = r643588 * r643588;
        double r643590 = y;
        double r643591 = r643590 * r643590;
        double r643592 = r643589 + r643591;
        double r643593 = z;
        double r643594 = r643593 * r643593;
        double r643595 = r643592 + r643594;
        double r643596 = 3.0;
        double r643597 = r643595 / r643596;
        double r643598 = sqrt(r643597);
        return r643598;
}

double f(double x, double y, double z) {
        double r643599 = x;
        double r643600 = -4.839580010133739e+89;
        bool r643601 = r643599 <= r643600;
        double r643602 = 3.0;
        double r643603 = sqrt(r643602);
        double r643604 = r643599 / r643603;
        double r643605 = -r643604;
        double r643606 = 1.537188568549187e+101;
        bool r643607 = r643599 <= r643606;
        double r643608 = r643599 * r643599;
        double r643609 = y;
        double r643610 = r643609 * r643609;
        double r643611 = r643608 + r643610;
        double r643612 = z;
        double r643613 = r643612 * r643612;
        double r643614 = r643611 + r643613;
        double r643615 = sqrt(r643614);
        double r643616 = r643615 / r643603;
        double r643617 = 0.3333333333333333;
        double r643618 = sqrt(r643617);
        double r643619 = r643599 * r643618;
        double r643620 = r643607 ? r643616 : r643619;
        double r643621 = r643601 ? r643605 : r643620;
        return r643621;
}

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.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 < -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 sqrt-div52.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\]
    5. Simplified19.7

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

    if -4.839580010133739e+89 < x < 1.537188568549187e+101

    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 sqrt-div29.2

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

    if 1.537188568549187e+101 < x

    1. Initial program 55.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{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)))