-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2BGA.gap
205 lines (174 loc) · 7.19 KB
/
2BGA.gap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#! This GAP program verifies parameteAOArs of the 2BGA codes constructed for the paper
#! Quantum two-block group algebra codes
#! by Hsiang-Ku Lin and Leonid P. Pryadko
## Using the script file, para.sh to find the parameter set. The 1st, 2nd, 3nd, 4th, 5th, and 6th columns are corresponding to the group size, group number, dimension, distance, and position sets of the group elements a and b excluding identity respectively.
## example of a parameter set, 42 6 10 3 [ 3 ] [ 4, 12, 24 ]
## Using the function, checkdata, to verifies the dimension and distance of the codes
## example, checkdata(SmallGroup(42,6),[3],[4,12,24]);
## Usinh the function, checkrank, to calculate the ranks of parity check matrices and the ranks of A, B, AB and delta_x and delta_z defined in the paper.
## example, checkrank(SmallGroup(42,6),[3],[4,12,24]);
# adjust the path in the second argument if needed
#SetPackagePath("QDistRnd","./QDistRnd" );
# package available from https://github.com/QEC-pages/QDistRnd/
LoadPackage("QDistRnd");
# adjust the path to run the gap program if needed
#Read("MY_PATH/2BGA.gap");
# set up the code in binary field
F:=GF(2);
#LeftMat(elt,gg); Rightmat(elt,gg);
#Given a group, grp, and a sigle group element, elt, from GAP small group library, the function RightMat and LeftMat return the right matrix of elt, R(g) and L(g) respectively.
LeftMat:=function(elt,grp)
local i,j,lis,n,miset,mi,mj,mip,veclist,vecperm,vec;
lis:=Elements(grp);
n:=Length(lis);
miset:=[];
veclist:=[];
for j in [1..n] do
mj:=lis[j];
mi:=elt*mj;
Append(miset,[mi]);
od;
for i in [1..n] do
mip:=Position(miset,lis[i]);
Add(veclist,mip);
od;
vecperm:=PermList(veclist);
vec:=PermutationMat(vecperm,n,1);
return vec;
end;
RightMat:=function(elt,grp)
local i,j,lis,n,miset,mi,mj,mip,veclist,vecperm,vec;
lis:=Elements(grp);
n:=Length(lis);
miset:=[];
veclist:=[];
for j in [1..n] do
mj:=lis[j];
mi:=mj*elt;
Append(miset,[mi]);
od;
for i in [1..n] do
mip:=Position(miset,lis[i]);
Add(veclist,mip);
od;
vecperm:=PermList(veclist);
vec:=PermutationMat(vecperm,n,1);
return vec;
end;
# the functions Alcomb and Brcomb are used to calculate Eq. (36) in the paper.
# Alcomb([2,3,4],gg) Brcomb([5,6,15],gg)
# The 2nd argument, gg= SmallGroup(n1,n2). n1 and n2 are the values of the 1st and 2nd columns. The 1st arguemnt in the functions of Alcomb and Brcomb are the values of 5th and 6th columns from the parameters set.
# Given a group, grp and a subset, elt1, the function Alcomb and Brcomb return the left and right matrices, A=I+L(g1)+L(g2)+... and B=I+R(g1)+R(g2)+... respectively.
# In gap, the whole group elements can be obtained from the command, Elements(grp). In the first argument of the function, [n1,n2,n3,..] represents the positions of those elements respectively.
Alcomb:=function(elt1,grp)
local elts,Al,id,n,list;
elts:=Elements(grp);
n:=Length(elts);
id:=IdentityMat(n);
Al:=(id+Sum(elt1,i->LeftMat(elts[i],grp)))*One(F);
#Display(Al);
return Al;
end;
Brcomb:=function(elt1,grp)
local elts,Br,id,n,list;
elts:=Elements(grp);
n:=Length(elts);
id:=IdentityMat(n);
Br:=(id+Sum(elt1,i->RightMat(elts[i],grp)))*One(F);
#Display(Br);
return Br;
end;
# the function gxgzcomb return the parity matrices Hx and HzT for the Eq. (16) in the paper.
# gxgzcomb([2,3],[4,5],gg) or gxgzcomb([2],[4,5,15,18],gg)
# Given a group, grp and the subsets of elt1 [ga1,ga2,..] and elt2 [gb1,gb2,...], gxgzcomb retruns and parity matrices Hx and HzT.
# The 1st and 2nd arguments in the funtion are corresponding to the vaules of 5th and 6th columns in the parameter set (a and b defined in the paper).
gxgzcomb:=function(elt1,elt2,grp)
local list,elts,Al,Br,id,AA,BB,AAT,BBT,gx,gzT,n;
elts:=Elements(grp);
n:=Length(elts);
id:=IdentityMat(n);
Al:=Sum(elt1,i->LeftMat(elts[i],grp));
Br:=Sum(elt2,i->RightMat(elts[i],grp));
AA:=TransposedMat(id+Al);
BB:=TransposedMat(id+Br);
BBT:=TransposedMat(id+TransposedMat(Br));
AAT:=TransposedMat(id+TransposedMat(Al));
gx:=TransposedMatMutable(Concatenation(AA,BB))*One(F);
gzT:=Concatenation(BBT,AAT)*One(F);
list:=[gx,gzT];
return list;
end;
# the function connected checks if a matrix is connected matrix or not.
# the function connected returns an empty list if a matrix is connected.
connected:=function(mat)
local i,len,check,checklist,che,eltset,eltset1,pos;
len:=Length(mat);
checklist:=[];
eltset:=[1..2*len];
check:=Positions(mat[1],Z(2)^0);
if not 1=check[1] then
SubtractSet(eltset,check);
Append(checklist,check);
check:=Positions(mat[checklist[1]],Z(2)^0);
else
Append(checklist,check);
fi;
i:=1;
while Length(checklist)>0 and Length(eltset)>0 do
SubtractSet(eltset,check);
Remove(checklist,1);
if Length(checklist)>0 then
che:=((checklist[1]-1) mod len)+1;
check:=Positions(mat[che],Z(2)^0);
fi;
eltset1:=[1..2*len];
SubtractSet(eltset1,eltset);
SubtractSet(check,eltset1);
Append(checklist,check);
i:=i+1;
od;
return eltset;
end;
## the function checkrank check if rank(Hx)=rank(Hz)>rank(A)+rank(B)-rank(AB)
## checkrank(gg,[3],[3,5,8]), where gg:=SmallGroup(10,1),setA and setB are the subsets excluding Identity (a and b defined in the paper).
## the function returns set:=[len,ss,k,setA,setB,rankHx,rankHz,rankA,rankB,diff,diff]. The return list represents: the size of the group, len; the number of the group, ss; the dimension of the code, k; two elements a and b, setA and setB; the ranks of Hx, Hz, A, B, and AB, deltax and deltaz.
checkrank:=function(grp,setA,setB)
local len,ss,gxz,k,rankHx,rankHz,al,br,rankA,rankB,rankAB,set,deltax,deltaz,diff;
len:=Size(grp);
ss:=IdSmallGroup(grp)[2];
Print("Abelian?",IsAbelian(grp),"\n");
gxz:=gxgzcomb(setA,setB,grp);
if connected(gxz[1])=[] and connected(TransposedMat(gxz[2]))=[] then
k:=2*len-RankMat(gxz[2])-RankMat(gxz[1]);
if k>0 then
rankHx:=RankMat(gxz[1]);
rankHz:=RankMat(gxz[2]);
al:=Alcomb(setA,grp)*One(F);
br:=Brcomb(setB,grp)*One(F);
rankA:=RankMat(al);
rankB:=RankMat(br);
rankAB:=RankMat(al*br);
diff:=rankA+rankB-rankAB;
deltax:=rankA+rankB-rankAB-rankHx;
deltaz:=rankA+rankB-rankAB-rankHz;
set:=[len,ss,k,setA,setB,rankHx,rankHz,rankA,rankB,rankAB,deltax,deltaz];
fi;
fi;
return set;
end;
# the function checkdata calculates the dimension and the distance of the codes given the group, grp, and group elements, a and b.
# the return list represts the group size id[1], the group number id[2], the dimension kk, the distance dd, the group eleemnts a and b and the last item is an empty list if the parity matrices Hx and HzT are both connected matrices.
checkdata:=function(grp,elt1,elt2)
local gxz,rescon,id,len,kk,dd,final;
dd:=0;
id:=IdSmallGroup(grp);
len:=id[1];
gxz:=gxgzcomb(elt1,elt2,grp);
if connected(gxz[1])=[] and connected(TransposedMat(gxz[2]))=[] then rescon:="conntected"; else rescon:="not connected"; fi;
kk:=2*len-RankMat(gxz[2])-RankMat(gxz[1]);
if kk>0 then
dd:=DistRandCSS(TransposedMat(gxz[2]),gxz[1],100000,1: field:=F,maxav:=10);
fi;
final:=[id[1],id[2],kk,dd,elt1,elt2,rescon];
return final;
end;