Average Error: 37.5 → 25.1
Time: 12.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\ \;\;\;\;\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}:\\ \;\;\;\;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 -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\
\;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\
\;\;\;\;\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}:\\
\;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\end{array}
double f(double x, double y, double z) {
        double r889568 = x;
        double r889569 = r889568 * r889568;
        double r889570 = y;
        double r889571 = r889570 * r889570;
        double r889572 = r889569 + r889571;
        double r889573 = z;
        double r889574 = r889573 * r889573;
        double r889575 = r889572 + r889574;
        double r889576 = 3.0;
        double r889577 = r889575 / r889576;
        double r889578 = sqrt(r889577);
        return r889578;
}

double f(double x, double y, double z) {
        double r889579 = x;
        double r889580 = -3.655717002048407e+123;
        bool r889581 = r889579 <= r889580;
        double r889582 = 0.3333333333333333;
        double r889583 = sqrt(r889582);
        double r889584 = r889579 * r889583;
        double r889585 = -r889584;
        double r889586 = 1.3221493030139048e+51;
        bool r889587 = r889579 <= r889586;
        double r889588 = r889579 * r889579;
        double r889589 = y;
        double r889590 = r889589 * r889589;
        double r889591 = r889588 + r889590;
        double r889592 = z;
        double r889593 = r889592 * r889592;
        double r889594 = r889591 + r889593;
        double r889595 = sqrt(r889594);
        double r889596 = 3.0;
        double r889597 = r889595 / r889596;
        double r889598 = r889595 * r889597;
        double r889599 = sqrt(r889598);
        double r889600 = r889587 ? r889599 : r889584;
        double r889601 = r889581 ? r889585 : r889600;
        return r889601;
}

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.5
Target25.7
Herbie25.1
\[\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 < -3.655717002048407e+123

    1. Initial program 58.2

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    3. Simplified15.8

      \[\leadsto \color{blue}{-x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if -3.655717002048407e+123 < x < 1.3221493030139048e+51

    1. Initial program 28.5

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

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

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

      \[\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 1.3221493030139048e+51 < x

    1. Initial program 50.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\ \;\;\;\;\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}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

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