Debian Codegraph @

texmf-dist/doc/latex/ribbonproofs/ribbonproofsmanual.tex

raw
1 \documentclass[12pt, a4paper]{article}
2 \usepackage[margin=1in]{geometry}
3 \usepackage[T1]{fontenc}
4 \renewcommand\floatpagefraction{.9}
5 \renewcommand\rmdefault{ptm}
6
7 \newcommand\COLORcom{MediumPurple}
8 \newcommand\COLORkey{SeaGreen}
9 \newcommand\COLORenv{MediumPurple}
10 \newcommand\COLORpkg{Chocolate}
11 \newcommand\COLORdef{blue}
12
13 \renewcommand{\refname}{Bibliography}
14 \usepackage[nottoc]{tocbibind}
15
16 \usepackage{makeidx}
17 \makeindex
18 \newcommand*\indexkey[1]{\index{%
19 #1 key@\texttt{\color{\COLORkey}#1} key}}
20 \newcommand*\indexenv[1]{\index{%
21 #1 environment@\texttt{\color{\COLORenv}#1} environment}}
22 \newcommand*\indexcom[1]{\index{%
23 #1 command@\texttt{\color{\COLORcom}\textbackslash #1} command}}
24
25 \newcommand*\packagename[1]{\textsf{\color{\COLORpkg}#1}}
26
27 \newcommand*\varsasresonly{\emph{[Variables-as-resource only.]}\index{variables-as-resource}}
28
29 \newcommand*\Ienv[1]{%
30 {\color{\COLORenv}\ttfamily #1}\indexenv{#1}}
31 \newcommand*\Icom[1]{%
32 {\color{\COLORcom}\ttfamily\textbackslash #1}\indexcom{#1}}
33 \newcommand*\Ikey[1]{%
34 {\color{\COLORkey}\ttfamily #1}\indexkey{#1}}
35
36
37 \usepackage{ribbonproofs}
38
39 \usepackage{framed}
40 \definecolor{shadecolor}{rgb}{0.95,0.95,1}
41
42 \usepackage{tkzexample}
43 \colorlet{graphicbackground}{white}
44 \colorlet{codebackground}{shadecolor}
45
46 %
47 \usepackage{listings}
48 \lstset{%
49 numbers=left,
50 numberstyle=\tiny,
51 stepnumber=5,
52 basicstyle=\tt,
53 columns=flexible
54 }
55 %
56
57 \usepackage{standalone}
58 \usepackage{filecontents} % Otherwise filecontents is
59 % only available in preamble.
60
61 \usepackage{fancyvrb}
62 \makeatletter
63 \renewcommand\FV@FontFamily{\color{\COLORdef}\ttfamily}
64 \makeatother
65 \DefineShortVerb{\"}
66
67 \newcommand{\dotneq}{\mathrel{\not\doteq}}
68 \newcommand\ls{\mathit{ls}}
69 \newcommand\x{\texttt{x}}
70 \newcommand\y{\texttt{y}}
71 \renewcommand\t{\texttt{t}}
72 \renewcommand\u{\texttt{u}}
73 \newcommand\List{\mathit{list}}
74 \newcommand*\rev[1]{#1^{\dagger}}
75 \newcommand\z{\texttt{z}}
76
77 \title{The \packagename{ribbonproofs} package}
78 \author{John Wickerson}
79 \date{Version 1.0 -- 26 June 2013}
80
81 \begin{document}
82
83 \maketitle
84
85 \begin{abstract}
86 \noindent The \packagename{ribbonproofs} package provides a mechanism for drawing ribbon proofs in \LaTeX{}. Ribbon proofs form a diagrammatic proof system, due to Wickerson, Dodds and Parkinson~\cite{wickerson+13}, for \emph{separation logic}~\cite{reynolds02}\index{separation logic}. They build on an earlier system, due to Bean~\cite{bean06}, for \emph{bunched implications logic}~\cite{ohearn+99}.
87 \end{abstract}
88
89 \tableofcontents
90
91 \begin{figure}
92 \begin{tkzexample}[]
93 \documentclass{standalone}
94 \usepackage{ribbonproofs}
95 \begin{document}
96 \def\to{\mapsto}
97 \begin{ribbonproof}[start ribbons={
98 a/{left=0, right=16, label={\tt x}\to0},
99 b/{left=18, right=34, label={\tt y}\to0},
100 c/{left=36, right=52, label={\tt z}\to0}}]
101 \com[finish ribbons={a}, start ribbons={
102 a/{label={\tt x}\to1}}]{[x]:=1} \\
103 \com[finish ribbons={b}, start ribbons={
104 b/{label={\tt y}\to1}}]{[y]:=1} \\
105 \com[finish ribbons={c}, start ribbons={
106 c/{label={\tt z}\to1}}]{[z]:=1} \\
107 \end{ribbonproof}
108 \end{document}
109 \end{tkzexample}
110 \caption{A test document and its expected result}
111 \label{fig:threeassign}
112 \end{figure}
113
114 \section{Getting started}
115
116 \subsection{Installation}
117
118 Place "ribbonproofs.sty" into the same directory as the ".tex" file you are compiling. To test that the package is working correctly, you might try to compile the little document given in Fig.~\ref{fig:threeassign}. The code is given on the lefthand side, with the expected output to the right.
119
120 \subsection{A simple example}
121
122 Figure~\ref{fig:threeassign} provides a good starting point for examining how the \packagename{ribbonproofs} package works.
123
124 All the action takes place within the \Ienv{ribbonproof} environment. Upon entering this environment, we provide the \Ikey{start ribbons} key, in order to introduce some ribbons at the top of the diagram. We name them "a", "b" and "c", give the horizontal positions of their \Ikey{left} and \Ikey{right} edges, and provide a \Ikey{label}.
125
126 We then proceed to build up the diagram in a series of rows, each terminated with \Icom{\textbackslash}. In this example, each row comprises a single \Icom{com} step (\Icom{com} stands for `command'). Each \Icom{com} has a number of optional parameters. The \Ikey{finish ribbons} key lists those ribbons that end at this step; they form the step's precondition. The \Ikey{start ribbons} key defines ribbons that begin at this step; they form the step's postcondition. Note that we used the same syntax (\Ikey{start ribbons}) to introduce some ribbons at the beginning of the proof. Each \Icom{com} has one mandatory parameter: the text, which is printed in white on the step.
127
128 \section{Examples}
129
130 \subsection{List append}
131
132 Figure~\ref{fig:listappend} shows the result.
133
134 \begin{filecontents*}{temp_example_listappend.tex}
135 \begin{ribbonproof}[start ribbons={
136 c/{left=35,right=53,label=\ls\,\x\,0},
137 e/{left=74,right=86,label=\ls\,\y\,0}}]
138 \startblock[extra left=33, extra right=2,
139 fit ribbons={c,e}, start ribbons={
140 d/{left=\RIBcRIGHT+2,right=\RIBeLEFT-4,label=\x\doteq 0}
141 }]{if (x==0) \{}
142 \\
143 \jus[finish ribbons={c,d}]{Unfold $\ls$ def}
144 \com[finish ribbons={e}, start ribbons={
145 e/{label=\ls\,\x\,0}}]{x:=y}
146 \\[-6]
147 \moveribbons{e/{left=4}}
148 \\[-1]
149 \continueblock[repeat labels, start ribbons={
150 d/{label=\x\dotneq 0}}]{\} else \{}
151 \\[-1]
152 \jus[start ribbons={
153 a/{left=6,right=\RIBcLEFT-2,label=\ls\,\x\,\x}}]{Fold $\ls$ def}
154 \\[-4]
155 \moveribbons{c/{left=20},a/{right=18}}
156 \\[-4]
157 \com[finish ribbons={a,c,d}, start ribbons={
158 a/{label=\ls\,\x\,\t},
159 c/{label=\ls\,\t\,0},
160 d/{label=\t\dotneq 0}}]{t:=x}
161 \\
162 \jus[finish ribbons={c,d}, start ribbons={
163 c/{label=\exists U\ldotp\t\mapsto U * \ls\,U\,0}}]{Unfold $\ls$ def}
164 \\
165 \com[finish ribbons={c}, start ribbons={
166 b/{left=\RIBcLEFT,right=33,label=\t\mapsto\u},
167 c/{left=35,right=\RIBcRIGHT,label=\ls\,\u\,0}}]{u:=[t]}
168 \\
169 \startblock[fit ribbons={a},
170 extra left=2, extra right=2,start ribbons={
171 d/{label=\u\dotneq 0}}]{while (u!=0) \{}
172 \\
173 \jus[finish ribbons={a,b,c}, height=10, start ribbons={
174 a/{right=\RIBbRIGHT, label=\ls\,\x\,\u},
175 c/{label=\ls\,\u\,0}}]{Lemma: $\ls\,a\,b *\ls\,b\,c * \ls\,c\,0$ \\
176 implies $\ls\,a\,c * \ls\,c\,0$}
177 \\
178 \moveribbons{a/{right=18},c/{left=20}}
179 \\[-3]
180 \com[finish ribbons={a,c,d}, start ribbons={
181 a/{label=\ls\,\x\,\t},
182 c/{label=\ls\,\t\,0},
183 d/{label=\t\dotneq 0}}]{t:=u}
184 \\
185 \jus[finish ribbons={c,d}, start ribbons={
186 c/{label=\exists U\ldotp\t\mapsto U * \ls\,U\,0}}]{Unfold $\ls$ def}
187 \\
188 \com[finish ribbons={c}, start ribbons={
189 b/{left=\RIBcLEFT,right=33,label=\t\mapsto\u},
190 c/{left=35,right=\RIBcRIGHT,label=\ls\,\u\,0}}]{u:=[t]}
191 \\
192 \finishblock[start ribbons={
193 d/{label=\u\doteq 0}}]{\}}
194 \\
195 \jus[finish ribbons={b,c,d}, start ribbons={
196 b/{label=\t\mapsto0}}]{Unfold $\ls$ def}
197 \\
198 \com[finish ribbons={b}, start ribbons={
199 b/{label=\t\mapsto\y}}]{[t]:=y}
200 \\
201 \jus[finish ribbons={b,e}, start ribbons={
202 b/{right=\RIBeRIGHT,label=\ls\,\t\,0}}]{Fold $\ls$ def}
203 \\
204 \jus[finish ribbons={a,b}, start ribbons={
205 a/{right=\RIBeRIGHT,label=\ls\,\x\,0}}]{
206 Lemma: $\ls\,a\,b * \ls\,b\,0$ implies $\ls\,a\,0$}
207 \\
208 \finishblock{\}}
209 \\
210 \end{ribbonproof}
211 \end{filecontents*}
212
213 \begin{shaded}
214 \lstinputlisting{temp_example_listappend.tex}
215 \end{shaded}
216
217 \begin{figure}
218 \small\centering
219 \include{temp_example_listappend}
220 \caption{A ribbon proof of list append}
221 \label{fig:listappend}
222 \end{figure}
223
224 \clearpage
225
226 \subsection{List reverse}
227
228 Figure~\ref{fig:listrev} shows the result.
229
230 \begin{filecontents*}{temp_example_listrev.tex}
231 \begin{ribbonproof}[start ribbons={
232 b/{left=20,right=38,label=\List\,\delta\,\x}}]
233 \com[start ribbons={
234 c/{left=40,right=78,label=\List\,\varepsilon\,\y}}]{y:=0};
235 \\
236 \jus[finish ribbons={b,c}, start ribbons={
237 b/{label=\List\,\alpha\,\x},
238 d/{label=\delta\doteq \rev{\beta}\cdot\alpha,
239 left=60, right=\RIBcRIGHT},
240 c/{label=\List\,\beta\,\y, right=58}
241 }, start boxes={
242 alpha/{left=14,right=82,label=\exists\alpha,color=SeaGreen},
243 beta/{left=18,right=80,label=\exists\beta,color=MediumPurple}
244 }]{Choose $\alpha:=\delta$ and $\beta:=\varepsilon$}
245 \\
246 \startblock[fit boxes={alpha},
247 extra left=10, extra right=2, start ribbons={
248 a/{left=0,right=10,label=\x\dotneq 0}}]{while (x!=0) \{}
249 \\
250 \extendboxes{alpha/{left=-4}}
251 \\[-9]
252 \extendboxes{beta/{left=-8}}
253 \\[-9]
254 \jus[finish ribbons={a,b}, start ribbons={
255 ab/{left=\RIBaLEFT, right=\RIBbRIGHT,
256 label={\exists\alpha',i,Z\ldotp\x\mapsto i,Z \\
257 {} * \List\,\alpha'\,Z * \alpha \doteq i \cdot \alpha'}}
258 }]{Unfold $\List$ def}
259 \\[-11]
260 \moveribbons{
261 c/{left=70,right=\RIBdRIGHT},
262 d/{left=40,right=64}}
263 \moveboxes{
264 alpha/{right=\RIBdRIGHT+4}}
265 \\[4]
266 \jus[finish boxes={alpha}, start boxes={
267 alpha/{label=\exists\alpha},
268 i/{left=\RIBabLEFT-2,right=\RIBdRIGHT+2,color=Chocolate,
269 vertical offset=10,label=\exists i}
270 }, finish ribbons={ab,d},
271 start ribbons={
272 ab/{label={\exists Z\ldotp\x \mapsto i,Z * \List\,\alpha\,Z}},
273 d/{label=\delta\doteq \rev{\beta}\cdot(i\cdot\alpha)}
274 }]{Choose $\alpha:=\alpha'$}
275 \\
276 \com[finish ribbons={ab}, start ribbons={
277 a/{right=14,label=\List\,\alpha\,\z},
278 b/{label={\x\mapsto i,\z}}
279 }]{z:=[x+1]}
280 \moveribbons{
281 c/{left=\RIBdLEFT, right=50},
282 d/{left=52, right=76}}
283 \moveboxes{
284 alpha/{left=-8,right=82},
285 beta/{left=-6},
286 i/{right=78}}
287 \\
288 \com[finish ribbons={b}, start ribbons={
289 b/{label={\x\mapsto i,\y}}}]{[x+1]:=y}
290 \jus[finish ribbons={d}, start ribbons={
291 d/{label={\delta\doteq \rev{(i\cdot\beta)}\cdot\alpha}}}]
292 {Reassociate $i$}
293 \moveboxes{
294 i/{left=\RIBbLEFT-2},
295 beta/{left=\RIBbLEFT-4}}
296 \\
297 \jus[finish ribbons={b,c}, start ribbons={
298 c/{left=\RIBbLEFT,label={\List (i\cdot\beta)\,\x}}}]{Fold $\List$ def}
299 \\
300 \jus[finish ribbons={c,d}, finish boxes={i,beta},
301 start boxes={
302 beta/{vertical offset=10,horizontal offset=2,label=\exists\beta}},
303 start ribbons={
304 c/{label={\List\,\beta\,\x}},
305 d/{label={\delta\doteq\rev{\beta}\cdot\alpha}}}]
306 {Choose $\beta:=(i\cdot\beta)$}
307 \\[-6]
308 \moveribbons{
309 d/{left=60,right=78},
310 c/{left=40,right=58},
311 a/{left=20,right=38}}
312 \moveboxes{
313 alpha/{left=14},
314 beta/{left=18}}
315 \\
316 \com[finish ribbons={c}, start ribbons={
317 c/{label={\List\,\beta\,\y}}}]{y:=x}
318 \\[-5]
319 \com[finish ribbons={a}, start ribbons={
320 b/{left=\RIBaLEFT,right=\RIBaRIGHT,label={\List\,\alpha\,\z}}}]{x:=z}
321 \\
322 \finishblock[start ribbons={
323 a/{left=0,right=10,label={\x\doteq 0}}
324 }]{\}}
325 \\
326 \extendboxes{alpha/{left=-8}}
327 \\[-9]
328 \extendboxes{beta/{left=-6}}
329 \\[-9]
330 \jus[finish ribbons={a,b},start ribbons={
331 a/{right=\RIBbRIGHT,label=\alpha\doteq \varepsilon}}]
332 {Unfold $\List$ def}
333 \swapribbons{c,d}{d,c}
334 \\
335 \jus[finish ribbons={a,d}, start ribbons={
336 a/{right=\RIBdRIGHT,label=\delta\doteq\rev{\beta}}}]
337 {Concatenate empty sequence}
338 \\
339 \jus[finish ribbons={a,c}, finish boxes={alpha,beta},
340 start ribbons={
341 a/{right=\RIBcRIGHT,label={\List\,\rev{\delta}\,\y}}}]
342 {Fold $\List$ def}
343 \\
344 \end{ribbonproof}
345 \end{filecontents*}
346
347 \begin{shaded}
348 \lstinputlisting{temp_example_listrev.tex}
349 \end{shaded}
350
351 \begin{figure}
352 \small\centering
353 \include{temp_example_listrev}
354 \caption{A ribbon proof of list reverse}
355 \label{fig:listrev}
356 \end{figure}
357
358 \clearpage
359
360 \subsection{List reverse with variables-as-resource}
361
362 Figure~\ref{fig:listrevvar} shows the result.
363
364 \begin{filecontents*}{temp_example_listrevvar.tex}
365 \begin{ribbonproof}[start ribbons={
366 b/{left=20,right=38,var width=5,label=\x&\List\,\delta\,\x},
367 e/{left=40,right=45, var width=5,label=\z&},
368 c/{left=50,right=55, var width=5,label=\y&}}]
369 \jus[finish ribbons={b}, start ribbons={
370 a/{left=-5,right=0,var width=5, label={\frac12\x&}},
371 b/{label={\frac12\x&\List\,\delta\,\x}}
372 }]{Split $\x$}
373 \com[finish ribbons={c},start ribbons={
374 c/{left=50,right=88,label=\y&\List\,\varepsilon\,\y}}]{y:=0};
375 \\
376 \jus[finish ribbons={b,c}, start ribbons={
377 b/{label=\frac12\x&\List\,\alpha\,\x},
378 c/{label=\y&\List\,\beta\,\y, right=68},
379 d/{label=\delta\doteq \rev{\beta}\cdot\alpha, left=70, right=88}
380 }, start boxes={
381 alpha/{left=14,right=94,label=\exists\alpha,color=SeaGreen},
382 beta/{left=18,right=92,label=\exists\beta,color=MediumPurple}
383 }]{Choose $\alpha:=\delta$ and $\beta:=\varepsilon$}
384 \\
385 \startblock[fit boxes={alpha},
386 extra left=10, extra right=2, finish ribbons={a}, start ribbons={
387 a/{left=-5,right=10,label=\frac12\x&\x\dotneq 0}}]{while (x!=0) \{}
388 \\
389 \extendboxes{alpha/{left=-9}}
390 \\[-9]
391 \extendboxes{beta/{left=-13}}
392 \\[-9]
393 \jus[finish ribbons={a,b}, start ribbons={
394 ab/{left=\RIBaLEFT, right=\RIBbRIGHT, var width=5,
395 label={\x&\exists\alpha',i,Z\ldotp\x\mapsto i,Z \\{}
396 * \List\,\alpha'\,Z * \alpha \doteq i \cdot \alpha'}}}]
397 {Unfold $\List$ def}
398 \moveboxes{
399 alpha/{right=92},
400 beta/{right=94}}
401 \\[4]
402 \jus[finish boxes={alpha}, start boxes={
403 alpha/{label=\exists\alpha},
404 i/{left=-7,right=90,color=Chocolate,
405 vertical offset=11,label=\exists i}
406 }, finish ribbons={ab,d},
407 start ribbons={
408 ab/{label={\x&\exists Z\ldotp\x \mapsto i,Z * \List\,\alpha\,Z}},
409 d/{label=\delta\doteq{}\\\rev{\beta}\cdot(i\cdot\alpha)}
410 }]{Choose $\alpha:=\alpha'$}
411 \\
412 \com[finish ribbons={ab,e}, start ribbons={
413 a/{right=14,label=\frac12\z&\List\,\alpha\,\z},
414 b/{var width=10,left=16,right=\RIBeRIGHT,
415 label={\x,\frac12\z&\x\mapsto i,\z}}
416 }]{z:=[x+1]}
417 \jus[finish ribbons={c}, start ribbons={
418 cc/{left=57, right=\RIBcRIGHT, var width=5,
419 rotated label={\List\,\beta\,\y}, label=\frac12\y&},
420 c/{right=55, label=\frac12\y&}
421 }]{Split $\y$}
422 \moveboxes{alpha/{left=-11}}
423 \\
424 \com[finish ribbons={b,c}, start ribbons={
425 b/{var width=5,right=21, label=\frac12\z&},
426 c/{left=27, var width=10,label={\x,\frac12\y&\x\mapsto i,\y}}
427 }]{[x+1]:=y}
428 \jus[finish ribbons={d}, start ribbons={
429 d/{label={\delta\doteq {}\\
430 \rev{(i\cdot\beta)}\cdot\alpha}}}]{Reassoc. $i$}
431 \\[-6]
432 \moveboxes{
433 i/{left=25},
434 beta/{left=23,right=92},
435 alpha/{right=94}}
436 \\
437 \jus[finish ribbons={a,b}, start ribbons={
438 a/{right=\RIBbRIGHT, label={\z&\List\,\alpha\,\z}}
439 }]{Combine $\z$}
440 \jus[finish ribbons={c,cc}, start ribbons={
441 c/{var width=5, label={\x&\List (i\cdot\beta)\,\x}},
442 cc/{left=63, label=\y&}
443 }]{Fold $\List$ def}
444 \\
445 \jus[finish ribbons={c,d}, finish boxes={i,beta},
446 start boxes={
447 beta/{horizontal offset=2,label=\exists\beta}},
448 start ribbons={
449 c/{label={\List\,\beta\,\x}, label=\x&},
450 d/{label={\delta\doteq\rev{\beta}\cdot\alpha}}}]
451 {Choose $\beta:=(i\cdot\beta)$}
452 \\[-2]
453 \moveribbons{c/{left=43,right=61},a/{left=20,right=41}}
454 \moveboxes{alpha/{left=14},beta/{left=18}}
455 \\
456 \com[finish ribbons={c,cc}, start ribbons={
457 e/{left=\RIBcLEFT, right=\RIBcLEFT+5, label=\x&},
458 c/{left=50,right=\RIBccRIGHT,label={\List\,\beta\,\y}, label=\y&}
459 }]{y:=x}
460 \\
461 \com[finish ribbons={a,e}, start ribbons={
462 b/{left=\RIBaLEFT,right=\RIBaRIGHT,label=\frac12\x&\List\,\alpha\,\x},
463 a/{left=-5,right=0,var width=5, label=\frac12\x&},
464 e/{label=\z&}
465 }]{x:=z}
466 \\
467 \finishblock[finish ribbons={a},start ribbons={
468 a/{right=10,label={\frac12\x&\x\doteq 0}}
469 }]{\}}
470 \\
471 \extendboxes{alpha/{left=-8}}
472 \\[-9]
473 \extendboxes{beta/{left=-6}}
474 \\[-9]
475 \jus[finish ribbons={a,b},start ribbons={
476 a/{right=0, label=\x&},
477 b/{left=6,label=\alpha\doteq \varepsilon, var width=0}
478 }]{Unfold $\List$ def}
479 \moveribbons{
480 d/{left=43,right=48},
481 e/{left=74,right=79}
482 }
483 \moveboxes{
484 alpha/{right=72},
485 beta/{right=70}}
486 \\
487 \jus[finish ribbons={b,d}, start ribbons={
488 b/{right=\RIBdRIGHT,label=\delta\doteq\rev{\beta}}
489 }]{Concatenate empty seq.}
490 \moveboxes{alpha/{left=2},beta/{left=4}}
491 \\
492 \jus[finish ribbons={b,c}, finish boxes={alpha,beta},
493 start ribbons={
494 c/{label={\y&\List\,\rev{\delta}\,\y}}
495 }]{Fold $\List$ def}
496 \\
497 \end{ribbonproof}
498 \end{filecontents*}
499
500 \begin{shaded}
501 \lstinputlisting{temp_example_listrevvar.tex}
502 \end{shaded}
503
504 \begin{figure}
505 \small\centering
506 \include{temp_example_listrevvar}
507 \caption{A ribbon proof of list reverse using variables-as-resource}
508 \label{fig:listrevvar}
509 \end{figure}
510
511 \clearpage
512
513 \section{Reference}
514
515 \subsection{Package dependencies}
516
517 The \packagename{ribbonproofs} package relies upon:
518 \begin{itemize}
519 \item the \packagename{xcolor} package for colours;
520 \item the \packagename{tikz} package, plus its \packagename{calc}, \packagename{fadings} and \packagename{decorations.pathmorphing} libraries, for drawing;
521 \item the \packagename{xstring} package for manipulating strings; and
522 \item the \packagename{etextools} package for controlling the expansion of \TeX{} macros.
523 \end{itemize}
524
525 \subsection{The \Ienv{ribbonproof} environment}
526
527 \begin{description}
528 \item "\begin{"\Ienv{ribbonproof}"}["$\mathit{options}$"]"$\ldots$"\end{"\Ienv{ribbonproof}"}" \quad This is the top-level environment for creating ribbon proofs. All of the ribbon-proof-building commands must only appear inside this environment. Available $\mathit{options}$ are:
529 \begin{description}
530 \item \Ikey{extra height}"="$n$ \quad (Default: "0".) This option adds $n$ (an integer or integer expression) to the height of the diagram's first row.
531 \item \label{key:startribbons}\Ikey{start ribbons}"={"$\mathit{ribbon}_1$","$\dots$","$\mathit{ribbon}_k$"}" \quad (Default: empty.) This defines a list of $k$ ribbons that henceforth are \emph{active}. Each $\mathit{ribbon}$ takes the form
532 \begin{center}
533 $\mathit{name}$"/{"$\mathit{options}$"}"
534 \end{center}
535 where $\mathit{name}$ is an alphabetic string that henceforth identifies the ribbon, and the available $\mathit{options}$ are:
536 \begin{description}
537 \item \Ikey{left}"="$n$ \quad (Default: "0".) The horizontal position of the ribbon's left edge. The value $n$ must either be an integer or an expression that evaluates to an integer. The value is stored in the command \Icom{RIBnameLEFT}, where "name" is the name of the ribbon. Ribbons can be positioned relatively by accessing this value. For instance, one can write "left=\RIBfooLEFT-20" to set the current ribbon's left edge 20 units to the left of the ribbon "foo"'s left edge.
538 \item \Ikey{right}"="$n$ \quad (Default: "0".) The horizontal position of the ribbon's right edge. The value $n$ must either be an integer or an expression that evaluates to an integer. The value is stored in the command \Icom{RIBnameRIGHT}, where "name" is the name of the ribbon.
539 \item \Ikey{label}"="$L$ \quad (Default: empty.) The label that is written on the ribbon. The value $L$ is parsed in math-mode. There are three complications here.
540 \begin{itemize}
541 \item If $L$ contains a comma or an equals-sign, it must be wrapped in braces; otherwise the parser will become confused. For instance, be sure to write "label={0<x,y<5}" instead of "label=0<x,y<5".
542 \item \varsasresonly{} If $L$ contains an \texttt{\color{\COLORcom}\&} symbol\index{\& command@\texttt{\color{\COLORcom}\&} command}, the portion to the left of the \texttt{\color{\COLORcom}\&} is used as the `variable resource'. Here are some examples.
543
544 \begin{tkzexample}[]
545 \begin{ribbonproof}[start ribbons={
546 a/{left=5, right=25, var width=5,
547 label=\texttt{x}&\texttt{x}<a},
548 b/{left=30, right=35, var width=5,
549 label=\texttt{y}&},
550 c/{left=40, right=80,
551 label={\exists b\ldotp a=2^b \wedge b<9}}}]
552 \end{ribbonproof}
553 \end{tkzexample}
554
555 \end{itemize}
556 \item \Ikey{var width}"="$n$ \quad (Default: "0".) \varsasresonly{} The width of the `variable resource' part of the ribbon. The value is stored in the command \Icom{RIBnameVARWIDTH}, where "name" is the name of the ribbon. In the case where
557 \[
558 n=\mbox{\Ikey{right}}-\mbox{\Ikey{left}}
559 \]
560 the ribbon consists \emph{only} of the variable resource.
561 \item \Ikey{rotated label}"="$L$ \quad (Default: empty.) If this key is given instead of \Ikey{label}, the label $L$ will be rotated through 90$^\circ$ clockwise. This feature can be handy when horizontal space is tight.\par \varsasresonly{} It is not currently possible to rotate the variable resource. However, a variable resource can be coupled with a rotated assertion by using both the \Ikey{label} and the \Ikey{rotated label} keys in the following manner.
562
563 \begin{tkzexample}[latex=2cm]
564 \begin{ribbonproof}[extra height=9, start ribbons={
565 a/{left=0, right=11, var width=5,
566 label=\texttt{x}&, rotated label=\texttt{x}<a}}]
567 \end{ribbonproof}
568 \end{tkzexample}
569 \end{description}
570
571 \item \label{key:startboxes}\Ikey{start boxes}"={"$\mathit{box}_1$","$\dots$","$\mathit{box}_k$"}" \quad (Default: empty.) This defines a list of $k$ boxes that henceforth are \emph{active}. Each $\mathit{box}$ takes the form
572 \begin{center}
573 $\mathit{name}$"/{"$\mathit{options}$"}"
574 \end{center}
575 where $\mathit{name}$ is an alphabetic string that henceforth identifies the box, and the available $\mathit{options}$ are:
576 \begin{description}
577 \item \Ikey{left}"="$n$ \quad (Default: "0".) The horizontal position of the box's left edge. The value $n$ must either be an integer or an expression that evaluates to an integer. The value is stored in the command \Icom{BOXnameLEFT}, where "name" is the name of the box. Boxes can be positioned relatively by accessing this value. For instance, one can write "left=\BOXfooLEFT-5" to set the current box's left edge 5 units to the left of the box "foo"'s left edge.
578 \item \Ikey{right}"="$n$ \quad (Default: "0".) The horizontal position of the box's right edge. The value $n$ must either be an integer or an expression that evaluates to an integer. The value is stored in the command \Icom{BOXnameRIGHT}, where "name" is the name of the box.
579 \item \Ikey{label}"="$L$ \quad (Default: empty.) The label that is written on the left edge of the box. The value $L$ is parsed in math-mode.
580 \item \Ikey{vertical offset}"="$n$ \quad (Default: "0".) Shifts the \Ikey{label} down by $n$. The value $n$ must either be an integer or an expression that evaluates to an integer.
581 \item \Ikey{horizontal offset}"="$n$ \quad (Default: "0".) Shifts the \Ikey{label} to the right by $n$. The value $n$ must either be an integer or an expression that evaluates to an integer.
582 \item \Ikey{color}"="$c$ \quad (Default: "black".) The colour of the box's lines and of its label text.
583 \end{description}
584
585 \item \Ikey{draw grid} \quad (Default: "false".) This option lays a grid underneath the picture. The grid looks like graph paper, and is intended to help the user to position the elements of the diagram. As additional visual aids, it places little `ticks' down the left-hand edge of the diagram, to show where each row begins, and it labels each ribbon with its name. Here is an example.
586 \begin{tkzexample}[]
587 \begin{ribbonproof}[draw grid,
588 start ribbons={
589 a/{left=0, right=10, label=A},
590 b/{left=12, right=22, label=B},
591 c/{left=24, right=34, label=C}}]
592 \com[finish ribbons={a,b},
593 start ribbons={
594 a/{label=D},
595 b/{label=E}}]{foo} \\
596 \com[finish ribbons={b,c},
597 start ribbons={
598 b/{label=F},
599 c/{label=G}}]{baz} \\
600 \end{ribbonproof}
601 \end{tkzexample}
602
603 \end{description}
604
605 \end{description}
606
607 \subsection{Commands}
608
609 \begin{description}
610 \item \label{command:com}\Icom{com}"["$\mathit{options}$"]{"$\mathit{text}$"}"\quad This creates a `command step' in the proof; that is, a black rectangle, labelled with $\mathit{text}$, that has a precondition above it and a postcondition below it. Available $\mathit{options}$ are:
611 \begin{description}
612 \item \Ikey{height}"="$n$ \quad (Default: {\tt\color{\COLORdef}\defaultStepHeight}.) The height of the step. The value $n$ must either be an integer or an expression that evaluates to an integer. The default step height can be changed by renewing the \Icom{defaultStepHeight} command.
613 \item \Ikey{finish ribbons}"={"$\mathit{name}_1$","$\ldots$","$\mathit{name}_k$"}" \quad (Default: empty.) The $k$ ribbons that are identified by the given names are preconditions of this step. They are henceforth \emph{inactive}.
614 \item \Ikey{start ribbons}\quad These ribbons are postconditions of this step. See page~\pageref{key:startribbons}.
615 \item \Ikey{finish boxes}"={"$\mathit{name}_1$","$\ldots$","$\mathit{name}_k$"}" \quad (Default: empty.) The $k$ boxes that are identified by the given names are preconditions of this step. They are henceforth \emph{inactive}.
616 \item \Ikey{start boxes}\quad These boxes are postconditions of this step. See page~\pageref{key:startboxes}.
617 \item \Ikey{extra left}"="$n$ \quad (Default: "0".) Additional width on the lefthand side of the step. The value $n$ must either be an integer or an expression that evaluates to an integer.
618 \item \Ikey{extra right}"="$n$ \quad (Default: "0".) Additional width on the righthand side of the step. The value $n$ must either be an integer or an expression that evaluates to an integer.
619 \end{description}
620 \item \Icom{jus}"["$\mathit{options}$"]{"$\mathit{text}$"}"\quad This creates a `justification step' in the proof; that is, a grey rectangle, labelled with $\mathit{text}$. The \Icom{jus} command has exactly the same behaviour and options as the \Icom{com} command, except:
621 \begin{itemize}
622 \item \Icom{com} creates a black rectangle, but \Icom{jus} creates a grey rectangle;
623 \item \Icom{com} sets its label in a monospaced font, but \Icom{jus} sets its in a roman font; and
624 \item \Icom{com} sets its label on the left of the rectangle, but \Icom{jus} sets its at the centre.
625 \end{itemize}
626
627 \item\Icom{\textbackslash}"["$\mathit{height}$"]"\quad Finish the current row and move to the next. The optional $\mathit{height}$ parameter (a positive or negative integer, default "0") is added to the default row height of \texttt{\color{\COLORdef}{\defaultRowHeight}}. This default row height can be changed by renewing the command \Icom{defaultRowHeight}.
628
629 \item\Icom{ribbonpagebreak}\quad Insert a page break at this point in the proof. When the proof restarts on the next page, the labels on the ribbons and boxes are printed again, so that the reader does not have to turn back several pages to find the label of a long-lived ribbon or box. Here is an example. (The page break appears as a horizontal gap in the middle of the proof.)
630 \begin{tkzexample}[latex=50mm]
631 \begin{ribbonproof}[start ribbons={
632 a/{left=0, right=18, label=P},
633 b/{left=20, right=38, label=R}}, start boxes={
634 x/{left=-2, right=40, label=\exists x}}]
635 \com[finish ribbons={a}, start ribbons={
636 a/{label=Q}}]{c()} \\
637 \ribbonpagebreak
638 \jus[finish ribbons={b}, start ribbons={
639 b/{label=S}}]{Lemma 1} \\
640 \end{ribbonproof}
641 \end{tkzexample}
642
643 \item \Icom{startblock}"["$\mathit{options}$"]{"$\mathit{text}$"}"\quad This command begins a new \emph{block}\index{block}. A block is a compound step such as an if-statement or a while-loop. Blocks may contain further steps, or even further blocks (which must be well-nested). The first segment of a block resembles an ordinary command step -- a black rectangle labelled with $\mathit{text}$ -- except that its top corners are rounded. (The radius of this rounding defaults to {\tt\color{\COLORdef}{\roundingRadius}}, but this can be adjusted by renewing the \Icom{roundingRadius} command.) Available $\mathit{options}$ are \Ikey{height}, \Ikey{finish ribbons}, \Ikey{start ribbons}, \Ikey{finish boxes}, \Ikey{start boxes}, \Ikey{extra left} and \Ikey{extra right}, which are the same as for the \Icom{com} command: see page~\pageref{command:com}. Additional options are:
644 \begin{description}
645 \item \Ikey{fit ribbons}"={"$\mathit{name}_1$","$\ldots$","$\mathit{name}_k$"}" \quad (Default: empty.) The $k$ ribbons that are identified by the given names are used to calculate the width of this block. That is, the block must be wide enough to cover each of the named ribbons. Being one of the \Ikey{fit ribbons} does not affect a ribbon in any way.
646 \item \Ikey{fit boxes}"={"$\mathit{name}_1$","$\ldots$","$\mathit{name}_k$"}" \quad (Default: empty.) As above, but for boxes instead of ribbons.
647 \end{description}
648
649 \item \Icom{continueblock}"["$\mathit{options}$"]{"$\mathit{text}$"}"\quad This command continues a block. If the block represents an if-statement, then \Icom{continueblock} corresponds to the `else' keyword. Every ribbon or box inside the block is deactivated, and every ribbon or box that was inside the block at the beginning is restored. This segment of a block resembles an ordinary command step -- a black rectangle labelled with $\mathit{text}$ -- except that its top edge is jagged (when the \Ikey{jagged} key is provided) to suggest the discontinuity at this point in the proof. Here is an example.
650 \begin{tkzexample}[latex=65mm]
651 \begin{ribbonproof}[extra height=2,
652 start ribbons={
653 q/{left=12, right=26, label=q},
654 r/{left=30, right=45, label=r}},
655 start boxes={
656 x/{left=10, right=28, color=red,
657 label=\exists x}}]
658 \startblock[fit ribbons={r},
659 extra left=5, extra right=2,
660 start ribbons={p/{left=-10, right=5,
661 label=b}}]{if ($b$) \{} \\
662 \com[finish ribbons={p,q,r},
663 finish boxes={x}, start ribbons={
664 s/{left=-8, right=21, label=s},
665 t/{left=25, right=45, label=t}},
666 start boxes={
667 y/{left=-10, right=23, color=green,
668 label=\exists y}}]{foo()} \\[2]
669 \continueblock[jagged, repeat labels,
670 start ribbons={
671 p/{label=\neg b}}]{\} else \{} \\
672 \end{ribbonproof}
673 \end{tkzexample}
674 Available $\mathit{options}$ are \Ikey{height}, \Ikey{start ribbons} and \Ikey{start boxes}, which are the same as for the \Icom{com} command: see page~\pageref{command:com}. Additional options are:
675 \begin{description}
676 \item \Ikey{jagged}\quad (Default: none.) If this option is present, the top edge of the rectangle is drawn jagged. If not, the top edge is simply a straight line.
677 \item \Ikey{repeat labels}\quad (Default: none.) If this option is present, each ribbon or box that is restored by this step is given a new label, as a reminder to the reader. If not, labels are only printed for those ribbons and boxes given explicitly in the \Ikey{start ribbons} or \Ikey{start boxes} lists.
678 \end{description}
679
680 \item \Icom{finishblock}"["$\mathit{options}$"]{"$\mathit{text}$"}"\quad This command ends a block. If the block represents an if-statement or a while-loop, then \Icom{finishblock} corresponds to the `end-if' or `end-while' keyword. Unlike the \Icom{continueblock} command, \Icom{finishblock} does not deactivate or restore any ribbons or boxes -- except for those explicitly given as \Ikey{start ribbons}, \Ikey{start boxes}, \Ikey{finish ribbons} or \Ikey{finish boxes}. This final segment of a block resembles an ordinary command step -- a black rectangle labelled with $\mathit{text}$ -- except that its bottom corners are rounded. (The radius of this rounding defaults to {\tt\color{\COLORdef}{\roundingRadius}}, but this can be adjusted by renewing the \Icom{roundingRadius} command.) Available $\mathit{options}$ are \Ikey{height}, \Ikey{finish ribbons}, \Ikey{start ribbons}, \Ikey{finish boxes}, \Ikey{start boxes}, \Ikey{extra left} and \Ikey{extra right}, which are the same as for the \Icom{com} command: see page~\pageref{command:com}.
681 \item \Icom{moveribbons}"{"$\mathit{ribbon}_1$","$\dots$","$\mathit{ribbon}_k$"}" \quad This command provides an opportunity to redefine the \Ikey{left} and \Ikey{right} positions of some ribbons. Each $\mathit{ribbon}$ takes the form
682 \begin{center}
683 $\mathit{name}$"/{"$\mathit{options}$"}"
684 \end{center}
685 where $\mathit{name}$ identifies an active ribbon, and the available $\mathit{options}$ are \Ikey{left}, \Ikey{right} and \Ikey{var width}, which are the same as for the \Ikey{start ribbons} key: see page~\pageref{key:startribbons}. At the end of the current row, the left and right positions of each ribbon are examined, and if they have changed as the result of a \Icom{moveribbons} command, a smooth shape is drawn from the old positions to the new positions. A thin white border is added to the left and right edges of each ribbon, to make overlapping ribbons easier to distinguish. The z-order of ribbons can be controlled by their position in the list provided to \Icom{moveribbons}: later ribbons are drawn over earlier ones. Here is an example that illustrates how to control overlapping in this way.
686 \begin{tkzexample}[latex=22mm]
687 \begin{ribbonproof}[start ribbons={
688 p/{left=0, right=8, label=p},
689 q/{left=10, right=18, label=q}}]
690 \moveribbons{p/{left=10, right=18}, q/{left=0, right=8}} \\
691 \moveribbons{q/{left=10, right=18}, p/{left=0, right=8}} \\
692 \end{ribbonproof}
693 \end{tkzexample}
694
695 \item \Icom{swapribbons}"{"$\mathit{name}_1$","$\dots$","$\mathit{name}_k$"}{"$\mathit{name}'_1$","$\dots$","$\mathit{name}'_k$"}" \quad This command provides an easy way to permute a number of ribbons. Each $\mathit{name}$ identifies an active ribbon. The second argument is expected to contain the same names as the first, but perhaps in a different order. The effect is that for each $i$ simultaneously, the new position of the ribbon identified by $\mathit{name}'_i$ becomes the old position of the ribbon identified by $\mathit{name}_i$. The z-order of ribbons can be controlled by their position in the second argument: later ribbons are drawn over earlier ones. Here is an example that illustrates how to control overlapping in this way.
696
697 \begin{tkzexample}[latex=22mm]
698 \begin{ribbonproof}[start ribbons={
699 p/{left=0, right=8, label=p},
700 q/{left=10, right=18, label=q}}]
701 \swapribbons{q,p}{p,q} \\
702 \swapribbons{p,q}{q,p} \\
703 \end{ribbonproof}
704 \end{tkzexample}
705
706 \item \Icom{moveboxes}"{"$\mathit{box}_1$","$\dots$","$\mathit{box}_k$"}" \quad This command provides an opportunity to redefine the \Ikey{left} and \Ikey{right} positions of some boxes. Each $\mathit{box}$ takes the form
707 \begin{center}
708 $\mathit{name}$"/{"$\mathit{options}$"}"
709 \end{center}
710 where $\mathit{name}$ identifies an active box, and the available $\mathit{options}$ are \Ikey{left} and \Ikey{right}, which are the same as for the \Ikey{start boxes} key: see page~\pageref{key:startboxes}. At the end of the current row, the left and right positions of each box are examined, and if they have changed as the result of a \Icom{moveboxes} command, a smooth shape is drawn from the old positions to the new positions. Here is an example.
711 \begin{tkzexample}[latex=27mm]
712 \begin{ribbonproof}[start ribbons={
713 p/{left=7, right=15, label=p}},
714 start boxes={
715 x/{left=5, right=17, color=red, label=\exists x},
716 y/{left=0, right=19, color=green, label=\exists y}}]
717 \moveboxes{x/{left=3, right=19}, y/{left=5, right=17}} \\
718 \end{ribbonproof}
719 \end{tkzexample}
720
721 \item \Icom{extendboxes}"{"$\mathit{box}_1$","$\dots$","$\mathit{box}_k$"}" \quad This command accepts the same input as the \Icom{moveboxes} command. Like the \Icom{moveboxes} command, it allows the \Ikey{left} and \Ikey{right} positions of some boxes to be modified. However, where \Icom{moveboxes} draws smooth curves between the old and new positions, \Icom{extendboxes} draws a `rounded elbow' shape between them. Such a shape may be preferable when extending a box's scope to include additional ribbons. Here is an example.
722 \begin{tkzexample}[latex=32mm]
723 \begin{ribbonproof}[start ribbons={
724 p/{left=8, right=16, label=p},
725 q/{left=20, right=28, label=q}},
726 start boxes={
727 x/{left=6, right=18, color=red, label=\exists x}}]
728 \extendboxes{x/{right=30}} \\
729 \end{ribbonproof}
730 \end{tkzexample}
731
732 \end{description}
733
734 \subsection{Adjustable parameters}
735
736 Each of the following parameters can be adjusted using \texttt{\color{\COLORcom}\textbackslash renewcommand}.
737
738 \newcommand\explainCom[1]{%
739 \item \Icom{#1}\quad
740 (Default: \texttt{\color{\COLORdef}\csname #1\endcsname}).}
741
742 \begin{description}
743
744 \explainCom{jusColor} Background colour of `justification' steps.
745 \explainCom{comColor} Background colour of `command' steps.
746 \explainCom{ribColor} Background colour of ribbons.
747 \explainCom{varribColor} \varsasresonly{} Background colour of the variable resource part of a ribbon.
748 \explainCom{ribTextColor} Colour of the textual label on ribbons.
749 \explainCom{boxTextColor} Colour of the textual label on boxes.
750 \explainCom{guideTextColor} Colour of the `guide' text (that is, the ribbon names and numeric scale that are printed when \Ikey{draw grid} is enabled).
751 \explainCom{defaultStepHeight} Default height of a step.
752 \explainCom{defaultRowHeight} Default height of a row. (This includes the step.)
753 \explainCom{ribTextVOffset} Vertical adjustment of ribbon labels.
754 \explainCom{boxTextVOffset} Vertical adjustment of box labels.
755 \explainCom{boxTextHOffset} Horizontal adjustment of box labels.
756 \explainCom{guideTextVOffset} Vertical adjustment of guide text on ribbons.
757 \explainCom{roundingRadius} Radius of rounded corners on blocks.
758 \explainCom{boxRoundingRadius} Radius of rounded corners on boxes. (Applies to the \Icom{extendboxes} command.)
759 \explainCom{blockLineWidth} Width of the vertical lines that delimit blocks.
760 \explainCom{boxLineWidth} Width of the vertical lines that delimit boxes.
761 \explainCom{shadowHeight} Height of the shadows that are drawn when a
762 step passes over a ribbon without affecting it.
763 \explainCom{shadowColor} Colour of the darkest point of a shadow.
764 \explainCom{zigzagHeight} Height of the jagged edges that are drawn on the top edge of each \Icom{continueblock} step.
765 \explainCom{zigzagLength} Length of the jagged edges that are drawn on the top edge of each \Icom{continueblock} step.
766 \explainCom{twistiness} For adjusting the shape of the ribbon twists. Must be a value between 0 and 1 inclusive.
767
768 \end{description}
769
770
771 \bibliographystyle{abbrv}
772 \bibliography{../../John}
773
774 \printindex
775
776 \end{document}