Average Error: 37.7 → 25.3
Time: 12.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.16634249568808763 \cdot 10^{121}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \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}:\\ \;\;\;\;x \cdot \sqrt{\frac{1}{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.16634249568808763 \cdot 10^{121}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

\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}:\\
\;\;\;\;x \cdot \sqrt{\frac{1}{3}}\\

\end{array}
double f(double x, double y, double z) {
        double r826708 = x;
        double r826709 = r826708 * r826708;
        double r826710 = y;
        double r826711 = r826710 * r826710;
        double r826712 = r826709 + r826711;
        double r826713 = z;
        double r826714 = r826713 * r826713;
        double r826715 = r826712 + r826714;
        double r826716 = 3.0;
        double r826717 = r826715 / r826716;
        double r826718 = sqrt(r826717);
        return r826718;
}

double f(double x, double y, double z) {
        double r826719 = x;
        double r826720 = -1.1663424956880876e+121;
        bool r826721 = r826719 <= r826720;
        double r826722 = -r826719;
        double r826723 = 3.0;
        double r826724 = sqrt(r826723);
        double r826725 = r826722 / r826724;
        double r826726 = 1.1586965865467858e+60;
        bool r826727 = r826719 <= r826726;
        double r826728 = 0.3333333333333333;
        double r826729 = r826719 * r826719;
        double r826730 = y;
        double r826731 = r826730 * r826730;
        double r826732 = r826729 + r826731;
        double r826733 = z;
        double r826734 = r826733 * r826733;
        double r826735 = r826732 + r826734;
        double r826736 = r826728 * r826735;
        double r826737 = sqrt(r826736);
        double r826738 = 1.0;
        double r826739 = r826738 / r826723;
        double r826740 = sqrt(r826739);
        double r826741 = r826719 * r826740;
        double r826742 = r826727 ? r826737 : r826741;
        double r826743 = r826721 ? r826725 : r826742;
        return r826743;
}

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.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.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 div-inv57.8

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

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}}\]
    5. Using strategy rm
    6. Applied sqrt-div57.8

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{3}}}\]
    7. Applied associate-*r/57.8

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

      \[\leadsto \frac{\color{blue}{\sqrt{{x}^{2} + \left({y}^{2} + {z}^{2}\right)}}}{\sqrt{3}}\]
    9. Taylor expanded around -inf 16.5

      \[\leadsto \frac{\color{blue}{-1 \cdot x}}{\sqrt{3}}\]
    10. Simplified16.5

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

    if -1.1663424956880876e+121 < x < 1.1586965865467858e+60

    1. Initial program 29.0

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

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

      \[\leadsto \sqrt{\color{blue}{0.333333333333333315 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\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. Using strategy rm
    3. Applied div-inv50.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.16634249568808763 \cdot 10^{121}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \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}:\\ \;\;\;\;x \cdot \sqrt{\frac{1}{3}}\\ \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)))