Universal Turing machine: Difference between revisions
Content deleted Content added
Line 3,759: | Line 3,759: | ||
The fixed tacit code was produced as follows: |
The fixed tacit code was produced as follows: |
||
<lang j> NB. Structured derivation of the universal Turing machine... |
<lang j> NB. Structured derivation of the universal Turing machine... |
||
NB. Quick and dirty tacit toolkit... |
|||
o=. @: |
|||
c=."_ |
|||
ver=. (0:`)([:^:) |
|||
d=. (fix=. (;:'f.')ver) (train=.(;:'`:')ver&6) (an=. <@:((,'0') (,&<) ])) |
|||
d=. (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) |
|||
Fetch=. (ver o train ;:'&{::')&.> o i. f.av |
|||
tie=. ver o train ;:'`' |
|||
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 |
|||
'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 |
|||
DropIfNB=. < o ('('"_ , ] , ')'"_) o ((}: ^: ('NB.' -: 3&{. o > o {:)) &. ;:) |
|||
pipe=. ([ , ' o ' , ])&:>/ o |. |
|||
is=. ". o (, o ": o > , '=. ' , pipe o (DropIfNB;._2) o ". o ('0 ( : 0)'c)) f.av |
|||
NB.-------------------------------------------------------------------------------------- |
|||
NB. Producing the main (dyadic) verb utm... |
|||
Note 0 |
|||
NB. X (boxed list)... |
NB. X (boxed list)... |
||
Q - Instruction table |
Q - Instruction table |
||
Line 3,809: | Line 3,809: | ||
C - Step Counter |
C - Step Counter |
||
) |
) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
T`(FillLeft , T , FillRight)h NB. Adjusting the tape |
T`(FillLeft , T , FillRight)h NB. Adjusting the tape |
||
P`(P + _1 = P) h NB. and the pointer (if necessary) |
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 |
M`(S ; P { T) h NB. Updating the state and reading the tape symbol |
||
[ (smoutput o display)^:(0 = F | C) NB. Displaying intermediate cycles |
[ (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 |
(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 |
T`(amend o ((PRINT P T)f)) h NB. Printing symbol on tape at the pointer position |
||
Line 3,834: | Line 3,834: | ||
) |
) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
,~ NB. Appending the arguments in reverse order |
,~ NB. Appending the arguments in reverse order |
||
,&(;:5$',') NB. Appending 5 local boxes (B M PRINT MOVE C) |
,&(;:5$',') NB. Appending 5 local boxes (B M PRINT MOVE C) |
||
Line 3,849: | Line 3,848: | ||
display NB. Displaying (returning) the final status |
display NB. Displaying (returning) the final status |
||
) |
) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Java}}== |
=={{header|Java}}== |