math.abs on complex

?

Percentage Accurate: 53.6% → 100.0%
Time: 1.1s
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)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 1 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 52.6%

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

    \[\leadsto \color{blue}{\mathsf{hypot}\left(re, im\right)} \]
    Step-by-step derivation

    [Start]52.6%

    \[ \sqrt{re \cdot re + im \cdot im} \]

    hypot-def [=>]100.0%

    \[ \color{blue}{\mathsf{hypot}\left(re, im\right)} \]
  3. Final simplification100.0%

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

Reproduce?

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