NTT-learning/notebooks/foundations/02_negative_wrapped_ntt/studio.ipynb

151 lines
7.1 KiB
Text

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "meta",
"difficulty": 1,
"kind": "orientation",
"title": "Studio Goals"
}
},
"source": "## META | difficulty 1 | Studio Goals\n\nThe studio compares direct positive-wrapped and negative-wrapped transforms so the learner stops treating \u201cNTT\u201d as one unqualified object.\n"
},
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 3,
"kind": "explanation",
"title": "Same Input, Different Transform Story"
}
},
"source": "## MANDATORY | difficulty 3 | Same Input, Different Transform Story\n\nThe same coefficient vector can be sent through two different transform stories depending on the quotient ring.\nThat difference is not implementation noise. It is structural.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 3,
"kind": "demo",
"title": "Compare Positive-Wrapped And Negative-Wrapped Views"
}
},
"outputs": [],
"source": "# MANDATORY | difficulty 3 | Compare Positive-Wrapped And Negative-Wrapped Views\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import find_primitive_root, find_psi, forward_ntt, forward_ntt_psi\nfrom ntt_learning.visuals import plot_vector_comparison\n\nsignal = [1, 2, 3, 4]\nmodulus = 17\nomega = find_primitive_root(4, modulus)\npsi = find_psi(4, modulus)\n\npositive = forward_ntt(signal, modulus, omega)\nnegative = forward_ntt_psi(signal, modulus, psi)\n\nprint(\"positive-wrapped NTT:\", positive)\nprint(\"negative-wrapped NTT_psi:\", negative)\ndisplay(\n plot_vector_comparison(\n positive,\n negative,\n left_label=\"positive\",\n right_label=\"negative\",\n title=\"Same signal, different transform story\",\n )\n)\n"
},
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 2,
"kind": "exercise",
"title": "Debug Checklist"
}
},
"source": "## MANDATORY | difficulty 2 | Debug Checklist\n\nIf a direct transform result looks suspicious, inspect:\n\n1. the chosen modulus\n2. the order of the root\n3. whether you are using `\u03c9` or `\u03c8`\n4. whether the inverse includes `n^-1`\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 2,
"kind": "exercise",
"title": "See A Wrong-Root Failure"
}
},
"outputs": [],
"source": "# MANDATORY | difficulty 2 | See A Wrong-Root Failure\n\nfrom IPython.display import display\n\nfrom ntt_learning.toy_ntt import find_primitive_root, find_psi, forward_ntt_psi\nfrom ntt_learning.visuals import plot_vector_comparison\n\nsignal = [1, 2, 3, 4]\nmodulus = 17\nomega = find_primitive_root(4, modulus)\npsi = find_psi(4, modulus)\n\ncorrect = forward_ntt_psi(signal, modulus, psi)\nwrong = forward_ntt_psi(signal, modulus, omega)\n\nprint(\"correct psi-based transform:\", correct)\nprint(\"wrongly using omega as if it were psi:\", wrong)\ndisplay(\n plot_vector_comparison(\n wrong,\n correct,\n left_label=\"wrong_root\",\n right_label=\"correct\",\n title=\"Wrong root vs correct root\",\n )\n)\n"
},
{
"cell_type": "markdown",
"metadata": {
"pedagogy": {
"role": "mandatory",
"difficulty": 2,
"kind": "reflection",
"title": "Reflection"
}
},
"source": "## MANDATORY | difficulty 2 | Reflection\n\nExplain why \u201cpick any root of unity\u201d is not an acceptable habit in this subject.\n"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pedagogy": {
"role": "facultative",
"difficulty": 4,
"kind": "exploration",
"title": "Optional: Matrix Comparison"
}
},
"outputs": [],
"source": "# FACULTATIVE | difficulty 4 | Optional: Matrix Comparison\n\nfrom ntt_learning.toy_ntt import find_primitive_root, find_psi, ntt_psi_matrix\n\nmodulus = 17\nomega = find_primitive_root(4, modulus)\npsi = find_psi(4, modulus)\n\nprint(\"omega:\", omega)\nprint(\"psi:\", psi)\nfor row in ntt_psi_matrix(4, modulus, psi):\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: `../../../butterfly_mechanics/03_fast_forward_ct/lecture.ipynb`\n"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
},
"ntt_learning": {
"title": "Studio: Negative-Wrapped 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
}