Average Error: 38.2 → 26.4
Time: 19.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -18637040731758232623605069933264714596350:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\ \;\;\;\;\sqrt{\frac{1}{3} \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \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 -18637040731758232623605069933264714596350:\\
\;\;\;\;-\frac{x}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r575263 = x;
        double r575264 = r575263 * r575263;
        double r575265 = y;
        double r575266 = r575265 * r575265;
        double r575267 = r575264 + r575266;
        double r575268 = z;
        double r575269 = r575268 * r575268;
        double r575270 = r575267 + r575269;
        double r575271 = 3.0;
        double r575272 = r575270 / r575271;
        double r575273 = sqrt(r575272);
        return r575273;
}

double f(double x, double y, double z) {
        double r575274 = x;
        double r575275 = -1.8637040731758233e+40;
        bool r575276 = r575274 <= r575275;
        double r575277 = 3.0;
        double r575278 = sqrt(r575277);
        double r575279 = r575274 / r575278;
        double r575280 = -r575279;
        double r575281 = 4.376373199179286e+91;
        bool r575282 = r575274 <= r575281;
        double r575283 = 1.0;
        double r575284 = r575283 / r575277;
        double r575285 = r575274 * r575274;
        double r575286 = y;
        double r575287 = r575286 * r575286;
        double r575288 = r575285 + r575287;
        double r575289 = z;
        double r575290 = r575289 * r575289;
        double r575291 = r575288 + r575290;
        double r575292 = r575284 * r575291;
        double r575293 = sqrt(r575292);
        double r575294 = 0.3333333333333333;
        double r575295 = sqrt(r575294);
        double r575296 = r575274 * r575295;
        double r575297 = r575282 ? r575293 : r575296;
        double r575298 = r575276 ? r575280 : r575297;
        return r575298;
}

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.2
Target25.7
Herbie26.4
\[\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 < -1.8637040731758233e+40

    1. Initial program 49.0

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied associate-/r*49.0

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

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

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

    if -1.8637040731758233e+40 < x < 4.376373199179286e+91

    1. Initial program 29.7

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied associate-/r*29.8

      \[\leadsto \sqrt{\color{blue}{\frac{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt{3}}}{\sqrt{3}}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity29.8

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

      \[\leadsto \sqrt{\frac{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{1} \cdot \sqrt{3}}}}{\sqrt{3}}}\]
    8. Applied add-sqr-sqrt29.8

      \[\leadsto \sqrt{\frac{\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{1} \cdot \sqrt{3}}}{\sqrt{3}}}\]
    9. Applied times-frac29.8

      \[\leadsto \sqrt{\frac{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{1}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}{\sqrt{3}}}\]
    10. Applied associate-/l*29.8

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

      \[\leadsto \sqrt{\frac{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{1}}}{\color{blue}{\frac{3}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}}}}\]
    12. Using strategy rm
    13. Applied div-inv29.7

      \[\leadsto \sqrt{\frac{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{1}}}{\color{blue}{3 \cdot \frac{1}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}}}}\]
    14. Applied add-cube-cbrt29.7

      \[\leadsto \sqrt{\frac{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\color{blue}{\left(\sqrt[3]{\sqrt{1}} \cdot \sqrt[3]{\sqrt{1}}\right) \cdot \sqrt[3]{\sqrt{1}}}}}{3 \cdot \frac{1}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}}}\]
    15. Applied *-un-lft-identity29.7

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

      \[\leadsto \sqrt{\frac{\frac{\color{blue}{\sqrt{1} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}{\left(\sqrt[3]{\sqrt{1}} \cdot \sqrt[3]{\sqrt{1}}\right) \cdot \sqrt[3]{\sqrt{1}}}}{3 \cdot \frac{1}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}}}\]
    17. Applied times-frac29.7

      \[\leadsto \sqrt{\frac{\color{blue}{\frac{\sqrt{1}}{\sqrt[3]{\sqrt{1}} \cdot \sqrt[3]{\sqrt{1}}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt[3]{\sqrt{1}}}}}{3 \cdot \frac{1}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}}}\]
    18. Applied times-frac29.7

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

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

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

    if 4.376373199179286e+91 < x

    1. Initial program 53.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -18637040731758232623605069933264714596350:\\ \;\;\;\;-\frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\ \;\;\;\;\sqrt{\frac{1}{3} \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

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