Average Error: 38.0 → 25.9
Time: 4.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5602497723888015 \cdot 10^{48}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 2.816119708780296 \cdot 10^{121}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\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 -1.5602497723888015 \cdot 10^{48}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r839994 = x;
        double r839995 = r839994 * r839994;
        double r839996 = y;
        double r839997 = r839996 * r839996;
        double r839998 = r839995 + r839997;
        double r839999 = z;
        double r840000 = r839999 * r839999;
        double r840001 = r839998 + r840000;
        double r840002 = 3.0;
        double r840003 = r840001 / r840002;
        double r840004 = sqrt(r840003);
        return r840004;
}

double f(double x, double y, double z) {
        double r840005 = x;
        double r840006 = -1.5602497723888015e+48;
        bool r840007 = r840005 <= r840006;
        double r840008 = -1.0;
        double r840009 = r840008 * r840005;
        double r840010 = 1.0;
        double r840011 = 3.0;
        double r840012 = r840010 / r840011;
        double r840013 = sqrt(r840012);
        double r840014 = r840009 * r840013;
        double r840015 = 2.816119708780296e+121;
        bool r840016 = r840005 <= r840015;
        double r840017 = r840005 * r840005;
        double r840018 = y;
        double r840019 = r840018 * r840018;
        double r840020 = r840017 + r840019;
        double r840021 = z;
        double r840022 = r840021 * r840021;
        double r840023 = r840020 + r840022;
        double r840024 = sqrt(r840023);
        double r840025 = sqrt(r840011);
        double r840026 = r840024 / r840025;
        double r840027 = r840026 * r840026;
        double r840028 = sqrt(r840027);
        double r840029 = r840005 / r840025;
        double r840030 = r840016 ? r840028 : r840029;
        double r840031 = r840007 ? r840014 : r840030;
        return r840031;
}

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.0
Target25.9
Herbie25.9
\[\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 3 regimes
  2. if x < -1.5602497723888015e+48

    1. Initial program 50.5

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

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

      \[\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 21.4

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

    if -1.5602497723888015e+48 < x < 2.816119708780296e+121

    1. Initial program 29.6

      \[\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 add-sqr-sqrt29.8

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

      \[\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}}}}\]

    if 2.816119708780296e+121 < x

    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.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-sqrt57.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-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. Taylor expanded around inf 15.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5602497723888015 \cdot 10^{48}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 2.816119708780296 \cdot 10^{121}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]

Reproduce

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