mirror of
https://github.com/saymrwulf/NTT-learning.git
synced 2026-09-10 20:10:41 +00:00
189 lines
16 KiB
Text
189 lines
16 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "theme",
|
|
"title": "Notebook Theme"
|
|
}
|
|
},
|
|
"source": "## META\n\n<style>\n.jp-RenderedHTMLCommon h2 {\n display: none;\n}\n\n.jp-RenderedHTMLCommon .ntt-cell-head {\n position: relative;\n margin: 0 0 0.8rem 0;\n padding: 0.95rem 1rem 0.95rem 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-row {\n display: flex;\n flex-wrap: wrap;\n gap: 0.45rem;\n align-items: center;\n margin-bottom: 0.55rem;\n}\n\n.jp-RenderedHTMLCommon .ntt-role-pill,\n.jp-RenderedHTMLCommon .ntt-kind-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, #fff0b3 0%, #ffd58a 100%);\n}\n\n.jp-RenderedHTMLCommon .ntt-role-facultative {\n background: linear-gradient(135deg, #ffe1d6 0%, #ffc9b9 100%);\n}\n\n.jp-RenderedHTMLCommon .ntt-role-pill {\n color: #102a43;\n background: rgba(16,42,67,0.1);\n}\n\n.jp-RenderedHTMLCommon .ntt-kind-pill {\n color: #486581;\n background: rgba(255,255,255,0.72);\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 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": "## META\n\n<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">META</span>\n <span class=\"ntt-kind-pill\">route nav</span>\n </div>\n <div class=\"ntt-cell-title\">Route Guardrails</div>\n</div>\n\nYou are at **step 15 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: [Butterfly Mechanics / 04 Fast Inverse GS / Lab](lab.ipynb)\n- Previous notebook: [Butterfly Mechanics / 03 Fast Forward CT / Studio](../03_fast_forward_ct/studio.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](../../foundations/01_convolution_to_toy_ntt/lecture.ipynb)\n4. [Foundations / 01 Convolution To Toy NTT / Lab](../../foundations/01_convolution_to_toy_ntt/lab.ipynb)\n5. [Foundations / 01 Convolution To Toy NTT / Problems](../../foundations/01_convolution_to_toy_ntt/problems.ipynb)\n6. [Foundations / 01 Convolution To Toy NTT / Studio](../../foundations/01_convolution_to_toy_ntt/studio.ipynb)\n7. [Foundations / 02 Negative Wrapped NTT / Lecture](../../foundations/02_negative_wrapped_ntt/lecture.ipynb)\n8. [Foundations / 02 Negative Wrapped NTT / Lab](../../foundations/02_negative_wrapped_ntt/lab.ipynb)\n9. [Foundations / 02 Negative Wrapped NTT / Problems](../../foundations/02_negative_wrapped_ntt/problems.ipynb)\n10. [Foundations / 02 Negative Wrapped NTT / Studio](../../foundations/02_negative_wrapped_ntt/studio.ipynb)\n11. [Butterfly Mechanics / 03 Fast Forward CT / Lecture](../03_fast_forward_ct/lecture.ipynb)\n12. [Butterfly Mechanics / 03 Fast Forward CT / Lab](../03_fast_forward_ct/lab.ipynb)\n13. [Butterfly Mechanics / 03 Fast Forward CT / Problems](../03_fast_forward_ct/problems.ipynb)\n14. [Butterfly Mechanics / 03 Fast Forward CT / Studio](../03_fast_forward_ct/studio.ipynb)\n15. **Butterfly Mechanics / 04 Fast Inverse GS / Lecture** <- you are here\n16. [Butterfly Mechanics / 04 Fast Inverse GS / Lab](lab.ipynb)\n17. [Butterfly Mechanics / 04 Fast Inverse GS / Problems](problems.ipynb)\n18. [Butterfly Mechanics / 04 Fast Inverse GS / Studio](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": "## META\n\n<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">META</span>\n <span class=\"ntt-kind-pill\">orientation</span>\n </div>\n <div class=\"ntt-cell-title\">Objectives</div>\n</div>\n\nThis bundle makes the inverse flow explicit.\n\nFocus:\n\n- GS as the fast inverse schedule\n- BO input and NO output\n- why the final `n^-1` scaling appears\n- how bit-reversal fits the forward/inverse pair\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 3,
|
|
"kind": "explanation",
|
|
"title": "GS Feels Like The Same Network Seen From The Other End"
|
|
}
|
|
},
|
|
"source": "## MANDATORY\n\n<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 3</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">MANDATORY</span>\n <span class=\"ntt-kind-pill\">explanation</span>\n </div>\n <div class=\"ntt-cell-title\">GS Feels Like The Same Network Seen From The Other End</div>\n</div>\n\nThe inverse is not \u201cmysterious undoing\u201d.\nIt is a staged network with the same family resemblance as CT, but with a different direction of arithmetic and a final scaling.\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 3,
|
|
"kind": "demo",
|
|
"title": "Trace The Exact n=4 GS Paper Example"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# MANDATORY\n# title: Trace The Exact n=4 GS Paper Example\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_intt_psi_gs_trace\nfrom ntt_learning.visuals import interactive_trace, plot_butterfly_network, plot_trace_overview, plot_vector_comparison\n\nbo_input = [1467, 3471, 2807, 7621]\ntrace = fast_intt_psi_gs_trace(bo_input, 7681, 1925)\n\nprint(\"unscaled NO output:\", trace.raw_output)\nprint(\"scaled NO output:\", trace.scaled_output)\ndisplay(plot_trace_overview(trace, title=\"GS overview for the n=4 paper example\"))\ndisplay(plot_butterfly_network(trace, title=\"Full GS network for the n=4 paper example\"))\ndisplay(\n plot_vector_comparison(\n trace.raw_output,\n trace.scaled_output,\n left_label=\"unscaled\",\n right_label=\"scaled\",\n title=\"Why the final n^-1 scaling matters\",\n )\n)\ndisplay(interactive_trace(trace, title=\"GS inverse trace\"))\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 3,
|
|
"kind": "demo",
|
|
"title": "See The Bit-Reversal Map Explicitly"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# MANDATORY\n# title: See The Bit-Reversal Map Explicitly\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.visuals import plot_bit_reversal_mapping\n\ndisplay(plot_bit_reversal_mapping(4, title=\"Bit-reversal for n=4\"))\ndisplay(plot_bit_reversal_mapping(8, title=\"Bit-reversal for n=8\"))\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 3,
|
|
"kind": "explanation",
|
|
"title": "Why Scaling Waits Until The End"
|
|
}
|
|
},
|
|
"source": "## MANDATORY\n\n<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 3</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">MANDATORY</span>\n <span class=\"ntt-kind-pill\">explanation</span>\n </div>\n <div class=\"ntt-cell-title\">Why Scaling Waits Until The End</div>\n</div>\n\nEach GS stage avoids local division by `2`.\nThe accumulated effect of those missing local divisions is corrected by the final multiplication with `n^-1`.\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 3,
|
|
"kind": "demo",
|
|
"title": "Full Forward And Inverse Round Trip"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# MANDATORY\n# title: Full Forward And Inverse Round Trip\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_intt_psi_gs_trace, fast_ntt_psi_ct_trace\nfrom ntt_learning.visuals import plot_vector_comparison\n\nsignal = [1, 2, 3, 4]\nforward_trace = fast_ntt_psi_ct_trace(signal, 7681, 1925)\ninverse_trace = fast_intt_psi_gs_trace(forward_trace.raw_output, 7681, 1925)\n\nprint(\"forward BO output:\", forward_trace.raw_output)\nprint(\"inverse scaled output:\", inverse_trace.scaled_output)\ndisplay(\n plot_vector_comparison(\n signal,\n inverse_trace.scaled_output,\n left_label=\"original\",\n right_label=\"recovered\",\n title=\"Forward CT followed by inverse GS\",\n )\n)\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "mandatory",
|
|
"difficulty": 2,
|
|
"kind": "quiz",
|
|
"title": "Retrieval Check"
|
|
}
|
|
},
|
|
"source": "## MANDATORY\n\n<div class=\"ntt-cell-head ntt-role-mandatory\">\n <span class=\"ntt-difficulty-pill\">Level 2</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">MANDATORY</span>\n <span class=\"ntt-kind-pill\">quiz</span>\n </div>\n <div class=\"ntt-cell-title\">Retrieval Check</div>\n</div>\n\n1. Why does GS want BO input?\n2. Why does the final scaling not disappear?\n3. What would go wrong if you visually compared GS input and CT NO output without respecting the order change?\n"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "facultative",
|
|
"difficulty": 4,
|
|
"kind": "exploration",
|
|
"title": "Optional: A Second GS Example"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": "# FACULTATIVE\n# title: Optional: A Second GS Example\n# kind: exploration | level: 4\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_intt_psi_gs_trace\nfrom ntt_learning.visuals import interactive_trace\n\ntrace = fast_intt_psi_gs_trace([2489, 6478, 7489, 6607], 7681, 1925)\nprint(\"scaled output:\", trace.scaled_output)\ndisplay(interactive_trace(trace, title=\"Second GS trace\"))\n"
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"pedagogy": {
|
|
"role": "meta",
|
|
"difficulty": 1,
|
|
"kind": "handoff",
|
|
"title": "Next Notebook"
|
|
}
|
|
},
|
|
"source": "## META\n\n<div class=\"ntt-cell-head ntt-role-meta\">\n <span class=\"ntt-difficulty-pill\">Level 1</span>\n <div class=\"ntt-cell-row\">\n <span class=\"ntt-role-pill\">META</span>\n <span class=\"ntt-kind-pill\">handoff</span>\n </div>\n <div class=\"ntt-cell-title\">Next Notebook</div>\n</div>\n\nYou finished **Butterfly Mechanics / 04 Fast Inverse GS / Lecture**.\n\n**Primary next action**\n- Next notebook: [Step 16 of 27 - Butterfly Mechanics / 04 Fast Inverse GS / Lab](lab.ipynb)\n\n**Recovery links if you get lost**\n- Previous notebook: [Butterfly Mechanics / 03 Fast Forward CT / Studio](../03_fast_forward_ct/studio.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: Fast Inverse GS",
|
|
"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
|
|
}
|