{ "cells": [ { "cell_type": "markdown", "id": "871e9bb1-5bac-487f-afd1-b560c89f33bb", "metadata": {}, "source": [ "MCS 320 Project One is due Wednesday 2 July 2025 at 2pm." ] }, { "cell_type": "markdown", "id": "ae2cc568-cd65-409b-a72f-9b0be4070306", "metadata": {}, "source": [ "Interval arithmetic provides an automated error analysis and helps to decide on the choice of the working precision. The goal of the project is to explore interval arithmetic in SageMath and to conduct systematically numerical experiments." ] }, { "cell_type": "markdown", "id": "ca29ac87-16bc-489a-b58e-995022475362", "metadata": {}, "source": [ "# 1. Arithmetic with Intervals" ] }, { "cell_type": "markdown", "id": "0b6082d4-5a58-4bfc-8e9f-a59edc2c0c8c", "metadata": {}, "source": [ "Instances of ``RIF`` are intervals where the lower and upper bounds are elements of ``RR``." ] }, { "cell_type": "code", "execution_count": 1, "id": "bc468ff0-5101-44c6-8346-23e48735e1e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Real Interval Field with 53 bits of precision" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "RIF" ] }, { "cell_type": "markdown", "id": "6835f3a7-e85f-4d7b-8494-f61feb6ca04a", "metadata": {}, "source": [ "Even though we are working with 53 bits of precision, we assume only the first five decimal places of the numbers are accurate. So we have an error of $10^{-5}$ on the numbers." ] }, { "cell_type": "code", "execution_count": 2, "id": "cef3e7d3-c0c7-4d09-b59f-52c4715e16d7", "metadata": {}, "outputs": [], "source": [ "e = 1.0e-5" ] }, { "cell_type": "code", "execution_count": 3, "id": "ea29f7b5-b8f8-43d4-991a-f793843e1d24", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0162893269919866" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = RR.random_element()\n", "x" ] }, { "cell_type": "code", "execution_count": 4, "id": "88436c8a-fd20-4be7-bf9b-a89f3693934c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0163?" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X = RIF(x-e, x+e)\n", "X" ] }, { "cell_type": "markdown", "id": "ab97a1e5-7ed7-4abf-8e38-e2ea7c765a80", "metadata": {}, "source": [ "The interval `X` represents $x \\pm 10^{-5}$." ] }, { "cell_type": "code", "execution_count": 5, "id": "806287e1-014c-4147-a382-861fc9817d7d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'[0.016279326991986597 .. 0.016299326991986597]'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X.str(style='brackets')" ] }, { "cell_type": "code", "execution_count": 6, "id": "2ea52726-7023-477e-9cb2-e879c8eb6e97", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0162793269919865" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X.lower()" ] }, { "cell_type": "code", "execution_count": 7, "id": "6970b707-fea1-47db-941f-c336c1901316", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0162993269919866" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X.upper()" ] }, { "cell_type": "code", "execution_count": 8, "id": "5db8c094-03e6-4612-a394-ab1ec0e60cbf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0000199999999999992" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X.absolute_diameter()" ] }, { "cell_type": "markdown", "id": "964b8c85-2d5d-46b3-8f8a-7e3b8bb6eded", "metadata": {}, "source": [ "To illustrate the elementary arithmetical operations, we define another interval `Y`." ] }, { "cell_type": "code", "execution_count": 9, "id": "3c4416ed-d0b2-46e7-aaf5-9bf7ff74c5fe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.9427?" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y = RR.random_element()\n", "Y = RIF(y-e, y+e)\n", "Y" ] }, { "cell_type": "code", "execution_count": 10, "id": "1afdd3ca-01ee-4d61-b6e4-6001c0bc88e4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.9264?" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = X + Y\n", "S" ] }, { "cell_type": "code", "execution_count": 11, "id": "95fad5df-3249-4cd0-9f21-c626231de6b5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.0154?" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P = X * Y\n", "P" ] }, { "cell_type": "code", "execution_count": 12, "id": "a572f948-cf43-4417-ae93-d3ac4dc7bf08", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.0173?" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Q = X / Y\n", "Q" ] }, { "cell_type": "markdown", "id": "dd401145-0c46-4184-93ea-1f49176674c2", "metadata": {}, "source": [ "We see that in the output we can trust the first 4 decimal places." ] }, { "cell_type": "markdown", "id": "7003ddd5-e2d0-4a59-bf78-9726c1ec6f10", "metadata": {}, "source": [ "However, there are instances that lead to a catastrophic loss of accuracy, when we subtract numbers that share several leading bits." ] }, { "cell_type": "code", "execution_count": 13, "id": "d0e69667-96b6-4a1f-97f9-c17839c0c4cb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.0001?" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = x + RR.random_element()*1.e-4\n", "Z = RIF(z-e,z+e)\n", "S = X-Z\n", "S" ] }, { "cell_type": "code", "execution_count": 14, "id": "9a639ed3-a4b2-41ee-884e-f8aad26239a1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0000399999999999984" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S.absolute_diameter()" ] }, { "cell_type": "markdown", "id": "43f9d062-5984-482d-98c7-9a00579a4e3a", "metadata": {}, "source": [ "Instead of 4 decimal places of accuracy, we have only one left." ] }, { "cell_type": "markdown", "id": "eb100615-2d0c-4ced-9598-d65373aae03c", "metadata": {}, "source": [ "## Assignment One" ] }, { "cell_type": "markdown", "id": "f3f273ea-d75c-47af-8284-76a5b7d5e533", "metadata": {}, "source": [ "Generate `X` as above and make `Y` as follows\n", "\n", "```\n", " y = x + f*RR.random_element()\n", " Y = RIF(y-e, y+e)\n", "```\n", "\n", "where `f` takes the values `1.0e-1`, `1.0e-2`,\n", "`1.0e-3`, `1.0e-4`, `1.0e-5`, and `1.0e-6`." ] }, { "cell_type": "markdown", "id": "700e106a-cf7d-4bc6-b93b-f253f0ffe135", "metadata": {}, "source": [ "1. For each value of `f`, compute `S = X - Y`\n", " and report `S.absolute_diameter()`.\n", "\n", "2. Write a couple of sentences interpreting the results." ] }, { "cell_type": "markdown", "id": "5ad95b60-f35e-4070-a7c1-9a495b9513e8", "metadata": {}, "source": [ "## Solution to Assignment One" ] }, { "cell_type": "code", "execution_count": 15, "id": "05363650-49ad-4908-bda5-7dbec53c287b", "metadata": {}, "outputs": [], "source": [ "e = 1.0e-5" ] }, { "cell_type": "code", "execution_count": 16, "id": "026ff8e6-22ae-4c45-b7df-97fc9bc46965", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.0443? 0.0000399999999999984\n", "-0.0073? 0.0000399999999999984\n", "-0.0007? 0.0000399999999999984\n", "0.0000? 0.0000399999999999984\n", "0.0000? 0.0000399999999999984\n", "0.0000? 0.0000399999999999984\n" ] } ], "source": [ "x = RR.random_element()\n", "X = RIF(x-e, x+e)\n", "for f in [1.0e-1, 1.0e-2, 1.0e-3, 1.0e-4, 1.0e-5, 1.0e-6]:\n", " y = x + f*RR.random_element()\n", " Y = RIF(y-e, y + e)\n", " S = X - Y\n", " print(S, S.absolute_diameter())" ] }, { "cell_type": "markdown", "id": "9c5560bc-06c9-49a9-87c6-3133d9e63e29", "metadata": {}, "source": [ "As we consider the difference of the intervals, we notice that the difference becomes zero viewed from the error on the accuracy of five decimal places on the numbers." ] }, { "cell_type": "markdown", "id": "0dcca4b3-92fe-4c5c-912a-1b61a8e2ce44", "metadata": {}, "source": [ "The absolute diameter represents the absolute error and remains the same." ] }, { "cell_type": "markdown", "id": "505300e3-9b69-428a-8111-981194b7d676", "metadata": {}, "source": [ "# 2. Algebraic Numbers" ] }, { "cell_type": "markdown", "id": "9066fa70-9d17-406b-bf7a-98bf44d6172b", "metadata": {}, "source": [ "An algebraic number is a root of a polynomial equation with integer coefficients. A feature of the intervals as instances of `RIF` is the `algdep()` method which computes algebraic dependencies." ] }, { "cell_type": "code", "execution_count": 17, "id": "cb781cc3-6b61-4222-b6f1-84bd551b5ae9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.41422?" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = sqrt(RIF(2-e, 2+e))\n", "r" ] }, { "cell_type": "code", "execution_count": 18, "id": "c33b7b11-f0c3-45cb-9819-c9cbe571ee39", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "29*x - 41" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.algdep(1)" ] }, { "cell_type": "code", "execution_count": 19, "id": "4200dd7f-a327-4d39-8cd4-161f044c2b61", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x^2 - 2" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.algdep(2)" ] }, { "cell_type": "markdown", "id": "dbfe0977-e180-4f29-8e5c-048f2dc4b076", "metadata": {}, "source": [ "Already a low accuracy approximation for $\\sqrt{2}$ suffices to obtain the correct polynomial $x^2 - 2$ which defines the algebraic number $\\sqrt{2}$." ] }, { "cell_type": "markdown", "id": "33d015a6-c00f-4837-86a8-7712d6c21df7", "metadata": {}, "source": [ "## Assignment Two." ] }, { "cell_type": "markdown", "id": "9242fbc8-a310-409c-8475-a4b7e1e73a86", "metadata": {}, "source": [ "Consider $2^{1/8}$, the 8-th root of 2.\n", "What is the smallest number of digits in the floating-point approximation\n", "of $2^{1/8}$ to accurately compute the coefficients of $2 - x^8$,\n", "using the default working precision and tolerance?" ] }, { "cell_type": "markdown", "id": "056d0354-bb12-48b7-a570-ee3826aac375", "metadata": {}, "source": [ "## Solution to Assignment Two" ] }, { "cell_type": "markdown", "id": "cac41b25-636f-490d-9fa2-10667db27f30", "metadata": {}, "source": [ "We begin with a large error." ] }, { "cell_type": "code", "execution_count": 20, "id": "ed8115d4-46f6-4411-b3ec-eec7fddfa152", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0100000000000000" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = 1.0e-2\n", "e" ] }, { "cell_type": "code", "execution_count": 21, "id": "e38defd9-3b20-4241-8c49-562170e7e6f6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.09?" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = RIF(2-e,2+e)^(1/8)\n", "r" ] }, { "cell_type": "code", "execution_count": 22, "id": "98b6f00f-b493-4bce-aa33-4b2d83fb2abe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x^6 + x^5 - x^2 - x - 1" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.algdep(8)" ] }, { "cell_type": "markdown", "id": "4a0c968f-0df7-4e4d-8b9b-14c6d27e26e4", "metadata": {}, "source": [ "With only 3 decimal places of accuracy in the approximation for $2^{1/8}$, we cannot recover the algebraic dependency correctly. Let us take then a smaller error." ] }, { "cell_type": "code", "execution_count": 23, "id": "c9aae245-4fdf-4ae0-ba86-a5b84f7b3902", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.00100000000000000" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = 1.0e-3\n", "e" ] }, { "cell_type": "code", "execution_count": 24, "id": "72e90f60-339c-48bd-82c3-7129f89cf0b2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0905?" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = RIF(2-e,2+e)^(1/8)\n", "r" ] }, { "cell_type": "code", "execution_count": 25, "id": "a679d2bb-8ae8-496f-a3d6-baeb1f8125a6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x^8 - 2" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r.algdep(8)" ] }, { "cell_type": "markdown", "id": "619717d7-f741-468a-98f3-3070c63a623c", "metadata": {}, "source": [ "Five decimal places of accuracy in the approximation for $2^{1/8}$ suffice to recover the correct algebraic dependency." ] }, { "cell_type": "markdown", "id": "3b9863a7-3e7c-4ca0-b66f-fc4ddae9ddc8", "metadata": {}, "source": [ "# 3. Evaluating a Polynomial" ] }, { "cell_type": "markdown", "id": "0f7136e6-be6e-44b3-8783-2c25923925fa", "metadata": {}, "source": [ "The higher the degree of a polynomial, the more errors accumulate in a numerical evaluation." ] }, { "cell_type": "code", "execution_count": 26, "id": "fa759735-2b4b-44a1-b5a1-e63a37d2ffb1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Univariate Polynomial Ring in x over Real Interval Field with 53 bits of precision" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "R. = RIF[]\n", "R" ] }, { "cell_type": "code", "execution_count": 27, "id": "35eb6674-46c4-43e5-aebc-bb5952f2e224", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x^6 - 6*x^5 + 15*x^4 - 20*x^3 + 15*x^2 - 6*x + 1" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = (1 - x)^6\n", "p" ] }, { "cell_type": "code", "execution_count": 28, "id": "74b87c12-af58-4778-889b-d89664eeb6bd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.500?" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = RIF(1.5 - e, 1.5 + e)\n", "z" ] }, { "cell_type": "code", "execution_count": 29, "id": "43cedbf8-3cad-415d-8cb9-5adf07492d67", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0?" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pz = p(z)\n", "pz" ] }, { "cell_type": "code", "execution_count": 30, "id": "5b72181c-3c27-4e75-999f-7edc63cfd139", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.162749906000022" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pz.absolute_diameter()" ] }, { "cell_type": "code", "execution_count": 31, "id": "8f76bb21-83b0-40d8-b918-e12f583acfa3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.0657771404872592" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pz.lower()" ] }, { "cell_type": "code", "execution_count": 32, "id": "7a90634d-b4fc-4b10-a6d8-aa2b9db21e27", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0969727655127633" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pz.upper()" ] }, { "cell_type": "code", "execution_count": 33, "id": "4553a48f-d4be-4db9-95d3-ce93b2dd2192", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.015625000000000000?" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p(3/2)" ] }, { "cell_type": "markdown", "id": "bc51cebb-7d7d-4ab3-a3b6-30ca95f79567", "metadata": {}, "source": [ "With a power of 6, we obtain only one correct decimal in the value when the error is 1.0e-5." ] }, { "cell_type": "markdown", "id": "0394dc27-dd7d-4fe0-907b-203e1bc9ca46", "metadata": {}, "source": [ "## Assignment Three" ] }, { "cell_type": "markdown", "id": "391ab821-dc40-453d-abdf-4afb21524c7f", "metadata": {}, "source": [ "Consider\n", "\n", "$$\n", " p(x) = (1 - x)^d, \\quad \\mbox{for } d = 1,2,\\ldots,10,\n", "$$\n", "\n", "evaluated at\n", "\n", "$$\n", " Z = [1.5 - 10^{-k}, 1.5 + 10^{+k}], \\quad \\mbox{for } k = 1,2,\\ldots,10.\n", "$$\n", "\n", "How does the width of the interval $p(Z)$ change for increasing\n", "values of $d$ and $k$?" ] }, { "cell_type": "markdown", "id": "9915b0f1-7752-497e-8eaf-424d8b05d841", "metadata": {}, "source": [ "1. Report the absolute diameter of the interval $p(Z)$,\n", " for $d = 1,2,\\ldots,10$ and $k=1,2,\\ldots,10$ in a table,\n", " where the rows are indexed by $k$ and the columns by $d$.\n", "\n", "2. Compare with the exact value $p(3/2)$ and the error predicted\n", " by the width of the intervals.\n", "\n", "3. Write a couple of sentences interpreting the numerical errors." ] }, { "cell_type": "markdown", "id": "169f235b-88f0-409b-96aa-99deec2515b5", "metadata": {}, "source": [ "## Solution to Assignment Three" ] }, { "cell_type": "markdown", "id": "919de7aa-9a22-4646-bcb2-9a458da6bb64", "metadata": {}, "source": [ "We start by computing the first table of diameters." ] }, { "cell_type": "code", "execution_count": 34, "id": "8c905637-75d9-45dc-bfe4-b9b037e6d2a5", "metadata": {}, "outputs": [], "source": [ "diam = [[0 for d in range(10)] for k in range(10)]" ] }, { "cell_type": "code", "execution_count": 35, "id": "a0642c46-357f-4586-80c7-c7e987cea0e7", "metadata": {}, "outputs": [], "source": [ "for k in range(1, 11):\n", " for d in range(1, 11):\n", " p = (1-x)^d\n", " Z = RIF(1.5 - 1.0/10^k, 1.5 + 1.0/10^k)\n", " pZ = p(Z)\n", " diam[k-1][d-1] = pZ.absolute_diameter()" ] }, { "cell_type": "markdown", "id": "0b83d0ec-d383-4a99-a7b8-5d6c1ffecbd0", "metadata": {}, "source": [ "Printing this table unformatted is a mess. As we are mainly interested in the magnitudes of the numbers, we use scientific notations, using two digits for the exponent." ] }, { "cell_type": "markdown", "id": "2865240a-91e7-4f8f-bb9c-d0649636f04f", "metadata": {}, "source": [ "While the C formatting conversions could be used, the most convenient format is available in numpy." ] }, { "cell_type": "code", "execution_count": 36, "id": "ec4d7ac7-593b-41d7-a665-f8506bb7d6ff", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 37, "id": "fdb4c83a-efd7-4a18-9c21-5ba70cc4af72", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.0e-01 4.0e-01 1.0e+00 2.6e+00 6.8e+00 1.7e+01 4.5e+01 1.1e+02 2.9e+02 7.5e+02 \n", "2.0e-02 4.0e-02 1.0e-01 2.6e-01 6.5e-01 1.6e+00 4.1e+00 1.0e+01 2.6e+01 6.4e+01 \n", "2.0e-03 4.0e-03 1.0e-02 2.6e-02 6.5e-02 1.6e-01 4.1e-01 1.0e+00 2.5e+00 6.4e+00 \n", "2.0e-04 4.0e-04 1.0e-03 2.6e-03 6.5e-03 1.6e-02 4.1e-02 1.0e-01 2.5e-01 6.4e-01 \n", "2.0e-05 4.0e-05 1.0e-04 2.6e-04 6.5e-04 1.6e-03 4.1e-03 1.0e-02 2.5e-02 6.4e-02 \n", "2.0e-06 4.0e-06 1.1e-05 2.6e-05 6.5e-05 1.6e-04 4.1e-04 1.0e-03 2.5e-03 6.4e-03 \n", "2.0e-07 4.0e-07 1.1e-06 2.6e-06 6.5e-06 1.6e-05 4.1e-05 1.0e-04 2.5e-04 6.4e-04 \n", "2.0e-08 4.0e-08 1.1e-07 2.6e-07 6.5e-07 1.6e-06 4.1e-06 1.0e-05 2.5e-05 6.4e-05 \n", "2.0e-09 4.0e-09 1.1e-08 2.6e-08 6.5e-08 1.6e-07 4.1e-07 1.0e-06 2.5e-06 6.4e-06 \n", "2.0e-10 4.0e-10 1.1e-09 2.6e-09 6.5e-09 1.6e-08 4.1e-08 1.0e-07 2.5e-07 6.4e-07 \n" ] } ], "source": [ "for k in range(10):\n", " for d in range(10):\n", " print(np.format_float_scientific(diam[k][d],unique=False,precision=1), end=' ')\n", " print('')" ] }, { "cell_type": "markdown", "id": "42c3e0c1-1acc-4fb7-9347-41f97f5fc304", "metadata": {}, "source": [ "We observe the following:\n", "\n", "1. The smallest diameter occurs at the bottom left of the table, for $k=10$ and $d=1$,\n", " for a linear polynomial and tiny interval of width $2 \\times 10^{-10}$.\n", "\n", "2. The largest diameter occurs at the top right of the table, for $k=1$ and $d=10$,\n", " for a polynomial of degree 10 and a large interval of width $2 \\times 10^{-1}$.\n", "\n", "3. The diameters grow smaller in each row and larger in each column,\n", " as the intervals get smaller and the degrees get larger." ] }, { "cell_type": "markdown", "id": "ee1fbe91-d4c6-4c81-a7e3-cf17fac0f671", "metadata": {}, "source": [ "The diameter of each evaluated interval serves as a prediction for the error." ] }, { "cell_type": "markdown", "id": "ef7f05ee-da42-407e-b004-1a51c2b87bb7", "metadata": {}, "source": [ "Let us compute another table of errors, as the diameters of the exact value subtracted from the evaluated intervals, for increasing degrees and decreasing interval diameters." ] }, { "cell_type": "code", "execution_count": 38, "id": "9f9f6d64-9375-4e99-81b9-e1aba02c9063", "metadata": {}, "outputs": [], "source": [ "errs = [[0 for d in range(10)] for k in range(10)]" ] }, { "cell_type": "code", "execution_count": 39, "id": "9280b7ab-1601-4f71-b782-a66eb1e9b839", "metadata": {}, "outputs": [], "source": [ "for k in range(1, 11):\n", " for d in range(1, 11):\n", " p = (1-x)^d\n", " exact = p(x=3/2)\n", " Z = RIF(1.5 - 1.0/10^k, 1.5 + 1.0/10^k)\n", " pZ = p(x=Z)\n", " eZ = pZ - exact\n", " errs[k-1][d-1] = eZ.absolute_diameter()" ] }, { "cell_type": "code", "execution_count": 40, "id": "cf7254fa-76ee-47d1-8549-d4aeda8ab568", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.0e-01 4.0e-01 1.0e+00 2.6e+00 6.8e+00 1.7e+01 4.5e+01 1.1e+02 2.9e+02 7.5e+02 \n", "2.0e-02 4.0e-02 1.0e-01 2.6e-01 6.5e-01 1.6e+00 4.1e+00 1.0e+01 2.6e+01 6.4e+01 \n", "2.0e-03 4.0e-03 1.0e-02 2.6e-02 6.5e-02 1.6e-01 4.1e-01 1.0e+00 2.5e+00 6.4e+00 \n", "2.0e-04 4.0e-04 1.0e-03 2.6e-03 6.5e-03 1.6e-02 4.1e-02 1.0e-01 2.5e-01 6.4e-01 \n", "2.0e-05 4.0e-05 1.0e-04 2.6e-04 6.5e-04 1.6e-03 4.1e-03 1.0e-02 2.5e-02 6.4e-02 \n", "2.0e-06 4.0e-06 1.1e-05 2.6e-05 6.5e-05 1.6e-04 4.1e-04 1.0e-03 2.5e-03 6.4e-03 \n", "2.0e-07 4.0e-07 1.1e-06 2.6e-06 6.5e-06 1.6e-05 4.1e-05 1.0e-04 2.5e-04 6.4e-04 \n", "2.0e-08 4.0e-08 1.1e-07 2.6e-07 6.5e-07 1.6e-06 4.1e-06 1.0e-05 2.5e-05 6.4e-05 \n", "2.0e-09 4.0e-09 1.1e-08 2.6e-08 6.5e-08 1.6e-07 4.1e-07 1.0e-06 2.5e-06 6.4e-06 \n", "2.0e-10 4.0e-10 1.1e-09 2.6e-09 6.5e-09 1.6e-08 4.1e-08 1.0e-07 2.5e-07 6.4e-07 \n" ] } ], "source": [ "for k in range(10):\n", " for d in range(10):\n", " print(np.format_float_scientific(errs[k][d],unique=False,precision=1), end=' ')\n", " print('')" ] }, { "cell_type": "markdown", "id": "b3f028d6-2a57-46fe-8ba3-92a1a6f5b2f2", "metadata": {}, "source": [ "We obtain exactly the same table as before." ] }, { "cell_type": "markdown", "id": "845d5470-f8b9-4eda-abe1-d48c68e0fdb5", "metadata": {}, "source": [ "The working precision of 53 bits of precision to compute the exact value at 3/2 is sufficient for still modest degrees and for the large diameters of the intervals." ] } ], "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": 5 }