Average Error: 37.8 → 26.0
Time: 3.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\

\mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\
\;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\sqrt{3}}\\

\end{array}
double f(double x, double y, double z) {
        double r1032797 = x;
        double r1032798 = r1032797 * r1032797;
        double r1032799 = y;
        double r1032800 = r1032799 * r1032799;
        double r1032801 = r1032798 + r1032800;
        double r1032802 = z;
        double r1032803 = r1032802 * r1032802;
        double r1032804 = r1032801 + r1032803;
        double r1032805 = 3.0;
        double r1032806 = r1032804 / r1032805;
        double r1032807 = sqrt(r1032806);
        return r1032807;
}

double f(double x, double y, double z) {
        double r1032808 = x;
        double r1032809 = -3.5794877859546974e+94;
        bool r1032810 = r1032808 <= r1032809;
        double r1032811 = -1.0;
        double r1032812 = r1032811 * r1032808;
        double r1032813 = 1.0;
        double r1032814 = 3.0;
        double r1032815 = r1032813 / r1032814;
        double r1032816 = sqrt(r1032815);
        double r1032817 = r1032812 * r1032816;
        double r1032818 = 6.058132317483692e-184;
        bool r1032819 = r1032808 <= r1032818;
        double r1032820 = r1032808 * r1032808;
        double r1032821 = y;
        double r1032822 = r1032821 * r1032821;
        double r1032823 = r1032820 + r1032822;
        double r1032824 = z;
        double r1032825 = r1032824 * r1032824;
        double r1032826 = r1032823 + r1032825;
        double r1032827 = sqrt(r1032826);
        double r1032828 = r1032827 * r1032816;
        double r1032829 = 4.463507529461489e-156;
        bool r1032830 = r1032808 <= r1032829;
        double r1032831 = sqrt(r1032814);
        double r1032832 = cbrt(r1032831);
        double r1032833 = r1032832 * r1032832;
        double r1032834 = r1032813 / r1032833;
        double r1032835 = r1032824 / r1032832;
        double r1032836 = r1032834 * r1032835;
        double r1032837 = 1.3881517315915455e+99;
        bool r1032838 = r1032808 <= r1032837;
        double r1032839 = r1032827 / r1032831;
        double r1032840 = r1032808 / r1032831;
        double r1032841 = r1032838 ? r1032839 : r1032840;
        double r1032842 = r1032830 ? r1032836 : r1032841;
        double r1032843 = r1032819 ? r1032828 : r1032842;
        double r1032844 = r1032810 ? r1032817 : r1032843;
        return r1032844;
}

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.8
Target25.7
Herbie26.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 < -3.5794877859546974e+94

    1. Initial program 52.6

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

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

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

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

    if -3.5794877859546974e+94 < x < 6.058132317483692e-184

    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 div-inv30.0

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

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

    if 6.058132317483692e-184 < x < 4.463507529461489e-156

    1. Initial program 32.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}\]
    4. Taylor expanded around 0 46.3

      \[\leadsto \frac{\color{blue}{z}}{\sqrt{3}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt46.4

      \[\leadsto \frac{z}{\color{blue}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}}\]
    7. Applied *-un-lft-identity46.4

      \[\leadsto \frac{\color{blue}{1 \cdot z}}{\left(\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}\right) \cdot \sqrt[3]{\sqrt{3}}}\]
    8. Applied times-frac46.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}}\]

    if 4.463507529461489e-156 < x < 1.3881517315915455e+99

    1. Initial program 27.3

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

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

    if 1.3881517315915455e+99 < x

    1. Initial program 54.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}\]
    4. Taylor expanded around inf 18.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;\frac{1}{\sqrt[3]{\sqrt{3}} \cdot \sqrt[3]{\sqrt{3}}} \cdot \frac{z}{\sqrt[3]{\sqrt{3}}}\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]

Reproduce

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