{ "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": "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": "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": "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": "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": "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": "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": "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": "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." ] } ], "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 }