Macaulay2 » Documentation
Packages » Macaulay2Doc :: CC
next | previous | forward | backward | up | index | toc

CC -- the class of all complex numbers

Description

In Macaulay2, complex numbers are represented as floating point numbers, and so are only approximate. The symbol ii represents the square root of -1 in many numeric contexts. A complex number is obtained by using the symbolic constant ii or the conversion functions toCC and numeric, in combination with real numbers (see RR). It is stored internally as a pair of arbitrary precision floating point real numbers, using the MPFR library.
i1 : z = 3-4*ii

o1 = 3-4*ii

o1 : CC (of precision 53)
i2 : z^5

o2 = -237.000000000002+3116*ii

o2 : CC (of precision 53)
i3 : 1/z

o3 = .12+.16*ii

o3 : CC (of precision 53)
i4 : +ii

o4 = ii

o4 : CC (of precision 53)
i5 : numeric_200 ii

o5 = ii

o5 : CC (of precision 200)
Complex numbers are ordered lexicographically, mingled with real numbers.
i6 : sort {1+ii,2+ii,1-ii,2-ii,1/2,2.1,7/5}

      1              7
o6 = {-, 1-ii, 1+ii, -, 2-ii, 2+ii, 2.1}
      2              5

o6 : List
The precision is measured in bits, is visible in the ring displayed on the second of each pair of output lines, and can be recovered using precision.
i7 : precision z

o7 = 53
For complex numbers, the functions class and ring yield different results. That allows numbers of various precisions to be used without creating a new ring for each precision.
i8 : class z

o8 = CC

o8 : InexactFieldFamily
i9 : ring z

o9 = CC
       53

o9 : ComplexField
A computation involving numbers of different precisions has a result with the minimal precision occurring. Numbers that appear alone on an output line are displayed with all their meaningful digits. (Specifying 100 bits of precision yields about 30 decimal digits of precision.)
i10 : 3p100+2p90e3*ii

o10 = 3+2000*ii

o10 : CC (of precision 90)
Numbers displayed inside more complicated objects are printed with the number of digits specified by printingPrecision.
i11 : printingPrecision

o11 = 6
i12 : x = {1/3.*ii,1/3p100*ii}

o12 = {.333333*ii, .333333*ii}

o12 : List
Use toExternalString to produce something that, when encountered as input, will reproduce exactly what you had before.
i13 : y = toExternalString x

o13 = {toCC(.0p53,.33333333333333331p53),toCC(.0p100
      ,.33333333333333333333333333333346p100)}
i14 : value y === x

o14 = true

Caveat

Currently, most transcendental functions are not implemented for complex arguments.

See also

Functions and methods returning a complex number :

Methods that use a complex number :

For the programmer

The object CC is an inexact field family, with ancestor classes InexactNumber < Number < Thing.