Advertisement
mate2code

Walsh spectra of 2-ary Boolean functions

Jun 22nd, 2019
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # https://en.wikiversity.org/wiki/Equivalence_classes_of_Boolean_functions#Walsh
  2.  
  3. import numpy as np
  4.  
  5. bin_walsh = np.array([[0, 0, 0, 0],
  6.                       [0, 1, 0, 1],
  7.                       [0, 0, 1, 1],
  8.                       [0, 1, 1, 0]])
  9.  
  10. walsh = (bin_walsh * -2) + 1
  11.  
  12. def int_to_bin_vect(n):
  13.     bin_str = format(n, 'b').zfill(4)[::-1]
  14.     bin_vect = [int(char) for char in bin_str]
  15.     return np.array(bin_vect)
  16.  
  17. arr_f = np.zeros((0, 4), np.int8)
  18. arr_ws = np.zeros((0, 4), np.int8)
  19. arr_bws = np.zeros((0, 4), np.int8)
  20.  
  21. for n in range(16):
  22.     f = int_to_bin_vect(n)
  23.     ws = np.dot(f, walsh)
  24.     bws = np.mod(np.dot(f, bin_walsh), 2)
  25.  
  26.     arr_f   = np.vstack((arr_f  , f  ))
  27.     arr_ws  = np.vstack((arr_ws , ws ))
  28.     arr_bws = np.vstack((arr_bws, bws))
  29.  
  30. print(arr_f)
  31. print(arr_ws)
  32. print(arr_bws)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement