September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,17 +1,16 @@
". noun define -. CRLF NB. Fixed tacit universal Turing machine code...
utm=.
(((":@:(]&:>)@:(6&({::)) ,: (":@] 9&({::))) ,. ':'"_) ,. 2&({::) >@:(((
48 + ]) { a."_)@[ ; (] $ ' '"_) , '^'"_) 3&({::))@:([ (0 0 $ 1!:2&2)@:(
'A changeless cycle was detected!'"_)^:(-.@:(_1"_ = 1&({::))))@:((((3&(
{::) + 8&({::)) ; 1 + 9&({::)) 3 9} ])@:(<@:((0: 0&({::)@]`(<@(1&({::))
@])`(2&({::)@])} ])@:(7 3 2&{)) 2} ])@:(<"0@:(6&({::) (<@[ { ]) 0&({::)
) 7 8 1} ])@:([ (0 0 $ 1!:2&2)@:(((":@:(]&:>)@:(6&({::)) ,: (":@] 9&({:
:))) ,. ':'"_) ,. 2&({::) >@:(((48 + ]) { a."_)@[ ; (] $ ' '"_) , '^'"_
) 3&({::))^:(0 = 4&({::) | 9&({::)))@:(<@:(1&({::) ; 3&({::) { 2&({::))
6} ])@:(<@:(3&({::) + _1 = 3&({::)) 3} ])@:(<@:(((_1 = 3&({::)) {:: 5&
({::)) , 2&({::) , (3&({::) = #@:(2&({::))) {:: 5&({::)) 2} ])^:(-.@:(_
1"_ = 1&({::)))^:_)@:((0 ; (({. , ({: % 3:) , 3:)@:$ $ ,)@:(}."1)@:(".;
._2)@:(0&({::))) 9 0} ])@:(<@:('' ; 0"_) 5} ])@:(5&(] , a: $~ [))@:(,~)
(((":@:(]&:>)@:(6&({::)) ,: (":@] 9&({::))) ,. ':'"_) ,. 2&({::) >@:(((48 + ]
) { a."_)@[ ; (] $ ' '"_) , '^'"_) 3&({::))@:([ (0 0 $ 1!:2&2)@:('A changeles
s cycle was detected!'"_)^:(-.@:(_1"_ = 1&({::))))@:((((3&({::) + 8&({::)) ;
1 + 9&({::)) 3 9} ])@:(<@:((0 (0 {:: ])`(<@:(1 {:: ]))`(2 {:: ])} ])@:(7 3 2&
{)) 2} ])@:(<"0@:(6&({::) (<@[ { ]) 0&({::)) 7 8 1} ])@:([ (0 0 $ 1!:2&2)@:((
(":@:(]&:>)@:(6&({::)) ,: (":@] 9&({::))) ,. ':'"_) ,. 2&({::) >@:(((48 + ])
{ a."_)@[ ; (] $ ' '"_) , '^'"_) 3&({::))^:(0 = 4&({::) | 9&({::)))@:(<@:(1&(
{::) ; 3&({::) { 2&({::)) 6} ])@:(<@:(3&({::) + _1 = 3&({::)) 3} ])@:(<@:(((_
1 = 3&({::)) {:: 5&({::)) , 2&({::) , (3&({::) = #@:(2&({::))) {:: 5&({::)) 2
} ])^:(-.@:(_1"_ = 1&({::)))^:_)@:((0 ; (({. , ({: % 3:) , 3:)@:$ $ ,)@:(}."1
)@:(".;._2)@:(0&({::))) 9 0} ])@:(<@:('' ; 0"_) 5} ])@:(,&(;:',,,,,'))@:(,~)
)

View file

@ -1,70 +1,95 @@
NB. Structured derivation of the universal Turing machine...
NB. Structured derivation of the universal Turing machine...
o=. @: NB. Composition of verbs (functions)
c=. "_ NB. Constant verb (function)
f=. &{:: NB. fetch
e=. <@: NB. enclose
NB.--------------------------------------------------------------------------------------
NB. Quick and dirty tacit toolkit...
NB. utm (dyadic verb)...
o=. @:
c=."_
'Q S T P F B M PRINT MOVE C'=. i.10 NB. Using 10 boxes
NB. Left: Q - Instruction table, S - Turing machine state
NB. Right: T - Data tape, P - Head position pointer, F - Display frequency
NB. Local: B - Blank defaults, M - State and tape symbol read, PRINT - Printing symbol
NB. MOVE - Tape head moving instruction, C - Step Counter
ver=. (0:`)([:^:)
DisplayTape=. > o (((48 + ]) { a.c)@[ ; ((] $ ' 'c) , '^'c))
display=. ((((": o (]&:>) o (M f)) ,: (":@] C f)) ,. ':'c ) ,. (T f DisplayTape P f))
NB. Displaying state, symbol, tape / step and pointer
amend=. 0: (0 f)@]`(<@(1 f)@])`(2 f@])} ]
d=. (fix=. (;:'f.')ver) (train=.(;:'`:')ver&6) (an=. <@:((,'0') (,&<) ]))
ver=. (an f. o fix'ver')ver o an f.
z=. ((an'')`($ ,)`) (`:6)
d=. (a0=. `'') (a1=. (@:[) ((<'&')`) (`:6)) (a2=. (`(<(":0);_)) (`:6))
av=. ((an o fix'a0')`) (`(an o fix'a1')) (`(an o fix'a2') ) (`:6)
NB. execute (monadic verb)...
Fetch=. (ver o train ;:'&{::')&.> o i. f.av
tie=. ver o train ;:'`'
FillLeft=. (_1 = P f ) {:: B f NB. Expanding and filling the tape
FillRight=. ( P f = # o (T f)) {:: B f NB. with 0's (if necessary)
ia=. <@[ { ] NB. Selecting by the indices of an array
indices=. (, $~ 1 -.~ $) o (train"0 o ((1 -: L.)S:1 # <S:1) o (tie&'') o fix :: ] @:[)
f=. ((ver o train ;:'&{')) o indices o train f.av
e0=. (FillLeft , T f , FillRight)e T}] NB. Adjusting the tape
e1=. (P f + _1 = P f)e P}] NB. and the pointer (if necessary)
e2=. (S f ; P f { T f)e M}] NB. Updating the state and reading the tape symbol
e3=. [(smoutput o display)^:(0 = F f | C f) NB. Displaying intermediate cycles
e4=. (<"0 o (M f ia Q f)) (PRINT,MOVE,S)}] NB. Performing the printing, moving and state actions
e5=. (amend o ((PRINT,P,T)&{))e T}] NB. Printing symbol on tape at the pointer position
e6=. ((P f + MOVE f) ; 1 + C f) (P,C)}] NB. Updating the pointer (and the counter)
'A B'=. 2 Fetch
head=. (;:'<@:') {.~ 2 * 1 = # o [
h=. train o (indices o train o (A f) (head , (B f) o ] , < o an o [ , (;:'}]')c) ]) f.av
execute=. e6 o e5 o e4 o e3 o e2 o e1 o e0
DropIfNB=. < o ('('"_ , ] , ')'"_) o ((}: ^: ('NB.' -: 3&{. o > o {:)) &. ;:)
pipe=. ([ , ' o ' , ])&:>/ o |.
al=. &(] , (a: $~ [)) NB. Appending local boxes
cc=. 'A changeless cycle was detected!'c
halt=. _1 c = S f NB. Halting when the current state is _1
rt=. ((({. , ({: % 3:) , 3:) o $) $ ,) o (}."1) o (". ;. _2)
NB. Reshaping the transition table as a 3D array (state,symbol,action)
is=. ". o (, o ": o > , '=. ' , pipe o (DropIfNB;._2) o ". o ('0 ( : 0)'c)) f.av
m0=. ,~ NB. Dyadic form (e.g., TPF f TuringMachine QS f )
m1=. 5 al NB. Appending 5 local boxes (B,M,PRINT,MOVE,C)
m2=. ('' ; 0 c)e B}] NB. Initializing local B (empty defaults as 0)
m3=. (0 ; rt o (Q f)) (C,Q)}] NB. Setting (the counter and) the transition table
m4=. execute^:(-. o halt)^:_ NB. Executing until a halt instruction is issued
m5=. [smoutput o cc ^: (-. o halt) NB. or a changeless single cycle is detected
m6=. display NB. Displaying (returning) the final status
NB.--------------------------------------------------------------------------------------
utm=. m6 o m5 o m4 o m3 o m2 o m1 o m0 f. NB. Fixing the universal Turing machine code
NB. Producing the main (dyadic) verb utm...
lr=. 5!:5@< NB. Linear representation
Note 0
NB. X (boxed list)...
Q - Instruction table
S - Turing machine initial state
q: o $ o lr'utm' NB. The fixed tacit code length factors
2 2 3 71
NB. Y (boxed list)...
T - Data tape
P - Head position pointer
F - Display frequency
(12 71 $ ]) o lr'utm' NB. The fixed tacit code...
(((":@:(]&:>)@:(6&({::)) ,: (":@] 9&({::))) ,. ':'"_) ,. 2&({::) >@:(((
48 + ]) { a."_)@[ ; (] $ ' '"_) , '^'"_) 3&({::))@:([ (0 0 $ 1!:2&2)@:(
'A changeless cycle was detected!'"_)^:(-.@:(_1"_ = 1&({::))))@:((((3&(
{::) + 8&({::)) ; 1 + 9&({::)) 3 9} ])@:(<@:((0: 0&({::)@]`(<@(1&({::))
@])`(2&({::)@])} ])@:(7 3 2&{)) 2} ])@:(<"0@:(6&({::) (<@[ { ]) 0&({::)
) 7 8 1} ])@:([ (0 0 $ 1!:2&2)@:(((":@:(]&:>)@:(6&({::)) ,: (":@] 9&({:
:))) ,. ':'"_) ,. 2&({::) >@:(((48 + ]) { a."_)@[ ; (] $ ' '"_) , '^'"_
) 3&({::))^:(0 = 4&({::) | 9&({::)))@:(<@:(1&({::) ; 3&({::) { 2&({::))
6} ])@:(<@:(3&({::) + _1 = 3&({::)) 3} ])@:(<@:(((_1 = 3&({::)) {:: 5&
({::)) , 2&({::) , (3&({::) = #@:(2&({::))) {:: 5&({::)) 2} ])^:(-.@:(_
1"_ = 1&({::)))^:_)@:((0 ; (({. , ({: % 3:) , 3:)@:$ $ ,)@:(}."1)@:(".;
._2)@:(0&({::))) 9 0} ])@:(<@:('' ; 0"_) 5} ])@:(5&(] , a: $~ [))@:(,~)
NB. Local...
B - Blank defaults
M - State and tape symbol read
PRINT - Printing symbol
MOVE - Tape head moving instruction
C - Step Counter
)
'Q S T P F B M PRINT MOVE C'=. 10 Fetch NB. Fetching 10 Boxes
DisplayTape=. > o (((48 + ]) { a.c)@[ ; ((] $ ' 'c) , '^'c))
display=. ((((": o (]&:>) o M) ,: (":@] C)) ,. ':'c ) ,. (T DisplayTape P))
NB. Displaying state, symbol, tape / step and pointer
amend=. 0 (0 {:: ])`(<@:(1 {:: ]))`(2 {:: ])} ]
NB. execute (monadic verb)...
FillLeft=. (_1 = P ) {:: B NB. Expanding and filling the tape
FillRight=. ( P = # o T) {:: B NB. with 0's (if necessary)
ia=. <@[ { ] NB. Selecting by the indices of an array
execute is
T`(FillLeft , T , FillRight)h NB. Adjusting the tape
P`(P + _1 = P) h NB. and the pointer (if necessary)
M`(S ; P { T) h NB. Updating the state and reading the tape symbol
[ (smoutput o display)^:(0 = F | C) NB. Displaying intermediate cycles
(PRINT MOVE S)`(<"0 o (M ia Q))h NB. Performing the printing, moving and state actions
T`(amend o ((PRINT P T)f)) h NB. Printing symbol on tape at the pointer position
(P C)`((P + MOVE) ; 1 + C) h NB. Updating the pointer and the counter
)
cc=. 'A changeless cycle was detected!'c
halt=. _1 c = S NB. Halting when the current state is _1
rt=. ((({. , ({: % 3:) , 3:) o $) $ ,) o (}."1) o (". ;. _2)
NB. Reshaping the transition table as a 3D array (state,symbol,action)
utm is NB. Universal Turing Machine (dyadic verb)
,~ NB. Appending the arguments in reverse order
,&(;:5$',') NB. Appending 5 local boxes (B M PRINT MOVE C)
B`('' ; 0 c) h NB. Setting empty blank defaults as 0
(C Q)`(0 ; rt o Q)h NB. Setting the counter and the transition table
execute^:(-. o halt)^:_ NB. Executing until a halt instruction is issued
[ smoutput o cc ^: (-. o halt) NB. or a changeless single cycle is detected
display NB. Displaying (returning) the final status
)
utm=. utm f. NB. Fixing the universal Turing machine code
NB. The simulation code is produced by 77 (-@:[ ]\ 5!:5@<@:]) 'utm'