{ "cells": [ { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "orientation", "title": "Lab Goals" } }, "source": "## META | difficulty 1 | Lab Goals\n\nPredict the movement before you run the code.\n\nThe point is not just to see the picture after the fact.\nThe point is to force your eye to anticipate where the products and wraparound terms will land.\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "exercise", "title": "Exercise 1" } }, "source": "## MANDATORY | difficulty 2 | Exercise 1\n\nBefore running the next cell:\n\n- name the diagonal sums of the raw schoolbook grid\n- say which tail terms will wrap into slot `0`\n- say whether they add or subtract in `x^4 + 1`\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "exercise", "title": "Run The Prediction Check" } }, "outputs": [], "source": "# MANDATORY | difficulty 2 | Run The Prediction Check\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import negacyclic_multiply, schoolbook_convolution\nfrom ntt_learning.visuals import plot_convolution_grid, plot_wraparound\n\nleft = [3, 0, 2, 1]\nright = [1, 4, 0, 2]\nraw = schoolbook_convolution(left, right)\n\nprint(\"raw convolution:\", raw)\nprint(\"negacyclic result:\", negacyclic_multiply(left, right, n=4))\ndisplay(plot_convolution_grid(left, right, title=\"Prediction check grid\"))\ndisplay(plot_wraparound(raw, n=4, negacyclic=True, title=\"Prediction check fold\"))\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "exercise", "title": "Exercise 2" } }, "source": "## MANDATORY | difficulty 2 | Exercise 2\n\nPick one number in the raw tail and follow it all the way to its final slot.\nDo not say \u201cit wraps around\u201d.\nSay exactly:\n\n- where it started\n- how many wraps happened\n- whether the sign flipped\n- where it finished\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "exercise", "title": "A Second Visual Drill" } }, "outputs": [], "source": "# MANDATORY | difficulty 2 | A Second Visual Drill\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import schoolbook_convolution\nfrom ntt_learning.visuals import plot_wraparound\n\nraw = schoolbook_convolution([2, 5, 0, 1], [1, 0, 3, 2])\nprint(\"raw convolution:\", raw)\ndisplay(plot_wraparound(raw, n=4, negacyclic=True, title=\"Trace one tail coefficient by eye\"))\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "reflection", "title": "Reflection" } }, "source": "## MANDATORY | difficulty 2 | Reflection\n\nReflection prompt:\n\n- What felt easier to see in the grid than in symbolic polynomial notation?\n- What exactly makes negacyclic folding more annoying than ordinary wraparound?\n- If you had to explain `x^n + 1` to somebody visually, what would you draw?\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "facultative", "difficulty": 4, "kind": "exploration", "title": "Optional: Try Your Own Arrays" } }, "outputs": [], "source": "# FACULTATIVE | difficulty 4 | Optional: Try Your Own Arrays\n\nimport ipywidgets as widgets\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import schoolbook_convolution\nfrom ntt_learning.visuals import plot_convolution_grid, plot_wraparound\n\ndef preview(a0=1, a1=2, a2=3, a3=4, b0=5, b1=6, b2=7, b3=8):\n left = [a0, a1, a2, a3]\n right = [b0, b1, b2, b3]\n raw = schoolbook_convolution(left, right)\n display(plot_convolution_grid(left, right, title=\"Interactive schoolbook grid\"))\n display(plot_wraparound(raw, n=4, negacyclic=True, title=\"Interactive negacyclic fold\"))\n\ndisplay(\n widgets.interact(\n preview,\n a0=(0, 6),\n a1=(0, 6),\n a2=(0, 6),\n a3=(0, 6),\n b0=(0, 6),\n b1=(0, 6),\n b2=(0, 6),\n b3=(0, 6),\n )\n)\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "handoff", "title": "Next Notebook" } }, "source": "## META | difficulty 1 | Next Notebook\n\nNext notebook: `problems.ipynb`\n" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" }, "ntt_learning": { "title": "Lab: Convolution To Toy NTT", "contract_version": "0.2", "sequence": [ "notebooks/START_HERE.ipynb", "notebooks/COURSE_BLUEPRINT.ipynb", "notebooks/foundations/01_convolution_to_toy_ntt/lecture.ipynb", "notebooks/foundations/01_convolution_to_toy_ntt/lab.ipynb", "notebooks/foundations/01_convolution_to_toy_ntt/problems.ipynb", "notebooks/foundations/01_convolution_to_toy_ntt/studio.ipynb", "notebooks/foundations/02_negative_wrapped_ntt/lecture.ipynb", "notebooks/foundations/02_negative_wrapped_ntt/lab.ipynb", "notebooks/foundations/02_negative_wrapped_ntt/problems.ipynb", "notebooks/foundations/02_negative_wrapped_ntt/studio.ipynb", "notebooks/butterfly_mechanics/03_fast_forward_ct/lecture.ipynb", "notebooks/butterfly_mechanics/03_fast_forward_ct/lab.ipynb", "notebooks/butterfly_mechanics/03_fast_forward_ct/problems.ipynb", "notebooks/butterfly_mechanics/03_fast_forward_ct/studio.ipynb", "notebooks/butterfly_mechanics/04_fast_inverse_gs/lecture.ipynb", "notebooks/butterfly_mechanics/04_fast_inverse_gs/lab.ipynb", "notebooks/butterfly_mechanics/04_fast_inverse_gs/problems.ipynb", "notebooks/butterfly_mechanics/04_fast_inverse_gs/studio.ipynb", "notebooks/kyber_mapping/05_kyber_ntt_and_base_multiplication/lecture.ipynb", "notebooks/kyber_mapping/05_kyber_ntt_and_base_multiplication/lab.ipynb", "notebooks/kyber_mapping/05_kyber_ntt_and_base_multiplication/problems.ipynb", "notebooks/kyber_mapping/05_kyber_ntt_and_base_multiplication/studio.ipynb", "notebooks/professional/06_debugging_ntt_failures/lecture.ipynb", "notebooks/professional/06_debugging_ntt_failures/lab.ipynb", "notebooks/professional/06_debugging_ntt_failures/problems.ipynb", "notebooks/professional/06_debugging_ntt_failures/studio.ipynb", "notebooks/COURSE_COMPLETE.ipynb" ] } }, "nbformat": 4, "nbformat_minor": 5 }