{ "cells": [ { "cell_type": "markdown", "id": "5c112e3c", "metadata": { "cq.autogen": "title_cell" }, "source": [ "# Polynomials over GF($p^m$) - Split and Join" ] }, { "cell_type": "code", "execution_count": 1, "id": "fa73d48d", "metadata": { "cq.autogen": "top_imports" }, "outputs": [], "source": [ "from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n", "from qualtran import QBit, QInt, QUInt, QAny\n", "from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n", "from typing import *\n", "import numpy as np\n", "import sympy\n", "import cirq" ] }, { "cell_type": "markdown", "id": "bc9d0e45", "metadata": { "cq.autogen": "GFPolySplit.bloq_doc.md" }, "source": [ "## `GFPolySplit`\n", "Split a register representing coefficients of a polynomial into an array of `QGF` types.\n", "\n", "A register of type `QGFPoly` represents a univariate polynomial $f(x)$ with coefficients in a\n", "galois field GF($p^m$). Given an input quantum register representing a degree $n$ polynomial\n", "$f(x)$, this bloq splits it into $n + 1$ registers of type $QGF(p, m)$.\n", "\n", "Given a polynomial\n", "$$\n", " f(x) = \\sum_{i = 0}^{n} a_{i} x^{i} \\\\ \\forall a_{i} \\in GF(p^m)\n", "$$\n", "\n", "the bloq splits it into a big-endian representation such that\n", "$$\n", " \\ket{f(x)} \\xrightarrow{\\text{split}} \\ket{a_{n}}\\ket{a_{n - 1}} \\cdots \\ket{a_0}\n", "$$\n", "\n", "See `GFPolyJoin` for the inverse operation.\n", "\n", "#### Parameters\n", " - `dtype`: An instance of `QGFPoly` type that represents a degree $n$ polynomial defined over a galois field GF($p^m$). \n", "\n", "#### Registers\n", " - `reg`: The register to be split. On its left, it is of the type `qgf_poly`. On the right, it is an array of `QGF`s of shape `(qgf_poly.degree + 1,)`.\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "f4ec23cc", "metadata": { "cq.autogen": "GFPolySplit.bloq_doc.py" }, "outputs": [], "source": [ "from qualtran.bloqs.gf_poly_arithmetic import GFPolySplit" ] }, { "cell_type": "markdown", "id": "99406fdd", "metadata": { "cq.autogen": "GFPolySplit.example_instances.md" }, "source": [ "### Example Instances" ] }, { "cell_type": "code", "execution_count": 3, "id": "3b1e7f86", "metadata": { "cq.autogen": "GFPolySplit.gf_poly_split" }, "outputs": [], "source": [ "from qualtran import QGF, QGFPoly\n", "\n", "gf_poly_split = GFPolySplit(QGFPoly(4, QGF(2, 3)))" ] }, { "cell_type": "markdown", "id": "4067682b", "metadata": { "cq.autogen": "GFPolySplit.graphical_signature.md" }, "source": [ "#### Graphical Signature" ] }, { "cell_type": "code", "execution_count": 4, "id": "0f323719", "metadata": { "cq.autogen": "GFPolySplit.graphical_signature.py" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8a9950f6d168442a8e27effa6d40820b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(Output(outputs=({'output_type': 'display_data', 'data': {'text/plain': '" }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": "\n\nmy_graph\n\n\n\nreg_G6\nreg\n\n\n\nGFPolySplit\n\nGFPolySplit\n\nreg\n\nreg[0]\n\nreg[1]\n\nreg[2]\n\nreg[3]\n\nreg[4]\n\n\n\nreg_G6:e->GFPolySplit:w\n\n\n15\n\n\n\nreg_G5\nreg[0]\n\n\n\nGFPolySplit:e->reg_G5:w\n\n\n3\n\n\n\nreg_G2\nreg[1]\n\n\n\nGFPolySplit:e->reg_G2:w\n\n\n3\n\n\n\nreg_G8\nreg[2]\n\n\n\nGFPolySplit:e->reg_G8:w\n\n\n3\n\n\n\nreg_G4\nreg[3]\n\n\n\nGFPolySplit:e->reg_G4:w\n\n\n3\n\n\n\nreg_G3\nreg[4]\n\n\n\nGFPolySplit:e->reg_G3:w\n\n\n3\n\n\n", "text/plain": "" }, "metadata": {}, "output_type": "display_data" } ], "tabbable": null, "tooltip": null } }, "7cd72e27407e42eca7cf368b861183d5": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_e26cfae8a725425ab0a2253120368074", "msg_id": "", "outputs": [ { "data": { "text/markdown": "`gf_poly_join`", "text/plain": "" }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": "\n\nmy_graph\n\n\n\nreg_G2\nreg[0]\n\n\n\nGFPolyJoin\n\nGFPolyJoin\n\nreg[0]\n\nreg\n\nreg[1]\n\nreg[2]\n\nreg[3]\n\nreg[4]\n\n\n\nreg_G2:e->GFPolyJoin:w\n\n\n3\n\n\n\nreg_G11\nreg[1]\n\n\n\nreg_G11:e->GFPolyJoin:w\n\n\n3\n\n\n\nreg_G6\nreg[2]\n\n\n\nreg_G6:e->GFPolyJoin:w\n\n\n3\n\n\n\nreg_G0\nreg[3]\n\n\n\nreg_G0:e->GFPolyJoin:w\n\n\n3\n\n\n\nreg_G8\nreg[4]\n\n\n\nreg_G8:e->GFPolyJoin:w\n\n\n3\n\n\n\nreg_G7\nreg\n\n\n\nGFPolyJoin:e->reg_G7:w\n\n\n15\n\n\n", "text/plain": "" }, "metadata": {}, "output_type": "display_data" } ], "tabbable": null, "tooltip": null } }, "8a9950f6d168442a8e27effa6d40820b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "HBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_6039463c733d4ca39811446becccdfb6" ], "layout": "IPY_MODEL_f1dd3edd0f0d4f5da4c6455c1a461f71", "tabbable": null, "tooltip": null } }, "996a0d626015410a963eb16291919f37": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "HBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_7cd72e27407e42eca7cf368b861183d5" ], "layout": "IPY_MODEL_b27539564d934467a82cf7a45b352bc5", "tabbable": null, "tooltip": null } }, "b27539564d934467a82cf7a45b352bc5": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "d9f6942acc7b483eb1e1844142c51481": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "e26cfae8a725425ab0a2253120368074": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "f1dd3edd0f0d4f5da4c6455c1a461f71": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }