[GAP Forum] Adding One to a Vector

Ian McLoughlin emailme at ianmcloughlin.com
Mon Mar 5 10:44:10 GMT 2007


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


More information about the Forum mailing list