Average Error: 38.3 → 27.4
Time: 5.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.4794970398246474 \cdot 10^{55}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 4.54583198998115572 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}\\ \mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\ \;\;\;\;\frac{z}{\sqrt{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.4794970398246474 \cdot 10^{55}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

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

\mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\
\;\;\;\;\frac{z}{\sqrt{3}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r868157 = x;
        double r868158 = r868157 * r868157;
        double r868159 = y;
        double r868160 = r868159 * r868159;
        double r868161 = r868158 + r868160;
        double r868162 = z;
        double r868163 = r868162 * r868162;
        double r868164 = r868161 + r868163;
        double r868165 = 3.0;
        double r868166 = r868164 / r868165;
        double r868167 = sqrt(r868166);
        return r868167;
}

double f(double x, double y, double z) {
        double r868168 = x;
        double r868169 = -3.4794970398246474e+55;
        bool r868170 = r868168 <= r868169;
        double r868171 = -1.0;
        double r868172 = 0.3333333333333333;
        double r868173 = sqrt(r868172);
        double r868174 = r868168 * r868173;
        double r868175 = r868171 * r868174;
        double r868176 = 4.545831989981156e+65;
        bool r868177 = r868168 <= r868176;
        double r868178 = r868168 * r868168;
        double r868179 = y;
        double r868180 = r868179 * r868179;
        double r868181 = r868178 + r868180;
        double r868182 = z;
        double r868183 = r868182 * r868182;
        double r868184 = r868181 + r868183;
        double r868185 = 1.0;
        double r868186 = 3.0;
        double r868187 = r868185 / r868186;
        double r868188 = r868184 * r868187;
        double r868189 = sqrt(r868188);
        double r868190 = 1.597460999541732e+121;
        bool r868191 = r868168 <= r868190;
        double r868192 = sqrt(r868186);
        double r868193 = r868182 / r868192;
        double r868194 = r868191 ? r868193 : r868174;
        double r868195 = r868177 ? r868189 : r868194;
        double r868196 = r868170 ? r868175 : r868195;
        return r868196;
}

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.3
Target25.7
Herbie27.4
\[\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.4794970398246474e+55

    1. Initial program 49.4

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)}\]

    if -3.4794970398246474e+55 < x < 4.545831989981156e+65

    1. Initial program 30.0

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

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

    if 4.545831989981156e+65 < x < 1.597460999541732e+121

    1. Initial program 29.4

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

      \[\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. Taylor expanded around 0 54.5

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

    if 1.597460999541732e+121 < x

    1. Initial program 58.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.4794970398246474 \cdot 10^{55}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 4.54583198998115572 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}\\ \mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

herbie shell --seed 2020036 +o rules:numerics
(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)))