Average Error: 38.1 → 26.2
Time: 38.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 2.030268028165567603283501741474824619367 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.507674832315874830585518015460277676166 \cdot 10^{110}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\
\;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\

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

\mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\
\;\;\;\;\frac{z}{\sqrt{3}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r38152667 = x;
        double r38152668 = r38152667 * r38152667;
        double r38152669 = y;
        double r38152670 = r38152669 * r38152669;
        double r38152671 = r38152668 + r38152670;
        double r38152672 = z;
        double r38152673 = r38152672 * r38152672;
        double r38152674 = r38152671 + r38152673;
        double r38152675 = 3.0;
        double r38152676 = r38152674 / r38152675;
        double r38152677 = sqrt(r38152676);
        return r38152677;
}

double f(double x, double y, double z) {
        double r38152678 = x;
        double r38152679 = -2.061657435745164e+101;
        bool r38152680 = r38152678 <= r38152679;
        double r38152681 = -r38152678;
        double r38152682 = 0.3333333333333333;
        double r38152683 = sqrt(r38152682);
        double r38152684 = r38152681 * r38152683;
        double r38152685 = 2.0302680281655676e-131;
        bool r38152686 = r38152678 <= r38152685;
        double r38152687 = z;
        double r38152688 = r38152687 * r38152687;
        double r38152689 = y;
        double r38152690 = r38152689 * r38152689;
        double r38152691 = r38152678 * r38152678;
        double r38152692 = r38152690 + r38152691;
        double r38152693 = r38152688 + r38152692;
        double r38152694 = sqrt(r38152693);
        double r38152695 = 3.0;
        double r38152696 = sqrt(r38152695);
        double r38152697 = r38152694 / r38152696;
        double r38152698 = 9.401516089224205e-110;
        bool r38152699 = r38152678 <= r38152698;
        double r38152700 = r38152687 / r38152696;
        double r38152701 = 1.5076748323158748e+110;
        bool r38152702 = r38152678 <= r38152701;
        double r38152703 = r38152683 * r38152678;
        double r38152704 = r38152702 ? r38152697 : r38152703;
        double r38152705 = r38152699 ? r38152700 : r38152704;
        double r38152706 = r38152686 ? r38152697 : r38152705;
        double r38152707 = r38152680 ? r38152684 : r38152706;
        return r38152707;
}

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
Target26.0
Herbie26.2
\[\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 4 regimes
  2. if x < -2.061657435745164e+101

    1. Initial program 54.3

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

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

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

    if -2.061657435745164e+101 < x < 2.0302680281655676e-131 or 9.401516089224205e-110 < x < 1.5076748323158748e+110

    1. Initial program 29.8

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

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

    if 2.0302680281655676e-131 < x < 9.401516089224205e-110

    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 sqrt-div29.4

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

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

    if 1.5076748323158748e+110 < x

    1. Initial program 55.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333148296162562473909929395}\\ \mathbf{elif}\;x \le 2.030268028165567603283501741474824619367 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.507674832315874830585518015460277676166 \cdot 10^{110}:\\ \;\;\;\;\frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

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