Trouble creating a set of vectors
I'm writing a script to compute the numbers of vectors with a given property.
I would like it to work is as the following does, so adding a vector to the set at every cycle
T = []
for j in GF(8):
c = (j)
T.append(j)
print(T)
That gives the following output
[0]
[0, z3]
[0, z3, z3^2]
[0, z3, z3^2, z3 + 1]
[0, z3, z3^2, z3 + 1, z3^2 + z3]
[0, z3, z3^2, z3 + 1, z3^2 + z3, z3^2 + z3 + 1]
[0, z3, z3^2, z3 + 1, z3^2 + z3, z3^2 + z3 + 1, z3^2 + 1]
[0, z3, z3^2, z3 + 1, z3^2 + z3, z3^2 + z3 + 1, z3^2 + 1, 1]
(the only purposeof the print
is to show how I want my set to be built).
However the actual code does this:
T = []
for j in GF(8):
b = random_matrix(GF(8), 1, 3)
b[0, 0] = j
T.append(b)
print(T)
[[ 0 z3^2 z3^2 z3 + 1]]
[[ z3 z3^2 z3^2 z3 + 1], [ z3 z3^2 z3^2 z3 + 1]]
[[ z3^2 z3^2 z3^2 z3 + 1], [ z3^2 z3^2 z3^2 z3 + 1], [ z3^2 z3^2 z3^2 z3 + 1]]
[[z3 + 1 z3^2 z3^2 z3 + 1], [z3 + 1 z3^2 z3^2 z3 + 1], [z3 + 1 z3^2 z3^2 z3 + 1], [z3 + 1 z3^2 z3^2 z3 + 1]]
[[z3^2 + z3 z3^2 z3^2 z3 + 1], [z3^2 + z3 z3^2 z3^2 z3 + 1], [z3^2 + z3 z3^2 z3^2 z3 + 1], [z3^2 + z3 z3^2 z3^2 z3 + 1], [z3^2 + z3 z3^2 z3^2 z3 + 1]]
[[z3^2 + z3 + 1 z3^2 z3^2 z3 + 1], [z3^2 + z3 + 1 z3^2 z3^2 z3 + 1], [z3^2 + z3 + 1 z3^2 z3^2 z3 + 1], [z3^2 + z3 + 1 z3^2 z3^2 z3 + 1], [z3^2 + z3 + 1 z3^2 z3^2 z3 + 1], [z3^2 + z3 + 1 z3^2 z3^2 z3 + 1]]
[[z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1], [z3^2 + 1 z3^2 z3^2 z3 + 1]]
[[ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1], [ 1 z3^2 z3^2 z3 + 1]]
So instead of adding the new vector it turns the set into a copy of several vectors all equal to the new one.
What's the problem in my code? And how can I solve it?
Hello, @Alain Ngalani! I don't seem to have this problem. Check this code. However, I am not 100% sure, because your code is wrongly indented.
By the way, here are a few details you might be interest on. There is also a
random_vector()
function which seems to better fit your code.I should point out that your code is not recursive (in the sense of computer science), nor is it a method (in the sense of computer science again). Perhaps the question should be edited to reflect more properly the situation. Perhaps simply write "why my code to define a set of vectors doesn't work?"
Indeed your code works, I made an error writing my wrong code. It should be this that as you see doesn't work well
I see... I have tried modify your original question so that it reflects that fact. Unfortunately, Ask SageMath won't let me, for some unknown reason (I just get an "oops, something went wrong" message.) Would you kind enough to make the change yourself? This question you pose is a very common issue, so somebody in the future will have the same problem, and can refer to your question and the answer I added.
I hope this helps you clarify your doubts. Hopefully, it won't add new ones.