Average Error: 37.5 → 0.4
Time: 7.2s
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(z, y\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 z 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) {
	return hypot(x, hypot(z, y)) / 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(z, y)) / 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(z, y)) / 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(z, y)) / 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(z, y)) / 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[z ^ 2 + y ^ 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(z, y\right)\right)}{\sqrt{3}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.5
Target25.6
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 37.5

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

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

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}} \]
    Proof
    (/.f64 (hypot.f64 x (hypot.f64 z y)) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (Rewrite<= hypot-def_binary64 (sqrt.f64 (+.f64 (*.f64 z z) (*.f64 y y))))) (sqrt.f64 3)): 95 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (sqrt.f64 (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 y y)))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (sqrt.f64 (+.f64 (pow.f64 z 2) (Rewrite<= unpow2_binary64 (pow.f64 y 2))))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (sqrt.f64 (Rewrite=> +-commutative_binary64 (+.f64 (pow.f64 y 2) (pow.f64 z 2))))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (sqrt.f64 (+.f64 (Rewrite=> unpow2_binary64 (*.f64 y y)) (pow.f64 z 2)))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (sqrt.f64 (+.f64 (*.f64 y y) (Rewrite=> unpow2_binary64 (*.f64 z z))))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (/.f64 (hypot.f64 x (Rewrite=> hypot-def_binary64 (hypot.f64 y z))) (sqrt.f64 3)): 0 points increase in error, 95 points decrease in error
    (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (hypot.f64 x (hypot.f64 y z)))) (sqrt.f64 3)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (sqrt.f64 3)) (hypot.f64 x (hypot.f64 y z)))): 122 points increase in error, 0 points decrease in error
    (Rewrite<= associate-/r/_binary64 (/.f64 1 (/.f64 (sqrt.f64 3) (hypot.f64 x (hypot.f64 y z))))): 1 points increase in error, 120 points decrease in error
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error17.0
Cost13188
\[\begin{array}{l} \mathbf{if}\;z \leq 125000:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{+165}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 2
Error20.9
Cost13056
\[\mathsf{hypot}\left(z, x\right) \cdot \sqrt{0.3333333333333333} \]
Alternative 3
Error20.9
Cost13056
\[\frac{\mathsf{hypot}\left(z, x\right)}{\sqrt{3}} \]
Alternative 4
Error44.0
Cost7496
\[\begin{array}{l} t_0 := \frac{-x}{\sqrt{3}}\\ \mathbf{if}\;z \leq 270000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+164}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 5
Error45.5
Cost7316
\[\begin{array}{l} t_0 := x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ t_1 := \frac{z}{\sqrt{3}}\\ \mathbf{if}\;z \leq 3600000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+98}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+164}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 6
Error45.4
Cost7316
\[\begin{array}{l} t_0 := \frac{-x}{\sqrt{3}}\\ t_1 := \frac{z}{\sqrt{3}}\\ \mathbf{if}\;z \leq 3600000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+97}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{+163}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 7
Error45.4
Cost7316
\[\begin{array}{l} t_0 := \frac{-x}{\sqrt{3}}\\ \mathbf{if}\;z \leq 185000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+72}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{+98}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{z \cdot \left(z \cdot 0.3333333333333333\right)}\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{+163}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 8
Error45.4
Cost7316
\[\begin{array}{l} t_0 := \frac{-x}{\sqrt{3}}\\ \mathbf{if}\;z \leq 3600000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+70}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(z \cdot z\right)}\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+99}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{z \cdot \left(z \cdot 0.3333333333333333\right)}\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+163}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 9
Error44.5
Cost7240
\[\begin{array}{l} t_0 := \frac{-x}{\sqrt{3}}\\ \mathbf{if}\;z \leq 980:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(x \cdot x + z \cdot z\right)}\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{+164}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]
Alternative 10
Error52.3
Cost6592
\[z \cdot \sqrt{0.3333333333333333} \]

Error

Reproduce

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