# Can't find error in my code

Please refer to my question at https://ask.sagemath.org/question/638...

According to the suggestion given in the end by Max Alekseyev I have made a complete code. Here I am showing only the initial part , as problem lies in it . I don't know what I am missing or what mistake I have made.

`M = matrix(3,3, [1, 1, 1, -1, 1, 1, -1, -1, 1]) List_S=[M^0,M^1,M^2] n = 3 V = GF(2)^(n^2) VL1=V.list()[1:] # Removing the all-zero list because not needed for our purpose VL2=VL1[:-1] #Removing the all-ones list because not needed for our purpose P=[] for v in VL2: P.append(matrix(ZZ,n,n,v)) #Forming n by n matrices from list in VL2. Contains all 0,1 matrices. N=[] for p in P: k=-p N.append(k) #Forming n by n matrices from P by taking their negative. Contains all 0,-1 matrices U = [] for a in P: U.append(a) for b in N: U.append(b) #Taking union of P and N show("U=",len(U)) def mat_to_vector(m): temp = [] for i in range(m.ncols()): for j in range(m.nrows()): temp.append(m[i][j]) return(vector(temp)) #Defining a function which converts matrix to vector CAND=[] for i in range(len(U)): List_U=[U[i]] List_SU=List_S+List_U W=U[:] W.remove(W[i]) T=tuple(List_SU) X = ZZ^(n^2) Y = X.span(mat_to_vector(T[i]) for i in range(len(T))) for w in W: if mat_to_vector(w) in Y: CAND.append(mat_to_vector(w)) VTM=[matrix(ZZ,n,n,u) for u in CAND] for b in VTM: b.set_immutable() B = set(VTM) show("B=",len(B))`

According to the suggestion, len(B) should come out to be less than len(U). But it is coming out to be same as len(U). Kindly find the error.

Can you explain what your code does, what are

`B`

and`U`

and why length of`B`

should be smaller than that of`U`

?Btw,

can be simplified to

`U.extend(P)`

.Commented the code, to make it clear. First, formed (in P) all possible 0,1 matrices(excluding all zero and all ones matrices). Took their negatives(in N) and took U to be union of P and N, to get all possible 0,1 and 0,-1 matrices(len(U)=1020) . The candidates(pl. see the previous link) for A2,A3,A4 should come from U only. In List_SU taking A1 to be U[i] and running i over the range(len(U)) we are going over all 0,1 and 0,-1 matrices A1. W being a copy of U, removed this U[i] and checked which of the remaining 1019 elements in W are in the span of T(=tuple(List_SU)). The corresponding matrices VTM would be be the candidates for A2,A3,A4. To remove repetions in VTM formed its set B. But len(B) is also ...(more)