Average Error: 37.7 → 25.4
Time: 9.0s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.16634249568808763 \cdot 10^{121}:\\ \;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -2.24510505347645 \cdot 10^{-269}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;x \le 5.75865971739732 \cdot 10^{-225}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.1586965865467858 \cdot 10^{60}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.16634249568808763 \cdot 10^{121}:\\
\;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \le -2.24510505347645 \cdot 10^{-269}:\\
\;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r746009 = x;
        double r746010 = r746009 * r746009;
        double r746011 = y;
        double r746012 = r746011 * r746011;
        double r746013 = r746010 + r746012;
        double r746014 = z;
        double r746015 = r746014 * r746014;
        double r746016 = r746013 + r746015;
        double r746017 = 3.0;
        double r746018 = r746016 / r746017;
        double r746019 = sqrt(r746018);
        return r746019;
}

double f(double x, double y, double z) {
        double r746020 = x;
        double r746021 = -1.1663424956880876e+121;
        bool r746022 = r746020 <= r746021;
        double r746023 = 3.0;
        double r746024 = sqrt(r746023);
        double r746025 = r746020 / r746024;
        double r746026 = -r746025;
        double r746027 = fabs(r746026);
        double r746028 = -2.24510505347645e-269;
        bool r746029 = r746020 <= r746028;
        double r746030 = 0.3333333333333333;
        double r746031 = r746020 * r746020;
        double r746032 = y;
        double r746033 = r746032 * r746032;
        double r746034 = r746031 + r746033;
        double r746035 = z;
        double r746036 = r746035 * r746035;
        double r746037 = r746034 + r746036;
        double r746038 = r746030 * r746037;
        double r746039 = sqrt(r746038);
        double r746040 = 5.75865971739732e-225;
        bool r746041 = r746020 <= r746040;
        double r746042 = r746035 / r746024;
        double r746043 = fabs(r746042);
        double r746044 = 1.1586965865467858e+60;
        bool r746045 = r746020 <= r746044;
        double r746046 = sqrt(r746030);
        double r746047 = r746046 * r746020;
        double r746048 = r746045 ? r746039 : r746047;
        double r746049 = r746041 ? r746043 : r746048;
        double r746050 = r746029 ? r746039 : r746049;
        double r746051 = r746022 ? r746027 : r746050;
        return r746051;
}

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.7
Target25.8
Herbie25.4
\[\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 x < -1.1663424956880876e+121

    1. Initial program 57.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt57.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-sqrt57.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-frac57.8

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

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

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

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

    if -1.1663424956880876e+121 < x < -2.24510505347645e-269 or 5.75865971739732e-225 < x < 1.1586965865467858e+60

    1. Initial program 28.7

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

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

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

    if -2.24510505347645e-269 < x < 5.75865971739732e-225

    1. Initial program 30.6

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt30.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-sqrt30.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-frac30.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}}}}\]
    6. Applied rem-sqrt-square30.7

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

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

    if 1.1586965865467858e+60 < x

    1. Initial program 50.1

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

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

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

      \[\leadsto \color{blue}{\sqrt{0.333333333333333315} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}\]
    6. Taylor expanded around inf 20.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.16634249568808763 \cdot 10^{121}:\\ \;\;\;\;\left|-\frac{x}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le -2.24510505347645 \cdot 10^{-269}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;x \le 5.75865971739732 \cdot 10^{-225}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 1.1586965865467858 \cdot 10^{60}:\\ \;\;\;\;\sqrt{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot x\\ \end{array}\]

Reproduce

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