{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Algebraic numbers are similar to complex numbers." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Complex Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The set of all complex numbers is predefined as ``CC`` (or ``CDF`` for the complex double field). Let us look at a random complex number." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.850863261870165 - 0.914313861818274*I\n" ] } ], "source": [ "z = CC.random_element()\n", "print(z)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the real part : 0.850863261870165\n", "the imaginary part : -0.914313861818274\n" ] } ], "source": [ "print('the real part :', z.real())\n", "print('the imaginary part :', z.imag())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The polar representation of a complex number is defined by the argument and the radius." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the radius of 0.850863261870165 - 0.914313861818274*I is 1.24897483093671\n" ] } ], "source": [ "r = abs(z)\n", "print('the radius of', z, 'is', r)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the argument of 0.850863261870165 - 0.914313861818274*I is -0.821328434738775\n" ] } ], "source": [ "t = z.argument()\n", "print('the argument of', z, 'is', t)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given the argument and radius, we can compute the rectangular representation." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the rectangular format : 0.850863261870165 - 0.914313861818275*I\n", " the original z : 0.850863261870165 - 0.914313861818274*I\n" ] } ], "source": [ "rz = r*(cos(t) + sin(t)*I)\n", "print('the rectangular format :', rz)\n", "print(' the original z :', z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To verify the formal definition of ``I`` we factor $x^2 + 1$ over the polynomial ring with complex coefficients." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Univariate Polynomial Ring in x over Complex Field with 53 bits of precision\n" ] } ], "source": [ "R. = CC[]\n", "print(R)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(x - I) * (x + I)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = x^2 + 1\n", "factor(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see that there are two square roots of $-1$." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[I, -I]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sqrt(-1, all=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Therefore, is not strictly correct to refer to ``I`` as *the* square root of $-1$, because there are two square roots. It is better to call ``I`` the positive square root of $-1$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Algebraic Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With a ``reset()`` we reset all names of variables." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We extend the rational numbers with $\\sqrt{2}$ in three steps:\n", "\n", "1. We define the polynomial ring ``P`` for the polynomials in ``x`` with rational coefficients in ``QQ``.\n", "\n", "2. The polynomial ``p`` is $x^2 - 2$ is the polynomial we want to factor over the field extension.\n", "\n", "3. The extended number field is called ``Q1`` using ``sqrt2`` as the symbol for $\\sqrt{-2}$." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number Field in sqrt2 with defining polynomial x^2 - 2\n" ] } ], "source": [ "P. = QQ[]\n", "p = x^2 - 2\n", "Q1. = QQ.extension(p)\n", "print(Q1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Any polynomial in ``x`` will be seen as a polynomial with rational coefficients. To define a polynomial over the extended field ``Q1``, we must use a new independent variable. Therefore, we define ``P1`` as the ring of polynomials in ``y`` with coefficients in ``Q1``." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(y - sqrt2) * (y + sqrt2)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P1. = Q1[]\n", "q = y^2 - 2\n", "factor(q)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we see that over this new field, that $y^2 - 2$ factors." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To factor also $y^2 + 1$, we add the imaginary unit to ``Q1`` to obtain the extension ``Q2``." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number Field in imagunit with defining polynomial y^2 + 1 over its base field\n" ] } ], "source": [ "r = y^2 + 1\n", "Q2. = Q1.extension(r)\n", "print(Q2)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(z + sqrt2*imagunit) * (z - sqrt2*imagunit)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P2. = Q2[]\n", "s = z^2 + 2\n", "factor(s)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Finite Field Extensions" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Over the binary number field, the polynomial $x^2 + 1$ factors." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ring of integers modulo 2\n" ] } ], "source": [ "Z2 = Integers(2)\n", "print(Z2)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(x + 1)^2" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P. = Z2[]\n", "p = x^2 + 1\n", "factor(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If a polynomial factors, then we say it is *reducible*, otherwise it is *irreducible*." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x^3 + x + 1" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = x^3 + x + 1\n", "factor(q)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see that $x^3 + x + 1$ does not factor over the binary numbers. So we can extend ``Z2``." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Univariate Quotient Polynomial Ring in c over Ring of integers modulo 2 with modulus c^3 + c + 1\n" ] } ], "source": [ "K. = Z2.extension(q)\n", "print(K)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In a finite field we can list all elements." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[x for x in K]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The multiplication table is printed below." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 0, 0, 0, 0, 0, 0, 0]\n", "[0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1]\n", "[0, c, c^2, c^2 + c, c + 1, 1, c^2 + c + 1, c^2 + 1]\n", "[0, c + 1, c^2 + c, c^2 + 1, c^2 + c + 1, c^2, 1, c]\n", "[0, c^2, c + 1, c^2 + c + 1, c^2 + c, c, c^2 + 1, 1]\n", "[0, c^2 + 1, 1, c^2, c, c^2 + c + 1, c + 1, c^2 + c]\n", "[0, c^2 + c, c^2 + c + 1, 1, c^2 + 1, c + 1, c, c^2]\n", "[0, c^2 + c + 1, c^2 + 1, c, 1, c^2 + c, c^2, c + 1]\n" ] } ], "source": [ "for x in K:\n", " print([x*y for y in K])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Except for the first row and first column, there is exactly one ``1`` in every row and column, which shows that every element (except zero) has an inverse." ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 10.3", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 4 }