Average Error: 38.4 → 25.9
Time: 12.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.801328071339668 \cdot 10^{105}:\\ \;\;\;\;-z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;z \le 1.27500165653461376 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\frac{\sqrt{{z}^{2} + \left(x \cdot x + y \cdot y\right)}}{\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}:\\ \;\;\;\;z \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}\;z \le -1.801328071339668 \cdot 10^{105}:\\
\;\;\;\;-z \cdot \sqrt{0.333333333333333315}\\

\mathbf{elif}\;z \le 1.27500165653461376 \cdot 10^{127}:\\
\;\;\;\;\sqrt{\frac{\sqrt{{z}^{2} + \left(x \cdot x + y \cdot y\right)}}{\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}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

\end{array}
double f(double x, double y, double z) {
        double r698716 = x;
        double r698717 = r698716 * r698716;
        double r698718 = y;
        double r698719 = r698718 * r698718;
        double r698720 = r698717 + r698719;
        double r698721 = z;
        double r698722 = r698721 * r698721;
        double r698723 = r698720 + r698722;
        double r698724 = 3.0;
        double r698725 = r698723 / r698724;
        double r698726 = sqrt(r698725);
        return r698726;
}

double f(double x, double y, double z) {
        double r698727 = z;
        double r698728 = -1.8013280713396678e+105;
        bool r698729 = r698727 <= r698728;
        double r698730 = 0.3333333333333333;
        double r698731 = sqrt(r698730);
        double r698732 = r698727 * r698731;
        double r698733 = -r698732;
        double r698734 = 1.2750016565346138e+127;
        bool r698735 = r698727 <= r698734;
        double r698736 = 2.0;
        double r698737 = pow(r698727, r698736);
        double r698738 = x;
        double r698739 = r698738 * r698738;
        double r698740 = y;
        double r698741 = r698740 * r698740;
        double r698742 = r698739 + r698741;
        double r698743 = r698737 + r698742;
        double r698744 = sqrt(r698743);
        double r698745 = 3.0;
        double r698746 = cbrt(r698745);
        double r698747 = r698746 * r698746;
        double r698748 = r698744 / r698747;
        double r698749 = r698727 * r698727;
        double r698750 = r698742 + r698749;
        double r698751 = sqrt(r698750);
        double r698752 = r698751 / r698746;
        double r698753 = r698748 * r698752;
        double r698754 = sqrt(r698753);
        double r698755 = r698735 ? r698754 : r698732;
        double r698756 = r698729 ? r698733 : r698755;
        return r698756;
}

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
Herbie25.9
\[\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 z < -1.8013280713396678e+105

    1. Initial program 54.5

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

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

      \[\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}}\]
    5. Applied times-frac54.5

      \[\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}}}\]
    6. Simplified54.5

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

      \[\leadsto \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\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}}}}\]
    9. Applied *-un-lft-identity54.5

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

      \[\leadsto \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\color{blue}{\sqrt{1} \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}}}\]
    11. Applied times-frac54.5

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sqrt{0.333333333333333315}\right)}\]
    15. Simplified18.5

      \[\leadsto \color{blue}{-z \cdot \sqrt{0.333333333333333315}}\]

    if -1.8013280713396678e+105 < z < 1.2750016565346138e+127

    1. Initial program 30.0

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

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

      \[\leadsto \sqrt{\color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\]
    7. Using strategy rm
    8. Applied add-cube-cbrt30.0

      \[\leadsto \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\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}}}}\]
    9. Applied *-un-lft-identity30.0

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

      \[\leadsto \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\color{blue}{\sqrt{1} \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}}}\]
    11. Applied times-frac30.0

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{{z}^{2} + \left(x \cdot x + y \cdot y\right)}}{\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.2750016565346138e+127 < z

    1. Initial program 58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.801328071339668 \cdot 10^{105}:\\ \;\;\;\;-z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;z \le 1.27500165653461376 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\frac{\sqrt{{z}^{2} + \left(x \cdot x + y \cdot y\right)}}{\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}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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