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.
Complex objects are created by the complex operation.
a := complex(4/3,5/2)
4 5
- + - %i
3 2
Type: Complex Fraction Integer
b := complex(4/3,-5/2)
4 5
- - - %i
3 2
Type: Complex Fraction Integer
The standard arithmetic operations are available.
a + b
8
-
3
Type: Complex Fraction Integer
a - b
5%i
Type: Complex Fraction Integer
a * b
289
---
36
Type: Complex Fraction Integer
If R is a field, you can also divide the complex objects.
a / b
161 240
- --- + --- %i
289 289
Type: Complex Fraction Integer
We can view the last object as a fraction of complex integers.
% :: Fraction Complex Integer
- 15 + 8%i
----------
15 + 8%i
Type: Fraction Complex Integer
The predefined macro %i is defined to be complex(0,1).
3.4 + 6.7 * %i
3.4 + 6.7 %i
Type: Complex Float
You can also compute the conjugate and norm of a complex number.
conjugate a
4 5
- - - %i
3 2
Type: Complex Fraction Integer
norm a
289
---
36
Type: Fraction Integer
The real and imag operations are provided to extract the real and imaginary parts, respectively.
real a
4
-
3
Type: Fraction Integer
imag a
5
-
2
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 - 39%i
Type: Complex Integer
You can factor Gaussian integers.
factor(13 - 13*%i)
- (1 + %i)(2 + 3%i)(3 + 2%i)
Type: Factored Complex Integer
factor complex(2,0)
2
- %i (1 + %i)
Type: Factored Complex Integer
See Also