Average Error: 35.6 → 24.6
Time: 12.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.1295859422058697 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\ \;\;\;\;\sqrt{\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{3.0} \cdot \sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}
\begin{array}{l}
\mathbf{if}\;x \le -1.1295859422058697 \cdot 10^{+130}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\

\mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\
\;\;\;\;\sqrt{\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{3.0} \cdot \sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r16057036 = x;
        double r16057037 = r16057036 * r16057036;
        double r16057038 = y;
        double r16057039 = r16057038 * r16057038;
        double r16057040 = r16057037 + r16057039;
        double r16057041 = z;
        double r16057042 = r16057041 * r16057041;
        double r16057043 = r16057040 + r16057042;
        double r16057044 = 3.0;
        double r16057045 = r16057043 / r16057044;
        double r16057046 = sqrt(r16057045);
        return r16057046;
}

double f(double x, double y, double z) {
        double r16057047 = x;
        double r16057048 = -1.1295859422058697e+130;
        bool r16057049 = r16057047 <= r16057048;
        double r16057050 = 0.3333333333333333;
        double r16057051 = sqrt(r16057050);
        double r16057052 = -r16057047;
        double r16057053 = r16057051 * r16057052;
        double r16057054 = 1.3936358732915887e+155;
        bool r16057055 = r16057047 <= r16057054;
        double r16057056 = z;
        double r16057057 = r16057056 * r16057056;
        double r16057058 = y;
        double r16057059 = r16057058 * r16057058;
        double r16057060 = r16057047 * r16057047;
        double r16057061 = r16057059 + r16057060;
        double r16057062 = r16057057 + r16057061;
        double r16057063 = sqrt(r16057062);
        double r16057064 = 3.0;
        double r16057065 = r16057063 / r16057064;
        double r16057066 = r16057065 * r16057063;
        double r16057067 = sqrt(r16057066);
        double r16057068 = r16057051 * r16057047;
        double r16057069 = r16057055 ? r16057067 : r16057068;
        double r16057070 = r16057049 ? r16057053 : r16057069;
        return r16057070;
}

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

Original35.6
Target24.3
Herbie24.6
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.1295859422058697e+130

    1. Initial program 54.6

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}\right) \cdot \sqrt[3]{3.0}}}}\]
    4. Applied *-un-lft-identity54.6

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}} \cdot \frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3.0}}}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt54.6

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}} \cdot \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]{3.0}}}\]
    8. Applied associate-/l*54.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
    10. Simplified16.0

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

    if -1.1295859422058697e+130 < x < 1.3936358732915887e+155

    1. Initial program 28.0

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity28.0

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{1 \cdot 3.0}}}\]
    4. Applied add-sqr-sqrt28.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}}}{1 \cdot 3.0}}\]
    5. Applied times-frac28.0

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

    if 1.3936358732915887e+155 < x

    1. Initial program 59.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.1295859422058697 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\ \;\;\;\;\sqrt{\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{3.0} \cdot \sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))