'Program COMPUTER.BAS evaluates truth table for PARAMSZ.DAT '\$error all on defext a-z n&=10 s=1.3## tmax&=10000 dim xo(n&), x(n&), dxdt(n&), xnew(n&), q\$(n&), tt&(5) cls while inkey\$<>chr\$(27) for i&=1 to 5: tt&(i&)=0: next i& tt&=0 if seed&=0 then seed&=37344 else seed&=10*timer randomize seed& xt=.01##*rnd(0,20) for i&=3 to n& if rnd<.5 then xo(i&)=xt else xo(i&)=1 next i& locate 1,2: print"N =";n&,"seed =";seed& locate 2,2: print"S =";s; locate 3,2: print"XT=";xt; xo(1)=xt: xo(2)=xt: c&=0 for i&=1 to n& x(i&)=xo(i&) locate 4+i&,1: print -(x(i&)>xt); next i& for t&=1 to tmax& RK4 x(), dxdt(), n&, .05, xnew() for i&=1 to n& if xnew(i&)csng(x(i&)) then c&=1 x(i&)=xnew(i&) next i& if c&=0 then exit for next t& for i&=1 to n& q\$=bin\$(-(x(i&)>xt)) locate 4+i&,4: print"--> ";q\$; q\$(i&)=q\$ next i& xo(1)=1: xo(2)=xt: c&=0 for i&=1 to n& x(i&)=xo(i&) locate 4+i&,21: print -(x(i&)>xt); next i& for t&=1 to tmax& RK4 x(), dxdt(), n&, .05, xnew() for i&=1 to n& if xnew(i&)csng(x(i&)) then c&=1 x(i&)=xnew(i&) next i& if c&=0 then exit for next t& for i&=1 to n& q\$=bin\$(-(x(i&)>xt)) locate 4+i&,24: print"--> ";q\$; q\$(i&)=q\$(i&)+q\$ next i& xo(1)=xt: xo(2)=1: c&=0 for i&=1 to n& x(i&)=xo(i&) locate 4+i&,41: print -(x(i&)>xt); next i& for t&=1 to tmax& RK4 x(), dxdt(), n&, .05, xnew() for i&=1 to n& if xnew(i&)csng(x(i&)) then c&=1 x(i&)=xnew(i&) next i& if c&=0 then exit for next t& for i&=1 to n& q\$=bin\$(-(x(i&)>xt)) locate 4+i&,44: print"--> ";q\$; q\$(i&)=q\$(i&)+q\$ next i& xo(1)=1: xo(2)=1: c&=0 for i&=1 to n& x(i&)=xo(i&) locate 4+i&,61: print -(x(i&)>xt); next i& for t&=1 to tmax& RK4 x(), dxdt(), n&, .05, xnew() for i&=1 to n& if xnew(i&)xt)) locate 4+i&,64: print"--> ";q\$; q\$(i&)=q\$(i&)+q\$ next i& for i&=1 to n& q\$=" " if q\$(i&)="0001" then q\$="AND ": if tt&(1)=0 then tt&(1)=1: incr tt& if q\$(i&)="0111" then q\$="OR ": if tt&(2)=0 then tt&(2)=1: incr tt& if q\$(i&)="0110" then q\$="XOR ": if tt&(3)=0 then tt&(3)=1: incr tt& if q\$(i&)="1000" then q\$="NOR ": if tt&(4)=0 then tt&(4)=1: incr tt& if q\$(i&)="1110" then q\$="NAND": if tt&(5)=0 then tt&(5)=1: incr tt& locate 4+i&,75: print q\$; next i& if tt&>=ttbest& then ttbest&=tt& locate 25,1: print tt&;" seed =";seed&;" XT =";xt; beep end if wend end SUB DERIVS (x(), dxdt(), n&) 'Returns the time derivatives dxdt(i&) of x(i&) SHARED s FOR i&=1 TO n& i1&=1+(i&-3+n&) MOD n& i3&=1+i& MOD n& dxdt(i&)=x(i&)*(1##-s*x(i1&)-x(i&)-s*x(i3&)) NEXT i& END SUB SUB RK4 (X(), DXDT(), N&, H, XNEW()) 'Fourth-order Runge-Kutta integrator DIM XT(N&), DXT(N&), DXM(N&) HH = H * .5## H6 = H / 6## CALL DERIVS(X(), DXDT(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + HH * DXDT(I&) NEXT I& CALL DERIVS(XT(), DXT(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + HH * DXT(I&) NEXT I& CALL DERIVS(XT(), DXM(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + H * DXM(I&) DXM(I&) = DXT(I&) + DXM(I&) NEXT I& CALL DERIVS(XT(), DXT(), N&) FOR I& = 1 TO N& XNEW(I&) = X(I&) + H6 * (DXDT(I&) + DXT(I&) + 2## * DXM(I&)) NEXT I& ERASE DXM, DXT, XT END SUB