{ "cells": [ { "cell_type": "markdown", "metadata": { "pedagogy": { "role": "meta", "difficulty": 1, "kind": "orientation", "title": "Objectives" } }, "source": "## META | difficulty 1 | Objectives\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 | difficulty 3 | CT Is A Schedule For Reusing Work\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": "Trace The Exact n=4 Paper Example" } }, "outputs": [], "source": "# MANDATORY | difficulty 3 | Trace The Exact n=4 Paper Example\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 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(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 | difficulty 3 | What You Should Notice In The Stage Viewer\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 | difficulty 3 | Run The Second n=4 Paper Example\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 | difficulty 3 | Go One Stage Deeper With n=8\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 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(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 | difficulty 3 | See BO Output And NO Output Side By Side\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 | difficulty 2 | Retrieval Check\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 | difficulty 4 | Optional: Inspect Stage Rows As Data\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 | difficulty 1 | Next Notebook\n\nNext notebook: `lab.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 }