Average Error: 38.1 → 25.8
Time: 12.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.2291282360035104 \cdot 10^{133}:\\ \;\;\;\;-\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;z \le 2.8539710068846394 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \le -2.2291282360035104 \cdot 10^{133}:\\
\;\;\;\;-\frac{z}{\sqrt{3}}\\

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

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

\end{array}
double f(double x, double y, double z) {
        double r923556 = x;
        double r923557 = r923556 * r923556;
        double r923558 = y;
        double r923559 = r923558 * r923558;
        double r923560 = r923557 + r923559;
        double r923561 = z;
        double r923562 = r923561 * r923561;
        double r923563 = r923560 + r923562;
        double r923564 = 3.0;
        double r923565 = r923563 / r923564;
        double r923566 = sqrt(r923565);
        return r923566;
}

double f(double x, double y, double z) {
        double r923567 = z;
        double r923568 = -2.2291282360035104e+133;
        bool r923569 = r923567 <= r923568;
        double r923570 = 3.0;
        double r923571 = sqrt(r923570);
        double r923572 = r923567 / r923571;
        double r923573 = -r923572;
        double r923574 = 2.8539710068846394e+65;
        bool r923575 = r923567 <= r923574;
        double r923576 = x;
        double r923577 = r923576 * r923576;
        double r923578 = y;
        double r923579 = r923578 * r923578;
        double r923580 = r923577 + r923579;
        double r923581 = r923567 * r923567;
        double r923582 = r923580 + r923581;
        double r923583 = sqrt(r923582);
        double r923584 = r923570 / r923583;
        double r923585 = r923583 / r923584;
        double r923586 = sqrt(r923585);
        double r923587 = 0.3333333333333333;
        double r923588 = sqrt(r923587);
        double r923589 = r923567 * r923588;
        double r923590 = r923575 ? r923586 : r923589;
        double r923591 = r923569 ? r923573 : r923590;
        return r923591;
}

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
Target25.6
Herbie25.8
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -2.2291282360035104e+133

    1. Initial program 59.8

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt59.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}}}{3}}\]
    4. Applied associate-/l*59.7

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

      \[\leadsto \sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\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}}}}}}\]
    7. Applied sqrt-prod59.8

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

      \[\leadsto \sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}}\]
    9. Applied times-frac59.8

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

      \[\leadsto \sqrt{\frac{\sqrt{\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}}}}{\frac{\sqrt{3}}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}} \cdot \frac{\sqrt{3}}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}}\]
    11. Applied sqrt-prod59.8

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}{\frac{\sqrt{3}}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}} \cdot \frac{\sqrt{3}}{\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}}\]
    12. Applied times-frac59.8

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{z}{\sqrt{3}}}\]
    16. Simplified17.4

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

    if -2.2291282360035104e+133 < z < 2.8539710068846394e+65

    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-sqr-sqrt29.2

      \[\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}}}{3}}\]
    4. Applied associate-/l*29.2

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

    if 2.8539710068846394e+65 < z

    1. Initial program 51.4

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.333333333333333315}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.2291282360035104 \cdot 10^{133}:\\ \;\;\;\;-\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;z \le 2.8539710068846394 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

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