ChengsongTanPhdThesis/Chapters/tape.tex
author Chengsong
Fri, 03 Jun 2022 16:45:30 +0100
changeset 532 cc54ce075db5
child 533 6acbc939af6a
permissions -rw-r--r--
restructured
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
532
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     1
\documentclass{standalone}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     2
\usepackage[utf8]{inputenc}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     3
\usepackage{ifthen}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     4
\usepackage{tikz}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     5
\usetikzlibrary{chains}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     6
\usetikzlibrary{calc, decorations.pathmorphing}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     7
\tikzstyle{tape}=[thick, draw, minimum height=5mm, minimum width=7mm, fill=green!35,outer sep=0pt]
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     8
\tikzstyle{head}=[very thick, draw, minimum height=6mm, minimum width=7mm, fill=none,outer sep=0pt]
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
     9
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    10
\def\DrawTape#1{
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    11
\begin{scope}[start chain=1 going right,node distance=-0.15mm]
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    12
    % start tape
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    13
    \node [on chain=1,tape,draw=none, tape, fill=none, draw=none] at (0,-\i*1) (node\i0){\ldots\ };
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    14
    \draw [thick,fill=green!35] (node\i0.north east) -- ++(-.07,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    15
    {-- ($(node\i0.south east)+(-.15,0)$)} -- (node\i0.south east) -- cycle;
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    16
    % draw tape 
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    17
      \foreach [count=\j] \element in \adlist {     
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    18
	  \ifthenelse{\j = \head}{ % read-write heads current position
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    19
		    \node [on chain=1,tape, fill=red!35] (node\i\j){\element};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    20
	      }
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    21
	      {
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    22
		    \node [on chain=1,tape] (node\i\j) {\element};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    23
	      }
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    24
      }    
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    25
    % close tape
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    26
    \draw [thick,fill=green!35] (node\i\j.north east) -- ++(.15,0) decorate [decoration={zigzag, segment length=.10cm, amplitude=.015cm}] 
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    27
    {-- ($(node\i\j.south east)+(.07,0)$)} -- (node\i\j.south east) -- cycle;
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    28
    \node [on chain=1,tape, fill=none, draw=none] (end\i) {\ \ldots};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    29
    \node [right = of end\i]{\tiny tape~\i};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    30
    
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    31
    % draw read-write head
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    32
    \prevnode=\head
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    33
    \advance\prevnode by -1
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    34
    \node [head,right = of node\i\the\prevnode] (head\i){};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    35
    \node [above = of head\i]{\tiny head \i};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    36
\end{scope}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    37
}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    38
\newcount\prevnode
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    39
\begin{document}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    40
% Define the turing machine as a list of pairs, where each pair consists of the read-writes head position the delimiter "/" and  the list of symbols on the tape.
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    41
\newcommand{\tapes}{ 3/{, , ,1,1, }, 1/{, 1, 0, 1 , 0,}, 2/{ , 1 , 1, 0, 1,}}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    42
\begin{tikzpicture}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    43
% Draw program node
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    44
\draw (-1.5,-2) node [draw, thick, rectangle, minimum height= 2.5cm, minimum width=2cm, fill=white, rounded corners] (program){program};
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    45
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    46
% Draw tapes and heads
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    47
\foreach [count=\i] \head/\adlist in \tapes {
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    48
    % Draw tape and head
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    49
    \DrawTape{\i,\head,\adlist}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    50
    % Draw link to program
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    51
    \draw[thick, rounded corners=3pt] (program) {-- ($(node\i0.south west) + (0,-0.15)$)} 
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    52
	{-- ($(head\i.south) + (0,-0.1)$)}-- (head\i.south);
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    53
}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    54
\end{tikzpicture}
cc54ce075db5 restructured
Chengsong
parents:
diff changeset
    55
\end{document}