Average Error: 38.2 → 0.4
Time: 8.6s
Precision: binary64
Cost: 19520
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
\[\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}{\sqrt{3}} \]
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z) :precision binary64 (/ (hypot x (hypot y z)) (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) {
	return hypot(x, hypot(y, z)) / sqrt(3.0);
}
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.hypot(x, Math.hypot(y, z)) / Math.sqrt(3.0);
}
def code(x, y, z):
	return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
def code(x, y, z):
	return math.hypot(x, math.hypot(y, z)) / math.sqrt(3.0)
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(hypot(x, hypot(y, z)) / sqrt(3.0))
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 = hypot(x, hypot(y, z)) / sqrt(3.0);
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[x ^ 2 + N[Sqrt[y ^ 2 + z ^ 2], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}{\sqrt{3}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.2
Target25.3
Herbie0.4
\[\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 38.2

    \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
  2. Applied egg-rr0.4

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}{\sqrt{3}}} \]
  3. Final simplification0.4

    \[\leadsto \frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}{\sqrt{3}} \]

Alternatives

Alternative 1
Error42.5
Cost13320
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6052289844242146 \cdot 10^{-75}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \frac{y}{\frac{x}{y}} - x\right)\\ \mathbf{elif}\;z \leq 1.9711743578636713 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(z, y\right)}{\sqrt{3}}\\ \end{array} \]
Alternative 2
Error18.5
Cost13320
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6052289844242146 \cdot 10^{-75}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(y, x\right)}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 1.9711743578636713 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(z, y\right)}{\sqrt{3}}\\ \end{array} \]
Alternative 3
Error20.6
Cost13056
\[\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right) \]
Alternative 4
Error43.2
Cost7240
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6052289844242146 \cdot 10^{-75}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 1.9711743578636713 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 5
Error43.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6052289844242146 \cdot 10^{-75}:\\ \;\;\;\;\frac{-0.5 \cdot \left(y \cdot \frac{y}{x}\right) - x}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 1.9711743578636713 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 6
Error43.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6052289844242146 \cdot 10^{-75}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \frac{y}{\frac{x}{y}} - x\right)\\ \mathbf{elif}\;z \leq 1.9711743578636713 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 7
Error44.9
Cost7052
\[\begin{array}{l} t_0 := x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ t_1 := \frac{z}{\sqrt{3}}\\ \mathbf{if}\;x \leq -3.293119197955147 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.415660045216952 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -281481616496445280:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error44.9
Cost7052
\[\begin{array}{l} t_0 := \frac{z}{\sqrt{3}}\\ \mathbf{if}\;x \leq -3.293119197955147 \cdot 10^{+71}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;x \leq -3.415660045216952 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -281481616496445280:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error51.9
Cost6592
\[\frac{z}{\sqrt{3}} \]
Alternative 10
Error51.9
Cost6592
\[z \cdot \sqrt{0.3333333333333333} \]

Error

Reproduce

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