Average Error: 38.3 → 26.6
Time: 9.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le -9.175538176234306774861124985348964759226 \cdot 10^{-47}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{elif}\;x \le -3.477829585500688835235463323893909614843 \cdot 10^{-87}:\\ \;\;\;\;\frac{z}{\sqrt{\sqrt[3]{3}} \cdot \left|\sqrt[3]{3}\right|}\\ \mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{elif}\;x \le 159214352571496419201890875382794551296:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.443929975645744209051574725726619657372 \cdot 10^{146}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\

\mathbf{elif}\;x \le -9.175538176234306774861124985348964759226 \cdot 10^{-47}:\\
\;\;\;\;\sqrt{\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}}}\\

\mathbf{elif}\;x \le -3.477829585500688835235463323893909614843 \cdot 10^{-87}:\\
\;\;\;\;\frac{z}{\sqrt{\sqrt[3]{3}} \cdot \left|\sqrt[3]{3}\right|}\\

\mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\
\;\;\;\;\sqrt{\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}}}\\

\mathbf{elif}\;x \le 159214352571496419201890875382794551296:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

\mathbf{elif}\;x \le 1.443929975645744209051574725726619657372 \cdot 10^{146}:\\
\;\;\;\;\sqrt{\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}}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r598074 = x;
        double r598075 = r598074 * r598074;
        double r598076 = y;
        double r598077 = r598076 * r598076;
        double r598078 = r598075 + r598077;
        double r598079 = z;
        double r598080 = r598079 * r598079;
        double r598081 = r598078 + r598080;
        double r598082 = 3.0;
        double r598083 = r598081 / r598082;
        double r598084 = sqrt(r598083);
        return r598084;
}

double f(double x, double y, double z) {
        double r598085 = x;
        double r598086 = -4.3499399230850033e+145;
        bool r598087 = r598085 <= r598086;
        double r598088 = 1.0;
        double r598089 = 3.0;
        double r598090 = cbrt(r598089);
        double r598091 = r598090 * r598090;
        double r598092 = r598088 / r598091;
        double r598093 = sqrt(r598092);
        double r598094 = -1.0;
        double r598095 = r598088 / r598090;
        double r598096 = sqrt(r598095);
        double r598097 = r598096 * r598085;
        double r598098 = r598094 * r598097;
        double r598099 = r598093 * r598098;
        double r598100 = -9.175538176234307e-47;
        bool r598101 = r598085 <= r598100;
        double r598102 = r598085 * r598085;
        double r598103 = y;
        double r598104 = r598103 * r598103;
        double r598105 = r598102 + r598104;
        double r598106 = z;
        double r598107 = r598106 * r598106;
        double r598108 = r598105 + r598107;
        double r598109 = sqrt(r598108);
        double r598110 = r598109 / r598091;
        double r598111 = r598109 / r598090;
        double r598112 = r598110 * r598111;
        double r598113 = sqrt(r598112);
        double r598114 = -3.477829585500689e-87;
        bool r598115 = r598085 <= r598114;
        double r598116 = sqrt(r598090);
        double r598117 = fabs(r598090);
        double r598118 = r598116 * r598117;
        double r598119 = r598106 / r598118;
        double r598120 = 770005.7426888434;
        bool r598121 = r598085 <= r598120;
        double r598122 = 1.5921435257149642e+38;
        bool r598123 = r598085 <= r598122;
        double r598124 = 0.3333333333333333;
        double r598125 = sqrt(r598124);
        double r598126 = r598106 * r598125;
        double r598127 = 1.4439299756457442e+146;
        bool r598128 = r598085 <= r598127;
        double r598129 = r598093 * r598097;
        double r598130 = r598128 ? r598113 : r598129;
        double r598131 = r598123 ? r598126 : r598130;
        double r598132 = r598121 ? r598113 : r598131;
        double r598133 = r598115 ? r598119 : r598132;
        double r598134 = r598101 ? r598113 : r598133;
        double r598135 = r598087 ? r598099 : r598134;
        return r598135;
}

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.3
Target26.1
Herbie26.6
\[\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 < -4.3499399230850033e+145

    1. Initial program 62.4

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt62.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-identity62.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-frac62.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-prod62.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. Taylor expanded around -inf 15.1

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

    if -4.3499399230850033e+145 < x < -9.175538176234307e-47 or -3.477829585500689e-87 < x < 770005.7426888434 or 1.5921435257149642e+38 < x < 1.4439299756457442e+146

    1. Initial program 29.3

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt29.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 add-sqr-sqrt29.3

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

      \[\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}}}}\]

    if -9.175538176234307e-47 < x < -3.477829585500689e-87

    1. Initial program 34.5

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

      \[\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-identity34.5

      \[\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-frac34.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-prod34.6

      \[\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. Taylor expanded around 0 47.3

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot z\right)}\]
    8. Using strategy rm
    9. Applied sqrt-div47.4

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{\sqrt[3]{3}}}} \cdot z\right)\]
    10. Applied associate-*l/47.3

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\frac{\sqrt{1} \cdot z}{\sqrt{\sqrt[3]{3}}}}\]
    11. Applied sqrt-div47.3

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}}}} \cdot \frac{\sqrt{1} \cdot z}{\sqrt{\sqrt[3]{3}}}\]
    12. Applied frac-times47.3

      \[\leadsto \color{blue}{\frac{\sqrt{1} \cdot \left(\sqrt{1} \cdot z\right)}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \sqrt{\sqrt[3]{3}}}}\]
    13. Simplified47.3

      \[\leadsto \frac{\color{blue}{z}}{\sqrt{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \sqrt{\sqrt[3]{3}}}\]
    14. Simplified47.3

      \[\leadsto \frac{z}{\color{blue}{\sqrt{\sqrt[3]{3}} \cdot \left|\sqrt[3]{3}\right|}}\]

    if 770005.7426888434 < x < 1.5921435257149642e+38

    1. Initial program 28.3

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

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

    if 1.4439299756457442e+146 < x

    1. Initial program 61.8

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

      \[\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-identity61.8

      \[\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-frac61.8

      \[\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-prod61.8

      \[\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. Taylor expanded around inf 14.3

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification26.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(-1 \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\right)\\ \mathbf{elif}\;x \le -9.175538176234306774861124985348964759226 \cdot 10^{-47}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{elif}\;x \le -3.477829585500688835235463323893909614843 \cdot 10^{-87}:\\ \;\;\;\;\frac{z}{\sqrt{\sqrt[3]{3}} \cdot \left|\sqrt[3]{3}\right|}\\ \mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{elif}\;x \le 159214352571496419201890875382794551296:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 1.443929975645744209051574725726619657372 \cdot 10^{146}:\\ \;\;\;\;\sqrt{\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}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot x\right)\\ \end{array}\]

Reproduce

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