Debian Codegraph @

texmf-dist/source/latex/texpower/texpower-addons.dtx

raw
1 % \iffalse meta-comment
2 % --------------------------------------------------------------
3 % Part of the TeXPower bundle
4 % Copyright (C) 1999-2004 Stephan Lehmke
5 %
6 % This program is free software; you can redistribute it and/or
7 % modify it under the terms of the GNU General Public License
8 % as published by the Free Software Foundation; either version 2
9 % of the License, or (at your option) any later version.
10 %
11 % This program is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 % GNU General Public License for more details.
15 % --------------------------------------------------------------
16 %
17 % texpower-addons.dtx,v 1.3 2005/03/28 22:36:05 hansfn Exp
18 %
19 % \fi
20 %
21 % \iffalse
22 %
23 %<*driver>
24 \documentclass{article}
25 \begin{document}
26 \typeout{***********************************************************}
27 \typeout{*}
28 \typeout{*\space\space\space\space\space\space\space Do NOT compile this dtx file!}
29 \typeout{*}
30 \typeout{***********************************************************}
31 \end{document}
32 %</driver>
33 %
34 % \fi
35 %
36 %<*automata>
37 %<<KEEPCOMMENTS
38 %=======================================================================================================================
39 % File: automata.sty
40 %
41 % Draw and animate `automata' as used in theoretical computer science, using PSTricks and TeXPower.
42 %
43 % This package is an addition to the TeXPower bundle, to be found at
44 %
45 % http://texpower.sourceforge.net/
46 %
47 %=======================================================================================================================
48 % Author: Stephan Lehmke <[email protected]>
49 %
50 % v0.2 Oct 05, 2001 First version for the pre-alpha release of texpower.
51 % Only deterministic FA and Mealy Automata yet.
52 %
53
54 \NeedsTeXFormat{LaTeX2e}
55
56 \ProvidesPackage%
57 {automata}%
58 [2001/10/05 v0.2 Draw and animate automata.]
59
60
61 %=======================================================================================================================
62
63 \RequirePackage{ifthen}
64
65 \RequirePackage{relsize}
66
67 \RequirePackage{texpower}
68
69 \ifthenelse{\boolean{psspecialsallowed}}{\RequirePackage{tppstcol}}{}
70
71
72 %=======================================================================================================================
73 % Implementation of the functionality.
74
75 %-----------------------------------------------------------------------------------------------------------------------
76 % Some definitions of general interest.
77
78 \defineTPcolor{automatoncolor}{gray}{0.8}
79 \defineTPcolor{autoplatecolor}{gray}{0.95}
80 \defineTPcolor{currstatecolor}{rgb}{0.8,1,0.8}
81 \colorbetween{markstatecolor@TPATM}{pagecolor}{currstatecolor}
82 \replacecolor{cellcolor}{white}
83
84
85
86 \newlength{\tapepos@TPATM}
87
88 \newcounter{tapecells@TPATM}
89 \newcounter{inputlength@TPATM}
90 \newcounter{states@TPATM}
91 \newcounter{currstate@TPATM}
92 \newcounter{nextstate@TPATM}
93 \newcounter{currinputsymbol@TPATM}
94 \newcounter{currtapepos@TPATM}
95
96 \newtoks\tabrows@TPATM
97 \newtoks\tabdecl@TPATM
98
99 \newsavebox{\tabbox@TPATM}
100
101 \newboolean{stategraph@TPATM}
102
103 \newif\iffliplabel@TPATM
104
105 \newcommand{\formatsymbol}[1]{\texttt{#1}}
106
107
108 %-----------------------------------------------------------------------------------------------------------------------
109 % Helper macros.
110
111 % Make a fixed point number have exactly five decimal places, either by truncating or by filling up with trailing
112 % zeroes.
113 \newcommand{\filltofive@TPATM}[1]{\expandafter\@filltofive@TPATM#1000000\@nil#1}
114
115 \def\@filltofive@TPATM#1.#2#3#4#5#6#7\@nil#8{\def#8{#1.#2#3#4#5#6}}
116
117
118 % Count the number of items in a comma-separated list.
119 \newcommand{\countsymbols@TPATM}[2]{\setcounter{#2}{1}\@countsymbols@TPATM#1,\@nil{#2}}
120
121 \def\@countsymbols@TPATM#1,#2\@nil#3{\ifthenelse{\equal{#2}{}}{}{\stepcounter{#3}\@countsymbols@TPATM#2\@nil{#3}}}
122
123
124
125 % Get a symbol from a (macro containing a) comma-separated list.
126 \newcommand{\getsymbol@TPATM}[2]
127 {%
128 \expandafter\@getsymbol@TPATM#1\@nil{#1}{#2}%
129 }
130
131 \def\@getsymbol@TPATM#1,#2\@nil#3#4{\gdef#3{#2}\@@getsymbol@TPATM#1\@nil{#4}}
132
133 \def\@@getsymbol@TPATM{\@ifnextchar({\@@@getsymbol@TPATM}{\@@@getsymbol@TPATM()}}
134
135 \def\@@@getsymbol@TPATM(#1)#2\@nil#3{\def\statepos@TPATM{#1}\def#3{#2}}
136
137
138 % Get a state from a (macro containing a) comma-separated list of states and check whether it's accepting.
139
140 \newif\ifacceptingstate@TPATM
141
142 \newcommand{\getstate@TPATM}[4]{\expandafter\@getstate@TPATM#1\@nil{#1}{#2}{#3}{#4}}
143
144 \def\@getstate@TPATM#1,#2\@nil#3#4#5#6{\gdef#3{#2}\@@getstate@TPATM#1\@nil{#4}{#5}{#6}}
145
146 \def\@@getstate@TPATM{\@ifnextchar({\@@@getstate@TPATM}{\@@@getstate@TPATM()}}
147
148 \def\@@@getstate@TPATM(#1)#2#3\@nil#4#5#6%
149 {%
150 \def\statepos@TPATM{#1}%
151 \def#6{#2#3}%
152 \ifx\accept#2%
153 \acceptingstate@TPATMtrue%
154 \def#5{#4}%
155 \else
156 \acceptingstate@TPATMfalse%
157 \let#5\empty
158 \fi
159 }
160
161 % Get a state transition from a (macro containing a) comma-separated list of states.
162 \newcommand{\getdeltapair@TPATM}[3]
163 {%
164 \expandafter\@getdeltapair@TPATM#1\@nil{#1}{#2}{#3}%
165 }
166
167 \def\@getdeltapair@TPATM{\@ifnextchar[{\@@getdeltapair@TPATM}{\@@getdeltapair@TPATM[\@nil]}}
168
169 \def\@@getdeltapair@TPATM[#1]%
170 {%
171 \def\optarg@TPATM{#1}%
172 \@ifstar{\let\fliplabel@TPATM=\fliplabel@TPATMtrue\@@@getdeltapair@TPATM}
173 {\let\fliplabel@TPATM=\fliplabel@TPATMfalse\@@@getdeltapair@TPATM}%
174 }
175
176 \def\@@@getdeltapair@TPATM{\@ifnextchar({\@@@@getdeltapair@TPATM}{\@@@@getdeltapair@TPATM(.5)}}
177
178 \def\@@@@getdeltapair@TPATM(#1)%
179 {%
180 \def\labelpos@TPATM{#1}%
181 \@ifnextchar[{\@@@@@getdeltapair@TPATM}{\@@@@@getdeltapair@TPATM[\@nil]}%
182 }
183
184 \def\@@@@@getdeltapair@TPATM[#1]#2->#3,#4\@nil#5#6#7{\def\labelopt@TPATM{#1}\protected@edef#6{#2}\protected@edef#7{#3}\gdef#5{#4}}
185
186 % Decompose a comma-separated pair (without parentheses) into its components.
187 \def\decomposestpos@TPATM#1,#2\@nil#3#4{\def#3{#1}\def#4{#2}}
188
189 % Remove trailing comma from a comma-separated list.
190 \def\gobblelastcomma@TPATM#1,\@nil#2{\gdef#2{#1}}
191
192 % A first step towards internationalization - german only at the moment.
193 \newcommand{\automatonname}{Automatenmodell}
194 \newcommand{\inputname}{Eingabe}
195 \newcommand{\inputtapename}{Eingabeband}
196 \newcommand{\outputname}{Ausgabe}
197 \newcommand{\outputtapename}{Ausgabeband}
198 \newcommand{\acceptname}{Akzeptieren}
199 \newcommand{\statename}{Zustand}
200 \newcommand{\statesname}{Zust"ande}
201 \newcommand{\statetransname}{Zustands"uberg"ange}
202 \newcommand{\nextstatename}{Folgezust.}
203
204 \newcommand{\statetransitiontablepreamble}{}
205
206 \newcommand{\transitionarrayparameters}
207 {%
208 \renewcommand{\arraystretch}{.3}%
209 \setlength{\extrarowheight}{16pt}%
210 \setlength{\tabcolsep}{.5pt}%
211 }
212
213 \let\accept\empty
214 \let\comma\empty
215
216
217 %-----------------------------------------------------------------------------------------------------------------------
218 % Finite Automata.
219
220 % Generic macros for drawing deterministic finite automata. The difference between simple dfa and mealy automata is made
221 % by setting parameters.
222
223 \def\finalisetabrows@TPATM#1\\\@nil#2{#2={#1\end{tabular}}}%
224
225 \newcommand{\draw@outputtape@TPATM}[1]{}%
226 \newcommand{\getoutput@TPATM}[2]{}
227 \newcommand{\inittabrows@TPATM}[1]{}
228 \newcommand{\addtabrow@TPATM}[2]{}
229 \newcommand{\label@output@TPATM}{}%
230 \newcommand{\fix@nextstate@TPATM}{}
231 \newcommand{\mk@new@outputtape@TPATM}[1]{}%
232
233
234
235 \newcommand{\genericdfa@TPATM}[8]
236 {%
237 \begin{pspicture}(1,1)
238 % Draw automaton body.
239 \psframe[fillstyle=solid,fillcolor=automatoncolor](0.05,0)(0.95,1)
240 \rput[b]{90}(0.05,0.5){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\automatonname}}%
241 % Draw input tape.
242 \rput[l](0.07,0.93){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\inputtapename}}%
243 \setlength{\tapepos@TPATM}{0.55pt-0.1pt*\real{#6}}%
244 \setcounter{currinputsymbol@TPATM}{1*\real{#6}}%
245 \mkfactor{\startx@TPATM}{\ratio{\tapepos@TPATM}{1pt}}%
246 \setcounter{tapecells@TPATM}{6+\value{currinputsymbol@TPATM}}%
247 \countsymbols@TPATM{#5}{inputlength@TPATM}%
248 \ifthenelse{\value{tapecells@TPATM}>\value{inputlength@TPATM}}
249 {\setcounter{tapecells@TPATM}{\value{inputlength@TPATM}}}
250 {}%
251 \multips(\startx@TPATM,0.88)(0.1,0){\value{tapecells@TPATM}}{\psframe[fillstyle=solid,fillcolor=cellcolor](0.1,0.1)}%
252 \mkfactor{\startx@TPATM}{\ratio{\tapepos@TPATM+0.05pt}{1pt}}%
253 \filltofive@TPATM{\startx@TPATM}%
254 \protected@edef\tapecontents@TPATM{#5,}%
255 \setcounter{currtapepos@TPATM}{0}%
256 \let\inputtapesymbol@TPATM\relax
257 \let\nextinputtapesymbol@TPATM\relax
258 \multido{\n=\startx@TPATM+0.10000}{\value{tapecells@TPATM}}
259 {%
260 \getsymbol@TPATM\tapecontents@TPATM\inputtapesymbol@TPATM
261 \ifnum\value{currtapepos@TPATM}=\value{currinputsymbol@TPATM}\relax
262 \global\let\nextinputtapesymbol@TPATM\inputtapesymbol@TPATM
263 \fi
264 \stepcounter{currtapepos@TPATM}%
265 \ifnum\value{currtapepos@TPATM}=\value{currinputsymbol@TPATM}\relax
266 \global\let\inputtapesymbol@TPATM\inputtapesymbol@TPATM
267 \fi
268 \rput(\n,0.93){\formatsymbol\inputtapesymbol@TPATM}%
269 }%
270 \psframe[linewidth=2pt,linecolor=conceptcolor](0.45,0.88)(0.55,0.98)
271 % Draw state transitions
272 \countsymbols@TPATM{#1}{states@TPATM}%
273 \mkfactor{\tapeadvancement@TPATM}{\real{#6}-\value{currinputsymbol@TPATM}pt}%
274 \def\defdelta@TPATM{#3,}%
275 \whiledo{\not\equal{\defdelta@TPATM}{}}
276 {%
277 \getdeltapair@TPATM\defdelta@TPATM\domainvalue@TPATM\rangevalue@TPATM
278 \expandafter\def\csname delta(\domainvalue@TPATM)@TPATM\expandafter\endcsname\expandafter{\rangevalue@TPATM}%
279 \expandafter\let\csname deltaopt(\domainvalue@TPATM)@TPATM\endcsname=\optarg@TPATM
280 \expandafter\let\csname deltalabelpos(\domainvalue@TPATM)@TPATM\endcsname=\labelpos@TPATM
281 \expandafter\let\csname deltalabelopt(\domainvalue@TPATM)@TPATM\endcsname=\labelopt@TPATM
282 \expandafter\let\csname deltaflag(\domainvalue@TPATM)@TPATM\endcsname=\empty
283 \expandafter\let\csname deltafliplabel(\domainvalue@TPATM)@TPATM\endcsname=\fliplabel@TPATM
284 }%
285 \ifthenelse{\boolean{stategraph@TPATM}}% Draw state transition diagram?
286 {% Yes.
287 \ifthenelse{\lengthtest{\tapeadvancement@TPATM pt=0pt}}
288 {%
289 \let\nextinputtapesymbol@TPATM\inputtapesymbol@TPATM
290 \ifthenelse{\value{nextstate@TPATM}>-1}{\def\tapeadvancement@TPATM{1}}{}%
291 }{}%
292 \colorbetween[\tapeadvancement@TPATM]{activetranscolor@TPATM}{currstatecolor}{pagecolor}%
293 \rput(0.5,0.5)
294 {%
295 \begingroup
296 % Make `subpicture' containing the state transition diagram.
297 \psset{xunit=.43\psxunit,yunit=.36\psyunit,labelsep=1pt}%
298 \begin{pspicture}(0,0)
299 \psframe[fillstyle=solid,fillcolor=cellcolor,dimen=inner](-1,-1)(1,1)
300 \rput[lt](-1,1){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\statetransname}}%
301 % First, the nodes representing states.
302 \mkfactor{\statedistance@TPATM}{2/\value{states@TPATM}}%
303 \mkfactor\startx@TPATM{-1+\statedistance@TPATM pt/2}%
304 \def\states@TPATM{#1,}%
305 \setcounter{currstate@TPATM}{0}%
306 \multido{\n=\startx@TPATM+\statedistance@TPATM}{\value{states@TPATM}}
307 {%
308 \stepcounter{currstate@TPATM}%
309 \getstate@TPATM{\states@TPATM}{,linewidth=2pt,linecolor=red}{\statetype@TPATM}{\state@TPATM}%
310 \ifnum\value{currstate@TPATM}=#7\relax
311 \ifacceptingstate@TPATM\global\acceptingstate@TPATMtrue\else\global\acceptingstate@TPATMfalse\fi
312 \fi
313 \edef\next
314 {%
315 \noexpand
316 \cnode
317 [%
318 fillstyle=solid,%
319 fillcolor=\ifnum\value{currstate@TPATM}=#7currstatecolor\else cellcolor\fi\statetype@TPATM
320 ]%
321 (\ifx\statepos@TPATM\empty\n,0\else\statepos@TPATM\fi)%
322 }%
323 \next{.4}{{state\state@TPATM}}%
324 \rput(\ifx\statepos@TPATM\empty\n,0\else\statepos@TPATM\fi){\let\comma,\state@TPATM}%
325 \ifthenelse{\value{currstate@TPATM}=#4}
326 {%
327 \ifx\statepos@TPATM\empty
328 \mkfactor{\stxpos@TPATM}{\real{\n}-.2pt}%
329 \def\stypos@TPATM{0}%
330 \else
331 \expandafter\decomposestpos@TPATM\statepos@TPATM\@nil{\stxpos@TPATM}{\stypos@TPATM}%
332 \mkfactor{\stxpos@TPATM}{\real{\stxpos@TPATM}-.2pt}%
333 \fi
334 \pnode(\stxpos@TPATM,\stypos@TPATM){start}%
335 \ncline{->}{start}{state\state@TPATM}%
336 }{}%
337 }%
338 % Next, the node connections.
339 \setcounter{currstate@TPATM}{0}%
340 \def\states@TPATM{#1,}%
341 \whiledo{\not\equal{\states@TPATM}{}}
342 {%
343 \stepcounter{currstate@TPATM}%
344 \getsymbol@TPATM\states@TPATM\state@TPATM
345 \protected@edef\state@TPATM{\state@TPATM}%
346 \def\inputalphabet@TPATM{#2,}%
347 \whiledo{\not\equal{\inputalphabet@TPATM}{}}
348 {%
349 \getsymbol@TPATM\inputalphabet@TPATM\inputsymbol@TPATM
350 \getoutput@TPATM\state@TPATM\inputsymbol@TPATM
351 \ifthenelse{\equal{\csname deltaflag(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname}{}}
352 {%
353 \let\currentnstate@TPATM=\nstate@TPATM
354 \let\currentia@TPATM=\inputalphabet@TPATM
355 \inittabrows@TPATM\tabrows@TPATM
356 \def\arrowparams@TPATM{border=1pt}%
357 \begingroup
358 \def\inputalphabet@TPATM{#2,}%
359 \whiledo{\not\equal{\inputalphabet@TPATM}{}}
360 {%
361 \getsymbol@TPATM\inputalphabet@TPATM\inputsymbol@TPATM
362 \getoutput@TPATM\state@TPATM\inputsymbol@TPATM
363 \ifx\currentnstate@TPATM\nstate@TPATM
364 \expandafter\global\expandafter\let
365 \csname deltaflag(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname=\relax
366 \ifthenelse
367 {%
368 \value{currstate@TPATM}=#7%
369 \and\equal\inputsymbol@TPATM\nextinputtapesymbol@TPATM
370 \and\lengthtest{\tapeadvancement@TPATM pt>0pt}%
371 }
372 {%
373 \xdef\arrowparams@TPATM
374 {%
375 doubleline=true,doublecolor=activetranscolor@TPATM,doublesep=\tapeadvancement@TPATM pt,%
376 arrowsize=1pt 1.5,border=1pt%
377 }%
378 \def\@hlinput@TPATM{\noexpand\rowcolor{activetranscolor@TPATM}}%
379 }
380 {\let\@hlinput@TPATM=\empty}%
381 \addtabrow@TPATM\tabrows@TPATM{\inputsymbol@TPATM}%
382 \ifnum\value{currstate@TPATM}=#7\relax
383 \ifx\inputsymbol@TPATM\inputtapesymbol@TPATM
384 \fix@nextstate@TPATM%
385 \fi
386 \fi
387 \fi
388 }%
389 \expandafter\finalisetabrows@TPATM\the\tabrows@TPATM\@nil\tabrows@TPATM
390 \global\tabrows@TPATM=\tabrows@TPATM
391 \endgroup
392 \expandafter\gdef\expandafter\fullarrowparams@TPATM\expandafter{\expandafter[\arrowparams@TPATM]}%
393 \expandafter\gdef\expandafter\addarrowparams@TPATM\expandafter{\expandafter,\arrowparams@TPATM}%
394 \global\let\inputalphabet@TPATM=\currentia@TPATM
395 \transitionarrayparameters
396 \csname deltafliplabel(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname
397 \edef\mkcirclabel@TPATM
398 {%
399 \iffliplabel@TPATM\noexpand\aput\else\noexpand\bput\fi
400 \expandafter\ifx\csname deltalabelopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\@nnil
401 \else
402 [\csname deltalabelopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname]%
403 \fi
404 (\csname deltalabelpos(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname)%
405 }%
406 \edef\mklinelabel@TPATM
407 {%
408 \iffliplabel@TPATM\noexpand\bput\else\noexpand\aput\fi
409 \expandafter\ifx\csname deltalabelopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\@nnil
410 \else
411 [\csname deltalabelopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname]%
412 \fi
413 (\csname deltalabelpos(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname)%
414 }%
415 \expandafter
416 \ifx\csname deltaopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\@nnil
417 \ifx\state@TPATM\nstate@TPATM
418 \expandafter\nccircle\fullarrowparams@TPATM{->}{state\state@TPATM}{.35}%
419 \mkcirclabel@TPATM{\the\tabrows@TPATM}%
420 \else
421 \expandafter\ncline\fullarrowparams@TPATM{->}{state\state@TPATM}{state\nstate@TPATM}%
422 \mklinelabel@TPATM{\the\tabrows@TPATM}%
423 \fi
424 \else
425 \ifx\state@TPATM\nstate@TPATM
426 \edef\next
427 {%
428 \noexpand\nccircle
429 \expandafter
430 \ifx\csname deltaopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\empty
431 \fullarrowparams@TPATM
432 \else
433 [\csname deltaopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\addarrowparams@TPATM]%
434 \fi
435 }%
436 \next{->}{state\state@TPATM}{.35}%
437 \mkcirclabel@TPATM{\the\tabrows@TPATM}%
438 \else
439 \edef\next
440 {%
441 \noexpand\ncarc
442 \expandafter
443 \ifx\csname deltaopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\empty
444 \fullarrowparams@TPATM
445 \else
446 [\csname deltaopt(\state@TPATM;\inputsymbol@TPATM)@TPATM\endcsname\addarrowparams@TPATM]%
447 \fi
448 }%
449 \next{->}{state\state@TPATM}{state\nstate@TPATM}%
450 \mklinelabel@TPATM{\the\tabrows@TPATM}%
451 \fi
452 \fi
453 }%
454 {}%
455 }%
456 }%
457 \end{pspicture}%
458 \endgroup
459 }%
460 }
461 {% No; draw state transition table.
462 % First, the list of states.
463 \rput[l](0.07,0.81){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\statesname}}%
464 \mkfactor\startx@TPATM
465 {\ratio{\widthof{\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\statesname}}}{\psyunit}}%
466 \mkfactor{\statewidth@TPATM}{0+(0.88pt-\startx@TPATM pt)/\value{states@TPATM}}%
467 \ifthenelse{\lengthtest{\statewidth@TPATM pt>.1pt}}{\def\statewidth@TPATM{.1}}{}%
468 \filltofive@TPATM{\startx@TPATM}%
469 \filltofive@TPATM{\statewidth@TPATM}%
470 \def\states@TPATM{#1,}%
471 \setcounter{currstate@TPATM}{0}%
472 \multido{\n=\startx@TPATM+\statewidth@TPATM}{\value{states@TPATM}}
473 {%
474 \stepcounter{currstate@TPATM}%
475 \mkfactor{\endx@TPATM}{\real{\n}+\statewidth@TPATM pt}%
476 \getstate@TPATM{\states@TPATM}{,linewidth=2pt,linecolor=red}{\statetype@TPATM}{\state@TPATM}%
477 \ifnum\value{currstate@TPATM}=#7
478 \ifacceptingstate@TPATM\global\acceptingstate@TPATMtrue\else\global\acceptingstate@TPATMfalse\fi
479 \fi
480 \edef\next
481 {%
482 \noexpand
483 \psframe
484 [%
485 fillstyle=solid,%
486 fillcolor=\ifnum\value{currstate@TPATM}=#7currstatecolor\else cellcolor\fi\statetype@TPATM
487 ]%
488 }%
489 \next(\n,0.76)(\endx@TPATM,0.86)%
490 \mkfactor{\charpos@TPATM}{\real{\n}+\statewidth@TPATM pt/2}%
491 \rput(\charpos@TPATM,0.81){\state@TPATM}%
492 \ifthenelse{\value{currstate@TPATM}=#4}{\psline{->}(\charpos@TPATM,0.74)(\charpos@TPATM,0.76)}{}%
493 }%
494 % Next, the state transition table itself.
495 \psframe[fillstyle=solid,fillcolor=cellcolor,dimen=inner](0.07,0.14)(0.93,0.74)
496 \rput[lt](0.07,0.74){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\smaller\statetransname}}%
497 % Construct tabular declaration and first row.
498 \def\inputalphabet@TPATM{#2,}%
499 \tabrows@TPATM={}%
500 \tabdecl@TPATM={}%
501 \ifthenelse{\equal{\inputtapesymbol@TPATM}{\nextinputtapesymbol@TPATM}}
502 {%
503 \replacecolor{oldinputcolor@TPATM}{markstatecolor@TPATM}%
504 \replacecolor{newinputcolor@TPATM}{markstatecolor@TPATM}%
505 \replacecolor{oldoutputcolor@TPATM}{currstatecolor}%
506 \replacecolor{newoutputcolor@TPATM}{currstatecolor}%
507 }
508 {%
509 \colorbetween[\tapeadvancement@TPATM]{oldinputcolor@TPATM}{pagecolor}{markstatecolor@TPATM}%
510 \colorbetween[\tapeadvancement@TPATM]{newinputcolor@TPATM}{markstatecolor@TPATM}{pagecolor}%
511 \ifthenelse{\lengthtest{\tapeadvancement@TPATM pt>0.5pt}}
512 {%
513 \colorbetween[\tapeadvancement@TPATM]{newoutputcolor@TPATM}{currstatecolor}{pagecolor}%
514 \replacecolor{oldoutputcolor@TPATM}{markstatecolor@TPATM}%
515 }
516 {%
517 \colorbetween[\tapeadvancement@TPATM]{oldoutputcolor@TPATM}{pagecolor}{currstatecolor}%
518 \replacecolor{newoutputcolor@TPATM}{markstatecolor@TPATM}%
519 }%
520 }%
521 \whiledo{\not\equal{\inputalphabet@TPATM}{}}
522 {%
523 \getsymbol@TPATM\inputalphabet@TPATM\inputsymbol@TPATM
524 \protected@edef\newtabrows@TPATM{\the\tabrows@TPATM&\noexpand\formatsymbol{\inputsymbol@TPATM}}%
525 \expandafter\tabrows@TPATM\expandafter{\newtabrows@TPATM}%
526 \edef\newtabdecl@TPATM
527 {%
528 \the\tabdecl@TPATM
529 \ifx\inputsymbol@TPATM\nextinputtapesymbol@TPATM>{\noexpand\columncolor{newinputcolor@TPATM}}\fi
530 \ifx\inputsymbol@TPATM\inputtapesymbol@TPATM>{\noexpand\columncolor{oldinputcolor@TPATM}}\fi
531 c%
532 }%
533 \expandafter\tabdecl@TPATM\expandafter{\newtabdecl@TPATM}%
534 }%
535 % Construct remaining rows.
536 \setcounter{currstate@TPATM}{0}%
537 \def\states@TPATM{#1,}%
538 \whiledo{\not\equal{\states@TPATM}{}}
539 {%
540 \stepcounter{currstate@TPATM}%
541 \getsymbol@TPATM\states@TPATM\state@TPATM
542 \protected@edef\newtabrows@TPATM
543 {%
544 \the\tabrows@TPATM\noexpand\\%
545 \ifnum\value{currstate@TPATM}=#7 \noexpand\rowcolor{markstatecolor@TPATM}\fi\state@TPATM
546 }%
547 \expandafter\tabrows@TPATM\expandafter{\newtabrows@TPATM}%
548 \def\inputalphabet@TPATM{#2,}%
549 \whiledo{\not\equal{\inputalphabet@TPATM}{}}
550 {%
551 \getsymbol@TPATM\inputalphabet@TPATM\inputsymbol@TPATM
552 \protected@edef\newtabrows@TPATM
553 {%
554 \the\tabrows@TPATM&%
555 \ifnum\value{currstate@TPATM}=#7
556 \ifx\inputsymbol@TPATM\inputtapesymbol@TPATM
557 \noexpand
558 \multicolumn{1}{>{\noexpand\columncolor{oldoutputcolor@TPATM}}c}
559 {\formatdfaoutput@TPATM\state@TPATM\inputsymbol@TPATM}%
560 \else
561 \ifx\inputsymbol@TPATM\nextinputtapesymbol@TPATM
562 \noexpand
563 \multicolumn{1}{>{\noexpand\columncolor{newoutputcolor@TPATM}}c}
564 {\formatdfaoutput@TPATM\state@TPATM\inputsymbol@TPATM}%
565 \else
566 \formatdfaoutput@TPATM\state@TPATM\inputsymbol@TPATM
567 \fi
568 \fi
569 \else
570 \formatdfaoutput@TPATM\state@TPATM\inputsymbol@TPATM
571 \fi
572 }%
573 \expandafter\tabrows@TPATM\expandafter{\newtabrows@TPATM}%
574 % Set succeeding state (and output symbol).
575 \ifnum\value{currstate@TPATM}=#7\relax
576 \ifx\inputsymbol@TPATM\inputtapesymbol@TPATM
577 \getoutput@TPATM{\state@TPATM}{\inputsymbol@TPATM}%
578 \fix@nextstate@TPATM
579 \fi
580 \fi
581 }%
582 }%
583 % Save tabular into a box.
584 \savebox{\tabbox@TPATM}
585 {%
586 \raisebox{\depth}
587 {%
588 \setlength{\fboxsep}{0.4pt}%
589 \fbox
590 {%
591 \clipbox
592 {%
593 \edef\next{\noexpand\begin{tabular}[b]{c\the\tabdecl@TPATM}}%
594 \statetransitiontablepreamble
595 \next
596 \the\tabrows@TPATM
597 \end{tabular}%
598 }%
599 }%
600 }%
601 }%
602 % Print state transition table, with some decoration.
603 \rput(0.5,0.44)
604 {%
605 \raisebox{.5\tabcolsep}
606 {\rotatebox{90}{\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\smaller \statename}}}%
607 \parbox[b]{\wd\tabbox@TPATM}
608 {%
609 \offinterlineskip\raggedleft
610 \psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\smaller \inputname}\kern\tabcolsep\\%
611 \usebox{\tabbox@TPATM}%
612 }%
613 \raisebox{.5\tabcolsep}
614 {%
615 \rotatebox{90}
616 {\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\smaller[2]\nextstatename}}%
617 }%
618 \label@output@TPATM
619 }%
620 }%
621 % Draw output tape, if mealy automaton.
622 \draw@outputtape@TPATM{#8}%
623 % Calculate number of succeeding state.
624 \setcounter{currstate@TPATM}{0}%
625 \def\states@TPATM{#1,}%
626 \whiledo{\not\equal{\states@TPATM}{}}
627 {%
628 \stepcounter{currstate@TPATM}%
629 \getsymbol@TPATM\states@TPATM\state@TPATM
630 \edef\state@TPATM{\state@TPATM}%
631 \ifx\state@TPATM\nextstate@TPATM
632 \setcounter{nextstate@TPATM}{\value{currstate@TPATM}}%
633 \fi
634 }%
635 % Calculate new output tape.
636 \mk@new@outputtape@TPATM{#8}%
637 \end{pspicture}%
638 \endgroup
639 }
640
641
642 % \dfa{<width>}{<height>}{<states>}{<inputalphabet>}{<statetransitions>}
643 % {<initial state>}{<input tape>}{<tape position>}{<current state>}
644 % draws a deterministic finite automaton.
645 %
646 % The parameters have the following meanings:
647 % <width> Width of the automaton to be drawn.
648 % <height> Height of the automaton to be drawn.
649 % <states> Comma-separated list (symbolically) specifying the set of states.
650 % <inputalphabet> Comma-separated list (symbolically) specifying the set of input symbols.
651 % <statetransitions> Comma-separated list (symbolically) specifying the state transition function (also giving the
652 % output symbols associated with state transitions).
653 % <initial state> Number of the initial state.
654 % <input tape> Comma-separated list (symbolically) specifying the contents of the input tape.
655 % <tape position> Fixed-point number (greater or equal 1) specifying the current position of the head reading input
656 % and output tape. The symbol currently read corresponds to the integer part of <tape position>.
657 % <current state> Number of the current state.
658 %
659 % The standard version of \dfa displays a state transition table, i.e. for every combination of state and
660 % input symbol, the successor state is displayed in a tabular. The current state, current input
661 % symbol and next input symbol (if <tape position> is not integer) are indicated by colored bars.
662 %
663 % There is a starred version \mealyautomaton* which displays a state transition graph where states are displayed as
664 % circles and state transitions as arrows between circles. The `active' transition (leading from the current to the next
665 % state) is highlighted.
666 %
667 % The <states> parameter looks like <state1>,<state2>,...,<staten>, where every single <state> has the following form:
668 % {(<x>,<y>)\accept <symbol>}
669 % where (<x>,<y>) and the special keyword \accept are optional and <symbol> is the symbolic name of the state.
670 % The optional parameter (<x>,<y>) is used only in the starred version \mealyautomaton*. If given, it specifies the
671 % position of the circle representing the state in the state transition graph, in PSTricks notation. The origin of the
672 % state transition graph is in the middle of the area reserved for it, stretching one unit in all directions, so that
673 % the corners of the area are at coordinates (-1,1), (1,1), (1,-1), (-1,-1). If not given in the starred version
674 % \mealyautomaton*, the position is calculated automatically in a `bead' style.
675 % The special keyword \accept flags this state as an accepting one.
676 % If the optional coordinates argument is not given, the outer curly braces may be left out, but otherwise leaving the
677 % curly braces out would disturb the parsing of the comma-separated list because of the comma between <x> and <y>.
678 %
679 % The <statetransitions> parameter looks like <trans1>,<trans2>,...,<transm>, where every single <trans> has the
680 % following form:
681 % [<opt>]<state>;<input>-><state'>
682 % where [<opt>] is optional. <state> and <input> are the arguments of the state transition function, and <state'> is the
683 % successor state.
684 % The optional parameter [<opt>] is used only in the starred version \mealyautomaton*. If given, it specifies additional
685 % optional parameters for the node connection command (\nccircle or \ncarc) drawing the arrow for this
686 % transition. \ncline is used for transitions from a state to itself. For transitions between states, \ncarc is used
687 % whenever the optional argument is given, otherwise \ncline is used. This is a seldom instance where giving an empty
688 % optional argument is different from giving no optional argument at all: Giving the optional argument [] switches
689 % between \ncline and \ncarc (useful if two transitions go `back and forth' between two states).
690 %
691
692 \newcommand{\initializedfa@TPATM}
693 {%
694 \renewcommand{\draw@outputtape@TPATM}[1]
695 {%
696 \colorbetween{outercirclecolor@TPATM}{black}{automatoncolor}%
697 \pscircle[fillstyle=solid,fillcolor=outercirclecolor@TPATM,linewidth=.5\pslinewidth](0.5,0.07){0.25}%
698 \ifacceptingstate@TPATM
699 \replacecolor{acceptlampcolor@TPATM}{red}%
700 \else
701 \colorbetween[.1]{acceptlampcolor@TPATM}{red}{automatoncolor}%
702 \fi
703 \pscircle[fillstyle=solid,fillcolor=acceptlampcolor@TPATM,linewidth=.5\pslinewidth](0.5,0.07){0.15}%
704 \rput[l](0.53,0.07){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\acceptname}}%
705 }%
706 \renewcommand{\getoutput@TPATM}[2]
707 {%
708 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\nstate@TPATM
709 \expandafter\expandafter\expandafter{\csname delta(##1;##2)@TPATM\endcsname}%
710 }%
711 \renewcommand{\inittabrows@TPATM}[1]{##1={\smaller\begin{tabular}{@{}r@{}}}}%
712 \renewcommand{\addtabrow@TPATM}[2]
713 {%
714 \protected@edef\newtabrows@TPATM{\the##1\@hlinput@TPATM\formatsymbol{##2}\noexpand\\}%
715 \expandafter##1\expandafter{\newtabrows@TPATM}%
716 }%
717 \def\formatdfaoutput@TPATM##1##2{\csname delta(##1;##2)@TPATM\endcsname}%
718 \renewcommand{\label@output@TPATM}{}%
719 \renewcommand{\fix@nextstate@TPATM}
720 {%
721 \global\let\nextstate@TPATM=\nstate@TPATM
722 }%
723 \renewcommand{\mk@new@outputtape@TPATM}[1]{}%
724 }%
725
726 \newcommand{\dfa}
727 {%
728 \initializedfa@TPATM
729 \dfa@TPATM
730 }
731
732 \newcommand{\dfa@TPATM}
733 {%
734 \@ifstar
735 {\setboolean{stategraph@TPATM}{true}\@dfa@TPATM}
736 {\setboolean{stategraph@TPATM}{false}\@dfa@TPATM}%
737 }
738
739 \newcommand{\@dfa@TPATM}[2]
740 {%
741 \ifthenelse{\boolean{psspecialsallowed}}
742 {%
743 \begingroup
744 \setlength{\@tempdima}{#1}%
745 \setlength{\@tempdimb}{#2}%
746 \psset{xunit=\@tempdima,yunit=\@tempdimb,arrowinset=0}%
747 \let\next=\@@dfa@TPATM
748 }
749 {%
750 \rule{#1}{#2}%
751 \let\next=\@@nodfa@TPATM
752 }%
753 \next
754 }
755
756 \newcommand{\@@nodfa@TPATM}[7]{}
757
758 \newcommand{\@@dfa@TPATM}[7]{\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{#6}{#7}{}}
759
760
761 % \simulatedfa{<width>}{<height>}{<states>}{<inputalphabet>}{<statetransitions>}
762 % {<initial state>}{<input tape>}{<number of steps>}{<tape move resolution>}
763 % simulates a deterministic finite automaton.
764 %
765 % The parameters <width>, <height>, <states>, <inputalphabet>, <statetransitions>, <initial state>, and <input tape>
766 % have the same meaning as for \dfa.
767 % <number of steps> gives the number of state transitions to perform (in fact, the first state transition occurs after
768 % the first step, so <number of steps>=1 means no state transition.
769 % The simulation starts with both tapes at the beginning, in the initial state. After this, the simulation proceeds in
770 % the following steps:
771 % 1) Change state.
772 % 2) Advance input tape and reiterate.
773 % The steps are realised with TeXPower's \step mechanism. This means the whole simulation will lead to the corresponding
774 % number of `subpages' each displaying the automaton in changing states.
775 % If <tape move resolution>=1, then step number 3 will just switch over the tape position. Otherwise, advancing the tape
776 % will take <tape move resolution> intermediate steps, which are automatically animated using hyperref's pdfpageduration
777 % mechanism, i.e. when displayed in acroread's full screen mode (with automatic advancing activated), a `smooth' tape
778 % movement will be seen.
779 % \simulatedfa comes in normal and starred versions, with the same semantics as for \dfa, i.e. the normal version
780 % displays a state transition table, the starred version displays a state transition graph.
781
782 \newcommand{\simulatedfa}
783 {%
784 \initializedfa@TPATM
785 \@ifstar
786 {\setboolean{stategraph@TPATM}{true}\@simulatedfa@TPATM}
787 {\setboolean{stategraph@TPATM}{false}\@simulatedfa@TPATM}%
788 }
789
790 \newcommand{\@simulatedfa@TPATM}[2]
791 {%
792 \ifthenelse{\boolean{psspecialsallowed}}
793 {%
794 \begingroup
795 \setlength{\@tempdima}{#1}%
796 \setlength{\@tempdimb}{#2}%
797 \psset{xunit=\@tempdima,yunit=\@tempdimb,arrowinset=0}%
798 \let\next=\@@simulatedfa@TPATM
799 }
800 {%
801 \rule{#1}{#2}%
802 \let\next=\@@nosimulatedfa@TPATM
803 }%
804 \next
805 }
806
807 \newcommand{\@@nosimulatedfa@TPATM}[7]{}
808
809 \newcounter{currentdfastate@TPATM}
810 \newcounter{currentsupstep@TPATM}
811 \newcounter{currentsubstep@TPATM}
812 \newboolean{beginautosim@TPATM}
813 \newcommand{\autosimduration}{0.04}
814 \releasecounter{currentdfastate@TPATM}\releasecounter{nextstate@TPATM}
815
816 \newcommand{\@@simulatedfa@TPATM}[7]
817 {%
818 % Setup initial state.
819 \setcounter{currentsupstep@TPATM}{0}%
820 \setcounter{currentdfastate@TPATM}{#4}%
821 \setcounter{nextstate@TPATM}{0}%
822 \stepwise[\setcounter{currentdfastate@TPATM}{#4}\setcounter{nextstate@TPATM}{0}]
823 {%
824 \setboolean{beginautosim@TPATM}{true}%
825 % Main loop for state transitions.
826 \whiledo{\value{currentsupstep@TPATM}<#6}
827 {%
828 % At the beginning, the situation right before the state transition is displayed. This is effected by only
829 % displaying the last step of the tape movement.
830 \ifthenelse{\boolean{beginautosim@TPATM}}
831 {\setboolean{beginautosim@TPATM}{false}\setcounter{currentsubstep@TPATM}{#7-1}}
832 {\setcounter{currentsubstep@TPATM}{0}}%
833 % Inner loop for tape movement.
834 \whiledo{\value{currentsubstep@TPATM}<#7}
835 {%
836 \stepcounter{currentsubstep@TPATM}%
837 % Display sequence of steps while the tape gradually moves.
838 \mkfactor{\tapeposition@TPATM}{\value{currentsupstep@TPATM}+\arabic{currentsubstep@TPATM}pt/#7}%
839 \ifthenelse{\value{currentsubstep@TPATM}=#7}
840 {%
841 \setcounter{tmpcnta@TP}{\value{currentsupstep@TPATM}+1}%
842 \ifthenelse{\value{tmpcnta@TP}=#6}{\switch}{\switch[][\boolean{firstactivation}]}{}
843 {%
844 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{}%
845 \afterstep{\stopAdvancing}%
846 \setcounter{currentdfastate@TPATM}{\value{nextstate@TPATM}}\setcounter{nextstate@TPATM}{-1}%
847 }%
848 }
849 {%
850 \switch[][\boolean{firstactivation}]{}
851 {%
852 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{}%
853 \afterstep{\pageDuration{\autosimduration}}%
854 }%
855 }%
856 }%
857 \stepcounter{currentsupstep@TPATM}%
858 % After the tape is in the next (or initial) position, switch state and reiterate.
859 \ifthenelse{\value{currentsupstep@TPATM}=#6}{}
860 {%
861 \switch[][\boolean{firstactivation}]{}%
862 {%
863 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{}%
864 }%
865 }%
866 }%
867 }%
868 \endgroup
869 }
870
871
872 %-----------------------------------------------------------------------------------------------------------------------
873 % Finite Automata with output.
874
875 % \mealyautomaton{<width>}{<height>}{<states>}{<inputalphabet>}{<statetransitions>}
876 % {<initial state>}{<input tape>}{<tape position>}{<current state>}{<output tape>}
877 % draws a mealy automaton (deterministic finite automaton with output tape, output is triggered by state transitions).
878 %
879 % The parameters have the same meanings as for \dfa, with one addition:
880 % <output tape> Comma-separated list (symbolically) specifying the contents of the output tape.
881 %
882 % The standard version of \mealyautomaton displays a state transition table, i.e. for every combination of state and
883 % input symbol, the successor state and output symbol are displayed in a tabular. The current state, current input
884 % symbol and next input symbol (if <tape position> is not integer) are indicated by colored bars.
885 %
886 % There is a starred version \mealyautomaton* which displays a state transition graph where states are displayed as
887 % circles and state transitions as arrows between circles. The `active' transition (leading from the current to the next
888 % state) is highlighted.
889 %
890 % The <states> parameter has the same structure as for \dfa.
891 %
892 % The <statetransitions> parameter looks like <trans1>,<trans2>,...,<transm>, where every single <trans> has the
893 % following form:
894 % [<opt>]<state>;<input>-><state'>;<output>
895 % where [<opt>] is optional. <state> and <input> are the arguments of the state transition function, and <state'> and
896 % <output> are the successor state and output symbol, respectively.
897 % The optional parameter [<opt>] is used only in the starred version \mealyautomaton*. If given, it specifies additional
898 % optional parameters for the node connection command (\nccircle or \ncarc) drawing the arrow for this
899 % transition. \ncline is used for transitions from a state to itself. For transitions between states, \ncarc is used
900 % whenever the optional argument is given, otherwise \ncline is used. This is a seldom instance where giving an empty
901 % optional argument is different from giving no optional argument at all: Giving the optional argument [] switches
902 % between \ncline and \ncarc (useful if two transitions go `back and forth' between two states).
903 %
904
905 \newcommand{\initializema@TPATM}
906 {%
907 \renewcommand{\draw@outputtape@TPATM}[1]
908 {%
909 \rput[l](0.07,0.07){\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\outputtapename}}%
910 \mkfactor{\startx@TPATM}{\ratio{\tapepos@TPATM}{1pt}}%
911 \setcounter{tapecells@TPATM}{6+\value{currinputsymbol@TPATM}}%
912 \multips(\startx@TPATM,0.02)(0.1,0){\value{tapecells@TPATM}}{\psframe[fillstyle=solid,fillcolor=cellcolor](0.1,0.1)}%
913 \mkfactor{\startx@TPATM}{\ratio{\tapepos@TPATM+0.05pt}{1pt}}%
914 \filltofive@TPATM{\startx@TPATM}%
915 \protected@edef\tapecontents@TPATM{##1,}%
916 \setcounter{currtapepos@TPATM}{0}%
917 \multido{\n=\startx@TPATM+0.10000}{\value{tapecells@TPATM}}
918 {%
919 \ifx\tapecontents@TPATM\empty
920 \else
921 \stepcounter{currtapepos@TPATM}%
922 \getsymbol@TPATM\tapecontents@TPATM\outputtapesymbol@TPATM
923 \ifnum\value{currtapepos@TPATM}=\value{currinputsymbol@TPATM}\relax
924 \global\let\outputtapesymbol@TPATM\outputtapesymbol@TPATM
925 \fi
926 \rput(\n,0.07){\formatsymbol\outputtapesymbol@TPATM}%
927 \fi
928 }%
929 \psframe[linewidth=2pt,linecolor=mathcolor](0.45,0.02)(0.55,0.12)
930 }%
931 \renewcommand{\getoutput@TPATM}[2]
932 {\expandafter\expandafter\expandafter\@getoutput@TPATM\csname delta(##1;##2)@TPATM\endcsname\@nil}%
933 \def\@getoutput@TPATM##1;##2\@nil{\def\nstate@TPATM{##1}\def\output@TPATM{##2}}%
934 \renewcommand{\inittabrows@TPATM}[1]{##1={\smaller\begin{tabular}{rcl}}}%
935 \renewcommand{\addtabrow@TPATM}[2]
936 {%
937 \protected@edef\newtabrows@TPATM
938 {%
939 \the##1%
940 \@hlinput@TPATM\formatsymbol{##2}&\origmath{\vartriangleright}&\noexpand\formatsymbol{\output@TPATM}\noexpand\\%
941 }%
942 \expandafter##1\expandafter{\newtabrows@TPATM}%
943 }%
944 \def\formatdfaoutput@TPATM##1##2%
945 {\expandafter\expandafter\expandafter\@formatdfaoutput@TPATM\csname delta(##1;##2)@TPATM\endcsname\@nil}%
946 \def\@formatdfaoutput@TPATM##1;##2\@nil{##1;\formatsymbol{##2}}%
947 \renewcommand{\label@output@TPATM}
948 {%
949 \raisebox{.5\tabcolsep}
950 {\rotatebox{90}{\psframebox[linestyle=none,fillstyle=solid,fillcolor=autoplatecolor]{\smaller \outputname}}}%
951 }%
952 \renewcommand{\fix@nextstate@TPATM}
953 {%
954 \global\let\newoutputsymbol@TPATM=\output@TPATM
955 \global\let\nextstate@TPATM=\nstate@TPATM
956 }%
957 \renewcommand{\mk@new@outputtape@TPATM}[1]%
958 {%
959 \setcounter{currtapepos@TPATM}{0}%
960 \protected@edef\tapecontents@TPATM{##1,}%
961 \let\newoutputtape@TPATM=\empty
962 \whiledo{\not\equal{\tapecontents@TPATM}{}}
963 {%
964 \stepcounter{currtapepos@TPATM}%
965 \getsymbol@TPATM\tapecontents@TPATM\outputsymbol@TPATM
966 \ifnum\value{currtapepos@TPATM}=\value{currinputsymbol@TPATM}%
967 \let\outputsymbol@TPATM=\newoutputsymbol@TPATM%
968 \fi
969 \protected@edef\newoutputtape@TPATM{\newoutputtape@TPATM\outputsymbol@TPATM,}%
970 }%
971 \expandafter\gobblelastcomma@TPATM\newoutputtape@TPATM\@nil\newoutputtape@TPATM
972 }%
973 }
974
975 \newcommand{\mealyautomaton}
976 {%
977 \initializema@TPATM
978 \mealyautomaton@TPATM
979 }
980
981 \newcommand{\mealyautomaton@TPATM}
982 {%
983 \@ifstar
984 {\setboolean{stategraph@TPATM}{true}\@mealyautomaton@TPATM}
985 {\setboolean{stategraph@TPATM}{false}\@mealyautomaton@TPATM}%
986 }
987
988 \newcommand{\@mealyautomaton@TPATM}[2]
989 {%
990 \ifthenelse{\boolean{psspecialsallowed}}
991 {%
992 \begingroup
993 \setlength{\@tempdima}{#1}%
994 \setlength{\@tempdimb}{#2}%
995 \psset{xunit=\@tempdima,yunit=\@tempdimb,arrowinset=0}%
996 \let\next=\@@genericdfa@TPATM
997 }
998 {%
999 \rule{#1}{#2}%
1000 \let\next=\@@nomealyautomaton@TPATM
1001 }%
1002 \next
1003 }
1004
1005 \newcommand{\@@nomealyautomaton@TPATM}[8]{}
1006
1007
1008 % \simulatema{<width>}{<height>}{<states>}{<inputalphabet>}{<statetransitions>}
1009 % {<initial state>}{<input tape>}{<number of steps>}{<tape move resolution>}{<output tape>}
1010 % simulates a mealy automaton (deterministic finite automaton with output tape, output is triggered by state
1011 % transitions).
1012 %
1013 % The parameters <width>, <height>, <states>, <inputalphabet>, <statetransitions>, <initial state>, <input tape>,
1014 % <output tape> have the same meaning as for \mealyautomaton.
1015 % The parameters <number of steps> and <tape move resolution> have the same meaning as for \simulatedfa.
1016 % The simulation starts with both tapes at the beginning, in the initial state and with the output tape in the state
1017 % given by <output tape>. After this, the simulation proceeds in the following steps:
1018 % 1) Write output symbol of the `active' transition to the output tape.
1019 % 2) Change state.
1020 % 3) Advance both tapes and reiterate.
1021 % \simulatema comes in normal and starred versions, with the same semantics as for \mealyautomaton, i.e. the normal
1022 % version displays a state transition table, the starred version displays a state transition graph.
1023
1024 \newcommand{\simulatema}
1025 {%
1026 \initializema@TPATM
1027 \@ifstar
1028 {\setboolean{stategraph@TPATM}{true}\@simulatema@TPATM}
1029 {\setboolean{stategraph@TPATM}{false}\@simulatema@TPATM}%
1030 }
1031
1032 \newcommand{\@simulatema@TPATM}[2]
1033 {%
1034 \ifthenelse{\boolean{psspecialsallowed}}
1035 {%
1036 \begingroup
1037 \setlength{\@tempdima}{#1}%
1038 \setlength{\@tempdimb}{#2}%
1039 \psset{xunit=\@tempdima,yunit=\@tempdimb,arrowinset=0}%
1040 \let\next=\@@simulatema@TPATM
1041 }
1042 {%
1043 \rule{#1}{#2}%
1044 \let\next=\@@nosimulatema@TPATM
1045 }%
1046 \next
1047 }
1048
1049 \newcommand{\@@nosimulatema@TPATM}[8]{}
1050
1051 \newcommand{\@@simulatema@TPATM}[8]
1052 {%
1053 % Setup initial state.
1054 \setcounter{currentsupstep@TPATM}{0}%
1055 \setcounter{currentdfastate@TPATM}{#4}\gdef\currentoutputtape@TPATM{#8}%
1056 \stepwise[\setcounter{currentdfastate@TPATM}{#4}\gdef\currentoutputtape@TPATM{#8}]
1057 {%
1058 \setboolean{beginautosim@TPATM}{true}%
1059 % Main loop for state transitions.
1060 \whiledo{\value{currentsupstep@TPATM}<#6}
1061 {%
1062 % At the beginning, the situation right before the state transition is displayed. This is effected by only
1063 % displaying the last step of the tape movement.
1064 \ifthenelse{\boolean{beginautosim@TPATM}}
1065 {\setboolean{beginautosim@TPATM}{false}\setcounter{currentsubstep@TPATM}{#7-1}}
1066 {\setcounter{currentsubstep@TPATM}{0}}%
1067 % Inner loop for tape movement.
1068 \whiledo{\value{currentsubstep@TPATM}<#7}
1069 {%
1070 \stepcounter{currentsubstep@TPATM}%
1071 % Display sequence of steps while the tape gradually moves.
1072 \mkfactor{\tapeposition@TPATM}{\value{currentsupstep@TPATM}+\arabic{currentsubstep@TPATM}pt/#7}%
1073 \switch[][\boolean{firstactivation}]{}
1074 {%
1075 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{\currentoutputtape@TPATM}%
1076 \ifthenelse{\value{currentsubstep@TPATM}=#7}
1077 {\afterstep{\stopAdvancing}\global\let\currentoutputtape@TPATM\newoutputtape@TPATM}%
1078 {\afterstep{\pageDuration{\autosimduration}}}%
1079 }%
1080 }%
1081 \stepcounter{currentsupstep@TPATM}%
1082 % After the tape is in the next (or initial) position, display new output symbol.
1083 \switch[][\boolean{firstactivation}]{}
1084 {%
1085 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{\currentoutputtape@TPATM}%
1086 \setcounter{currentdfastate@TPATM}{\value{nextstate@TPATM}}\setcounter{nextstate@TPATM}{-1}%
1087 }%
1088 % Next, switch state and reiterate.
1089 \ifthenelse{\value{currentsupstep@TPATM}=#6}{\switch}{\switch[][\boolean{firstactivation}]}{}%
1090 {%
1091 \begingroup\genericdfa@TPATM{#1}{#2}{#3}{#4}{#5}{\tapeposition@TPATM}{\value{currentdfastate@TPATM}}{\currentoutputtape@TPATM}%
1092 }%
1093 }%
1094 }%
1095 \endgroup
1096 }
1097
1098 %KEEPCOMMENTS
1099 %</automata>
1100 %=======================================================================================================================
1101 %<*fixseminar>
1102 %<<KEEPCOMMENTS
1103 %=======================================================================================================================
1104 % File: fixseminar.sty
1105 %
1106 % Fix some problems in conjunction with seminar.
1107 %
1108 % This package is part of the TeXPower bundle, to be found at
1109 %
1110 % http://texpower.sourceforge.net/
1111 %
1112 % If using hyperref, load this package _after_ hyperref.
1113 %
1114 %=======================================================================================================================
1115 % Author: Stephan Lehmke <[email protected]>
1116 %
1117 % v0.0.1 Mar 28, 2000 First version for the pre-alpha release of texpower and hyperref v6.70a.
1118 %
1119 % v0.0.1a May 18, 2000 Added a \vss to a \vbox to get rid of an `overfull vbox' message.
1120 %
1121 % v0.0.2 Jun 02, 2000 Now handle seminar as well as powersem.
1122 %
1123 % v0.0.3 Sep 07, 2000 hyperref v6.70u and later don't have the \@hyperfixhead bug any more.
1124 %
1125 % v0.0.4 Nov 22, 2002 Now using ifpdf package if available.
1126 % As hyperref v6.70u exists for some time now, the \@hyperfixhead hack is removed.
1127 % Fixed a problem with \twoup (bug found and fix proposed by Laurent Mugnier).
1128 % Added a preliminary fix for rotating slides with pdftex.
1129 %
1130 % v0.0.5 May 26, 2003 A small change to make fixseminar work better when hyperref is not loaded.
1131
1132
1133 \NeedsTeXFormat{LaTeX2e}
1134
1135 \ProvidesPackage%
1136 {fixseminar}%
1137 [2003/05/26 v0.0.5 Fix some problems of seminar.]
1138
1139
1140 %=======================================================================================================================
1141
1142 \RequirePackage{ifthen}
1143
1144
1145 %=======================================================================================================================
1146 % Options and general setup.
1147
1148 \ProcessOptions
1149
1150
1151 % The switch \ifpdf is to determine whether pdfLaTeX is being run and outputting pdf, using Heiko Oberdiek's faultproof
1152 % pdf detector:
1153
1154 \IfFileExists{ifpdf.sty}
1155 {%
1156 \RequirePackage{ifpdf}%
1157 }
1158 {%
1159 \@ifundefined{pdftrue}
1160 {%
1161 \expandafter\newif\csname ifpdf\endcsname
1162 \ifx\pdfoutput\undefined
1163 \else
1164 \ifx\pdfoutput\relax
1165 \else
1166 \ifcase\pdfoutput
1167 \else
1168 \pdftrue
1169 \fi
1170 \fi
1171 \fi
1172 }{}%
1173 }
1174
1175
1176 %=======================================================================================================================
1177 % Here come the fixes.
1178
1179 % We need to make sure that magnification, as used by seminar, is respected when setting \pdfpageheight and
1180 % \pdfpagewidth. We strip the pt and add truept which respects magnification.
1181
1182
1183 \ifthenelse{\boolean{pdf}}% Are we outputting PDF?
1184 {% Yes.
1185 \@ifclassloaded{seminar}% seminar document class?
1186 {%
1187 \RequirePackage{graphics}%
1188 \def\leftsliderotation#1{\rotatebox{90}{#1}}%
1189 \def\rightsliderotation#1{\rotatebox{270}{#1}}%
1190 \sliderotation{left}%
1191 }{}%
1192 \AtBeginDocument% Then we need to set \pdfpagewidth and \pdfpageheight in a _true_ unit to make sure
1193 {% the pdf page has the right dimensions even when magnifying (as seminar does).
1194 \setlength{\pdfhorigin}{1truein}% \pdfhorigin and \pdfvorigin also need to be set to true dimensions.
1195 \setlength{\pdfvorigin}{1truein}%
1196 \@ifclassloaded{seminar}% seminar document class?
1197 {%
1198 \ifportrait% Portrait slides?
1199 \setlength{\pdfpageheight}{\strip@pt\paperheight truept}%
1200 \setlength{\pdfpagewidth}{\strip@pt\paperwidth truept}%
1201 \else% Landscape. Need to exchange height and width.
1202 \renewcommand{\printlandscape}
1203 {%
1204 \setlength{\pdfpagewidth}{\strip@pt\paperheight truept}%
1205 \setlength{\pdfpageheight}{\strip@pt\paperwidth truept}%
1206 }%
1207 \fi
1208 }%
1209 {%
1210 \setlength{\pdfpageheight}{\strip@pt\paperheight truept}%
1211 \setlength{\pdfpagewidth}{\strip@pt\paperwidth truept}%
1212 }%
1213 }%
1214 }
1215 {% No. In this case we define \special@paper which will put an appropriate \special into the dvi file.
1216 \@ifclassloaded{seminar}
1217 {%
1218 \ifportrait
1219 \edef\special@paper{\the\paperwidth,\the\paperheight}%
1220 \else% Need to exchange height and width.
1221 \renewcommand{\printlandscape}{\edef\special@paper{\the\paperheight,\the\paperwidth}}
1222 \fi
1223 \AtBeginDocument{\special{papersize=\special@paper}}%
1224 }%
1225 {%
1226 }%
1227 }%
1228
1229
1230 % There is a bug in old hyperref versions to the effect that apparently, when using seminar there is a glitch in
1231 % vertical spacing. Issue a warning if hyperref is too old.
1232
1233 \@ifpackageloaded{hyperref}% Looking for \@hyperfixhead bug.
1234 {%
1235 \@ifpackagelater{hyperref}{2000/09/07}% Is the \@hyperfixhead bug present in hyperref?
1236 {}% No.
1237 {% Yes. Issue a warning.
1238 \PackageWarning{fixseminar}
1239 {Package hyperref too old (older than 6.70u).\MessageBreak Expect problems with seminar}%
1240 }%
1241 }{}
1242 %KEEPCOMMENTS
1243 %</fixseminar>
1244 %=======================================================================================================================
1245 %<*tppstcol>
1246 %<<KEEPCOMMENTS
1247 %=======================================================================================================================
1248 % File: tppstcol.sty
1249 %
1250 % Replacement for ``pstcol.sty'' with some quirks corrected.
1251 % There is a small problem with pstcol.sty which makes it impossible
1252 % to set something like "fillcolor=\linecolor" in pstricks (see LaTeX
1253 % Bug graphics/3366). As this is absolutely indispensible for
1254 % automata.sty, I had to make a modified version to be used until the
1255 % bug is mended.
1256 % The following code is identical with the original pstcol.sty, with
1257 % some modifications to correct the bug.
1258 %
1259 % This package is an addition to the TeXPower bundle, to be found at
1260 %
1261 % http://texpower.sourceforge.net/
1262 %
1263 % Beware! As soon as the original bug in pstcol is corrected, this
1264 % package will be deleted.
1265 %
1266 %=======================================================================================================================
1267
1268 \NeedsTeXFormat{LaTeX2e}
1269 \ProvidesPackage{tppstcol}
1270 [2001/08/28 v0.2 PSTricks color compatibility (DPC; revised
1271 by STL)]
1272 %%%%%%%%%%%%%%%%%%
1273 \let\saved@gray\color@gray
1274 \RequirePackage{pstricks}
1275 \let\color@gray\saved@gray
1276 %%%%%%%%%%%%%%%%
1277 \DeclareOption*{\PassOptionsToPackage\CurrentOption{color}}
1278 \ProcessOptions
1279 \RequirePackage{color}
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1281 \def\pst@getcolor#1#2{%
1282 \@ifundefined{\string\color@#1}%
1283 {\@pstrickserr{Color `#1' not defined}\@eha}%
1284 {\edef#2{#1}}}
1285 \def\pst@usecolor#1%
1286 {%
1287 \expandafter\expandafter\expandafter
1288 \c@lor@to@ps\csname\string\color @#1\endcsname\@@\space%
1289 }
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 \definecolor{darkgray}{gray}{.25}
1292 \definecolor{gray}{gray}{.5}
1293 \definecolor{lightgray}{gray}{.75}
1294 \definecolor{gradbegin}{rgb}{0,1,1}
1295 \definecolor{gradend}{rgb}{0,.1,.95}
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 \psset@bordercolor{white}
1298 \psset@doublecolor{white}
1299 \psset@linecolor{black}
1300 \psset@fillcolor{white}
1301 \psset@hatchcolor{black}
1302 \psset@gridcolor{black}
1303 \psset@gridlabelcolor{black}
1304 \psset@shadowcolor{darkgray}
1305 \psset@subgridcolor{gray}
1306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1307 \def\newgray#1{%
1308 \definecolor{#1}{gray}}
1309 \def\newrgbcolor#1#2{%
1310 \newrgbcolorx{#1}#2\@@}
1311 \def\newrgbcolorx#1#2 #3 #4\@@{%
1312 \definecolor{#1}{rgb}{#2,#3,#4}}
1313 \def\newcmykcolor#1#2{%
1314 \newcmykcolorx{#1}#2\@@}
1315 \def\newcmykcolorx#1#2 #3 #4 #5\@@{%
1316 \definecolor{#1}{cmyk}{#2,#3,#4,#5}}
1317 %KEEPCOMMENTS
1318 %</tppstcol>
1319 %=======================================================================================================================
1320 %<*tpsem-a4>
1321 %<<KEEPCOMMENTS
1322 % Fixed for LaTeX2e (\paperwidth and \paperheight are dimensions) by
1323 % Stephan Lehmke.
1324 \setlength\paperwidth{210mm}
1325 \setlength\paperheight{297mm}
1326 \input sem-page.sty
1327 \slidewidth 222mm
1328 \slideheight 152mm
1329 %KEEPCOMMENTS
1330 %</tpsem-a4>
1331 \endinput