Average Error: 37.9 → 0.8
Time: 3.6s
Precision: binary64
\[[x, y, z] = \mathsf{sort}([x, y, z]) \\]
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
\[\begin{array}{l} t_0 := \sqrt{\sqrt{0.3333333333333333}}\\ t_0 \cdot \left(t_0 \cdot \mathsf{hypot}\left(x, z\right)\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (sqrt (sqrt 0.3333333333333333)))) (* t_0 (* t_0 (hypot x z)))))
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 t_0 = sqrt(sqrt(0.3333333333333333));
	return t_0 * (t_0 * hypot(x, z));
}
public static double code(double x, double y, double z) {
	return Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
public static double code(double x, double y, double z) {
	double t_0 = Math.sqrt(Math.sqrt(0.3333333333333333));
	return t_0 * (t_0 * Math.hypot(x, z));
}
def code(x, y, z):
	return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
def code(x, y, z):
	t_0 = math.sqrt(math.sqrt(0.3333333333333333))
	return t_0 * (t_0 * math.hypot(x, z))
function code(x, y, z)
	return sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0))
end
function code(x, y, z)
	t_0 = sqrt(sqrt(0.3333333333333333))
	return Float64(t_0 * Float64(t_0 * hypot(x, z)))
end
function tmp = code(x, y, z)
	tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
end
function tmp = code(x, y, z)
	t_0 = sqrt(sqrt(0.3333333333333333));
	tmp = t_0 * (t_0 * hypot(x, z));
end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[Sqrt[N[Sqrt[0.3333333333333333], $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(t$95$0 * N[Sqrt[x ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
t_0 := \sqrt{\sqrt{0.3333333333333333}}\\
t_0 \cdot \left(t_0 \cdot \mathsf{hypot}\left(x, z\right)\right)
\end{array}

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.9
Target19.8
Herbie0.8
\[\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. Initial program 37.9

    \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
  2. Simplified37.9

    \[\leadsto \color{blue}{\sqrt{\frac{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, x, y \cdot y\right)\right)}{3}}} \]
  3. Taylor expanded in y around 0 38.2

    \[\leadsto \color{blue}{\sqrt{{z}^{2} + {x}^{2}} \cdot \sqrt{0.3333333333333333}} \]
  4. Simplified0.9

    \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(x, z\right)} \]
  5. Applied add-sqr-sqrt_binary640.9

    \[\leadsto \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{\sqrt{0.3333333333333333}}\right)} \cdot \mathsf{hypot}\left(x, z\right) \]
  6. Applied associate-*l*_binary640.8

    \[\leadsto \color{blue}{\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot \mathsf{hypot}\left(x, z\right)\right)} \]
  7. Final simplification0.8

    \[\leadsto \sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot \mathsf{hypot}\left(x, z\right)\right) \]

Reproduce

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