We all know that
4^2 + 22^2 = 500
Is there a natural way to generates 500
from the complex number 4 + 22I
?
Two examples :
ex1)
Abs[4 + 22I]^2
generates 500
, but first Abs[4 + 22I]
becomes (Sqrt[500])^2
, then (10 Sqrt[5])^2
, then 100*5
, then 500
. It generated 500 but did some unnecessary works.
Trace[Norm[4 + 22 I]^2]
{{{{{I,I},22 I,22 I},4+22 I,4+22 I},Norm[4+22 I],10 Sqrt[5]},(10 Sqrt[5])^2,100 5,500}
ex2)
(Re[#]^2+Im[#]^2)&[4 + 22I]
generates 500
but I believe there should be a built-in function.
The problem was about performance and naturality of the program.
Thanks to MichaelE2, there is a built-in function Internal`AbsSquare[] with good performance.
The below screenshot will help you understand everything.
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Norm[4 + 22 I]^2
? $\endgroup$(4 + 22 I)*Conjugate[4 + 22 I]
or#*Conjugate[#] &[(4 + 22 I)]
? $\endgroup$Internal
AbsSquare[]` is faster than# Conjugate[#] &
on my machine (mmv). (Did you meanDo[# Conjugate[#] & [5790570927 + 49802948104 I], 10000]
, because the code in your comment has a mistake?) $\endgroup$