{ "cells": [ { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "theme", "title": "Notebook Theme" } }, "source": "## META\n\n\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "route_nav", "title": "Route Guardrails" } }, "source": "## META\n\n
\n Level 1\n
\n META\n route nav\n
\n
Route Guardrails
\n
\n\nYou are at **step 11 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 / 03 Fast Forward CT / Lab](lab.ipynb)\n- Previous notebook: [Foundations / 02 Negative Wrapped NTT / Studio](../../foundations/02_negative_wrapped_ntt/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** <- you are here\n12. [Butterfly Mechanics / 03 Fast Forward CT / Lab](lab.ipynb)\n13. [Butterfly Mechanics / 03 Fast Forward CT / Problems](problems.ipynb)\n14. [Butterfly Mechanics / 03 Fast Forward CT / Studio](studio.ipynb)\n15. [Butterfly Mechanics / 04 Fast Inverse GS / Lecture](../04_fast_inverse_gs/lecture.ipynb)\n16. [Butterfly Mechanics / 04 Fast Inverse GS / Lab](../04_fast_inverse_gs/lab.ipynb)\n17. [Butterfly Mechanics / 04 Fast Inverse GS / Problems](../04_fast_inverse_gs/problems.ipynb)\n18. [Butterfly Mechanics / 04 Fast Inverse GS / Studio](../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": "## META\n\n
\n Level 1\n
\n META\n orientation\n
\n
Objectives
\n
\n\nThis bundle is where the transform stops being a full matrix multiplication and becomes a staged butterfly network.\n\nFocus:\n\n- CT as the fast forward NTT strategy\n- visible stage arrays\n- explicit zeta values per pair\n- BO output vs NO output\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "explanation", "title": "CT Is A Schedule For Reusing Work" } }, "source": "## MANDATORY\n\n
\n Level 3\n
\n MANDATORY\n explanation\n
\n
CT Is A Schedule For Reusing Work
\n
\n\nThe point of the CT butterfly is not to invent a new transform.\nThe point is to compute the same transform by reusing shared bracket terms instead of recomputing everything from scratch.\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "demo", "title": "See The Schedule Geometry Before The Numbers" } }, "outputs": [], "source": "# MANDATORY\n# title: See The Schedule Geometry Before The Numbers\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.visuals import plot_stage_pairing_map, plot_stage_schedule\n\ndisplay(plot_stage_schedule(8, title=\"CT schedule skeleton for n=8\"))\ndisplay(plot_stage_pairing_map(8, 2, title=\"Stage 1 pairings for n=8\"))\ndisplay(plot_stage_pairing_map(8, 4, title=\"Stage 2 pairings for n=8\"))\ndisplay(plot_stage_pairing_map(8, 8, title=\"Stage 3 pairings for n=8\"))\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "demo", "title": "Trace The Exact n=4 Paper Example" } }, "outputs": [], "source": "# MANDATORY\n# title: Trace The Exact n=4 Paper Example\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_ntt_psi_ct_trace, forward_ntt_psi\nfrom ntt_learning.visuals import butterfly_story_player, interactive_trace, plot_butterfly_network, plot_trace_overview\n\nsignal = [1, 2, 3, 4]\nmodulus = 7681\npsi = 1925\ntrace = fast_ntt_psi_ct_trace(signal, modulus, psi)\n\nprint(\"raw CT output (BO):\", trace.raw_output)\nprint(\"bit-reversed back to NO:\", trace.normal_order_output)\nprint(\"direct NTT_psi:\", forward_ntt_psi(signal, modulus, psi))\ndisplay(butterfly_story_player(trace))\ndisplay(plot_trace_overview(trace, title=\"CT overview for [1,2,3,4]\"))\ndisplay(plot_butterfly_network(trace, title=\"Full CT network for [1,2,3,4]\"))\ndisplay(interactive_trace(trace, title=\"CT forward trace\"))\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "explanation", "title": "What You Should Notice In The Stage Viewer" } }, "source": "## MANDATORY\n\n
\n Level 3\n
\n MANDATORY\n explanation\n
\n
What You Should Notice In The Stage Viewer
\n
\n\nDo not just read the final answer.\nNotice:\n\n- which pairs talk to each other in each stage\n- which `zeta` each pair uses\n- how the array order changes before the final bit-reversal correction\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "demo", "title": "Run The Second n=4 Paper Example" } }, "outputs": [], "source": "# MANDATORY\n# title: Run The Second n=4 Paper Example\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_ntt_psi_ct_trace\nfrom ntt_learning.visuals import interactive_trace\n\nsignal = [5, 6, 7, 8]\ntrace = fast_ntt_psi_ct_trace(signal, 7681, 1925)\nprint(\"BO output:\", trace.raw_output)\nprint(\"NO output:\", trace.normal_order_output)\ndisplay(interactive_trace(trace, title=\"Second CT trace\"))\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "demo", "title": "Go One Stage Deeper With n=8" } }, "outputs": [], "source": "# MANDATORY\n# title: Go One Stage Deeper With n=8\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_ntt_psi_ct_trace, find_psi\nfrom ntt_learning.visuals import butterfly_story_player, interactive_trace, plot_butterfly_network, plot_trace_overview\n\nsignal = [0, 1, 2, 3, 4, 5, 6, 7]\nmodulus = 97\npsi = find_psi(8, modulus)\ntrace = fast_ntt_psi_ct_trace(signal, modulus, psi)\n\nprint(\"psi:\", psi)\nprint(\"BO output:\", trace.raw_output)\nprint(\"NO output:\", trace.normal_order_output)\ndisplay(butterfly_story_player(trace))\ndisplay(plot_trace_overview(trace, title=\"Three CT stages for n=8\"))\ndisplay(plot_butterfly_network(trace, title=\"Full CT network for n=8\"))\ndisplay(interactive_trace(trace, title=\"n=8 CT stage explorer\"))\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 3, "kind": "demo", "title": "See BO Output And NO Output Side By Side" } }, "outputs": [], "source": "# MANDATORY\n# title: See BO Output And NO Output Side By Side\n# kind: demo | level: 3\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import fast_ntt_psi_ct_trace\nfrom ntt_learning.visuals import plot_bit_reversal_mapping, plot_vector_comparison\n\ntrace = fast_ntt_psi_ct_trace([1, 2, 3, 4], 7681, 1925)\ndisplay(\n plot_vector_comparison(\n trace.raw_output,\n trace.normal_order_output,\n left_label=\"BO\",\n right_label=\"NO\",\n title=\"Same CT values, different ordering\",\n )\n)\ndisplay(plot_bit_reversal_mapping(4, title=\"Why BO becomes NO after bit-reversal\"))\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "mandatory", "difficulty": 2, "kind": "quiz", "title": "Retrieval Check" } }, "source": "## MANDATORY\n\n
\n Level 2\n
\n MANDATORY\n quiz\n
\n
Retrieval Check
\n
\n\n1. What does CT change: the transform definition or the computation schedule?\n2. Why is the output naturally in BO rather than NO?\n3. In a stage diagram, what are the first three things you should inspect before any formula?\n" }, { "cell_type": "code", "execution_count": null, "metadata": { "pedagogy": { "role": "facultative", "difficulty": 4, "kind": "exploration", "title": "Optional: Inspect Stage Rows As Data" } }, "outputs": [], "source": "# FACULTATIVE\n# title: Optional: Inspect Stage Rows As Data\n# kind: exploration | level: 4\n\nfrom ntt_learning.toy_ntt import fast_ntt_psi_ct_trace, stage_rows\n\ntrace = fast_ntt_psi_ct_trace([1, 2, 3, 4], 7681, 1925)\nfor stage in trace.stages:\n print(\"stage\", stage.stage_index)\n for row in stage_rows(stage):\n print(row)\n" }, { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "handoff", "title": "Next Notebook" } }, "source": "## META\n\n
\n Level 1\n
\n META\n handoff\n
\n
Next Notebook
\n
\n\nYou finished **Butterfly Mechanics / 03 Fast Forward CT / Lecture**.\n\n**Primary next action**\n- Next notebook: [Step 12 of 27 - Butterfly Mechanics / 03 Fast Forward CT / Lab](lab.ipynb)\n\n**Recovery links if you get lost**\n- Previous notebook: [Foundations / 02 Negative Wrapped NTT / Studio](../../foundations/02_negative_wrapped_ntt/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 Forward CT", "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 }