Boolean Model

Last updated: August 28th, 20202020-08-28Project preview
In [1]:
import numpy as np
In [2]:
def OR(x,y):
    z = x + y -x*y
    return z 

def AND(x,y):
    z = x*y
    return z
In [6]:
def booleanTest(x):
    r1, r2, c1, c2, i1, i2, i3, i4, i5, i6, t1, t2 = x
    i1 = AND(r1,(1-i2))
    i2 = r2
    i3 = AND(i1,c1)
    i4 = i2
    i5 = AND(OR(i3, c2),(1-i4))
    i6 = AND(i3,i4)
    t1 = i5
    t2 = i6
    return np.array([r1,r2,c1,c2,i1,i2,i3,i4,i5,i6,t1,t2])
In [7]:
# [R1 R2 C1 C2 I1 I2 I3 I4 I5 I6 T1 T2]
f0 = np.array([1,0,1,1,0,0,0,0,0,0,0,0])
booleanTest(f0)
Out[7]:
array([1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0])
In [10]:
#  [L, T, TL, S, PK, A, PKA, P3, P2, PT, PTP, Ak, AP3, PD, PAP3, mT, P2AP3, P2A]
f0=[1, 1, 0,  0, 1,  1, 0,   0,  1,  1,  0,   1,  0,   1,  0,    1,  0,     0]

def booleanTLR(x):
    L, T, TL, S, PK, A, PKA, P3, P2, PT, PTP, Ak, AP3, PD, PAP3, mT, P2AP3, P2A = x 
    TL = AND(L,T)
    S = TL
    PKA = AND(AND(A,PK),S)
    P3 = AND(P2,PKA)
    PTP = AND(P3,PT)
    PT = AND(PTP,(1-P2A))
    AP3 = OR(AND(P3,Ak),AND(PAP3,PD))
    PAP3 = OR(AP3,AND(P2AP3,AND(mT,A)))
    P2AP3 = PAP3
    P2A = P2AP3
    return [L, T, TL, S, PK, A, PKA, P3, P2, PT, PTP, Ak, AP3, PD, PAP3, mT, P2AP3, P2A]
In [19]:
f0=[1, 1, 0,  0, 1,  1, 0,   0,  1,  1,  0,   1,  0,   1,  0,    1,  0,     0]
print('L=',f0[0],
      'T=',f0[1],
      'TL=',f0[2],
      'S=',f0[3], 
      'PK=',f0[4], 
      'A=',f0[5],
      'KA=',f0[6], 
      'P3=',f0[7],
      'P2=',f0[8],
      'PT=',f0[9],
      'PTP=',f0[10],
      'Ak=',f0[11],
      'AP3=',f0[12],
      'PD=',f0[13],
      'PAP3=',f0[14],
      'mT=',f0[15],
      'P2AP3=',f0[16],
      'P2A=',f0[17])
for i in np.arange(5):
    f0 = booleanTLR(f0)
    print('L=',f0[0],
      'T=',f0[1],
      'TL=',f0[2],
      'S=',f0[3], 
      'PK=',f0[4], 
      'A=',f0[5],
      'KA=',f0[6], 
      'P3=',f0[7],
      'P2=',f0[8],
      'PT=',f0[9],
      'PTP=',f0[10],
      'Ak=',f0[11],
      'AP3=',f0[12],
      'PD=',f0[13],
      'PAP3=',f0[14],
      'mT=',f0[15],
      'P2AP3=',f0[16],
      'P2A=',f0[17])
L= 1 T= 1 TL= 0 S= 0 PK= 1 A= 1 KA= 0 P3= 0 P2= 1 PT= 1 PTP= 0 Ak= 1 AP3= 0 PD= 1 PAP3= 0 mT= 1 P2AP3= 0 P2A= 0
L= 1 T= 1 TL= 1 S= 1 PK= 1 A= 1 KA= 1 P3= 1 P2= 1 PT= 1 PTP= 1 Ak= 1 AP3= 1 PD= 1 PAP3= 1 mT= 1 P2AP3= 1 P2A= 1
L= 1 T= 1 TL= 1 S= 1 PK= 1 A= 1 KA= 1 P3= 1 P2= 1 PT= 0 PTP= 1 Ak= 1 AP3= 1 PD= 1 PAP3= 1 mT= 1 P2AP3= 1 P2A= 1
L= 1 T= 1 TL= 1 S= 1 PK= 1 A= 1 KA= 1 P3= 1 P2= 1 PT= 0 PTP= 0 Ak= 1 AP3= 1 PD= 1 PAP3= 1 mT= 1 P2AP3= 1 P2A= 1
L= 1 T= 1 TL= 1 S= 1 PK= 1 A= 1 KA= 1 P3= 1 P2= 1 PT= 0 PTP= 0 Ak= 1 AP3= 1 PD= 1 PAP3= 1 mT= 1 P2AP3= 1 P2A= 1
L= 1 T= 1 TL= 1 S= 1 PK= 1 A= 1 KA= 1 P3= 1 P2= 1 PT= 0 PTP= 0 Ak= 1 AP3= 1 PD= 1 PAP3= 1 mT= 1 P2AP3= 1 P2A= 1
In [22]:
def booleanTLR2(x):
    L, T, TL, A, PK, PKA, P3, PT, Ak, mT, pAk, S = x 
    TL = AND(L,T)
    PKA = AND(AND(A,PK),TL)
    P3 = PKA
    Ak = AND(P3,(1-PT))
    pAk = AND(Ak,mT)
    PT = OR(PT,(1-pAk))
    S = pAk
    return [L, T, TL, A, PK, PKA, P3, PT, Ak, mT, pAk, S]
