# 9.11 Complex¶

The Complex constructor implements complex objects over a commutative ring R. Typically, the ring R is Integer, Fraction Integer, Float or DoubleFloat. R can also be a symbolic type, like Polynomial Integer. For more information about the numerical and graphical aspects of complex numbers, see ugProblemNumeric .

Complex objects are created by the complexcomplexComplex operation.

a := complex(4/3,5/2)


 43+52i

Type: Complex Fraction Integer

b := complex(4/3,-5/2)


 43-52i

Type: Complex Fraction Integer

The standard arithmetic operations are available.

a + b


 83

Type: Complex Fraction Integer

a - b


 5i

Type: Complex Fraction Integer

a * b


 28936

Type: Complex Fraction Integer

If R is a field, you can also divide the complex objects.

a / b


 -161289+240289i

Type: Complex Fraction Integer

Use a conversion (ugTypesConvertPage in Section ugTypesConvertNumber ) to view the last object as a fraction of complex integers.

% :: Fraction Complex Integer


 -15+8i15+8i

Type: Fraction Complex Integer

The predefined macro %i is defined to be complex(0,1).

3.4 + 6.7 * %i


 3.4+6.7i

Type: Complex Float

You can also compute the conjugateconjugateComplex and normnormComplex of a complex number.

conjugate a


 43-52i

Type: Complex Fraction Integer

norm a


 28936

Type: Fraction Integer

The realrealComplex and imagimagComplex operations are provided to extract the real and imaginary parts, respectively.

real a


 43

Type: Fraction Integer

imag a


 52

Type: Fraction Integer

The domain Complex Integer is also called the Gaussian integers. If R is the integers (or, more generally, a EuclideanDomain), you can compute greatest common divisors.

gcd(13 - 13*%i,31 + 27*%i)


 5+i

Type: Complex Integer

You can also compute least common multiples.

lcm(13 - 13*%i,31 + 27*%i)


 143-39i

Type: Complex Integer

You can factorfactorComplex Gaussian integers.

factor(13 - 13*%i)


 -(1+i)(2+3i)(3+2i)

Type: Factored Complex Integer

factor complex(2,0)


 -i(1+i)2

Type: Factored Complex Integer