Lecture 5: Complex and Algebraic Numbers ======================================== We have integer, rational, and irrational numbers. Among the irrational numbers, we distinguish between the algebraic and the transcendental numbers. An algebraic number is a root of a polynomial with integer coefficients. For a transcendental number, there does not exist a polynomial with integer coefficients that has that number as one of its roots. Complex numbers are special type algebraic numbers and merit separate treatment. Sage knows the symbol I as the imaginary unit. While we may define I as the square root of negative one, this definition has its problems, as we then see when we cover algebraic numbers. A :index:complex number is a special algebraic number and arises from the polynomial \ :math:x^2 + 1, which as no real root, or equivalently, \ :math:x^2 + 1 does not factor over the field of real numbers. The outcome of the factor command on a polynomial in one variable depends on the choice of coefficient field. We introduce finite fields, multiplication tables, and field extensions. Complex Numbers --------------- We could define the :index:imaginary unit as the square root of -1 and we see that Sage represents sqrt(-1) with the symbol :index:I. :: print(sqrt(-1)) print(type(I)) print(I^2) The I has type sage.symbolic.expression.Expression and its square evaluates to \ :math:-1. In :index:rectangular coordinates, complex numbers have a :index:real part and an :index:imaginary part. :: x = 2/3 + 5*I; print(' x =', x, '|x| =', abs(x)) y = complex(2/3,5); print('y =', y, '|x| =', abs(y)) print('x has type', type(x)) print('y has type', type(y)) While x is considers as an expression, the y is the complex type of Python. As an expression, the real and imaginary part of a complex number may be any number type, whereas Python's complex number is a tuple of two hardware floats. An alternative to representing a complex number via its real and imaginary part (rectangular coordinates) is the :index:polar representation as its :index:absolute value and an :index:argument. We first must make sure the number belongs to the :index:Complex Double Field, abbreviated by :index:CDF. :: ax = CDF(x).argument(); rx = abs(x) print(ax, rx, 'x =', complex(rx*(cos(ax) + I*sin(ax)))) and we recognize the rectangular representation of x as we defined x above. Complex numbers are introduced so every polynomial with real coefficients of degree d has d roots, :index:counted with multiplicities. By default, we get complex roots if we solve a polynomial equation. If we want to see the multiplicities of the roots, we must turn on the multiplicities flag. :: var('z') solve(z^2 + 4 == 0, z) solve(z^2 - 2*z + 1 == 0, z, multiplicities=True) Defining I as the :index:square root of -1 has its problems, as we will try to illustrate next. :: a = (-1 + I)^2; b = (1 - I)^2; If we apply the sqrt() function to a and b we would expect to see -1 + I and 1 - I respectively. Instead we get sqrt(-2*I) in both cases. Why? Because, if we take a square root, we are solving a quadratic equation. :: aq = z^2 - a == 0; bq = z^2 - b == 0; The solution is \ :math:\pm \sqrt{-2I}. With the option all we get to see all square roots: :: sqrt(a, all=True) In contrast, we can also :index:prevent evaluation, after coercing the argument of sqrt() to a :index:symbolic ring, denoted by :index:SR. :: sqrt(SR(4), hold=True) Algebraic Numbers ----------------- A square root is an algebraic number. The smallest polynomial that has an :index:algebraic number as its root is the :index:minimal polynomial. The command :: sqrt(2).minpoly() returns \ :math:x^2 - 2 as the minimal polynomial of \ :math:\sqrt{2}. The outcome of the factoring of a polynomial depends on the number field. :: print(factor(z^2 - 1)) print(factor(z^2 - 2)) The first command will print (z + 1)*(z - 1) whereas the second polynomial does :index:factor and we get z^2 - 2 returned. If a polynomial does not factor over a specific number field (the default number field is the field of rational numbers), then we say that the polynomial is *irreducible over that specific number field*. We can define a number field where c is the square root of 2, we can compute modulo the minimal polynomial of sqrt(2), that is c^2 - 2 = 0. We use c^2 = 2 to simplify expressions in c. :: K. = NumberField(x^2 - 2); print K print(c^2 - 2) print(c^3) The defining polynomial of the number field K is x^2 - 2. In this number field, the expression c^2 - c evaluates to zero and c^3 simplifies to 2*c. If we now consider a :index:polynomial ring over the number field K, then the polynomial x^2 - 2 will factor. :: R. = PolynomialRing(K) p = x^2 - 2 factor(p) On return we see (x - c) * (x + c). In coding and cryptography we often work with finite fields. :: k = GF(8,'c'); print(k) e = [a for a in k]; print(e) The GF is an abbreviation for Galois Field. This makes k a field of size \ :math:2^3 with elements :: [0, c, c^2, c + 1, c^2 + c, c^2 + c + 1, c^2 + 1, 1] In a field every element has a :index:multiplicative inverse. We can see this in table of multiplications. :: for x in e: [x*y for y in e] The :index:multiplication table is :: [0, 0, 0, 0, 0, 0, 0, 0] [0, c^2, c + 1, c^2 + c, c^2 + c + 1, c^2 + 1, 1, c] [0, c + 1, c^2 + c, c^2 + c + 1, c^2 + 1, 1, c, c^2] [0, c^2 + c, c^2 + c + 1, c^2 + 1, 1, c, c^2, c + 1] [0, c^2 + c + 1, c^2 + 1, 1, c, c^2, c + 1, c^2 + c] [0, c^2 + 1, 1, c, c^2, c + 1, c^2 + c, c^2 + c + 1] [0, 1, c, c^2, c + 1, c^2 + c, c^2 + c + 1, c^2 + 1] [0, c, c^2, c + 1, c^2 + c, c^2 + c + 1, c^2 + 1, 1] Observe that, except for the first row, there is 1 in every row. Except for the first column, there is 1 in every column. To verify, let us look at the 1 in the second row. :: print e[1], '* (', e[-2], ') =', e[1]*e[-2] The output is c * ( c^2 + 1 ) = 1. We can factor over finite fields. We make a polynomial ring with coefficients in the finite field we just constructed: :: R. = PolynomialRing(k) p = x^3 + x + 1 factor(p) which leads to (x + c) * (x + c^2) * (x + c^2 + c). Note that over the default field, the polynomial is :index:irreducible. :: q = z^3 + z + 1; factor(q) To verify that the polynomial \ :math:p = x^4 + 3 x + 4 does not factor over the finite field of five elements, we do :: R. = PolynomialRing(GF(5)) p = x^4 + 3*x + 4; print factor(p) We can then extend the field of five elements with a root of \ :math:p as follows :: F. = GF(5).extension(p) e = [n for n in F]; print e Because the degree of \ :math:p is four, every element in the field extension F can be expressed as a polynomial of degree three or less, because every fourth power of \ :math:a simplifies via \ :math:a^4 = 2 a + 1. We have five choices for every coefficient of a degree three polynomials and since we can make those choices independently, we have a field with \ :math:5^4 elements. Over this field extension, we have a factorization. :: R. = PolynomialRing(F) q = y^4 + 3*y + 4; print(factor(q)) Assignments ----------- 1. The complex number \ :math:z in polar representation is given by the radius (absolute value) \ :math:r = 3 and angle (argument) \ :math:\theta = \pi/3. Use Sage to find the exact (no floating-point) value of \ :math:z in the form \ :math:a + b I. 2. Execute solve(x^3 - 5 == 0, x) and show that all solutions of \ :math:x^3 - 5 = 0 are of the form \ :math:\sqrt[3]{5} e^{I \theta}, with \ :math:\theta being either 0 or \ :math:\pm \frac{2}{3} \pi. 3. Take the complex number \ :math:z = 1 + I and let Sage compute \ :math:\sqrt{1/z} and \ :math:1/\sqrt{z}. Are the results symbolically the same? Are the results numerically the same? Give reasons for your answers, illustrated with the appropriate Sage instructions. 4. Use Sage to show that the polynomial \ :math:p = x^4 + 3 x + 4 is irreducible over the finite field with 5 elements. Declare \ :math:z to be a root of \ :math:p and express \ :math:z^{13} as a polynomial in \ :math:z of degree 4 (or less). 5. Compute all irreducible polynomials of degree 2 over a field with 3 elements.