Average Error: 38.0 → 0.8
Time: 8.0s
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

Original38.0
Target20.0
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 38.0

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

    \[\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)} \]
    Proof
    (*.f64 (sqrt.f64 1/3) (hypot.f64 z x)): 0 points increase in error, 0 points decrease in error
    (*.f64 (sqrt.f64 1/3) (Rewrite<= hypot-def_binary64 (sqrt.f64 (+.f64 (*.f64 z z) (*.f64 x x))))): 161 points increase in error, 0 points decrease in error
    (*.f64 (sqrt.f64 1/3) (sqrt.f64 (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 x x)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (sqrt.f64 1/3) (sqrt.f64 (+.f64 (pow.f64 z 2) (Rewrite<= unpow2_binary64 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 (sqrt.f64 (+.f64 (pow.f64 z 2) (pow.f64 x 2))) (sqrt.f64 1/3))): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.8

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

Alternatives

Alternative 1
Error0.8
Cost13056
\[\frac{\mathsf{hypot}\left(z, x\right)}{\sqrt{3}} \]
Alternative 2
Error11.8
Cost7760
\[\begin{array}{l} t_0 := \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{if}\;z \leq 1.689795153928526 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 1.3620628828259381 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.84609961846016 \cdot 10^{-48}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 1.7016962358190419 \cdot 10^{+139}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \]
Alternative 3
Error13.4
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq -123540533935966.03:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-0.5 \cdot \left(z \cdot \frac{z}{x}\right) - x\right)\\ \mathbf{elif}\;x \leq -9.584113791128849 \cdot 10^{-5}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;x \leq -1.324235702978373 \cdot 10^{-39}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \]
Alternative 4
Error13.2
Cost7116
\[\begin{array}{l} \mathbf{if}\;x \leq -123540533935966.03:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -9.584113791128849 \cdot 10^{-5}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;x \leq -1.324235702978373 \cdot 10^{-39}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \]
Alternative 5
Error13.2
Cost7052
\[\begin{array}{l} t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -123540533935966.03:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9.584113791128849 \cdot 10^{-5}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;x \leq -1.324235702978373 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \]
Alternative 6
Error31.4
Cost6592
\[\frac{z}{\sqrt{3}} \]
Alternative 7
Error31.4
Cost6592
\[\sqrt{0.3333333333333333} \cdot z \]

Error

Reproduce

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