Skip to content

Complex

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Complex[re, im]
    represents the complex number re + im I.
Complex is the canonical head produced by arithmetic when an Integer,
Real, or Rational acquires an imaginary part. Pure-real inputs collapse
to the underlying number; im == 0 unwraps to re.

Examples

No verified examples yet for this function.

Implementation notes

builtin_complex (src/arithmetic.c) is the Complex[re, im] constructor's auto-simplifier. It only collapses zero-imaginary cases: Complex[r, 0] (integer 0) returns re unchanged; Complex[r, 0.0] (real 0) returns re, promoting an integer real part to a Real so the result stays inexact. Any genuinely complex value returns NULL, leaving the literal Complex[re, im] in place as the canonical representation. Re/Im decomposition, arithmetic on complex values, and printing as a + b I live elsewhere (src/complex.c, src/print.c); this handler is purely the constructor normalisation step.

Attributes: none registered.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References

Notes & additional examples

Worked examples

In[1]:= Complex[3, 4]
Out[1]= 3 + 4*I

In[2]:= Complex[5, 0]
Out[2]= 5
In[1]:= (1 + I)^8
Out[1]= 16
In[1]:= (2 + 3 I)/(1 - I)
Out[1]= -1/2 + 5/2*I
In[1]:= N[(3 + 4 I)^(1/3), 40]
Out[1]= 1.6289371459221758752146093717175049715341 + 0.52017450230454583954569417015944746788805*I

Notes

Complex[re, im] is the canonical head for re + im I; a zero imaginary part collapses back to the underlying real number.