Average Error: 37.6 → 0.8
Time: 5.4s
Precision: binary64
Cost: 13056
\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
\[\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right) \]
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z) :precision binary64 (* (sqrt 0.3333333333333333) (hypot z x)))
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) {
	return sqrt(0.3333333333333333) * hypot(z, x);
}
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) {
	return Math.sqrt(0.3333333333333333) * Math.hypot(z, x);
}
def code(x, y, z):
	return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
def code(x, y, z):
	return math.sqrt(0.3333333333333333) * math.hypot(z, x)
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)
	return Float64(sqrt(0.3333333333333333) * hypot(z, x))
end
function tmp = code(x, y, z)
	tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
end
function tmp = code(x, y, z)
	tmp = sqrt(0.3333333333333333) * hypot(z, x);
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_] := N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.6
Target19.6
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.6

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

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

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

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

Alternatives

Alternative 1
Error12.7
Cost13836
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, y\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \cdot x \leq 10^{+239}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\ \end{array} \]
Alternative 2
Error13.0
Cost13316
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+63}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, y\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \cdot x \leq 10^{+239}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \left(z \cdot \frac{z}{x}\right) - x\right)\\ \end{array} \]
Alternative 3
Error13.3
Cost7884
\[\begin{array}{l} t_0 := \frac{z}{\sqrt{3}}\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \cdot x \leq 10^{+239}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \left(z \cdot \frac{z}{x}\right) - x\right)\\ \end{array} \]
Alternative 4
Error14.3
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq -1.297110601513885 \cdot 10^{+101}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \left(z \cdot \frac{z}{x}\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \end{array} \]
Alternative 5
Error14.2
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -1.297110601513885 \cdot 10^{+101}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \end{array} \]
Alternative 6
Error31.4
Cost6592
\[\frac{z}{\sqrt{3}} \]

Error

Reproduce

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