Average Error: 37.2 → 26.7
Time: 20.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.224655211931350154467905423564222198286 \cdot 10^{105}:\\ \;\;\;\;\frac{-y}{\sqrt{3}}\\ \mathbf{elif}\;y \le -5.954117318185457006023099047372652421673 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)} \cdot \frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{3}}\\ \mathbf{elif}\;y \le 1.788568988664100371947120533217940202845 \cdot 10^{-256}:\\ \;\;\;\;-\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \mathbf{elif}\;y \le 1.540169940903586483251096568897866173672 \cdot 10^{62}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;y \le -2.224655211931350154467905423564222198286 \cdot 10^{105}:\\
\;\;\;\;\frac{-y}{\sqrt{3}}\\

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

\mathbf{elif}\;y \le 1.788568988664100371947120533217940202845 \cdot 10^{-256}:\\
\;\;\;\;-\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r43103167 = x;
        double r43103168 = r43103167 * r43103167;
        double r43103169 = y;
        double r43103170 = r43103169 * r43103169;
        double r43103171 = r43103168 + r43103170;
        double r43103172 = z;
        double r43103173 = r43103172 * r43103172;
        double r43103174 = r43103171 + r43103173;
        double r43103175 = 3.0;
        double r43103176 = r43103174 / r43103175;
        double r43103177 = sqrt(r43103176);
        return r43103177;
}

double f(double x, double y, double z) {
        double r43103178 = y;
        double r43103179 = -2.2246552119313502e+105;
        bool r43103180 = r43103178 <= r43103179;
        double r43103181 = -r43103178;
        double r43103182 = 3.0;
        double r43103183 = sqrt(r43103182);
        double r43103184 = r43103181 / r43103183;
        double r43103185 = -5.954117318185457e-251;
        bool r43103186 = r43103178 <= r43103185;
        double r43103187 = z;
        double r43103188 = r43103187 * r43103187;
        double r43103189 = r43103178 * r43103178;
        double r43103190 = x;
        double r43103191 = r43103190 * r43103190;
        double r43103192 = r43103189 + r43103191;
        double r43103193 = r43103188 + r43103192;
        double r43103194 = sqrt(r43103193);
        double r43103195 = r43103194 / r43103182;
        double r43103196 = r43103194 * r43103195;
        double r43103197 = sqrt(r43103196);
        double r43103198 = 1.7885689886641004e-256;
        bool r43103199 = r43103178 <= r43103198;
        double r43103200 = 0.3333333333333333;
        double r43103201 = sqrt(r43103200);
        double r43103202 = r43103201 * r43103190;
        double r43103203 = -r43103202;
        double r43103204 = 1.5401699409035865e+62;
        bool r43103205 = r43103178 <= r43103204;
        double r43103206 = 1.0;
        double r43103207 = cbrt(r43103182);
        double r43103208 = r43103207 * r43103207;
        double r43103209 = r43103206 / r43103208;
        double r43103210 = r43103193 / r43103207;
        double r43103211 = r43103209 * r43103210;
        double r43103212 = sqrt(r43103211);
        double r43103213 = r43103178 / r43103183;
        double r43103214 = r43103205 ? r43103212 : r43103213;
        double r43103215 = r43103199 ? r43103203 : r43103214;
        double r43103216 = r43103186 ? r43103197 : r43103215;
        double r43103217 = r43103180 ? r43103184 : r43103216;
        return r43103217;
}

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.2
Target25.0
Herbie26.7
\[\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 y < -2.2246552119313502e+105

    1. Initial program 54.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity54.8

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

      \[\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}}}{1 \cdot 3}}\]
    5. Applied times-frac54.8

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}}\]
    6. Using strategy rm
    7. Applied frac-times54.8

      \[\leadsto \sqrt{\color{blue}{\frac{\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}}{1 \cdot 3}}}\]
    8. Applied sqrt-div54.9

      \[\leadsto \color{blue}{\frac{\sqrt{\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}}}{\sqrt{1 \cdot 3}}}\]
    9. Simplified54.9

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot y}}{\sqrt{3}}\]
    12. Simplified16.6

      \[\leadsto \frac{\color{blue}{-y}}{\sqrt{3}}\]

    if -2.2246552119313502e+105 < y < -5.954117318185457e-251

    1. Initial program 27.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity27.8

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

      \[\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}}}{1 \cdot 3}}\]
    5. Applied times-frac27.9

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

    if -5.954117318185457e-251 < y < 1.7885689886641004e-256

    1. Initial program 30.3

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

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

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

    if 1.7885689886641004e-256 < y < 1.5401699409035865e+62

    1. Initial program 29.2

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

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

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

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

    if 1.5401699409035865e+62 < y

    1. Initial program 50.0

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

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

      \[\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}}}{1 \cdot 3}}\]
    5. Applied times-frac50.0

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}}\]
    6. Using strategy rm
    7. Applied frac-times50.0

      \[\leadsto \sqrt{\color{blue}{\frac{\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}}{1 \cdot 3}}}\]
    8. Applied sqrt-div50.0

      \[\leadsto \color{blue}{\frac{\sqrt{\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}}}{\sqrt{1 \cdot 3}}}\]
    9. Simplified50.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.224655211931350154467905423564222198286 \cdot 10^{105}:\\ \;\;\;\;\frac{-y}{\sqrt{3}}\\ \mathbf{elif}\;y \le -5.954117318185457006023099047372652421673 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)} \cdot \frac{\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}}{3}}\\ \mathbf{elif}\;y \le 1.788568988664100371947120533217940202845 \cdot 10^{-256}:\\ \;\;\;\;-\sqrt{0.3333333333333333148296162562473909929395} \cdot x\\ \mathbf{elif}\;y \le 1.540169940903586483251096568897866173672 \cdot 10^{62}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}} \cdot \frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{\sqrt[3]{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\sqrt{3}}\\ \end{array}\]

Reproduce

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