Average Error: 37.5 → 25.3
Time: 4.3s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.56421241030458443 \cdot 10^{110}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 1.960163308790063 \cdot 10^{125}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{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 -1.56421241030458443 \cdot 10^{110}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r1006915 = x;
        double r1006916 = r1006915 * r1006915;
        double r1006917 = y;
        double r1006918 = r1006917 * r1006917;
        double r1006919 = r1006916 + r1006918;
        double r1006920 = z;
        double r1006921 = r1006920 * r1006920;
        double r1006922 = r1006919 + r1006921;
        double r1006923 = 3.0;
        double r1006924 = r1006922 / r1006923;
        double r1006925 = sqrt(r1006924);
        return r1006925;
}

double f(double x, double y, double z) {
        double r1006926 = x;
        double r1006927 = -1.5642124103045844e+110;
        bool r1006928 = r1006926 <= r1006927;
        double r1006929 = -1.0;
        double r1006930 = 0.3333333333333333;
        double r1006931 = sqrt(r1006930);
        double r1006932 = r1006926 * r1006931;
        double r1006933 = r1006929 * r1006932;
        double r1006934 = 1.960163308790063e+125;
        bool r1006935 = r1006926 <= r1006934;
        double r1006936 = r1006926 * r1006926;
        double r1006937 = y;
        double r1006938 = r1006937 * r1006937;
        double r1006939 = r1006936 + r1006938;
        double r1006940 = z;
        double r1006941 = r1006940 * r1006940;
        double r1006942 = r1006939 + r1006941;
        double r1006943 = 1.0;
        double r1006944 = 3.0;
        double r1006945 = r1006943 / r1006944;
        double r1006946 = r1006942 * r1006945;
        double r1006947 = sqrt(r1006946);
        double r1006948 = r1006935 ? r1006947 : r1006932;
        double r1006949 = r1006928 ? r1006933 : r1006948;
        return r1006949;
}

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

Original37.5
Target25.6
Herbie25.3
\[\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.5642124103045844e+110

    1. Initial program 56.1

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

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

    if -1.5642124103045844e+110 < x < 1.960163308790063e+125

    1. Initial program 28.7

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

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

    if 1.960163308790063e+125 < x

    1. Initial program 58.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.56421241030458443 \cdot 10^{110}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 1.960163308790063 \cdot 10^{125}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +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)))