Average Error: 38.3 → 28.5
Time: 5.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.95551520736679148 \cdot 10^{121}:\\ \;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \mathbf{elif}\;z \le -2.110786827503938 \cdot 10^{24}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -3.265579843763803 \cdot 10^{-100}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -5.1783904668289256 \cdot 10^{-174}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 3.6020310138858934 \cdot 10^{-62}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 1.40799492458206149 \cdot 10^{79}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 4.24573433835075588 \cdot 10^{110}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -3.95551520736679148 \cdot 10^{121}:\\
\;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\

\mathbf{elif}\;z \le -2.110786827503938 \cdot 10^{24}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

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

\mathbf{elif}\;z \le -5.1783904668289256 \cdot 10^{-174}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

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

\mathbf{elif}\;z \le 1.40799492458206149 \cdot 10^{79}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

\mathbf{elif}\;z \le 4.24573433835075588 \cdot 10^{110}:\\
\;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r975318 = x;
        double r975319 = r975318 * r975318;
        double r975320 = y;
        double r975321 = r975320 * r975320;
        double r975322 = r975319 + r975321;
        double r975323 = z;
        double r975324 = r975323 * r975323;
        double r975325 = r975322 + r975324;
        double r975326 = 3.0;
        double r975327 = r975325 / r975326;
        double r975328 = sqrt(r975327);
        return r975328;
}

double f(double x, double y, double z) {
        double r975329 = z;
        double r975330 = -3.9555152073667915e+121;
        bool r975331 = r975329 <= r975330;
        double r975332 = 3.0;
        double r975333 = cbrt(r975332);
        double r975334 = fabs(r975333);
        double r975335 = r975329 / r975334;
        double r975336 = sqrt(r975333);
        double r975337 = r975335 / r975336;
        double r975338 = fabs(r975337);
        double r975339 = -2.110786827503938e+24;
        bool r975340 = r975329 <= r975339;
        double r975341 = -1.0;
        double r975342 = x;
        double r975343 = sqrt(r975332);
        double r975344 = r975342 / r975343;
        double r975345 = r975341 * r975344;
        double r975346 = fabs(r975345);
        double r975347 = -3.265579843763803e-100;
        bool r975348 = r975329 <= r975347;
        double r975349 = r975342 * r975342;
        double r975350 = y;
        double r975351 = r975350 * r975350;
        double r975352 = r975349 + r975351;
        double r975353 = r975329 * r975329;
        double r975354 = r975352 + r975353;
        double r975355 = sqrt(r975354);
        double r975356 = r975355 / r975343;
        double r975357 = fabs(r975356);
        double r975358 = -5.178390466828926e-174;
        bool r975359 = r975329 <= r975358;
        double r975360 = 3.6020310138858934e-62;
        bool r975361 = r975329 <= r975360;
        double r975362 = 1.4079949245820615e+79;
        bool r975363 = r975329 <= r975362;
        double r975364 = 4.245734338350756e+110;
        bool r975365 = r975329 <= r975364;
        double r975366 = 0.3333333333333333;
        double r975367 = 2.0;
        double r975368 = pow(r975342, r975367);
        double r975369 = pow(r975350, r975367);
        double r975370 = pow(r975329, r975367);
        double r975371 = r975369 + r975370;
        double r975372 = r975368 + r975371;
        double r975373 = r975366 * r975372;
        double r975374 = sqrt(r975373);
        double r975375 = r975365 ? r975374 : r975338;
        double r975376 = r975363 ? r975346 : r975375;
        double r975377 = r975361 ? r975357 : r975376;
        double r975378 = r975359 ? r975346 : r975377;
        double r975379 = r975348 ? r975357 : r975378;
        double r975380 = r975340 ? r975346 : r975379;
        double r975381 = r975331 ? r975338 : r975380;
        return r975381;
}

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
Herbie28.5
\[\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 z < -3.9555152073667915e+121 or 4.245734338350756e+110 < z

    1. Initial program 57.0

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

      \[\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-sqrt57.1

      \[\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-frac57.0

      \[\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. Applied rem-sqrt-square57.0

      \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
    7. Taylor expanded around 0 16.7

      \[\leadsto \left|\frac{\color{blue}{z}}{\sqrt{3}}\right|\]
    8. Using strategy rm
    9. Applied add-cube-cbrt16.7

      \[\leadsto \left|\frac{z}{\sqrt{\color{blue}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}}\right|\]
    10. Applied sqrt-prod16.7

      \[\leadsto \left|\frac{z}{\color{blue}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \sqrt{\sqrt[3]{3}}}}\right|\]
    11. Applied associate-/r*16.7

      \[\leadsto \left|\color{blue}{\frac{\frac{z}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}}}}{\sqrt{\sqrt[3]{3}}}}\right|\]
    12. Simplified16.7

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

    if -3.9555152073667915e+121 < z < -2.110786827503938e+24 or -3.265579843763803e-100 < z < -5.178390466828926e-174 or 3.6020310138858934e-62 < z < 1.4079949245820615e+79

    1. Initial program 28.1

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

      \[\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-sqrt28.3

      \[\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-frac28.2

      \[\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. Applied rem-sqrt-square28.2

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

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

    if -2.110786827503938e+24 < z < -3.265579843763803e-100 or -5.178390466828926e-174 < z < 3.6020310138858934e-62

    1. Initial program 30.9

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

      \[\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-sqrt31.0

      \[\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-frac31.0

      \[\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. Applied rem-sqrt-square31.0

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

    if 1.4079949245820615e+79 < z < 4.245734338350756e+110

    1. Initial program 28.5

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

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot {x}^{2} + \left(0.333333333333333315 \cdot {y}^{2} + 0.333333333333333315 \cdot {z}^{2}\right)}}\]
    3. Simplified28.5

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification28.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.95551520736679148 \cdot 10^{121}:\\ \;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \mathbf{elif}\;z \le -2.110786827503938 \cdot 10^{24}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -3.265579843763803 \cdot 10^{-100}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le -5.1783904668289256 \cdot 10^{-174}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 3.6020310138858934 \cdot 10^{-62}:\\ \;\;\;\;\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 1.40799492458206149 \cdot 10^{79}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;z \le 4.24573433835075588 \cdot 10^{110}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\frac{z}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\\ \end{array}\]

Reproduce

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