In [25]:
#   L, T, TL, A, PK, PKA, P3, PT, Ak, mT, pAk, S
f0=[1, 1, 0,  1, 1,  0,   0,  1,  0,  1,  0,   0]
print('L=',f0[0],
      'T=',f0[1],
      'TL=',f0[2],
      'A=',f0[3], 
      'PK=',f0[4], 
      'PKA=',f0[5],
      'P3=',f0[6], 
      'PT=',f0[7],
      'Ak=',f0[8],
      'mT=',f0[9],
      'pAk=',f0[10],
      'S=',f0[11])

for i in np.arange(5):
    f0 = booleanTLR2(f0)
    print('L=',f0[0],
          'T=',f0[1],
          'TL=',f0[2],
          'A=',f0[3], 
          'PK=',f0[4], 
          'PKA=',f0[5],
          'P3=',f0[6], 
          'PT=',f0[7],
          'Ak=',f0[8],
          'mT=',f0[9],
          'pAk=',f0[10],
          'S=',f0[11])
L= 1 T= 1 TL= 0 A= 1 PK= 1 PKA= 0 P3= 0 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0
L= 1 T= 1 TL= 1 A= 1 PK= 1 PKA= 1 P3= 1 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0
L= 1 T= 1 TL= 1 A= 1 PK= 1 PKA= 1 P3= 1 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0
L= 1 T= 1 TL= 1 A= 1 PK= 1 PKA= 1 P3= 1 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0
L= 1 T= 1 TL= 1 A= 1 PK= 1 PKA= 1 P3= 1 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0
L= 1 T= 1 TL= 1 A= 1 PK= 1 PKA= 1 P3= 1 PT= 1 Ak= 0 mT= 1 pAk= 0 S= 0

image

In [98]:
def booleanTest2(x):
    c1, c2, c3, r1, r2, r3, a1, a2, a3, a4, a5, s1, s2, s3, s4, s5, s6, s7 = x
    f1 = AND(c1, r1)
    f2 = OR(AND(c1,r2),AND(c2,r2))
    f3 = AND(c3,r3)
    f4 = OR(a1,a2)
    f5 = AND(f1,f4)
    f6 = OR(a3,a4)
    f7 = AND(f2,f6)
    f8 = OR(f5,f7)
    f9 = AND(f3,f7)
    s1 = f5
    s3 = f9
    s4 = f3
    f10 = OR((1-s1),s3)
    f11 = AND((s4),a5)
    f12 = AND(f8,(1-s4))
    s2 = f12
    s6 = s2
    s7 = f11
    s5 = f10
    return [c1, c2, c3, r1, r2, r3, a1, a2, a3, a4, a5, s1, s2, s3, s4, s5, s6, s7]
In [99]:
#  c1, c2, c3, r1, r2, r3, a1, a2, a3, a4, a5, s1, s2, s3, s4, s5, s6, s7
i1=[0, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i2=[1, 0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i3=[1, 1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i4=[0, 1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i5=[0, 0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i6=[1, 0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i7=[1, 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i8=[1, 1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  0,  0,  0,  0,  0,  0,  0 ]
i9=[1, 1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0 ]
In [107]:
a = i7

print('s1=',a[11],
      's5=',a[15],
      's6=',a[16],
      's7=',a[17])

for i in np.arange(1):
    a = booleanTest2(a)
    print('s1=',a[11],
          's5=',a[15],
          's6=',a[16],
          's7=',a[17])
    
    if a[11] == 1 and a[16] == 1:
        print('type 1')
    elif a[15] == 1 and a[17] == 1:
        print("type 2")
    else:
        print("undetermined")
s1= 0 s5= 0 s6= 0 s7= 0
s1= 1 s5= 1 s6= 0 s7= 1
type 2
In [ ]:
 
Notebooks AI
Notebooks AI Profile20060