Average Error: 37.2 → 25.7
Time: 5.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -1.262994537780197180949403796631520932245 \cdot 10^{-11}:\\ \;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\ \mathbf{elif}\;x \le -1.269615265176485075087604094279278999453 \cdot 10^{-133}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\ \;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\

\mathbf{elif}\;x \le -1.262994537780197180949403796631520932245 \cdot 10^{-11}:\\
\;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\

\mathbf{elif}\;x \le -1.269615265176485075087604094279278999453 \cdot 10^{-133}:\\
\;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\

\mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\
\;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\

\mathbf{else}:\\
\;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\

\end{array}
double f(double x, double y, double z) {
        double r844664 = x;
        double r844665 = r844664 * r844664;
        double r844666 = y;
        double r844667 = r844666 * r844666;
        double r844668 = r844665 + r844667;
        double r844669 = z;
        double r844670 = r844669 * r844669;
        double r844671 = r844668 + r844670;
        double r844672 = 3.0;
        double r844673 = r844671 / r844672;
        double r844674 = sqrt(r844673);
        return r844674;
}

double f(double x, double y, double z) {
        double r844675 = x;
        double r844676 = -9.459978473614104e+97;
        bool r844677 = r844675 <= r844676;
        double r844678 = -1.0;
        double r844679 = r844678 * r844675;
        double r844680 = 1.0;
        double r844681 = 3.0;
        double r844682 = r844680 / r844681;
        double r844683 = sqrt(r844682);
        double r844684 = r844679 * r844683;
        double r844685 = -1.2629945377801972e-11;
        bool r844686 = r844675 <= r844685;
        double r844687 = r844675 * r844675;
        double r844688 = y;
        double r844689 = r844688 * r844688;
        double r844690 = r844687 + r844689;
        double r844691 = z;
        double r844692 = r844691 * r844691;
        double r844693 = r844690 + r844692;
        double r844694 = r844693 * r844682;
        double r844695 = 0.5;
        double r844696 = pow(r844694, r844695);
        double r844697 = -1.269615265176485e-133;
        bool r844698 = r844675 <= r844697;
        double r844699 = sqrt(r844681);
        double r844700 = r844691 / r844699;
        double r844701 = fabs(r844700);
        double r844702 = 5.252172480184968e+109;
        bool r844703 = r844675 <= r844702;
        double r844704 = r844675 / r844699;
        double r844705 = r844678 * r844704;
        double r844706 = fabs(r844705);
        double r844707 = r844703 ? r844696 : r844706;
        double r844708 = r844698 ? r844701 : r844707;
        double r844709 = r844686 ? r844696 : r844708;
        double r844710 = r844677 ? r844684 : r844709;
        return r844710;
}

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.3
Herbie25.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 4 regimes
  2. if x < -9.459978473614104e+97

    1. Initial program 53.4

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

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

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

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

    if -9.459978473614104e+97 < x < -1.2629945377801972e-11 or -1.269615265176485e-133 < x < 5.252172480184968e+109

    1. Initial program 29.1

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

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

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt{\frac{1}{3}}}\]
    5. Using strategy rm
    6. Applied pow1/229.2

      \[\leadsto \sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \color{blue}{{\left(\frac{1}{3}\right)}^{\frac{1}{2}}}\]
    7. Applied pow1/229.2

      \[\leadsto \color{blue}{{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}^{\frac{1}{2}}} \cdot {\left(\frac{1}{3}\right)}^{\frac{1}{2}}\]
    8. Applied pow-prod-down29.1

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

    if -1.2629945377801972e-11 < x < -1.269615265176485e-133

    1. Initial program 28.3

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

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

      \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac28.4

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}\]
    6. Applied rem-sqrt-square28.4

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

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

    if 5.252172480184968e+109 < x

    1. Initial program 54.9

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied add-sqr-sqrt55.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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac55.0

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}\]
    6. Applied rem-sqrt-square55.0

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

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{\sqrt{3}}}\right|\]
  3. Recombined 4 regimes into one program.
  4. Final simplification25.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\ \;\;\;\;\left(-1 \cdot x\right) \cdot \sqrt{\frac{1}{3}}\\ \mathbf{elif}\;x \le -1.262994537780197180949403796631520932245 \cdot 10^{-11}:\\ \;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\ \mathbf{elif}\;x \le -1.269615265176485075087604094279278999453 \cdot 10^{-133}:\\ \;\;\;\;\left|\frac{z}{\sqrt{3}}\right|\\ \mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\ \;\;\;\;{\left(\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}\right)}^{\frac{1}{2}}\\ \mathbf{else}:\\ \;\;\;\;\left|-1 \cdot \frac{x}{\sqrt{3}}\right|\\ \end{array}\]

Reproduce

herbie shell --seed 2019356 
(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.396479394109776e+136) (/ (- z) (sqrt 3)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.3333333333333333) z)))

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