Advertisement
Benjamin_Loison

LGformel.py

Mar 18th, 2021
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. def getBin(x):
  2.     return list(reversed([int(i) for i in bin(x)[2:]]))
  3.    
  4. def getExtendedBin(x, n):
  5.     bin = getBin(x)
  6.     binLen = len(bin)
  7.     for i in range(binLen, n):
  8.         bin += [0]
  9.     return bin
  10.  
  11. def testGet(n, c):
  12.     return [c + str(i) for i in range(n)]
  13.  
  14. def getW(a, b, max):
  15.     #n = 4
  16.     #aL, bL = testGet(n, 'a'), testGet(n, 'b')
  17.     #aL, bL = getBin(a), getBin(b)
  18.     aLLen = len(getBin(max))
  19.     #aL = getBin(a, aLLen)
  20.     aL = getExtendedBin(a, aLLen)
  21.     #aL = getBin(a)
  22.     #aLLen = len(aL)
  23.     bL = getExtendedBin(b, aLLen)
  24.     res = []
  25.     #return [aL[i] + bL[i] for i in range(aLLen)]
  26.     for i in range(aLLen):
  27.         res += [aL[i]]
  28.         res += [bL[i]]
  29.     return res
  30.  
  31. def nextState(currentState, j):
  32.     # I will name (p) state by 6
  33.     #l = [[0, 1, 0], [0, 2, 1], [1, 0, 0], [1, 6, 1], [2, 6, 0], [2, 3, 1], [3, 4, 0], [3, 5, 1], [4, 6, 0], [4, 3, 1], [5, 3, 0], [5, 6, 1], [6, 6, 0], [6, 6, 1]] # src, dest, transition
  34.     l = [[1, 0], [2, 1], [0, 0], [6, 1], [6, 0], [3, 1], [4, 0], [5, 1], [6, 0], [3, 1], [3, 0], [6, 1], [6, 0], [6, 1]] # dest, transition
  35.     lLen = len(l)
  36.     for lIndex in range(lLen):
  37.         src = lIndex // 2
  38.         #src, dest, transition = l[lIndex]
  39.         dest, transition = l[lIndex]
  40.         if src == currentState and transition == j:
  41.             return dest
  42.     print("THIS SHOULDN'T OCCUR")
  43.            
  44. def automate(a, b, max):
  45.     w = getW(a, b, max)
  46.     print(w)
  47.     currentState = 0
  48.     wLen = len(w)
  49.     for wIndex in range(wLen):
  50.         wi = w[wIndex]
  51.         currentState = nextState(currentState, wi)
  52.     return currentState in [0, 3]
  53.  
  54. n = 0
  55. while True:
  56.     print("Working on n=" + str(n))
  57.     max = 2**(n)-1 # used to be n+1 - THIS DOESN'T MAKE EXAUSTIVE
  58.     for a in range(0, max):
  59.         for b in range(0, max):
  60.             first = (a + b) % (2**n) == 0
  61.             second = automate(a, b, max)
  62.             #if (first and not second) or (second and not first):
  63.             if first != second:
  64.                 print("Contre-exemple: " + str(a) + " " + str(b) + " " + str(first) + " " + str(second))
  65.     n += 1
  66.     #if n == 3:
  67.     #    break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement