Average Error: 37.7 → 25.9
Time: 18.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.189641880819210225013444092263738436314 \cdot 10^{82}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;z \le 2.467313987424882841771707352404249918134 \cdot 10^{82}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot z\right)\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -1.189641880819210225013444092263738436314 \cdot 10^{82}:\\
\;\;\;\;-z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot z\right)\\

\end{array}
double f(double x, double y, double z) {
        double r543747 = x;
        double r543748 = r543747 * r543747;
        double r543749 = y;
        double r543750 = r543749 * r543749;
        double r543751 = r543748 + r543750;
        double r543752 = z;
        double r543753 = r543752 * r543752;
        double r543754 = r543751 + r543753;
        double r543755 = 3.0;
        double r543756 = r543754 / r543755;
        double r543757 = sqrt(r543756);
        return r543757;
}

double f(double x, double y, double z) {
        double r543758 = z;
        double r543759 = -1.1896418808192102e+82;
        bool r543760 = r543758 <= r543759;
        double r543761 = 0.3333333333333333;
        double r543762 = sqrt(r543761);
        double r543763 = r543758 * r543762;
        double r543764 = -r543763;
        double r543765 = 2.467313987424883e+82;
        bool r543766 = r543758 <= r543765;
        double r543767 = x;
        double r543768 = y;
        double r543769 = r543768 * r543768;
        double r543770 = fma(r543767, r543767, r543769);
        double r543771 = fma(r543758, r543758, r543770);
        double r543772 = sqrt(r543771);
        double r543773 = 3.0;
        double r543774 = cbrt(r543773);
        double r543775 = r543774 * r543774;
        double r543776 = r543772 / r543775;
        double r543777 = r543772 / r543774;
        double r543778 = r543776 * r543777;
        double r543779 = sqrt(r543778);
        double r543780 = 1.0;
        double r543781 = r543780 / r543775;
        double r543782 = sqrt(r543781);
        double r543783 = r543780 / r543774;
        double r543784 = sqrt(r543783);
        double r543785 = r543784 * r543758;
        double r543786 = r543782 * r543785;
        double r543787 = r543766 ? r543779 : r543786;
        double r543788 = r543760 ? r543764 : r543787;
        return r543788;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original37.7
Target25.6
Herbie25.9
\[\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 z < -1.1896418808192102e+82

    1. Initial program 52.4

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

      \[\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-identity52.4

      \[\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-frac52.4

      \[\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-prod52.4

      \[\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. Simplified52.4

      \[\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 \cdot y\right)\right)}{\sqrt[3]{3}}}}\]
    8. Taylor expanded around -inf 20.1

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sqrt{0.3333333333333333148296162562473909929395}\right)}\]
    9. Simplified20.1

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

    if -1.1896418808192102e+82 < z < 2.467313987424883e+82

    1. Initial program 29.1

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

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

      \[\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-frac29.2

      \[\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}}}}\]
    6. Simplified29.2

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\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}}}\]
    7. Simplified29.2

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

    if 2.467313987424883e+82 < z

    1. Initial program 54.0

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

      \[\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-identity54.0

      \[\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-frac54.0

      \[\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-prod54.0

      \[\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. Simplified54.0

      \[\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 \cdot y\right)\right)}{\sqrt[3]{3}}}}\]
    8. Taylor expanded around inf 20.1

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot z\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.9

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

Reproduce

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