##
## BIBINAIRE
##




# conversion binaire

bine:=proc(n)
 local q,L,B,k;
 q:=iquo(n,2);
 L:=irem(n,2);
 while q>0 do
   L:=L,irem(q,2);
   q:=iquo(q,2);
 od;
 L:=[L];
 L:=[seq(L[-k],k=1..nops(L))];
 end:



bine(256);

                     [1, 0, 0, 0, 0, 0, 0, 0, 0]



# conversion décimal -> bibinaire

bibine:=proc(n)
 local bi,bibi,k;
   bi:=bine(n);
   while evalb(irem(nops(bi),4)=0)=false do bi:=[0,(op(bi))];od;
   bibi:=NULL;
   for k from nops(bi) to 1 by -4 do
     if evalb(bi[-k..-k+1]=[0,0])=true then bibi:=bibi,H;
     elif evalb(bi[-k..-k+1]=[0,1])=true then bibi:=bibi,B;
     elif evalb(bi[-k..-k+1]=[1,0])=true then bibi:=bibi,K;
     else bibi:=bibi,D;
     fi;
  
     if evalb(bi[-k+2...-k+3]=[0,0])=true then bibi:=bibi,O;
     elif evalb(bi[-k+2..-k+3]=[0,1])=true then bibi:=bibi,A;
     elif evalb(bi[-k+2..-k+3]=[1,0])=true then bibi:=bibi,E;
     else bibi:=bibi,I;
     fi;
   od;
   [bibi];
   end:
  


bibine(2751);

                          [K, E, K, I, D, I]


# table des seize caractères bibinaires

decod:=table([seq(bibine(k)=k,k=0..15)]):


# conversion bibinaire -> décimal

enibib:=proc(L)
   local N,k;
   N:=0;
   for k from 1 to nops(L)-1 by 2 do
   N:=N+decod[L[k..k+1]]*16^((nops(L)-(k-1))/2-1);
   od;
   N;
   end:


enibib([K,E,K,I,D,I]);

                        2751


###
### GROUPES FINIS
###


 ordre:=proc(k,U)
 local j;
 j:=1;
 while evalc((U[k])^j)<>1 do
 j:=j+1:
 od;
 j;
 end:
 
 GroupeFini:=proc(n)
 local U,A,T,k,i,j,o,x;
  U:=[seq(exp(2*I*k*Pi/n),k=0..n-1)]:
 A:=[seq([seq(evalc(U[i]*U[j]),j=1..n)],i=1..n)]:
 T:=convert(A,array):
 o:=seq(ordre(x,U),x=1..n);
 print(U);
 print(o);
 print(T);
 end:
 
 
 
 GroupeFini(3);

                                1/2                 1/2
             [1, - 1/2 + 1/2 I 3   , - 1/2 - 1/2 I 3   ]


                               1, 3, 3


            [                  1/2                 1/2  ]
            [1 ,- 1/2 + 1/2 I 3    ,- 1/2 - 1/2 I 3     ]
            [                                           ]
            [               1/2                 1/2     ]
            [- 1/2 + 1/2 I 3    ,- 1/2 - 1/2 I 3    ,1  ]
            [                                           ]
            [               1/2                    1/2  ]
            [- 1/2 - 1/2 I 3    ,1 ,- 1/2 + 1/2 I 3     ]

>