{ "cells": [ { "cell_type": "markdown", "id": "1fe3c5b8-c84c-4fe2-9d19-6d47163364dc", "metadata": {}, "source": [ "Submit your answers to gradescope before, or at 3:40pm." ] }, { "cell_type": "markdown", "id": "1f2fabe0-0a28-4eb8-a899-2f68684b378b", "metadata": {}, "source": [ "# Question 1" ] }, { "cell_type": "markdown", "id": "cb3fa653-a074-44e7-90f2-333c5f4a253a", "metadata": {}, "source": [ "Let $N = \\cos(\\pi/5)$.\n", "\n", "1. Compute a nearby rational approximation for $N$,\n", " with the denominator bounded by 999.\n", "\n", "2. What is the accuracy of your nearby rational approximation?" ] }, { "cell_type": "markdown", "id": "d4cd370b-90d3-4126-a217-e92e6a3cf31d", "metadata": {}, "source": [ "## answer to question 1" ] }, { "cell_type": "code", "execution_count": 1, "id": "ecae2985-36f3-4f58-92e1-d2cc086b2c45", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 2, "id": "98f8c25c-850b-438c-b207-91a5a66599c0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{1}{4} \\, \\sqrt{5} + \\frac{1}{4}\\)" ], "text/latex": [ "$\\displaystyle \\frac{1}{4} \\, \\sqrt{5} + \\frac{1}{4}$" ], "text/plain": [ "1/4*sqrt(5) + 1/4" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "N = cos(pi/5)\n", "show(N)" ] }, { "cell_type": "code", "execution_count": 3, "id": "318e08df-0c5e-4df3-a8f0-5d73968aade0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{682}{843}\\)" ], "text/latex": [ "$\\displaystyle \\frac{682}{843}$" ], "text/plain": [ "682/843" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "q = RR(N).nearby_rational(max_denominator=999)\n", "show(q)" ] }, { "cell_type": "code", "execution_count": 4, "id": "aca515f1-2a93-495f-aad1-548684f0d4f1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-1.944657839e-6" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = ((q - N)/N).n(digits=10)\n", "e" ] }, { "cell_type": "markdown", "id": "74e48448-a0f0-48c7-b3e3-bc7574125fe6", "metadata": {}, "source": [ "The accuracy of `q` as a rational approximation for `N` is about six decimal places." ] }, { "cell_type": "markdown", "id": "5d751818-8407-453d-9651-5543027bafce", "metadata": {}, "source": [ "# Question 2" ] }, { "cell_type": "markdown", "id": "2638f774-369f-4733-b6cf-ed95d2ca1657", "metadata": {}, "source": [ "Compute the square roots of $c = 5 - 4 I$.\n", "\n", "Verify that the square of your computed roots equals $c$." ] }, { "cell_type": "markdown", "id": "59d87dfd-8181-428d-8ca6-c8f1f9ce79d9", "metadata": {}, "source": [ "## answer to question 2" ] }, { "cell_type": "code", "execution_count": 5, "id": "dda86f1d-38d0-426f-be09-10b6f4e88123", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 6, "id": "76951238-7c60-4694-922a-e5bafa06ba79", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[sqrt(-4*I + 5), -sqrt(-4*I + 5)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = 5 - 4*I\n", "roots = sqrt(c, all=True)\n", "roots" ] }, { "cell_type": "code", "execution_count": 7, "id": "2f046d6c-da79-43df-b699-11f038a385ac", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 0]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[abs(root^2 - c) for root in roots]" ] }, { "cell_type": "markdown", "id": "6749831f-9e1c-4432-9004-fcaa25ed4965", "metadata": {}, "source": [ "# Question 3" ] }, { "cell_type": "markdown", "id": "c3b0a674-0660-4a0e-9df4-554cbd5a6e78", "metadata": {}, "source": [ "Let $p = x^3 + x + 4$ be a polynomial with coefficients in\n", "a finite field with 11 elements.\n", "\n", "Show that $p$ is irreducible.\n", "\n", "Declare $\\alpha$ as a formal root of $p$ and show that $p$\n", "factors over the field extended with $\\alpha$." ] }, { "cell_type": "markdown", "id": "1c667687-6423-4191-a08c-e246a827e111", "metadata": {}, "source": [ "## answer to question 3" ] }, { "cell_type": "code", "execution_count": 8, "id": "bbe20b2f-a97f-4680-930b-b300af67ceaa", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 9, "id": "152fe74c-6fe1-4f28-923d-180dfa938381", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = polygen(GF(11))\n", "p = x^3 + x + 4\n", "p.is_irreducible()" ] }, { "cell_type": "code", "execution_count": 10, "id": "e60c5dda-0164-412e-9190-50c8f8ba32d6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Finite Field in alpha of size 11^3" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "K. = GF(11).extension(p)\n", "K" ] }, { "cell_type": "code", "execution_count": 11, "id": "dcf47265-aee9-496b-a6ea-ec172da09adc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(x + 10*alpha) * (x + 4*alpha^2 + 4*alpha + 10) * (x + 7*alpha^2 + 8*alpha + 1)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "factor(K[x](p))" ] }, { "cell_type": "markdown", "id": "54937e88-7d12-46f9-b16d-a76c985b864e", "metadata": {}, "source": [ "Observe that, after casting `p` into the new field `K[x]`, the polynomial factors into linear factors." ] }, { "cell_type": "markdown", "id": "95918f38-50c5-4267-942d-502358b35636", "metadata": {}, "source": [ "# Question 4" ] }, { "cell_type": "markdown", "id": "23770e4e-0b21-4442-b919-b1d119aea512", "metadata": {}, "source": [ "Define an equation `eqn` that shows `cos(pi/2) == 0` when printed.\n", "\n", "Without retyping `eqn`, change `eqn` so `print(eqn)` shows `0 == 0`." ] }, { "cell_type": "markdown", "id": "d48b9bae-ee16-407c-8e90-e70657ac84a1", "metadata": {}, "source": [ "## answer to question 4" ] }, { "cell_type": "code", "execution_count": 12, "id": "497b322f-c32d-4138-891f-8af680323d79", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 13, "id": "8c5e2674-90b0-491a-895d-3618b23c626f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cos(1/2*pi) == 0\n" ] } ], "source": [ "eqn = cos(pi/2, hold=true) == 0\n", "print(eqn)" ] }, { "cell_type": "code", "execution_count": 14, "id": "44634d4f-02ef-43d6-8975-f03e60c8e9a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 == 0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "eqn.unhold()" ] }, { "cell_type": "markdown", "id": "6533c95a-42e9-4a57-839b-012986faf2e6", "metadata": {}, "source": [ "# Question 5" ] }, { "cell_type": "markdown", "id": "ac095ddb-a9cd-430e-a0fd-3b8afa7329e1", "metadata": {}, "source": [ "Consider the evaluation of \n", "$p = x^8 - 2 x^7 + x^6 + 3 x^5 - x^4 + 4 x^3 + x + 6$.\n", "\n", "What is the fastest way to evaluate $p$ at hardware floats? \n", "\n", "Justify your answer." ] }, { "cell_type": "markdown", "id": "b6f25200-4496-4d02-bb86-9bba0f84dd0a", "metadata": {}, "source": [ "## answer to question 5" ] }, { "cell_type": "code", "execution_count": 15, "id": "70703b73-883a-4a6f-9a81-bbd7e0832cc6", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 16, "id": "c6e2ccef-cc75-4285-9d4f-0a5b91a2ae48", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle x^{8} - 2 \\, x^{7} + x^{6} + 3 \\, x^{5} - x^{4} + 4 \\, x^{3} + x + 6\\)" ], "text/latex": [ "$\\displaystyle x^{8} - 2 \\, x^{7} + x^{6} + 3 \\, x^{5} - x^{4} + 4 \\, x^{3} + x + 6$" ], "text/plain": [ "x^8 - 2*x^7 + x^6 + 3*x^5 - x^4 + 4*x^3 + x + 6" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x = var('x')\n", "p = x^8 - 2*x^7 + x^6 + 3*x^5 - x^4 + 4*x^3 + x + 6\n", "show(p)" ] }, { "cell_type": "markdown", "id": "b178eddb-543c-4727-8ff8-93b8aaa22814", "metadata": {}, "source": [ "The fastest way to evaluate `p` at hardware floats is to make a fast callable object of the Horner form of `p`. The Horner form ensures we need as many multiplications as additions (or subtractions) to evaluate `p`. The fast callable is an optimized data structure for numerical evaluation." ] }, { "cell_type": "code", "execution_count": 17, "id": "e3efae71-a2e8-4e20-9f78-e80247d40cc7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle {\\left({\\left({\\left({\\left({\\left({\\left(x - 2\\right)} x + 1\\right)} x + 3\\right)} x - 1\\right)} x + 4\\right)} x^{2} + 1\\right)} x + 6\\)" ], "text/latex": [ "$\\displaystyle {\\left({\\left({\\left({\\left({\\left({\\left(x - 2\\right)} x + 1\\right)} x + 3\\right)} x - 1\\right)} x + 4\\right)} x^{2} + 1\\right)} x + 6$" ], "text/plain": [ "((((((x - 2)*x + 1)*x + 3)*x - 1)*x + 4)*x^2 + 1)*x + 6" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hp = p.horner(x)\n", "show(hp)" ] }, { "cell_type": "code", "execution_count": 18, "id": "25ae3782-6d9c-4f33-9932-2b1cb9943e46", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[('load_arg', 0),\n", " ('load_const', -2),\n", " 'add',\n", " ('load_arg', 0),\n", " 'mul',\n", " ('load_const', 1),\n", " 'add',\n", " ('load_arg', 0),\n", " 'mul',\n", " ('load_const', 3),\n", " 'add',\n", " ('load_arg', 0),\n", " 'mul',\n", " ('load_const', -1),\n", " 'add',\n", " ('load_arg', 0),\n", " 'mul',\n", " ('load_const', 4),\n", " 'add',\n", " ('load_arg', 0),\n", " ('ipow', 2),\n", " 'mul',\n", " ('load_const', 1),\n", " 'add',\n", " ('load_arg', 0),\n", " 'mul',\n", " ('load_const', 6),\n", " 'add',\n", " 'return']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = fast_callable(hp, vars=['x'])\n", "f.op_list()" ] }, { "cell_type": "markdown", "id": "549547c7-68cb-4f4b-942f-c14b746c42c1", "metadata": {}, "source": [ "Let us verify the correctness at a random element." ] }, { "cell_type": "code", "execution_count": 19, "id": "33d9fb6c-a88b-412d-ada5-16830ec810c0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.238285927138154" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rx = RR.random_element()\n", "rx" ] }, { "cell_type": "code", "execution_count": 20, "id": "b9b850ad-382b-4bcc-9898-0f1f5a5e623f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.29159251815385" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p(x=rx)" ] }, { "cell_type": "code", "execution_count": 21, "id": "f2eb3ae3-3346-4de3-8a28-b21af0def468", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.29159251815385" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f(rx)" ] }, { "cell_type": "code", "execution_count": 22, "id": "f7c8e4b2-418a-461f-bdc4-575ca9b83e15", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "625 loops, best of 3: 30.2 μs per loop" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timeit('p(x = rx)')" ] }, { "cell_type": "code", "execution_count": 23, "id": "5d446dd6-1b6b-48ae-a921-2758d1a8d2ad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "625 loops, best of 3: 5.08 μs per loop" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timeit('f(rx)')" ] }, { "cell_type": "markdown", "id": "90fff16c-ee5c-4588-b245-c3f307885c9e", "metadata": {}, "source": [ "Observe the significant drop in the time it takes to evaluate `f` compared to `p`." ] }, { "cell_type": "markdown", "id": "996c0e0b-45d6-4b4c-851c-816603637f1a", "metadata": {}, "source": [ "# Question 6" ] }, { "cell_type": "markdown", "id": "78c7e392-5f6e-4372-bd2d-150b758d6e04", "metadata": {}, "source": [ "The\n", "``f = lambda n: float(sum([(1+k/n)**2*ln(1+k/n) for k in range(1,n)])/n)``\n", "\n", "computes the right hand side of\n", "\n", "$$\n", " \\qquad \\int_1^2 x^2 \\ln(x) dx \\approx \\frac{1}{n} \n", " \\sum_{k=1}^{n-1} \\left( 1 + \\frac{k}{n} \\right)\n", " \\ln \\left( 1 + \\frac{k}{n} \\right).\n", "$$\n", "\n", "1. Time the execution of `f` for $n = 10000$.\n", " \n", " Explain why `f` is inefficient.\n", "\n", "2. Apply vectorization to improve the efficiency. Verify the correctness.\n", "\n", " Time the execution of the vectorized function for $n = 10000$,\n", " compare with timings of `f`." ] }, { "cell_type": "markdown", "id": "6c2795b8-5ece-4fce-beb6-caa00e7e250f", "metadata": {}, "source": [ "## answer to question 6" ] }, { "cell_type": "code", "execution_count": 24, "id": "c103a24a-c975-4e11-b2ee-a52bdc8a9838", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 25, "id": "e406986e-a959-469e-926a-a6854f61f095", "metadata": {}, "outputs": [], "source": [ "f = lambda n: float(sum([(1+k/n)**2*ln(1+k/n) for k in range(1,n)])/n)" ] }, { "cell_type": "code", "execution_count": 26, "id": "9cce8b1b-b7da-4c09-b753-3f6574ffabc9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5 loops, best of 3: 819 ms per loop" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timeit('f(10000)')" ] }, { "cell_type": "markdown", "id": "e55ab3db-4d64-490a-8e3f-5431fa2b0fdb", "metadata": {}, "source": [ "The evaluation of `f` is inefficient because all computations happen symbolically, with exact arithmetic. Only at the very end does the conversion to a float happen." ] }, { "cell_type": "code", "execution_count": 27, "id": "f67b9b9c-ed02-4684-ac78-93948854b46d", "metadata": {}, "outputs": [], "source": [ "def vf(n):\n", " \"\"\"\n", " Returns the result of the vectorized version of f.\n", " \"\"\"\n", " from numpy import log, arange, sum\n", " arg = 1 + arange(1, n)/n\n", " return sum(arg**2*ln(arg))/n" ] }, { "cell_type": "markdown", "id": "19e812bb-6ef9-4e40-b74c-466fd1a7ec1d", "metadata": {}, "source": [ "Let us first check the correctness." ] }, { "cell_type": "code", "execution_count": 28, "id": "de8f4abc-df11-4fa6-ae6b-892b987be0d8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0567831983574514" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yf = f(100)\n", "yf" ] }, { "cell_type": "code", "execution_count": 29, "id": "6988492d-3d4e-4e2f-a54c-38b0a6074f2f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0567831983574514" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yvf = vf(100)\n", "yvf" ] }, { "cell_type": "code", "execution_count": 30, "id": "672f04ef-c379-4d74-ae6f-4178b40ccc41", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(yf - yvf)" ] }, { "cell_type": "code", "execution_count": 31, "id": "02eac041-8904-4ff1-aefa-815082e6db05", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "625 loops, best of 3: 55.8 μs per loop" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timeit('vf(10000)')" ] }, { "cell_type": "markdown", "id": "f3cf13f2-38df-4463-b258-4f87e3a23304", "metadata": {}, "source": [ "Observe the drop in magnitudes, from milliseconds to microseconds." ] }, { "cell_type": "markdown", "id": "8d185c24-858b-42e0-84ae-7ba418889d56", "metadata": {}, "source": [ "# Question 7" ] }, { "cell_type": "markdown", "id": "74d5778b-44e9-4b6f-8b78-306b1ea43ab9", "metadata": {}, "source": [ "Consider the rational expression \n", "$\\displaystyle \\frac{u^{1000} - v^{1000}}{u - v}$. \n", "\n", "Explain why it is bad to simplify this expression automatically." ] }, { "cell_type": "markdown", "id": "0551a7a0-23f6-4388-b185-00d8b17fb392", "metadata": {}, "source": [ "## answer to question 7" ] }, { "cell_type": "code", "execution_count": 32, "id": "86cc980c-78ae-4407-b41d-60717744a089", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "markdown", "id": "aa870fe3-66cc-497b-891f-7105d461d403", "metadata": {}, "source": [ "Simplifying the expression leads to expression swell as illustrated below." ] }, { "cell_type": "code", "execution_count": 33, "id": "f6a061a8-506c-47b8-840a-bb3ac541404f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "u^999 + u^998*v + u^997*v^2 + u^996*v^3 + u^995*v^4 + u^994*v^5 + u^993*v^6 + u^992*v^7 + u^991*v^8 + u^990*v^9 + u^989*v^10 + u^988*v^11 + u^987*v^12 + u^986*v^13 + u^985*v^14 + u^984*v^15 + u^983*v^16 + u^982*v^17 + u^981*v^18 + u^980*v^19 + u^979*v^20 + u^978*v^21 + u^977*v^22 + u^976*v^23 + u^975*v^24 + u^974*v^25 + u^973*v^26 + u^972*v^27 + u^971*v^28 + u^970*v^29 + u^969*v^30 + u^968*v^31 + u^967*v^32 + u^966*v^33 + u^965*v^34 + u^964*v^35 + u^963*v^36 + u^962*v^37 + u^961*v^38 + u^960*v^39 + u^959*v^40 + u^958*v^41 + u^957*v^42 + u^956*v^43 + u^955*v^44 + u^954*v^45 + u^953*v^46 + u^952*v^47 + u^951*v^48 + u^950*v^49 + u^949*v^50 + u^948*v^51 + u^947*v^52 + u^946*v^53 + u^945*v^54 + u^944*v^55 + u^943*v^56 + u^942*v^57 + u^941*v^58 + u^940*v^59 + u^939*v^60 + u^938*v^61 + u^937*v^62 + u^936*v^63 + u^935*v^64 + u^934*v^65 + u^933*v^66 + u^932*v^67 + u^931*v^68 + u^930*v^69 + u^929*v^70 + u^928*v^71 + u^927*v^72 + u^926*v^73 + u^925*v^74 + u^924*v^75 + u^923*v^76 + u^922*v^77 + u^921*v^78 + u^920*v^79 + u^919*v^80 + u^918*v^81 + u^917*v^82 + u^916*v^83 + u^915*v^84 + u^914*v^85 + u^913*v^86 + u^912*v^87 + u^911*v^88 + u^910*v^89 + u^909*v^90 + u^908*v^91 + u^907*v^92 + u^906*v^93 + u^905*v^94 + u^904*v^95 + u^903*v^96 + u^902*v^97 + u^901*v^98 + u^900*v^99 + u^899*v^100 + u^898*v^101 + u^897*v^102 + u^896*v^103 + u^895*v^104 + u^894*v^105 + u^893*v^106 + u^892*v^107 + u^891*v^108 + u^890*v^109 + u^889*v^110 + u^888*v^111 + u^887*v^112 + u^886*v^113 + u^885*v^114 + u^884*v^115 + u^883*v^116 + u^882*v^117 + u^881*v^118 + u^880*v^119 + u^879*v^120 + u^878*v^121 + u^877*v^122 + u^876*v^123 + u^875*v^124 + u^874*v^125 + u^873*v^126 + u^872*v^127 + u^871*v^128 + u^870*v^129 + u^869*v^130 + u^868*v^131 + u^867*v^132 + u^866*v^133 + u^865*v^134 + u^864*v^135 + u^863*v^136 + u^862*v^137 + u^861*v^138 + u^860*v^139 + u^859*v^140 + u^858*v^141 + u^857*v^142 + u^856*v^143 + u^855*v^144 + u^854*v^145 + u^853*v^146 + u^852*v^147 + u^851*v^148 + u^850*v^149 + u^849*v^150 + u^848*v^151 + u^847*v^152 + u^846*v^153 + u^845*v^154 + u^844*v^155 + u^843*v^156 + u^842*v^157 + u^841*v^158 + u^840*v^159 + u^839*v^160 + u^838*v^161 + u^837*v^162 + u^836*v^163 + u^835*v^164 + u^834*v^165 + u^833*v^166 + u^832*v^167 + u^831*v^168 + u^830*v^169 + u^829*v^170 + u^828*v^171 + u^827*v^172 + u^826*v^173 + u^825*v^174 + u^824*v^175 + u^823*v^176 + u^822*v^177 + u^821*v^178 + u^820*v^179 + u^819*v^180 + u^818*v^181 + u^817*v^182 + u^816*v^183 + u^815*v^184 + u^814*v^185 + u^813*v^186 + u^812*v^187 + u^811*v^188 + u^810*v^189 + u^809*v^190 + u^808*v^191 + u^807*v^192 + u^806*v^193 + u^805*v^194 + u^804*v^195 + u^803*v^196 + u^802*v^197 + u^801*v^198 + u^800*v^199 + u^799*v^200 + u^798*v^201 + u^797*v^202 + u^796*v^203 + u^795*v^204 + u^794*v^205 + u^793*v^206 + u^792*v^207 + u^791*v^208 + u^790*v^209 + u^789*v^210 + u^788*v^211 + u^787*v^212 + u^786*v^213 + u^785*v^214 + u^784*v^215 + u^783*v^216 + u^782*v^217 + u^781*v^218 + u^780*v^219 + u^779*v^220 + u^778*v^221 + u^777*v^222 + u^776*v^223 + u^775*v^224 + u^774*v^225 + u^773*v^226 + u^772*v^227 + u^771*v^228 + u^770*v^229 + u^769*v^230 + u^768*v^231 + u^767*v^232 + u^766*v^233 + u^765*v^234 + u^764*v^235 + u^763*v^236 + u^762*v^237 + u^761*v^238 + u^760*v^239 + u^759*v^240 + u^758*v^241 + u^757*v^242 + u^756*v^243 + u^755*v^244 + u^754*v^245 + u^753*v^246 + u^752*v^247 + u^751*v^248 + u^750*v^249 + u^749*v^250 + u^748*v^251 + u^747*v^252 + u^746*v^253 + u^745*v^254 + u^744*v^255 + u^743*v^256 + u^742*v^257 + u^741*v^258 + u^740*v^259 + u^739*v^260 + u^738*v^261 + u^737*v^262 + u^736*v^263 + u^735*v^264 + u^734*v^265 + u^733*v^266 + u^732*v^267 + u^731*v^268 + u^730*v^269 + u^729*v^270 + u^728*v^271 + u^727*v^272 + u^726*v^273 + u^725*v^274 + u^724*v^275 + u^723*v^276 + u^722*v^277 + u^721*v^278 + u^720*v^279 + u^719*v^280 + u^718*v^281 + u^717*v^282 + u^716*v^283 + u^715*v^284 + u^714*v^285 + u^713*v^286 + u^712*v^287 + u^711*v^288 + u^710*v^289 + u^709*v^290 + u^708*v^291 + u^707*v^292 + u^706*v^293 + u^705*v^294 + u^704*v^295 + u^703*v^296 + u^702*v^297 + u^701*v^298 + u^700*v^299 + u^699*v^300 + u^698*v^301 + u^697*v^302 + u^696*v^303 + u^695*v^304 + u^694*v^305 + u^693*v^306 + u^692*v^307 + u^691*v^308 + u^690*v^309 + u^689*v^310 + u^688*v^311 + u^687*v^312 + u^686*v^313 + u^685*v^314 + u^684*v^315 + u^683*v^316 + u^682*v^317 + u^681*v^318 + u^680*v^319 + u^679*v^320 + u^678*v^321 + u^677*v^322 + u^676*v^323 + u^675*v^324 + u^674*v^325 + u^673*v^326 + u^672*v^327 + u^671*v^328 + u^670*v^329 + u^669*v^330 + u^668*v^331 + u^667*v^332 + u^666*v^333 + u^665*v^334 + u^664*v^335 + u^663*v^336 + u^662*v^337 + u^661*v^338 + u^660*v^339 + u^659*v^340 + u^658*v^341 + u^657*v^342 + u^656*v^343 + u^655*v^344 + u^654*v^345 + u^653*v^346 + u^652*v^347 + u^651*v^348 + u^650*v^349 + u^649*v^350 + u^648*v^351 + u^647*v^352 + u^646*v^353 + u^645*v^354 + u^644*v^355 + u^643*v^356 + u^642*v^357 + u^641*v^358 + u^640*v^359 + u^639*v^360 + u^638*v^361 + u^637*v^362 + u^636*v^363 + u^635*v^364 + u^634*v^365 + u^633*v^366 + u^632*v^367 + u^631*v^368 + u^630*v^369 + u^629*v^370 + u^628*v^371 + u^627*v^372 + u^626*v^373 + u^625*v^374 + u^624*v^375 + u^623*v^376 + u^622*v^377 + u^621*v^378 + u^620*v^379 + u^619*v^380 + u^618*v^381 + u^617*v^382 + u^616*v^383 + u^615*v^384 + u^614*v^385 + u^613*v^386 + u^612*v^387 + u^611*v^388 + u^610*v^389 + u^609*v^390 + u^608*v^391 + u^607*v^392 + u^606*v^393 + u^605*v^394 + u^604*v^395 + u^603*v^396 + u^602*v^397 + u^601*v^398 + u^600*v^399 + u^599*v^400 + u^598*v^401 + u^597*v^402 + u^596*v^403 + u^595*v^404 + u^594*v^405 + u^593*v^406 + u^592*v^407 + u^591*v^408 + u^590*v^409 + u^589*v^410 + u^588*v^411 + u^587*v^412 + u^586*v^413 + u^585*v^414 + u^584*v^415 + u^583*v^416 + u^582*v^417 + u^581*v^418 + u^580*v^419 + u^579*v^420 + u^578*v^421 + u^577*v^422 + u^576*v^423 + u^575*v^424 + u^574*v^425 + u^573*v^426 + u^572*v^427 + u^571*v^428 + u^570*v^429 + u^569*v^430 + u^568*v^431 + u^567*v^432 + u^566*v^433 + u^565*v^434 + u^564*v^435 + u^563*v^436 + u^562*v^437 + u^561*v^438 + u^560*v^439 + u^559*v^440 + u^558*v^441 + u^557*v^442 + u^556*v^443 + u^555*v^444 + u^554*v^445 + u^553*v^446 + u^552*v^447 + u^551*v^448 + u^550*v^449 + u^549*v^450 + u^548*v^451 + u^547*v^452 + u^546*v^453 + u^545*v^454 + u^544*v^455 + u^543*v^456 + u^542*v^457 + u^541*v^458 + u^540*v^459 + u^539*v^460 + u^538*v^461 + u^537*v^462 + u^536*v^463 + u^535*v^464 + u^534*v^465 + u^533*v^466 + u^532*v^467 + u^531*v^468 + u^530*v^469 + u^529*v^470 + u^528*v^471 + u^527*v^472 + u^526*v^473 + u^525*v^474 + u^524*v^475 + u^523*v^476 + u^522*v^477 + u^521*v^478 + u^520*v^479 + u^519*v^480 + u^518*v^481 + u^517*v^482 + u^516*v^483 + u^515*v^484 + u^514*v^485 + u^513*v^486 + u^512*v^487 + u^511*v^488 + u^510*v^489 + u^509*v^490 + u^508*v^491 + u^507*v^492 + u^506*v^493 + u^505*v^494 + u^504*v^495 + u^503*v^496 + u^502*v^497 + u^501*v^498 + u^500*v^499 + u^499*v^500 + u^498*v^501 + u^497*v^502 + u^496*v^503 + u^495*v^504 + u^494*v^505 + u^493*v^506 + u^492*v^507 + u^491*v^508 + u^490*v^509 + u^489*v^510 + u^488*v^511 + u^487*v^512 + u^486*v^513 + u^485*v^514 + u^484*v^515 + u^483*v^516 + u^482*v^517 + u^481*v^518 + u^480*v^519 + u^479*v^520 + u^478*v^521 + u^477*v^522 + u^476*v^523 + u^475*v^524 + u^474*v^525 + u^473*v^526 + u^472*v^527 + u^471*v^528 + u^470*v^529 + u^469*v^530 + u^468*v^531 + u^467*v^532 + u^466*v^533 + u^465*v^534 + u^464*v^535 + u^463*v^536 + u^462*v^537 + u^461*v^538 + u^460*v^539 + u^459*v^540 + u^458*v^541 + u^457*v^542 + u^456*v^543 + u^455*v^544 + u^454*v^545 + u^453*v^546 + u^452*v^547 + u^451*v^548 + u^450*v^549 + u^449*v^550 + u^448*v^551 + u^447*v^552 + u^446*v^553 + u^445*v^554 + u^444*v^555 + u^443*v^556 + u^442*v^557 + u^441*v^558 + u^440*v^559 + u^439*v^560 + u^438*v^561 + u^437*v^562 + u^436*v^563 + u^435*v^564 + u^434*v^565 + u^433*v^566 + u^432*v^567 + u^431*v^568 + u^430*v^569 + u^429*v^570 + u^428*v^571 + u^427*v^572 + u^426*v^573 + u^425*v^574 + u^424*v^575 + u^423*v^576 + u^422*v^577 + u^421*v^578 + u^420*v^579 + u^419*v^580 + u^418*v^581 + u^417*v^582 + u^416*v^583 + u^415*v^584 + u^414*v^585 + u^413*v^586 + u^412*v^587 + u^411*v^588 + u^410*v^589 + u^409*v^590 + u^408*v^591 + u^407*v^592 + u^406*v^593 + u^405*v^594 + u^404*v^595 + u^403*v^596 + u^402*v^597 + u^401*v^598 + u^400*v^599 + u^399*v^600 + u^398*v^601 + u^397*v^602 + u^396*v^603 + u^395*v^604 + u^394*v^605 + u^393*v^606 + u^392*v^607 + u^391*v^608 + u^390*v^609 + u^389*v^610 + u^388*v^611 + u^387*v^612 + u^386*v^613 + u^385*v^614 + u^384*v^615 + u^383*v^616 + u^382*v^617 + u^381*v^618 + u^380*v^619 + u^379*v^620 + u^378*v^621 + u^377*v^622 + u^376*v^623 + u^375*v^624 + u^374*v^625 + u^373*v^626 + u^372*v^627 + u^371*v^628 + u^370*v^629 + u^369*v^630 + u^368*v^631 + u^367*v^632 + u^366*v^633 + u^365*v^634 + u^364*v^635 + u^363*v^636 + u^362*v^637 + u^361*v^638 + u^360*v^639 + u^359*v^640 + u^358*v^641 + u^357*v^642 + u^356*v^643 + u^355*v^644 + u^354*v^645 + u^353*v^646 + u^352*v^647 + u^351*v^648 + u^350*v^649 + u^349*v^650 + u^348*v^651 + u^347*v^652 + u^346*v^653 + u^345*v^654 + u^344*v^655 + u^343*v^656 + u^342*v^657 + u^341*v^658 + u^340*v^659 + u^339*v^660 + u^338*v^661 + u^337*v^662 + u^336*v^663 + u^335*v^664 + u^334*v^665 + u^333*v^666 + u^332*v^667 + u^331*v^668 + u^330*v^669 + u^329*v^670 + u^328*v^671 + u^327*v^672 + u^326*v^673 + u^325*v^674 + u^324*v^675 + u^323*v^676 + u^322*v^677 + u^321*v^678 + u^320*v^679 + u^319*v^680 + u^318*v^681 + u^317*v^682 + u^316*v^683 + u^315*v^684 + u^314*v^685 + u^313*v^686 + u^312*v^687 + u^311*v^688 + u^310*v^689 + u^309*v^690 + u^308*v^691 + u^307*v^692 + u^306*v^693 + u^305*v^694 + u^304*v^695 + u^303*v^696 + u^302*v^697 + u^301*v^698 + u^300*v^699 + u^299*v^700 + u^298*v^701 + u^297*v^702 + u^296*v^703 + u^295*v^704 + u^294*v^705 + u^293*v^706 + u^292*v^707 + u^291*v^708 + u^290*v^709 + u^289*v^710 + u^288*v^711 + u^287*v^712 + u^286*v^713 + u^285*v^714 + u^284*v^715 + u^283*v^716 + u^282*v^717 + u^281*v^718 + u^280*v^719 + u^279*v^720 + u^278*v^721 + u^277*v^722 + u^276*v^723 + u^275*v^724 + u^274*v^725 + u^273*v^726 + u^272*v^727 + u^271*v^728 + u^270*v^729 + u^269*v^730 + u^268*v^731 + u^267*v^732 + u^266*v^733 + u^265*v^734 + u^264*v^735 + u^263*v^736 + u^262*v^737 + u^261*v^738 + u^260*v^739 + u^259*v^740 + u^258*v^741 + u^257*v^742 + u^256*v^743 + u^255*v^744 + u^254*v^745 + u^253*v^746 + u^252*v^747 + u^251*v^748 + u^250*v^749 + u^249*v^750 + u^248*v^751 + u^247*v^752 + u^246*v^753 + u^245*v^754 + u^244*v^755 + u^243*v^756 + u^242*v^757 + u^241*v^758 + u^240*v^759 + u^239*v^760 + u^238*v^761 + u^237*v^762 + u^236*v^763 + u^235*v^764 + u^234*v^765 + u^233*v^766 + u^232*v^767 + u^231*v^768 + u^230*v^769 + u^229*v^770 + u^228*v^771 + u^227*v^772 + u^226*v^773 + u^225*v^774 + u^224*v^775 + u^223*v^776 + u^222*v^777 + u^221*v^778 + u^220*v^779 + u^219*v^780 + u^218*v^781 + u^217*v^782 + u^216*v^783 + u^215*v^784 + u^214*v^785 + u^213*v^786 + u^212*v^787 + u^211*v^788 + u^210*v^789 + u^209*v^790 + u^208*v^791 + u^207*v^792 + u^206*v^793 + u^205*v^794 + u^204*v^795 + u^203*v^796 + u^202*v^797 + u^201*v^798 + u^200*v^799 + u^199*v^800 + u^198*v^801 + u^197*v^802 + u^196*v^803 + u^195*v^804 + u^194*v^805 + u^193*v^806 + u^192*v^807 + u^191*v^808 + u^190*v^809 + u^189*v^810 + u^188*v^811 + u^187*v^812 + u^186*v^813 + u^185*v^814 + u^184*v^815 + u^183*v^816 + u^182*v^817 + u^181*v^818 + u^180*v^819 + u^179*v^820 + u^178*v^821 + u^177*v^822 + u^176*v^823 + u^175*v^824 + u^174*v^825 + u^173*v^826 + u^172*v^827 + u^171*v^828 + u^170*v^829 + u^169*v^830 + u^168*v^831 + u^167*v^832 + u^166*v^833 + u^165*v^834 + u^164*v^835 + u^163*v^836 + u^162*v^837 + u^161*v^838 + u^160*v^839 + u^159*v^840 + u^158*v^841 + u^157*v^842 + u^156*v^843 + u^155*v^844 + u^154*v^845 + u^153*v^846 + u^152*v^847 + u^151*v^848 + u^150*v^849 + u^149*v^850 + u^148*v^851 + u^147*v^852 + u^146*v^853 + u^145*v^854 + u^144*v^855 + u^143*v^856 + u^142*v^857 + u^141*v^858 + u^140*v^859 + u^139*v^860 + u^138*v^861 + u^137*v^862 + u^136*v^863 + u^135*v^864 + u^134*v^865 + u^133*v^866 + u^132*v^867 + u^131*v^868 + u^130*v^869 + u^129*v^870 + u^128*v^871 + u^127*v^872 + u^126*v^873 + u^125*v^874 + u^124*v^875 + u^123*v^876 + u^122*v^877 + u^121*v^878 + u^120*v^879 + u^119*v^880 + u^118*v^881 + u^117*v^882 + u^116*v^883 + u^115*v^884 + u^114*v^885 + u^113*v^886 + u^112*v^887 + u^111*v^888 + u^110*v^889 + u^109*v^890 + u^108*v^891 + u^107*v^892 + u^106*v^893 + u^105*v^894 + u^104*v^895 + u^103*v^896 + u^102*v^897 + u^101*v^898 + u^100*v^899 + u^99*v^900 + u^98*v^901 + u^97*v^902 + u^96*v^903 + u^95*v^904 + u^94*v^905 + u^93*v^906 + u^92*v^907 + u^91*v^908 + u^90*v^909 + u^89*v^910 + u^88*v^911 + u^87*v^912 + u^86*v^913 + u^85*v^914 + u^84*v^915 + u^83*v^916 + u^82*v^917 + u^81*v^918 + u^80*v^919 + u^79*v^920 + u^78*v^921 + u^77*v^922 + u^76*v^923 + u^75*v^924 + u^74*v^925 + u^73*v^926 + u^72*v^927 + u^71*v^928 + u^70*v^929 + u^69*v^930 + u^68*v^931 + u^67*v^932 + u^66*v^933 + u^65*v^934 + u^64*v^935 + u^63*v^936 + u^62*v^937 + u^61*v^938 + u^60*v^939 + u^59*v^940 + u^58*v^941 + u^57*v^942 + u^56*v^943 + u^55*v^944 + u^54*v^945 + u^53*v^946 + u^52*v^947 + u^51*v^948 + u^50*v^949 + u^49*v^950 + u^48*v^951 + u^47*v^952 + u^46*v^953 + u^45*v^954 + u^44*v^955 + u^43*v^956 + u^42*v^957 + u^41*v^958 + u^40*v^959 + u^39*v^960 + u^38*v^961 + u^37*v^962 + u^36*v^963 + u^35*v^964 + u^34*v^965 + u^33*v^966 + u^32*v^967 + u^31*v^968 + u^30*v^969 + u^29*v^970 + u^28*v^971 + u^27*v^972 + u^26*v^973 + u^25*v^974 + u^24*v^975 + u^23*v^976 + u^22*v^977 + u^21*v^978 + u^20*v^979 + u^19*v^980 + u^18*v^981 + u^17*v^982 + u^16*v^983 + u^15*v^984 + u^14*v^985 + u^13*v^986 + u^12*v^987 + u^11*v^988 + u^10*v^989 + u^9*v^990 + u^8*v^991 + u^7*v^992 + u^6*v^993 + u^5*v^994 + u^4*v^995 + u^3*v^996 + u^2*v^997 + u*v^998 + v^999" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u, v = var('u, v')\n", "q = (u^1000 - v^1000)/(u-v)\n", "q.numerator(normalize=True)" ] }, { "cell_type": "markdown", "id": "5b7c67c2-9e1d-423d-b68c-9c14e236a514", "metadata": {}, "source": [ "Observe that we started in `q` with four terms. The division of the common factor `u - v` leads to an expression with 1000 terms." ] }, { "cell_type": "markdown", "id": "4861d1b0-ed55-4d80-bc0b-a4a9d3fd4370", "metadata": {}, "source": [ "# Question 8" ] }, { "cell_type": "markdown", "id": "987503b6-e566-41bb-9760-5fbe3c155b61", "metadata": {}, "source": [ "Transform\n", "$q = \\displaystyle (x-y)^2 + \\frac{(x+y)^7}{(x-y)^2}$\n", "into $\\displaystyle r = \\frac{(x-y)^4 + (x+y)^7}{(x-y)^2}$,\n", "without typing $r$." ] }, { "cell_type": "markdown", "id": "b9ea7ddb-6f13-4646-9d14-77f89dc5beee", "metadata": {}, "source": [ "## answer to question 8" ] }, { "cell_type": "code", "execution_count": 34, "id": "90e65fbc-3bdc-428a-ba06-531a57c7272a", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 35, "id": "a77872ae-24d4-49fe-a0ad-7c2e1ad19af6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{{\\left(x + y\\right)}^{7}}{{\\left(x - y\\right)}^{2}} + {\\left(x - y\\right)}^{2}\\)" ], "text/latex": [ "$\\displaystyle \\frac{{\\left(x + y\\right)}^{7}}{{\\left(x - y\\right)}^{2}} + {\\left(x - y\\right)}^{2}$" ], "text/plain": [ "(x + y)^7/(x - y)^2 + (x - y)^2" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x, y = var('x, y')\n", "q = (x - y)^2 + (x + y)^7/(x - y)^2\n", "show(q)" ] }, { "cell_type": "code", "execution_count": 36, "id": "167c1097-5714-4fe7-94c1-04a19f8cf01b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{v^{7}}{u^{2}} + u^{2}\\)" ], "text/latex": [ "$\\displaystyle \\frac{v^{7}}{u^{2}} + u^{2}$" ], "text/plain": [ "v^7/u^2 + u^2" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "u, v = var('u, v')\n", "quv = q.subs({x - y: u, x + y: v})\n", "show(quv)" ] }, { "cell_type": "code", "execution_count": 37, "id": "ca4c0ee4-d6af-49ad-8505-870545b4f9e9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{v^{7} + u^{4}}{u^{2}}\\)" ], "text/latex": [ "$\\displaystyle \\frac{v^{7} + u^{4}}{u^{2}}$" ], "text/plain": [ "(v^7 + u^4)/u^2" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "equv = quv.factor()\n", "show(equv)" ] }, { "cell_type": "code", "execution_count": 38, "id": "d434f737-c378-41f3-bf53-9837bc52e3f6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{{\\left(x + y\\right)}^{7} + {\\left(x - y\\right)}^{4}}{{\\left(x - y\\right)}^{2}}\\)" ], "text/latex": [ "$\\displaystyle \\frac{{\\left(x + y\\right)}^{7} + {\\left(x - y\\right)}^{4}}{{\\left(x - y\\right)}^{2}}$" ], "text/plain": [ "((x + y)^7 + (x - y)^4)/(x - y)^2" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result = equv(u = x-y, v = x+y)\n", "show(result)" ] }, { "cell_type": "markdown", "id": "1c2990b6-d622-480b-9714-7d25de67d68b", "metadata": {}, "source": [ "# Question 9" ] }, { "cell_type": "markdown", "id": "65238de0-a5fc-459b-b129-51cc74e356b5", "metadata": {}, "source": [ "Are the expressions $\\displaystyle p = \\frac{x^2 - 6 x + 9}{x - 3}$\n", "and $q = x - 3$ the same?\n", "\n", "Justify your answer by appropriate *symbolic* computations.\n", "\n", "Demonstrate the application of a *numerical* \n", "probability-one equality test." ] }, { "cell_type": "markdown", "id": "e87214d3-cbc7-4245-9638-f8cc4a57766f", "metadata": {}, "source": [ "## answer to question 9" ] }, { "cell_type": "code", "execution_count": 39, "id": "ab8ab7d3-f4f3-496b-91f5-534bb0a98453", "metadata": {}, "outputs": [], "source": [ "reset()" ] }, { "cell_type": "code", "execution_count": 40, "id": "28d44217-945d-4bb6-a064-1aa6e2da474c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\frac{x^{2} - 6 \\, x + 9}{x - 3}\\)" ], "text/latex": [ "$\\displaystyle \\frac{x^{2} - 6 \\, x + 9}{x - 3}$" ], "text/plain": [ "(x^2 - 6*x + 9)/(x - 3)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "p = (x^2 - 6*x + 9)/(x- 3)\n", "show(p)" ] }, { "cell_type": "code", "execution_count": 41, "id": "25fd93ab-2e9e-492f-9799-4690c2fdfc3c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle x - 3\\)" ], "text/latex": [ "$\\displaystyle x - 3$" ], "text/plain": [ "x - 3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "q = x - 3\n", "show(q)" ] }, { "cell_type": "markdown", "id": "46f716dc-18f9-4f33-bb23-0b84ee9ef0b2", "metadata": {}, "source": [ "For the symbolic test on equality we normalize `q`." ] }, { "cell_type": "code", "execution_count": 42, "id": "0305563d-f046-45bf-ab06-985f05779bbd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "x - 3" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.numerator(normalize=True)/p.denominator(normalize=True)" ] }, { "cell_type": "markdown", "id": "c0337cb0-09e1-431a-85e3-cafd904e43ad", "metadata": {}, "source": [ "After the normalization, we see that `p` equals `q`." ] }, { "cell_type": "markdown", "id": "3a446524-2089-4a72-9e3e-a3a349db143b", "metadata": {}, "source": [ "For the numerical test, we generate a random number and compare the evaluation of `p` with `q`." ] }, { "cell_type": "code", "execution_count": 43, "id": "228a8d5e-bb26-46ef-8ef0-bb957cbd876a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.129446383773113" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rx = RR.random_element()\n", "rx" ] }, { "cell_type": "code", "execution_count": 44, "id": "c30c31b1-4ccd-4460-8960-e206a317a7d4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2.87055361622689" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vp = p(x = rx)\n", "vp" ] }, { "cell_type": "code", "execution_count": 45, "id": "1e51d989-3a48-4e9d-889d-0ec69f75e25c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2.87055361622689" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vq = q(x = rx)\n", "vq" ] }, { "cell_type": "code", "execution_count": 46, "id": "5076bd39-8512-47ea-9e74-3c974a3c6afc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.000000000000000" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(vp - vq)" ] }, { "cell_type": "markdown", "id": "df0b5ca0-b4f8-4659-a737-8678d99d1457", "metadata": {}, "source": [ "The difference between the two values shows that numerically, both expressions `p` and `q` are the same." ] } ], "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 }