The wikipedia definition for span(S):
http://en.wikipedia.org/wiki/Linear_span#Definition
So for doing the sum, we can first make a list of all possible coefficients. For the binary case (q = 2), it will be all possible n-tuples containing 0 and 1. So that is just: Tuples[{0,1},n] where n is the number of vectors in S.
Now to find the span, we need to add the basis vectors with different choices for the coefficients. Each possible choice is an element from Tuples[{0,1},n] . So, we just have to do a vector dot product of an element from this set and S. This will give one possible linear combination. Similarly, we can do all the linear combinations.
span[S_] := (coef = Tuples[{0, 1}, Length[S]]; Map[Mod[#1, 2] &, Table[coef[[i]].S, {i, 1, Length[coef]}], {2}]);
Just one small issue was that the dot product will produce vectors with integer (numbers other than 0 and 1) components. But then finally we can replace every such component to itself Mod 2. That was the purpose of putting the Map
function.
For the case of general (non-binary) fields, we have coef
defined as:
coef = Tuples[Range[0,q-1],Length[S]]
where $F_q$ is a field ($q$ is a prime power). Hence the argument to the Map
function will change accordingly.
span[S_,q_] := (coef = Tuples[Range[0,q-1], Length[S]]; Map[Mod[#1, q] &, Table[coef[[i]].S, {i, 1, Length[coef]}], {2}]);
Hope this is a simple solution. Here is a output for $q = 2$ case:
In[46]:= span[S_, q_] := (coef = Tuples[Range[0, q - 1], Length[S]]; Map[Mod[#1, q] &, Table[coef[[i]].S, {i, 1, Length[coef]}], {2}])
In[51]:= BAS
Out[51]= {{1, 0, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 1, 0, 0}, {1, 1, 0, 1, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0}}
In[50]:= span[BAS, 2]
Out[50]= {{0, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0}, {0, 1, 0, 0, 1, 0, 0}, {1, 1, 1, 0, 1, 0, 0}, {1, 0, 0, 1, 1, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 1, 0, 0, 0, 1, 0}, {1, 1, 1, 0, 0, 1, 0}, {1, 0, 0, 1, 0, 1, 0}, {0, 0, 1, 1, 0, 1, 0}, {0, 0, 0, 0, 1, 1, 0}, {1, 0, 1, 0, 1, 1, 0}, {1, 1, 0, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 0}, {1, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 0, 0, 0, 1}, {0, 1, 0, 1, 0, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {1, 1, 0, 0, 1, 0, 1}, {0, 1, 1, 0, 1, 0, 1}, {0, 0, 0, 1, 1, 0, 1}, {1, 0, 1, 1, 1, 0, 1}, {1, 1, 0, 0, 0, 1, 1}, {0, 1, 1, 0, 0, 1, 1}, {0, 0, 0, 1, 0, 1, 1}, {1, 0, 1, 1, 0, 1, 1}, {1, 0, 0, 0, 1, 1, 1}, {0, 0, 1, 0, 1, 1, 1}, {0, 1, 0, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}
It works for $q = 3$ with the same basis set BAS
. But, sorry, the output is fairly long to paste it here.