Im¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Im[z]
gives the imaginary part of numeric z, and 0 for real or real-valued (Re/Im/Abs/Arg) arguments.
Examples (16)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (7)¶
In[1]:= Re[1/(2 + 3 I)]
Out[1]= 2/13
In[2]:= Im[Log[-1]]
Out[2]= Pi
In[3]:= ReIm[(2 + I)^3]
Out[3]= {2, 11}
In[4]:= Abs[-9223372036854775807 - 1]
Out[4]= 9223372036854775808
In[5]:= Sign[3 + 4 I]
Out[5]= 3/5 + 4/5*I
In[6]:= Conjugate[(2 + I)/(1 - 3 I)]
Out[6]= -1/10 - 7/10*I
In[7]:= Arg[(-1)^(1/6)]
Out[7]= 1/6 Pi
Applications (9)¶
Sqrt[-4] evaluates to 2 I
The principal branch: Log[-1] = I Pi
Listable
A real-valued head gives 0
No closed form, so it stays symbolic
But it evaluates numerically
The narrowing kernel gives exact zeros for integer data
Implementation notes¶
Algorithm. builtin_im mirrors builtin_re. It returns 0 for a call to a head that is real by construction (Re, Im, Abs, Arg), for a real AlgebraicNumber or Root (FLINT qqbar reality test), and for any real number leaf (an Integer, bigint, machine Real, MPFR, or Rational with int64 or bignum parts). A Complex[re, im] literal gives im. Otherwise complex_decompose, a recursive Plus/Times walk that multiplies Complex factors through, supplies the imaginary part when both decomposed parts are concretely numeric (is_numeric_real). This is how Im[Sqrt[-4]] is 2 and Im[Log[-1]] is Pi: those arguments have already evaluated to 2 I and I Pi. Anything else returns NULL, including special-function values with no closed form such as Im[Gamma[1 + I]], whose N still evaluates.
Data structures. The routine works on fresh re/im trees from the decomposition. On the packed and NDArray surfaces the kernel NDKU_ImInt narrows: a real or int64 buffer gives an int64 buffer of exact zeros (matching the List path's exact 0), and a complex buffer gives the real buffer of imaginary parts. In Compile[] Im lowers at scalar and array shapes, and it is 0 over integers.
Complexity / limits. The leaf cases are O(1), and the decomposition is linear in the size of the expression. Symbols are not assumed real (Im[x] stays unevaluated). A gap: an exact real constant with no Complex literal, such as Im[Pi - 4], stays unevaluated at present (Mathematica gives 0).
Attributes: Listable, NumericFunction, Protected.
References¶
See also: Re, ReIm, Abs, Sign, Conjugate, Arg, Real, Rational
- Source:
src/complex.c - Specification:
docs/spec/builtins/arithmetic.md - Tests:
tests/test_accuracygoal.c - Tests:
tests/test_airyai.c - Tests:
tests/test_airybi.c - Tests:
tests/test_algebraicnumber.c
Notes & additional examples¶
Notes¶
Im[z]is the imaginary part of a numericz. It is0for real numbers, for realRootandAlgebraicNumberobjects, and for calls to the real-valued headsRe,Im,Abs,Arg.- Symbols are not assumed real (
Im[x]stays unevaluated). An exact real constant with no complex part written out, such asIm[Pi - 4], also stays unevaluated at present (Mathematica gives0). Listable,NumericFunction,Protected. The packed/NDArray kernel gives an int64 zero buffer for real or integer data and the imaginary parts for complex data.Compile[]lowersImat scalar and array shapes.- See also:
Re,ReIm,Conjugate,ComplexExpand.