Average Error: 38.1 → 26.4
Time: 23.1s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.907936129816997801228578464985264226071 \cdot 10^{126}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.746633267683835356728824682810074508397 \cdot 10^{59}:\\ \;\;\;\;\left(\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}}}\right) \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -1.907936129816997801228578464985264226071 \cdot 10^{126}:\\
\;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 1.746633267683835356728824682810074508397 \cdot 10^{59}:\\
\;\;\;\;\left(\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}}}\right) \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r579717 = x;
        double r579718 = r579717 * r579717;
        double r579719 = y;
        double r579720 = r579719 * r579719;
        double r579721 = r579718 + r579720;
        double r579722 = z;
        double r579723 = r579722 * r579722;
        double r579724 = r579721 + r579723;
        double r579725 = 3.0;
        double r579726 = r579724 / r579725;
        double r579727 = sqrt(r579726);
        return r579727;
}

double f(double x, double y, double z) {
        double r579728 = x;
        double r579729 = -1.9079361298169978e+126;
        bool r579730 = r579728 <= r579729;
        double r579731 = 0.3333333333333333;
        double r579732 = sqrt(r579731);
        double r579733 = r579728 * r579732;
        double r579734 = -r579733;
        double r579735 = 1.7466332676838354e+59;
        bool r579736 = r579728 <= r579735;
        double r579737 = 1.0;
        double r579738 = 3.0;
        double r579739 = cbrt(r579738);
        double r579740 = r579739 * r579739;
        double r579741 = r579737 / r579740;
        double r579742 = sqrt(r579741);
        double r579743 = cbrt(r579739);
        double r579744 = r579743 * r579743;
        double r579745 = r579737 / r579744;
        double r579746 = sqrt(r579745);
        double r579747 = r579742 * r579746;
        double r579748 = z;
        double r579749 = y;
        double r579750 = 2.0;
        double r579751 = pow(r579749, r579750);
        double r579752 = fma(r579728, r579728, r579751);
        double r579753 = fma(r579748, r579748, r579752);
        double r579754 = r579753 / r579743;
        double r579755 = sqrt(r579754);
        double r579756 = r579747 * r579755;
        double r579757 = r579736 ? r579756 : r579733;
        double r579758 = r579730 ? r579734 : r579757;
        return r579758;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original38.1
Target25.5
Herbie26.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.9079361298169978e+126

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    3. Simplified17.3

      \[\leadsto \color{blue}{-x \cdot \sqrt{0.3333333333333333148296162562473909929395}}\]

    if -1.9079361298169978e+126 < x < 1.7466332676838354e+59

    1. Initial program 29.6

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

      \[\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 *-un-lft-identity29.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} \cdot \sqrt[3]{3}\right) \cdot \sqrt[3]{3}}}\]
    5. Applied times-frac29.6

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

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

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{3}}}}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt29.7

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\color{blue}{\left(\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}\right) \cdot \sqrt[3]{\sqrt[3]{3}}}}}\]
    10. Applied *-un-lft-identity29.7

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}}{\left(\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}\right) \cdot \sqrt[3]{\sqrt[3]{3}}}}\]
    11. Applied times-frac29.7

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\color{blue}{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}} \cdot \frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}}\]
    12. Applied sqrt-prod29.7

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}}} \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}\right)}\]
    13. Applied associate-*r*29.7

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}}}\right) \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}}\]

    if 1.7466332676838354e+59 < x

    1. Initial program 50.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.907936129816997801228578464985264226071 \cdot 10^{126}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.746633267683835356728824682810074508397 \cdot 10^{59}:\\ \;\;\;\;\left(\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{1}{\sqrt[3]{\sqrt[3]{3}} \cdot \sqrt[3]{\sqrt[3]{3}}}}\right) \cdot \sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, {y}^{2}\right)\right)}{\sqrt[3]{\sqrt[3]{3}}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

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