{ "cells": [ { "cell_type": "markdown", "id": "bb78925f", "metadata": {}, "source": [ "## coeff_make" ] }, { "cell_type": "markdown", "id": "f4f8c14c", "metadata": {}, "source": [ "### **Outline**" ] }, { "cell_type": "markdown", "id": "cff6965a", "metadata": {}, "source": [ "This function generates the input arguments used by [mat_maker](../eng/mat_maker_en.ipynb) function within `PItBE`.\\\n", "It is strongly recommended to use the output of this function when executing [mat_maker](../eng/mat_maker_en.ipynb)." ] }, { "cell_type": "markdown", "id": "3768a7f5", "metadata": {}, "source": [ "This function solves a system of equations that depends on the length of the input vector `vec`.\\\n", "For example, when the length is 8, it solves a system of equations as shown below.\\\n", "Here, the values $\\alpha_i$ represent the input, and the corresponding outputs are denoted by $\\alpha_i$." ] }, { "cell_type": "markdown", "id": "6883f717", "metadata": {}, "source": [ "$$\n", "\\begin{aligned} \n", " &\\alpha_1\\sum_{n=0}^{7}{}a_{0n}^2 \n", " - \\alpha_1^{-1}\\sum_{n=8}^{15}{}a_{0n}^2 = 0\\\\ \n", " &\\alpha_2\\sum_{n=0}^{3}{}a_{0n}^2 - \\alpha_2^{-1}\\sum_{n=4}^{7}{}a_{0n}^2 +\\alpha_3 \\sum_{n=8}^{11}{}a_{0n}^2 \n", " - \\alpha_3^{-1}\\sum_{n=12}^{15}{}a_{0n}^2 = 0\\\\ \n", " &\\alpha_1\\alpha_2\\sum_{n=0}^{3}{}a_{0n}^2 \n", " - \\alpha_1\\alpha_2^{-1}\\sum_{n=4}^{7}{}a_{0n}^2 +\n", " \\alpha_1^{-1}\\alpha_3 \\sum_{n=8}^{11}{}a_{0n}^2 \n", " - \\alpha_1^{-1}\\alpha_3^{-1}\\sum_{n=12}^{15}{}a_{0n}^2 = 0\\\\\n", " &\\sum_{n=0}^3\\Biggl(\\alpha_{n+4}\\sum_{l=4n}^{4n+1}a_{02l}^2+\\alpha_{n+4}^{-1}\\sum_{l=4n+2}^{4n+3}a_{02l}^2\\Biggr) = 0\\\\\n", " &\\alpha_1\\sum_{n=0}^1\\Biggl(\\alpha_{n+4}\\sum_{l=4n}^{4n+1}a_{02l}^2+\\alpha_{n+4}^{-1}\\sum_{l=4n+2}^{4n+3}a_{02l}^2\\Biggr) + \\alpha_1^{-1}\\sum_{n=2}^3\\Biggl(\\alpha_{n+4}\\sum_{l=4n}^{4n+1}a_{02l}^2+\\alpha_{n+4}^{-1}\\sum_{l=4n+2}^{4n+3}a_{02l}^2\\Biggr) = 0\\\\\n", " &\\sum_{n=0}^1\\alpha_{n+1}\\Biggl(\\alpha_{2n+4}\\sum_{l=0}^{1}a_{0(8n+l)}^2+\\alpha_{2n+4}^{-1}\\sum_{l=0}^{1}a_{{02(8n+l+2)}}^2\\Biggr) + \\sum_{n=0}^1\\alpha_{n+1}^{-1}\\Biggl(\\alpha_{2n+5}\\sum_{l=0}^{1}a_{0(8n+l+5)}^2+\\alpha_{2n+2}^{-1}\\sum_{l=0}^{1}a_{{02(8n+l+6)}}^2\\Biggr) = 0\\\\\n", " &\\sum_{n=0}^1\\alpha_{1}^{(-1)^n}\\alpha_{n+1}\\Biggl(\\alpha_{2n+4}\\sum_{l=0}^{1}a_{0(8n+l)}^2+\\alpha_{2n+4}^{-1}\\sum_{l=0}^{1}a_{{02(8n+l+2)}}^2\\Biggr) \n", " + \\sum_{n=0}^1\\alpha_{1}^{(-1)^n}\\alpha_{n+1}^{-1}\\Biggl(\\alpha_{2n+5}\\sum_{l=0}^{1}a_{0(8n+l+5)}^2+\\alpha_{2n+2}^{-1}\\sum_{l=0}^{1}a_{{02(8n+l+6)}}^2\\Biggr) = 0\\\\\n", "\\end{aligned}\n", "$$" ] }, { "cell_type": "markdown", "id": "438da276", "metadata": {}, "source": [ "By solving the above system of equations, it is possible to construct a unitary matrix whose first column vector corresponds to an arbitrary input sequence." ] }, { "cell_type": "markdown", "id": "40843de0", "metadata": {}, "source": [ "### **Index List**" ] }, { "cell_type": "markdown", "id": "25523a5c", "metadata": {}, "source": [ "\n", "|argument name|type|role|\n", "|---|---|---|\n", "|vec|list(elements:float)|A list of normalized coefficients used in the linear combination|" ] }, { "cell_type": "markdown", "id": "932cfe14", "metadata": {}, "source": [ "### **Return**" ] }, { "cell_type": "markdown", "id": "df53da88", "metadata": {}, "source": [ "\n", "coeff_list (list): \\\n", "A list containing the computed results. Required for executing the mat_make function." ] }, { "cell_type": "markdown", "id": "2316c217", "metadata": {}, "source": [ "### **Python code**" ] }, { "cell_type": "markdown", "id": "7245efb1", "metadata": {}, "source": [ "```python\n", "def coeff_make(vec):\n", " \"\"\"\n", " This function generates the arguments used by the mat_make function within this package.\n", " It is strongly recommended to use the output of this function when executing mat_make.\n", " This function solves the system of equations described above.\n", " (a_i is the input value, and α_i is the desired solution.)\n", "\n", " Parameters:\n", " vec: The first column vector of the unitary matrix to be constructed\n", "\n", " Returns:\n", " list: the desired solution\n", " \"\"\"\n", " # Local Value\n", " coeff_list = [] # A list to store the desired solution\n", " cal_list = [] # A list to store the sumation (ex: a_1 + a_2 + a_3 + a_4) \n", " # Solve the system of equations\n", " if len(vec) == 2:\n", " print(\"You do not need to calculate coefficients!!\")\n", " return [vec[1], vec[0]]\n", " else:\n", " # Take the sum over a subset of the input values, 'vec' \n", " for i in range(int(np.log2(len(vec))) - 1):\n", " pre_list = []\n", " sep_num = 2**(i+1)\n", " elelen = len(vec)\n", " for j in range(sep_num):\n", " sum_list = vec[elelen//sep_num*j: \n", " (elelen//sep_num*(j+1))]\n", " sum_pow = np.sum(np.array(sum_list)**2)\n", " if sum_pow == 0:\n", " pre_list.append(1)\n", " else:\n", " pre_list.append(sum_pow)\n", " cal_list.append(pre_list)\n", " # Compute the square of the ratio of two sums\n", " for i in range(len(cal_list)):\n", " save_list = []\n", " for j in range(len(cal_list[i])//2):\n", " save_list.append(np.sqrt(cal_list[i]\\\n", " [2*j]/cal_list[i][2*j+1]))\n", " coeff_list.append(save_list)\n", " return coeff_list\n", "```" ] }, { "cell_type": "markdown", "id": "cd54d364", "metadata": {}, "source": [ "### **Sample Run**" ] }, { "cell_type": "code", "execution_count": null, "id": "de762da1", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pitbe" ] }, { "cell_type": "code", "execution_count": null, "id": "85163b7a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1.483163853864426], [1.3228881288499281, 0.5590366356510099]]\n" ] } ], "source": [ "input_vector = [0.5, 0.433, 0.25, 0.433, 0.433, 0.3536, 0., 0.]\n", "print(pitbe.coeff_make(input_vector))" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }