mirror of
https://github.com/saymrwulf/NTT-learning.git
synced 2026-09-07 19:40:49 +00:00
187 lines
16 KiB
Text
187 lines
16 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "theme",
|
|
"title": "Notebook Theme"
|
|
}
|
|
},
|
|
"source": "<style>\n.jp-RenderedHTMLCommon .ntt-cell-head {\n position: relative;\n margin: 0 0 0.8rem 0;\n padding: 0.95rem 1rem 1rem 1rem;\n border-radius: 16px;\n border: 1px solid rgba(16,42,67,0.12);\n box-shadow: 0 8px 24px rgba(16,42,67,0.06);\n font-family: \"Avenir Next\", \"Trebuchet MS\", sans-serif;\n}\n\n.jp-RenderedHTMLCommon .ntt-cell-topline {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5rem;\n align-items: center;\n margin-bottom: 0.55rem;\n}\n\n.jp-RenderedHTMLCommon .ntt-kind-pill,\n.jp-RenderedHTMLCommon .ntt-route-pill,\n.jp-RenderedHTMLCommon .ntt-difficulty-pill {\n display: inline-flex;\n align-items: center;\n padding: 0.18rem 0.58rem;\n border-radius: 999px;\n font-size: 0.72rem;\n font-weight: 800;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n}\n\n.jp-RenderedHTMLCommon .ntt-role-meta {\n background: linear-gradient(135deg, #e2f3ff 0%, #f5fbff 100%);\n}\n\n.jp-RenderedHTMLCommon .ntt-role-mandatory {\n background: linear-gradient(135deg, #fff1b8 0%, #ffd980 100%);\n}\n\n.jp-RenderedHTMLCommon .ntt-role-facultative {\n background: linear-gradient(135deg, #ffe3d4 0%, #ffc3ae 100%);\n}\n\n.jp-RenderedHTMLCommon .ntt-kind-pill {\n color: #102a43;\n background: rgba(16,42,67,0.08);\n}\n\n.jp-RenderedHTMLCommon .ntt-route-pill {\n color: #102a43;\n background: rgba(255,255,255,0.82);\n}\n\n.jp-RenderedHTMLCommon .ntt-difficulty-pill {\n position: absolute;\n top: 0.95rem;\n right: 1rem;\n color: #102a43;\n background: rgba(255,255,255,0.88);\n border: 1px solid rgba(16,42,67,0.08);\n box-shadow: 0 4px 12px rgba(16,42,67,0.08);\n}\n\n.jp-RenderedHTMLCommon .ntt-cell-title {\n margin: 0;\n font-size: 1.25rem;\n line-height: 1.25;\n font-weight: 850;\n color: #102a43;\n padding-right: 5.3rem;\n}\n\n.jp-RenderedHTMLCommon .ntt-cell-body-hint {\n margin-top: 0.3rem;\n font-size: 0.84rem;\n color: #486581;\n}\n\n.jupyter-widgets.widget-container,\n.jupyter-widgets.widget-box,\n.jupyter-widgets.widget-vbox,\n.jupyter-widgets.widget-hbox {\n width: 100% !important;\n max-width: 100% !important;\n min-width: 0 !important;\n}\n\n.widget-html-content svg {\n display: block !important;\n width: 100% !important;\n max-width: 100% !important;\n height: auto !important;\n}\n</style>\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "route_nav",
|
|
"title": "Route Guardrails"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">route map</span>\n <span class=\"ntt-route-pill\">route help</span>\n </div>\n <h2 class=\"ntt-cell-title\">Route Guardrails</h2>\n</div>\n\nYou are at **step 3 of 27** in the only supported route.\n\nNever choose the next notebook manually from the file tree. Use only the links in this cell and the final handoff cell.\n\n**Immediate navigation**\n- Next notebook: [Foundations / 01 Convolution To Toy NTT / Lab](lab.ipynb)\n- Previous notebook: [Course Blueprint](../../COURSE_BLUEPRINT.ipynb)\n- Restart route: [Start Here](../../START_HERE.ipynb)\n\n**Official route chain**\n1. [Start Here](../../START_HERE.ipynb)\n2. [Course Blueprint](../../COURSE_BLUEPRINT.ipynb)\n3. **Foundations / 01 Convolution To Toy NTT / Lecture** <- you are here\n4. [Foundations / 01 Convolution To Toy NTT / Lab](lab.ipynb)\n5. [Foundations / 01 Convolution To Toy NTT / Problems](problems.ipynb)\n6. [Foundations / 01 Convolution To Toy NTT / Studio](studio.ipynb)\n7. [Foundations / 02 Negative Wrapped NTT / Lecture](../02_negative_wrapped_ntt/lecture.ipynb)\n8. [Foundations / 02 Negative Wrapped NTT / Lab](../02_negative_wrapped_ntt/lab.ipynb)\n9. [Foundations / 02 Negative Wrapped NTT / Problems](../02_negative_wrapped_ntt/problems.ipynb)\n10. [Foundations / 02 Negative Wrapped NTT / Studio](../02_negative_wrapped_ntt/studio.ipynb)\n11. [Butterfly Mechanics / 03 Fast Forward CT / Lecture](../../butterfly_mechanics/03_fast_forward_ct/lecture.ipynb)\n12. [Butterfly Mechanics / 03 Fast Forward CT / Lab](../../butterfly_mechanics/03_fast_forward_ct/lab.ipynb)\n13. [Butterfly Mechanics / 03 Fast Forward CT / Problems](../../butterfly_mechanics/03_fast_forward_ct/problems.ipynb)\n14. [Butterfly Mechanics / 03 Fast Forward CT / Studio](../../butterfly_mechanics/03_fast_forward_ct/studio.ipynb)\n15. [Butterfly Mechanics / 04 Fast Inverse GS / Lecture](../../butterfly_mechanics/04_fast_inverse_gs/lecture.ipynb)\n16. [Butterfly Mechanics / 04 Fast Inverse GS / Lab](../../butterfly_mechanics/04_fast_inverse_gs/lab.ipynb)\n17. [Butterfly Mechanics / 04 Fast Inverse GS / Problems](../../butterfly_mechanics/04_fast_inverse_gs/problems.ipynb)\n18. [Butterfly Mechanics / 04 Fast Inverse GS / Studio](../../butterfly_mechanics/04_fast_inverse_gs/studio.ipynb)\n19. [Kyber Mapping / 05 Kyber NTT And Base Multiplication / Lecture](../../kyber_mapping/05_kyber_ntt_and_base_multiplication/lecture.ipynb)\n20. [Kyber Mapping / 05 Kyber NTT And Base Multiplication / Lab](../../kyber_mapping/05_kyber_ntt_and_base_multiplication/lab.ipynb)\n21. [Kyber Mapping / 05 Kyber NTT And Base Multiplication / Problems](../../kyber_mapping/05_kyber_ntt_and_base_multiplication/problems.ipynb)\n22. [Kyber Mapping / 05 Kyber NTT And Base Multiplication / Studio](../../kyber_mapping/05_kyber_ntt_and_base_multiplication/studio.ipynb)\n23. [Professional / 06 Debugging NTT Failures / Lecture](../../professional/06_debugging_ntt_failures/lecture.ipynb)\n24. [Professional / 06 Debugging NTT Failures / Lab](../../professional/06_debugging_ntt_failures/lab.ipynb)\n25. [Professional / 06 Debugging NTT Failures / Problems](../../professional/06_debugging_ntt_failures/problems.ipynb)\n26. [Professional / 06 Debugging NTT Failures / Studio](../../professional/06_debugging_ntt_failures/studio.ipynb)\n27. [Course Complete](../../COURSE_COMPLETE.ipynb)\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "orientation",
|
|
"title": "Objectives"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">big picture</span>\n <span class=\"ntt-route-pill\">route help</span>\n </div>\n <h2 class=\"ntt-cell-title\">Objectives</h2>\n</div>\n\nThis first bundle is about making the raw multiplication problem visible before any transform is introduced.\n\nFocus:\n\n- the schoolbook product grid\n- diagonal sums\n- cyclic vs negacyclic folding\n- a tiny teaser of why transforms help\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "explanation",
|
|
"title": "Schoolbook Multiplication Is A Grid"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 2</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">explanation</span>\n <span class=\"ntt-route-pill\">core path</span>\n </div>\n <h2 class=\"ntt-cell-title\">Schoolbook Multiplication Is A Grid</h2>\n</div>\n\nStop thinking \u201cmultiply two polynomials\u201d as one sentence.\nThe mechanical reality is a grid of pairwise products whose diagonals have to be accumulated.\n\nIf that grid is not concrete, the NTT has nothing to optimize in your mind.\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "demo",
|
|
"title": "Play The Diagonal Sweep"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# Play The Diagonal Sweep\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import convolution_contributions, schoolbook_convolution\nfrom ntt_learning.visuals import plot_convolution_grid, schoolbook_diagonal_player\n\nleft = [1, 2, 3, 4]\nright = [5, 6, 7, 8]\nraw = schoolbook_convolution(left, right)\n\nprint(\"raw convolution:\", raw)\nfor row in convolution_contributions(left, right):\n print(row)\n\ndisplay(schoolbook_diagonal_player(left, right))\nfig = plot_convolution_grid(left, right, title=\"Schoolbook products for [1,2,3,4] * [5,6,7,8]\")\ndisplay(fig)\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "explanation",
|
|
"title": "Wraparound Is The First Structural Fork"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 2</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">explanation</span>\n <span class=\"ntt-route-pill\">core path</span>\n </div>\n <h2 class=\"ntt-cell-title\">Wraparound Is The First Structural Fork</h2>\n</div>\n\nOnce the raw tail exists, the ring tells you what to do with it.\n\n- in `x^n - 1`, high-degree terms wrap back with a positive sign\n- in `x^n + 1`, high-degree terms wrap back with a sign flip\n\nThat sign flip is not cosmetic. It is exactly what makes the negacyclic story different.\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "demo",
|
|
"title": "Play The Wraparound Step By Step"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# Play The Wraparound Step By Step\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import negacyclic_multiply, schoolbook_convolution, wraparound_contributions\nfrom ntt_learning.visuals import plot_wraparound, wraparound_comparison_player\n\nleft = [1, 2, 3, 4]\nright = [5, 6, 7, 8]\nraw = schoolbook_convolution(left, right)\n\nprint(\"raw convolution:\", raw)\nprint(\"negacyclic in x^4 + 1:\", negacyclic_multiply(left, right, n=4))\nprint(\"cyclic folding rows:\")\nfor row in wraparound_contributions(raw, n=4, negacyclic=False):\n print(row)\nprint(\"negacyclic folding rows:\")\nfor row in wraparound_contributions(raw, n=4, negacyclic=True):\n print(row)\n\ndisplay(wraparound_comparison_player(raw, n=4))\ndisplay(plot_wraparound(raw, n=4, negacyclic=False, title=\"Cyclic folding into x^4 - 1\"))\ndisplay(plot_wraparound(raw, n=4, negacyclic=True, title=\"Negacyclic folding into x^4 + 1\"))\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "explanation",
|
|
"title": "The Tiny Transform Teaser"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 2</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">explanation</span>\n <span class=\"ntt-route-pill\">core path</span>\n </div>\n <h2 class=\"ntt-cell-title\">The Tiny Transform Teaser</h2>\n</div>\n\nThe transform is not magic. It is a change of coordinates chosen so that multiplication gets easier.\n\nThe next bundle will treat the transform itself directly.\nThis first bundle only makes sure the learner can see the raw thing being optimized.\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "quiz",
|
|
"title": "Retrieval Check"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 2</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">quiz</span>\n <span class=\"ntt-route-pill\">core path</span>\n </div>\n <h2 class=\"ntt-cell-title\">Retrieval Check</h2>\n</div>\n\nAnswer in words before moving on:\n\n1. Why do diagonal sums appear in schoolbook multiplication?\n2. What is the one exact sign difference between cyclic and negacyclic folding?\n3. If you cannot track the tail wraparound, what part of the NTT story will stay vague?\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "facultative",
|
|
"difficulty": 4,
|
|
"kind": "exploration",
|
|
"title": "Optional: Compare Another Example"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# Optional: Compare Another Example\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 = [2, 1, 0, 3]\nright = [4, 0, 1, 2]\nraw = schoolbook_convolution(left, right)\n\nprint(\"raw convolution:\", raw)\nprint(\"negacyclic:\", negacyclic_multiply(left, right, n=4))\ndisplay(plot_convolution_grid(left, right, title=\"A second schoolbook grid\"))\ndisplay(plot_wraparound(raw, n=4, negacyclic=True, title=\"A second negacyclic fold\"))\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "handoff",
|
|
"title": "Next Notebook"
|
|
}
|
|
},
|
|
"source": "<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-topline\">\n <span class=\"ntt-kind-pill\">next step</span>\n <span class=\"ntt-route-pill\">route help</span>\n </div>\n <h2 class=\"ntt-cell-title\">Next Notebook</h2>\n</div>\n\nYou finished **Foundations / 01 Convolution To Toy NTT / Lecture**.\n\n**Primary next action**\n- Next notebook: [Step 4 of 27 - Foundations / 01 Convolution To Toy NTT / Lab](lab.ipynb)\n\n**Recovery links if you get lost**\n- Previous notebook: [Course Blueprint](../../COURSE_BLUEPRINT.ipynb)\n- Restart route: [Start Here](../../START_HERE.ipynb)\n"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python"
|
|
},
|
|
"ntt_learning": {
|
|
"title": "Lecture: 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
|
|
}
|