Average Error: 34.8 → 24.1
Time: 15.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.9223608795668832 \cdot 10^{+146}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{\sqrt[3]{3.0}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}
\begin{array}{l}
\mathbf{if}\;x \le -1.9223608795668832 \cdot 10^{+146}:\\
\;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r41742576 = x;
        double r41742577 = r41742576 * r41742576;
        double r41742578 = y;
        double r41742579 = r41742578 * r41742578;
        double r41742580 = r41742577 + r41742579;
        double r41742581 = z;
        double r41742582 = r41742581 * r41742581;
        double r41742583 = r41742580 + r41742582;
        double r41742584 = 3.0;
        double r41742585 = r41742583 / r41742584;
        double r41742586 = sqrt(r41742585);
        return r41742586;
}

double f(double x, double y, double z) {
        double r41742587 = x;
        double r41742588 = -1.9223608795668832e+146;
        bool r41742589 = r41742587 <= r41742588;
        double r41742590 = -r41742587;
        double r41742591 = 0.3333333333333333;
        double r41742592 = sqrt(r41742591);
        double r41742593 = r41742590 * r41742592;
        double r41742594 = 2.8767154662268737e+124;
        bool r41742595 = r41742587 <= r41742594;
        double r41742596 = 1.0;
        double r41742597 = 3.0;
        double r41742598 = cbrt(r41742597);
        double r41742599 = r41742598 * r41742598;
        double r41742600 = r41742596 / r41742599;
        double r41742601 = y;
        double r41742602 = r41742601 * r41742601;
        double r41742603 = r41742587 * r41742587;
        double r41742604 = r41742602 + r41742603;
        double r41742605 = z;
        double r41742606 = r41742605 * r41742605;
        double r41742607 = r41742604 + r41742606;
        double r41742608 = r41742607 / r41742598;
        double r41742609 = r41742600 * r41742608;
        double r41742610 = sqrt(r41742609);
        double r41742611 = r41742592 * r41742587;
        double r41742612 = r41742595 ? r41742610 : r41742611;
        double r41742613 = r41742589 ? r41742593 : r41742612;
        return r41742613;
}

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

Original34.8
Target23.7
Herbie24.1
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3.0}}\\ \mathbf{elif}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3.0}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.9223608795668832e+146

    1. Initial program 57.8

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

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

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

    if -1.9223608795668832e+146 < x < 2.8767154662268737e+124

    1. Initial program 26.9

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\left(\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}\right) \cdot \sqrt[3]{3.0}}}}\]
    4. Applied *-un-lft-identity26.9

      \[\leadsto \sqrt{\frac{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}}{\left(\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}\right) \cdot \sqrt[3]{3.0}}}\]
    5. Applied times-frac27.0

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

    if 2.8767154662268737e+124 < x

    1. Initial program 54.0

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.3333333333333333}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.9223608795668832 \cdot 10^{+146}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{\sqrt[3]{3.0}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]

Reproduce

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