Average Error: 38.4 → 26.4
Time: 7.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.35612836383285588 \cdot 10^{108}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt[3]{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.35612836383285588 \cdot 10^{108}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

\mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\
\;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt[3]{3}}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r873169 = x;
        double r873170 = r873169 * r873169;
        double r873171 = y;
        double r873172 = r873171 * r873171;
        double r873173 = r873170 + r873172;
        double r873174 = z;
        double r873175 = r873174 * r873174;
        double r873176 = r873173 + r873175;
        double r873177 = 3.0;
        double r873178 = r873176 / r873177;
        double r873179 = sqrt(r873178);
        return r873179;
}

double f(double x, double y, double z) {
        double r873180 = x;
        double r873181 = -1.356128363832856e+108;
        bool r873182 = r873180 <= r873181;
        double r873183 = -1.0;
        double r873184 = 0.3333333333333333;
        double r873185 = sqrt(r873184);
        double r873186 = r873180 * r873185;
        double r873187 = r873183 * r873186;
        double r873188 = 1.0479353069555717e+77;
        bool r873189 = r873180 <= r873188;
        double r873190 = r873180 * r873180;
        double r873191 = y;
        double r873192 = r873191 * r873191;
        double r873193 = r873190 + r873192;
        double r873194 = z;
        double r873195 = r873194 * r873194;
        double r873196 = r873193 + r873195;
        double r873197 = sqrt(r873196);
        double r873198 = 3.0;
        double r873199 = cbrt(r873198);
        double r873200 = r873199 * r873199;
        double r873201 = r873197 / r873200;
        double r873202 = r873197 / r873199;
        double r873203 = r873201 * r873202;
        double r873204 = sqrt(r873203);
        double r873205 = r873189 ? r873204 : r873186;
        double r873206 = r873182 ? r873187 : r873205;
        return r873206;
}

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.4
Target25.9
Herbie26.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 3 regimes
  2. if x < -1.356128363832856e+108

    1. Initial program 55.4

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

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

    if -1.356128363832856e+108 < x < 1.0479353069555717e+77

    1. Initial program 29.9

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

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

      \[\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}}}{\left(\sqrt[3]{3} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    5. Applied times-frac30.0

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

    if 1.0479353069555717e+77 < x

    1. Initial program 53.1

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

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

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

Reproduce

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