NTT-learning/notebooks/foundations/01_convolution_to_toy_ntt/lab.ipynb

130 lines
4.9 KiB
Text

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "meta",
"difficulty": 1,
"kind": "orientation",
"title": "Lab Goals"
}
},
"source": "## META | difficulty 1 | Lab Goals\n\nThis lab asks for prediction before execution.\n\nThe learner should pause and name the expected pairings and sign changes before reading the output.\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, predict which coefficients will collide when the raw convolution is folded into `x^4 + 1`.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 2,
"kind": "exercise",
"title": "Work Two Multiplication Examples"
}
},
"outputs": [],
"source": "# MANDATORY | difficulty 2 | Work Two Multiplication Examples\n\nfrom ntt_learning.toy_ntt import negacyclic_multiply, schoolbook_convolution\n\nsamples = [\n ([1, 2, 0, 0], [3, 4, 0, 0]),\n ([5, 0, 1, 2], [2, 1, 0, 1]),\n]\n\nfor left, right in samples:\n print(\"left:\", left, \"right:\", right)\n print(\" convolution:\", schoolbook_convolution(left, right))\n print(\" negacyclic:\", negacyclic_multiply(left, right, n=4))\n"
},
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 3,
"kind": "exercise",
"title": "Exercise 2"
}
},
"source": "## MANDATORY | difficulty 3 | Exercise 2\n\nPredict the pairings for a single Cooley-Tukey stage on eight values with block size four.\nName the index pairs before running the cell.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 3,
"kind": "exercise",
"title": "Trace One Butterfly Layer"
}
},
"outputs": [],
"source": "# MANDATORY | difficulty 3 | Trace One Butterfly Layer\n\nfrom ntt_learning.toy_ntt import action_rows, apply_ct_stage\n\nvalues = [0, 1, 2, 3, 4, 5, 6, 7]\nstage_output, stage_actions = apply_ct_stage(\n values,\n block_size=4,\n zetas=[1, 4, 1, 4],\n modulus=17,\n)\n\nprint(\"stage output:\", stage_output)\nfor row in action_rows(stage_actions):\n print(row)\n"
},
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 2,
"kind": "reflection",
"title": "Reflection"
}
},
"source": "## MANDATORY | difficulty 2 | Reflection\n\nReflection prompt:\n\n- Which part of the stage felt mechanical and local?\n- Which part still feels global or mysterious?\n- If one zeta is wrong, what kind of output difference would you expect to see?\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "facultative",
"difficulty": 4,
"kind": "exploration",
"title": "Optional Inverse-Style Stage"
}
},
"outputs": [],
"source": "# FACULTATIVE | difficulty 4 | Optional Inverse-Style Stage\n\nfrom ntt_learning.toy_ntt import action_rows, apply_gs_stage\n\nvalues = [5, 1, 9, 3, 7, 2, 6, 4]\nstage_output, stage_actions = apply_gs_stage(\n values,\n block_size=4,\n zetas=[1, 4, 1, 4],\n modulus=17,\n)\n\nprint(\"stage output:\", stage_output)\nfor row in action_rows(stage_actions):\n print(row)\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.1",
"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"
]
}
},
"nbformat": 4,
"nbformat_minor": 5
}