coeff_make
概要
この関数では本パッケージ内の関数”mat_make”でもちいる引数を作成する
“mat_make”の実行においては本関数による出力結果を用いることを強く推奨する
この関数は入力するvecのlengthによって変化する方程式を解いている
例えばlengthが8の場合は以下のような方程式を解いている
ここでは\(a_i\)が入力値であり、\(\alpha_i\)が出力値である
\[\begin{split}\begin{aligned}
&\alpha_1\sum_{n=0}^{7}{}a_{0n}^2
- \alpha_1^{-1}\sum_{n=8}^{15}{}a_{0n}^2 = 0\\
&\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
- \alpha_3^{-1}\sum_{n=12}^{15}{}a_{0n}^2 = 0\\
&\alpha_1\alpha_2\sum_{n=0}^{3}{}a_{0n}^2
- \alpha_1\alpha_2^{-1}\sum_{n=4}^{7}{}a_{0n}^2 +
\alpha_1^{-1}\alpha_3 \sum_{n=8}^{11}{}a_{0n}^2
- \alpha_1^{-1}\alpha_3^{-1}\sum_{n=12}^{15}{}a_{0n}^2 = 0\\
&\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\\
&\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\\
&\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\\
&\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)
+ \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\\
\end{aligned}\end{split}\]
以上の連立方程式を解くことにより、任意の数列に対して数列を一番目の列ベクトルとするユニタリ行列を作成できる、
引数一覧
argument name |
type |
role |
---|---|---|
vec |
list(elements:float) |
線型結合で表現したときの係数を規格化したlist |
戻り値
coeff_list (list): 計算結果が格納されたlist。”mat_make”の実行において必要となる。
Python code
def coeff_make(vec):
"""
This function generates the arguments used by the mat_make function within this package.
It is strongly recommended to use the output of this function when executing mat_make.
This function solves the system of equations described above.
(a_i is the input value, and α_i is the desired solution.)
Parameters:
vec: The first column vector of the unitary matrix to be constructed
Returns:
list: the desired solution
"""
# Local Value
coeff_list = [] # A list to store the desired solution
cal_list = [] # A list to store the sumation (ex: a_1 + a_2 + a_3 + a_4)
# Solve the system of equations
if len(vec) == 2:
print("You do not need to calculate coefficients!!")
return [vec[1], vec[0]]
else:
# Take the sum over a subset of the input values, 'vec'
for i in range(int(np.log2(len(vec))) - 1):
pre_list = []
sep_num = 2**(i+1)
elelen = len(vec)
for j in range(sep_num):
sum_list = vec[elelen//sep_num*j:
(elelen//sep_num*(j+1))]
sum_pow = np.sum(np.array(sum_list)**2)
if sum_pow == 0:
pre_list.append(1)
else:
pre_list.append(sum_pow)
cal_list.append(pre_list)
# Compute the square of the ratio of two sums
for i in range(len(cal_list)):
save_list = []
for j in range(len(cal_list[i])//2):
save_list.append(np.sqrt(cal_list[i]\
[2*j]/cal_list[i][2*j+1]))
coeff_list.append(save_list)
return coeff_list
実行例
[1]:
import numpy as np
import pitbe
[2]:
input_vector = [0.5, 0.433, 0.25, 0.433, 0.433, 0.3536, 0., 0.]
print(pitbe.coeff_make(input_vector))
[[1.483163853864426], [1.3228881288499281, 0.5590366356510099]]