[GAP Forum] Adding One to a Vector
Max Neunhoeffer
max.neunhoeffer at math.rwth-aachen.de
Mon Mar 5 12:10:37 GMT 2007
Dear Ian,
The following completes in 35 seconds on one of our machines and
probably does what you want:
i := Iterator(GF(2)^24);
while not(IsDoneIterator(i)) do
v := NextIterators(i);
# Do something with v
od;
It produces all vectors you want one after another. Unfortunately,
the vectors coming out of this are not yet compressed. So you probably
want to add a "ConvertToVectorRep(v,2)" in the loop, depending on your
applications.
Also you cannot change the order in which the vectors occur.
Note that there is also an enumerator, but this is much slower.
I hope this helps, if not, please do not hesitate to ask again.
Best regards,
Max.
On Mon, Mar 05, 2007 at 10:44:10AM +0000, Ian McLoughlin wrote:
> Hi everyone,
>
> I need to loop over all the vectors of length 24 over GF(2) of weight at
> least 8. The current way I'm doing this is the following....
>
>
> AddOne := function( vector )
>
> local i ;;
>
> for i in [24,23..1] do
>
> if ( vector[i] = 0*Z(2) ) then
>
> vector[i] := 1*Z(2) ;;
> break ;;
>
> fi ;;
>
> if ( vector[i] = 1*Z(2) ) then
>
> vector[i] := 0*Z(2) ;;
>
> fi ;;
>
> od ;;
>
> end ;;
>
>
> start := Z(2) * [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0] ;;
> zerovec := Z(2) * [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ;;
>
> ConvertToVectorRep( start , GF(2) ) ;;
> ConvertToVectorRep( zerovec , GF(2) ) ;;
>
> while ( start <> zerovec ) do
>
> AddOne( start ) ;;
>
> if ( WeightVecFFE( start ) < 8 ) then
> continue ;;
> fi ;;
>
> od ;;
>
>
>
> Obviously I do some stuff with each new value of start, but I've omitted it
> to make my email less ugly. :)
> The reason I wrote my own method called AddOne was because I couldn't find
> any Gap method that did the equivalent of c's "start++;".
> Apologies for representing the vector backwards(compared to the usual in
> Gap) by the way!
>
> My question is this: does Gap have an inbuilt method to add one to a binary
> vector as if the whole vector represented a single number(i.e. with
> carrying)?
> If anyone has a suggestion as to how to loop through all binary vectors of
> length 24 and weight at least eight another way I'd love to hear it too! My
> main concern is speed!
>
> Thanks a lot,
> Ian
>
>
> --
> Ian McLoughlin
> emailme at ianmcloughlin.com
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>
--
# # Max Neunhoeffer <max.neunhoeffer at math.rwth-aachen.de>
##### Gerlachstrasse 20-22, 52064 Aachen, Germany (private)
# # Lehrstuhl D fuer Mathematik, RWTH, Templergraben 64, 52062 Aachen
##### Tel.: +49 241 406605 (private) / +49 241 8094550 (institute)
# # May the Source be with you!
More information about the Forum
mailing list