Average Error: 38.1 → 27.0
Time: 32.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.62918886015480700245891178761632271543 \cdot 10^{100}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\ \;\;\;\;\sqrt{\frac{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3} \cdot \sqrt[3]{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.62918886015480700245891178761632271543 \cdot 10^{100}:\\
\;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\
\;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\

\mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\
\;\;\;\;\sqrt{\frac{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3} \cdot \sqrt[3]{3}}}{\sqrt[3]{3}}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r747752 = x;
        double r747753 = r747752 * r747752;
        double r747754 = y;
        double r747755 = r747754 * r747754;
        double r747756 = r747753 + r747755;
        double r747757 = z;
        double r747758 = r747757 * r747757;
        double r747759 = r747756 + r747758;
        double r747760 = 3.0;
        double r747761 = r747759 / r747760;
        double r747762 = sqrt(r747761);
        return r747762;
}

double f(double x, double y, double z) {
        double r747763 = x;
        double r747764 = -1.629188860154807e+100;
        bool r747765 = r747763 <= r747764;
        double r747766 = 0.3333333333333333;
        double r747767 = sqrt(r747766);
        double r747768 = r747763 * r747767;
        double r747769 = -r747768;
        double r747770 = 5.393455774424304e-203;
        bool r747771 = r747763 <= r747770;
        double r747772 = 2.0;
        double r747773 = pow(r747763, r747772);
        double r747774 = y;
        double r747775 = pow(r747774, r747772);
        double r747776 = z;
        double r747777 = pow(r747776, r747772);
        double r747778 = r747775 + r747777;
        double r747779 = r747773 + r747778;
        double r747780 = r747766 * r747779;
        double r747781 = sqrt(r747780);
        double r747782 = 6.220903762266977e-149;
        bool r747783 = r747763 <= r747782;
        double r747784 = r747776 * r747767;
        double r747785 = 2.9682675892586475e+95;
        bool r747786 = r747763 <= r747785;
        double r747787 = r747763 * r747763;
        double r747788 = r747774 * r747774;
        double r747789 = r747787 + r747788;
        double r747790 = r747776 * r747776;
        double r747791 = r747789 + r747790;
        double r747792 = 3.0;
        double r747793 = cbrt(r747792);
        double r747794 = r747793 * r747793;
        double r747795 = r747791 / r747794;
        double r747796 = r747795 / r747793;
        double r747797 = sqrt(r747796);
        double r747798 = r747786 ? r747797 : r747768;
        double r747799 = r747783 ? r747784 : r747798;
        double r747800 = r747771 ? r747781 : r747799;
        double r747801 = r747765 ? r747769 : r747800;
        return r747801;
}

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.1
Target25.3
Herbie27.0
\[\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 5 regimes
  2. if x < -1.629188860154807e+100

    1. Initial program 54.3

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

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

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

    if -1.629188860154807e+100 < x < 5.393455774424304e-203

    1. Initial program 29.6

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

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

      \[\leadsto \sqrt{\color{blue}{0.3333333333333333148296162562473909929395 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}}\]

    if 5.393455774424304e-203 < x < 6.220903762266977e-149

    1. Initial program 28.5

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

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

    if 6.220903762266977e-149 < x < 2.9682675892586475e+95

    1. Initial program 30.3

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

      \[\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 associate-/r*30.4

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

    if 2.9682675892586475e+95 < x

    1. Initial program 54.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.62918886015480700245891178761632271543 \cdot 10^{100}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395 \cdot \left({x}^{2} + \left({y}^{2} + {z}^{2}\right)\right)}\\ \mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\ \;\;\;\;\sqrt{\frac{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3} \cdot \sqrt[3]{3}}}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \end{array}\]

Reproduce

herbie shell --seed 2019305 
(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.3964793941097758e136) (/ (- z) (sqrt 3)) (if (< z 7.3202936944041821e117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.333333333333333315) z)))

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