Average Error: 38.3 → 31.9
Time: 6.9s
Precision: binary64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 1.497190811277626 \cdot 10^{+303}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot 0.3333333333333333}\\ \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}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 1.497190811277626 \cdot 10^{+303}:\\
\;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot 0.3333333333333333}\\

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

\end{array}
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z)
 :precision binary64
 (if (<= (+ (+ (* x x) (* y y)) (* z z)) 1.497190811277626e+303)
   (sqrt (* (+ (+ (* x x) (* y y)) (* z z)) 0.3333333333333333))
   (/ y (sqrt 3.0))))
double code(double x, double y, double z) {
	return sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
}
double code(double x, double y, double z) {
	double tmp;
	if ((((x * x) + (y * y)) + (z * z)) <= 1.497190811277626e+303) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)) * 0.3333333333333333);
	} else {
		tmp = y / sqrt(3.0);
	}
	return tmp;
}

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.3
Target25.8
Herbie31.9
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) < 1.4971908112776259e303

    1. Initial program 2.4

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

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

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

    if 1.4971908112776259e303 < (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z))

    1. Initial program 63.2

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{{z}^{2} + {y}^{2}}}}{\sqrt{3}}\]
    5. Simplified62.9

      \[\leadsto \frac{\color{blue}{\sqrt{y \cdot y + z \cdot z}}}{\sqrt{3}}\]
    6. Taylor expanded around 0 52.4

      \[\leadsto \frac{\color{blue}{y}}{\sqrt{3}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 1.497190811277626 \cdot 10^{+303}:\\ \;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot 0.3333333333333333}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\sqrt{3}}\\ \end{array}\]

Reproduce

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