Average Error: 38.6 → 27.0
Time: 16.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -2.623547536657377133536502149572890753313 \cdot 10^{-278}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 3.871233825359605951288495732077425103951 \cdot 10^{64}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 1}{\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 -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

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

\mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r623119 = x;
        double r623120 = r623119 * r623119;
        double r623121 = y;
        double r623122 = r623121 * r623121;
        double r623123 = r623120 + r623122;
        double r623124 = z;
        double r623125 = r623124 * r623124;
        double r623126 = r623123 + r623125;
        double r623127 = 3.0;
        double r623128 = r623126 / r623127;
        double r623129 = sqrt(r623128);
        return r623129;
}

double f(double x, double y, double z) {
        double r623130 = x;
        double r623131 = -9.893983514208573e+152;
        bool r623132 = r623130 <= r623131;
        double r623133 = -1.0;
        double r623134 = r623133 * r623130;
        double r623135 = 1.0;
        double r623136 = 3.0;
        double r623137 = r623135 / r623136;
        double r623138 = sqrt(r623137);
        double r623139 = r623134 * r623138;
        double r623140 = -2.623547536657377e-278;
        bool r623141 = r623130 <= r623140;
        double r623142 = r623130 * r623130;
        double r623143 = y;
        double r623144 = r623143 * r623143;
        double r623145 = r623142 + r623144;
        double r623146 = z;
        double r623147 = r623146 * r623146;
        double r623148 = r623145 + r623147;
        double r623149 = r623148 / r623136;
        double r623150 = sqrt(r623149);
        double r623151 = -8.416887720474182e-307;
        bool r623152 = r623130 <= r623151;
        double r623153 = 0.3333333333333333;
        double r623154 = sqrt(r623153);
        double r623155 = r623146 * r623154;
        double r623156 = 3.871233825359606e+64;
        bool r623157 = r623130 <= r623156;
        double r623158 = r623130 * r623135;
        double r623159 = sqrt(r623136);
        double r623160 = r623158 / r623159;
        double r623161 = r623157 ? r623150 : r623160;
        double r623162 = r623152 ? r623155 : r623161;
        double r623163 = r623141 ? r623150 : r623162;
        double r623164 = r623132 ? r623139 : r623163;
        return r623164;
}

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.6
Target25.9
Herbie27.0
\[\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 4 regimes
  2. if x < -9.893983514208573e+152

    1. Initial program 63.9

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}}\]
    4. Applied sqrt-prod63.9

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

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

    if -9.893983514208573e+152 < x < -2.623547536657377e-278 or -8.416887720474182e-307 < x < 3.871233825359606e+64

    1. Initial program 30.1

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

    if -2.623547536657377e-278 < x < -8.416887720474182e-307

    1. Initial program 32.5

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if 3.871233825359606e+64 < x

    1. Initial program 51.1

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

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

      \[\leadsto \color{blue}{x} \cdot \sqrt{\frac{1}{3}}\]
    6. Using strategy rm
    7. Applied sqrt-div22.6

      \[\leadsto x \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3}}}\]
    8. Applied associate-*r/22.3

      \[\leadsto \color{blue}{\frac{x \cdot \sqrt{1}}{\sqrt{3}}}\]
    9. Simplified22.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -2.623547536657377133536502149572890753313 \cdot 10^{-278}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 3.871233825359605951288495732077425103951 \cdot 10^{64}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 1}{\sqrt{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019297 
(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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3)))