Advertisement
mate2code

Equivalence classes (sec, bec) of Boolean functions

Jul 25th, 2013
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.88 KB | None | 0 0
  1. % Calculations of the OEIS sequences A227722 (SecList) and A227723 (BecList)
  2. % If not stopped manually, these scripts check all the 2^32 5-ary Boolean functions,
  3. % which would probably take some weeks.
  4.  
  5. % BitPerm32 = oeis.org/A195665/a195665_3.txt
  6. BitPerm32 = BitPerm32(1:120,1:32) + 1 ;
  7.  
  8. SecPerm32 = zeros(32) ;
  9. for m=1:32
  10.     for n=1:32
  11.         SecPerm32(m,n) = bitxor(m-1,n-1) ;
  12.     end
  13. end
  14. SecPerm32 = SecPerm32 + 1 ;
  15.  
  16. BecPerm32 = zeros(3840,32) ;
  17. for m=1:120
  18.     for n=1:32
  19.         BecPerm32(   (m-1)*32 + n   ,   1:32   ) = SecPerm32(   n   ,   BitPerm32(m,:)   ) ;
  20.     end
  21. end
  22.  
  23. Powtwo32 = zeros(32,1) ;
  24. for m=0:31
  25.     Powtwo32(32-m) = 2^m ;
  26. end
  27.  
  28.  
  29. Bin16char = dec2bin(0:65535) ;
  30. Bin16 = false(65536,16) ;
  31. for m=1:65536
  32.     for n=1:16
  33.         Bin16(m,n) = str2double( Bin16char(m,n) ) ;
  34.     end
  35. end
  36. clear Bin16char
  37.  
  38. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39.  
  40. % SecList
  41. SecList = 0 ;
  42. SecListLong = 1 ;
  43. for m=1:65536
  44.     Bin32 = [  repmat(Bin16(m,:),65536,1)  Bin16  ] ;
  45.     for n=1:65536
  46.         F = Bin32(n,:) ;
  47.         Sec = selfintersect( F(SecPerm32) ) ;
  48.         Candidate = Sec(1,:)*Powtwo32 ;
  49.         if Candidate > SecList(end)
  50.             SecList(end+1) = Candidate ;
  51.             SecListLong = SecListLong + 1
  52.         end
  53.     end
  54. end
  55.  
  56. % BecList
  57. LastSec = 0 ;
  58. BecList = 0 ;
  59. BecListLong = 1 ;
  60. for m=1:65536
  61.     Bin32 = [  repmat(Bin16(m,:),65536,1)  Bin16  ] ;
  62.     for n=1:65536
  63.         F = Bin32(n,:) ;
  64.         Sec = selfintersect( F(SecPerm32) ) ;
  65.         PreCandidate = Sec(1,:)*Powtwo32 ;
  66.         if PreCandidate > LastSec
  67.             LastSec = PreCandidate ;
  68.             Bec = selfintersect( F(BecPerm32) ) ;
  69.             Candidate = Bec(1,:)*Powtwo32 ;
  70.             if Candidate > BecList(end)
  71.                 BecList(end+1) = Candidate ;
  72.                 BecListLong = BecListLong + 1
  73.             end
  74.         end
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement