Average Error: 31.4 → 0.0
Time: 1.7s
Precision: binary64
Cost: 6528
\[\sqrt{re \cdot re + im \cdot im} \]
\[\mathsf{hypot}\left(re, im\right) \]
(FPCore modulus (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
(FPCore modulus (re im) :precision binary64 (hypot re im))
double modulus(double re, double im) {
	return sqrt(((re * re) + (im * im)));
}
double modulus(double re, double im) {
	return hypot(re, im);
}
public static double modulus(double re, double im) {
	return Math.sqrt(((re * re) + (im * im)));
}
public static double modulus(double re, double im) {
	return Math.hypot(re, im);
}
def modulus(re, im):
	return math.sqrt(((re * re) + (im * im)))
def modulus(re, im):
	return math.hypot(re, im)
function modulus(re, im)
	return sqrt(Float64(Float64(re * re) + Float64(im * im)))
end
function modulus(re, im)
	return hypot(re, im)
end
function tmp = modulus(re, im)
	tmp = sqrt(((re * re) + (im * im)));
end
function tmp = modulus(re, im)
	tmp = hypot(re, im);
end
modulus[re_, im_] := N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
modulus[re_, im_] := N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]
\sqrt{re \cdot re + im \cdot im}
\mathsf{hypot}\left(re, im\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 31.4

    \[\sqrt{re \cdot re + im \cdot im} \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{hypot}\left(re, im\right)} \]
    Proof
    (hypot.f64 re im): 0 points increase in error, 0 points decrease in error
    (Rewrite<= hypot-def_binary64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im)))): 129 points increase in error, 0 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{hypot}\left(re, im\right) \]

Reproduce

herbie shell --seed 2022291 
(FPCore modulus (re im)
  :name "math.abs on complex"
  :precision binary64
  (sqrt (+ (* re re) (* im im))))