Average Error: 34.8 → 24.1
Time: 17.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.5524096722827354 \cdot 10^{+146}:\\ \;\;\;\;\frac{-x}{\sqrt{3.0}}\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{\sqrt[3]{3.0}} \cdot \frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333}\\ \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.5524096722827354 \cdot 10^{+146}:\\
\;\;\;\;\frac{-x}{\sqrt{3.0}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r43380645 = x;
        double r43380646 = r43380645 * r43380645;
        double r43380647 = y;
        double r43380648 = r43380647 * r43380647;
        double r43380649 = r43380646 + r43380648;
        double r43380650 = z;
        double r43380651 = r43380650 * r43380650;
        double r43380652 = r43380649 + r43380651;
        double r43380653 = 3.0;
        double r43380654 = r43380652 / r43380653;
        double r43380655 = sqrt(r43380654);
        return r43380655;
}

double f(double x, double y, double z) {
        double r43380656 = x;
        double r43380657 = -1.5524096722827354e+146;
        bool r43380658 = r43380656 <= r43380657;
        double r43380659 = -r43380656;
        double r43380660 = 3.0;
        double r43380661 = sqrt(r43380660);
        double r43380662 = r43380659 / r43380661;
        double r43380663 = 2.8767154662268737e+124;
        bool r43380664 = r43380656 <= r43380663;
        double r43380665 = z;
        double r43380666 = r43380665 * r43380665;
        double r43380667 = y;
        double r43380668 = r43380667 * r43380667;
        double r43380669 = r43380656 * r43380656;
        double r43380670 = r43380668 + r43380669;
        double r43380671 = r43380666 + r43380670;
        double r43380672 = cbrt(r43380660);
        double r43380673 = r43380671 / r43380672;
        double r43380674 = 1.0;
        double r43380675 = r43380672 * r43380672;
        double r43380676 = r43380674 / r43380675;
        double r43380677 = r43380673 * r43380676;
        double r43380678 = sqrt(r43380677);
        double r43380679 = 0.3333333333333333;
        double r43380680 = sqrt(r43380679);
        double r43380681 = r43380656 * r43380680;
        double r43380682 = r43380664 ? r43380678 : r43380681;
        double r43380683 = r43380658 ? r43380662 : r43380682;
        return r43380683;
}

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.5524096722827354e+146

    1. Initial program 57.7

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot x}}{\sqrt{3.0}}\]
    5. Simplified15.1

      \[\leadsto \frac{\color{blue}{-x}}{\sqrt{3.0}}\]

    if -1.5524096722827354e+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.5524096722827354 \cdot 10^{+146}:\\ \;\;\;\;\frac{-x}{\sqrt{3.0}}\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + \left(y \cdot y + x \cdot x\right)}{\sqrt[3]{3.0}} \cdot \frac{1}{\sqrt[3]{3.0} \cdot \sqrt[3]{3.0}}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.3333333333333333}\\ \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)))