Debian Codegraph @

texmf-dist/source/latex/flagderiv/flagderiv.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2005 by Paul van Tilburg <[email protected]>
4 % ------------------------------------------------------
5 %
6 % This package is free software; you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation; either version 2 of the License, or
9 % (at your option) any later version.
10 %
11 % This package 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 % You should have received a copy of the GNU General Public License
17 % along with this package; if not, write to the Free Software
18 % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.%
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{flagderiv.dtx}
25 %</driver>
26 %<flagderiv>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
27 %<flagderiv>\ProvidesPackage{flagderiv}
28 %<*flagderiv>
29 [2005/08/26 v0.10 Flag style derivation package]
30 %</flagderiv>
31 %
32 %<*driver>
33 \documentclass{ltxdoc}
34
35 \usepackage{amsmath, amssymb}
36 \usepackage{calc}
37 \usepackage{flagderiv}
38 \usepackage{fvrb-ex}
39 \usepackage{theorem}
40 \usepackage{url}
41
42 \setlength{\parindent}{0pt}
43 \setlength{\parskip}{\medskipamount}
44 \setcounter{tocdepth}{2}
45
46 \theoremstyle{plain}
47 \newtheorem{lemma}{Lemma}
48 \newcommand{\false}{\textit{False}}
49 \newcommand{\flags}{\texttt{flagderiv}}
50 \newcommand{\IHbase}{\underline{\textit{Base}}:~}
51 \newcommand{\IHhyp}{\underline{\textit{Induction-hypothesis}}:~}
52 \newcommand{\IHstep}{\underline{\textit{Step}}:~}
53 \newcommand{\Nat}{\ensuremath{\mathbb{N}}}
54 \newcommand{\All}{\ensuremath{\mathbb{Z}}}
55 \newcommand{\Powerset}{\ensuremath{\mathcal{P}}}
56
57 \renewcommand{\implies}{\Rightarrow}
58 \newcommand{\biimplies}{\Leftrightarrow}
59 \newcommand{\OHA}{\rightarrow}
60 \newcommand{\THA}{\twoheadrightarrow}
61 \newcommand{\NHA}[1]{\stackrel{#1}{\rightarrow}}
62 \newcommand{\CRtext}{\ensuremath{\mathit{CR}}}
63 \newcommand{\CR}{\ensuremath{(\forall a, b, c\in A: a\THA b\land a\THA c:%
64 (\exists d\in A:: b\THA d\land c\THA d))}}
65 \newcommand{\MCtext}{\ensuremath{\mathit{mixed~confluent}}}
66 \newcommand{\MC}{\ensuremath{(\forall a, b, c\in A: a\OHA b\land a\THA c:%
67 (\exists d\in A:: b\THA d\land c\THA d))}}
68
69 \EnableCrossrefs
70 \CodelineIndex
71 \RecordChanges
72
73 \begin{document}
74 \DocInput{flagderiv.dtx}
75 \end{document}
76 %</driver>
77 % \fi
78 %
79 % \CheckSum{0}
80 %
81 % \CharacterTable
82 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
83 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
84 % Digits \0\1\2\3\4\5\6\7\8\9
85 % Exclamation \! Double quote \" Hash (number) \#
86 % Dollar \$ Percent \% Ampersand \&
87 % Acute accent \' Left paren \( Right paren \)
88 % Asterisk \* Plus \+ Comma \,
89 % Minus \- Point \. Solidus \/
90 % Colon \: Semicolon \; Less than \<
91 % Equals \= Greater than \> Question mark \?
92 % Commercial at \@ Left bracket \[ Backslash \\
93 % Right bracket \] Circumflex \^ Underscore \_
94 % Grave accent \` Left brace \{ Vertical bar \|
95 % Right brace \} Tilde \~}
96 %
97 %
98 % \changes{v0.9f}{2005/02/04}{Initial version.}
99 % \changes{v0.9g}{2005/05/16}{Added example and usage documentation.}
100 % \changes{v0.9h}{2005/06/06}{Added the flagderiv* environment.}
101 % \changes{v0.9i}{2005/06/10}{Fixed minor issues in the documentation
102 % and resolved a ref-format bug.}
103 % \changes{v0.10}{2005/08/26}{Drop dependancy on farray, include fix.}
104 %
105 % \GetFileInfo{flagderiv.dtx}
106 %
107 % \DoNotIndex{\newcommand,\newenvironment}
108 %
109 % \title{The \textsf{flagderiv} package\thanks{This document
110 % corresponds to \textsf{flagderiv}~\fileversion, dated \filedate.}}
111 % \author{Paul van Tilburg \\ \url{[email protected]}}
112 %
113 % \maketitle
114 %
115 % \tableofcontents
116 %
117 % \section{Introduction}
118 %
119 % This document describes how to use \flags~to make flag-style proofs in
120 % \LaTeX.
121 %
122 % It can handle taking steps, making assumptions, introducing variables and
123 % conclusions. The package allows the style to be configured. For
124 % example, the variable introduction symbol can be redefined. Other
125 % features include multiple page flag-style proofs.
126 %
127 % The documentation and all examples are based upon version \fileversion\
128 % of \flags.
129 %
130 % \begin{center}
131 % \scriptsize
132 % \renewcommand{\introsymb}{\text{Let}}
133 % \begin{flagderiv}
134 % \assume{i:assume:no-package}{\text{There is no nice package to do flag-style proofs}}{}
135 % \introduce{i:intro:feature}{x\text{, such that } x\text{ is a flag-style feature}}{}
136 % \skipsteps{5}{\vdots}{}
137 % \step{i:feature-met}{\flags~\text{can do it}}{}
138 % \conclude{i:conclusion}{\flags~\text{fulfils my every flag-style proof need}}
139 % {$\forall$-introduction on \ref{i:intro:feature} and \ref{i:feature-met}}
140 % \step{i:false}{\false}{\false-introduction on \ref{i:assume:no-package} and \ref{i:conclusion}}
141 % \conclude{i:conclude:not-no-package}{\lnot (\text{There is no nice package to do flag-style proofs})}
142 % {$\lnot$-introduction on \ref{i:assume:no-package} and \ref{i:false}}
143 % \step{i:step:nice-package}{\text{So, there exists a nice package to do flag-style proofs}}
144 % {$\lnot\lnot$-elimination on \ref{i:conclude:not-no-package}}
145 % \end{flagderiv}
146 % \end{center}
147 %
148 % \section{Acknowledgements}
149 %
150 % I want to thank Jan Zwanenburg and Erik Poll for the first versions of
151 % this package, professor R.P.\ Nederpelt for his ever-persisting package
152 % reviews, feedback and suggestions and last but not least Mark van Eijk,
153 % who has written parts of section~\ref{sec:usage} and all examples in
154 % section~\ref{sec:ex}.
155 %
156 % \section{Usage\label{sec:usage}}
157 %
158 % This section explains how the \flags\ package works by means of examples
159 % and how the commands should be used. I try to cover all possibilities and
160 % features of this package. For bigger examples, please refer to
161 % section~\ref{sec:ex}; for more detailed documentation on the commands
162 % and inner workings, refer to the \flags\ package itself.
163 %
164 % \subsection{Basic derivations}
165 % \DescribeEnv{flagderiv}
166 % Basic derivations are written using an intuitive command sequence
167 % placed in the |flagderiv| environment\index{usage}. The example below
168 % uses auto-numbering of the lines. Variable introductions, assumptions,
169 % steps and conclusions can be done using the following commands
170 % respectively:
171 %
172 % \begin{itemize}
173 % \item \DescribeMacro{\introduce}\index{usage}
174 % |\introduce|\marg{label}\marg{formula}\marg{comment},
175 % \item \DescribeMacro{\assume}\index{usage}
176 % |\assume|\marg{label}\marg{formula}\marg{comment},
177 % \item \DescribeMacro{\step}\index{usage}
178 % |\step|\marg{label}\marg{formula}\marg{comment}, and
179 % \item \DescribeMacro{\conclude}\index{usage}
180 % |\conclude|\oarg{number}\marg{label}\marg{formula}\marg{comment}.
181 % \end{itemize}
182 %
183 % Lines can be referred to using the {\em label} that is provided as the
184 % first argument to each of the commands. {\em Formulas} are placed in
185 % the second argument and a {\em comment} in the third.
186 % See subsection~\ref{sec:usage:multi} for the explanation of the optional
187 % argument {\em number} of |\conclude|.
188 %
189 % \begin{Example}[gobble=7,frame=single,label=Auto-numbering]
190 % \begin{flagderiv}
191 % \introduce{in-x}{x: \Nat}{Introduction of $x$}
192 % \assume{as-x}{x > 5}{Assumption}
193 % \step{big-x}{x > 1}{Arithmetic on \ref{in-x} and \ref{as-x}}
194 % \conclude{conc}{x > 5 \implies x > 1}
195 % {$\implies$-intro on \ref{as-x} and \ref{big-x}}
196 % \conclude{}{\forall x \in \Nat: x > 5 \implies x > 1}
197 % {$\forall$-intro on \ref{in-x} and \ref{conc}}
198 % \end{flagderiv}
199 % \end{Example}
200 %
201 % The following example uses manual numbering. This is done by using the
202 % \DescribeMacro{\introduce*}
203 % starred versions of the previous given commands (|\introduce*|,
204 % \DescribeMacro{\assume*}
205 % \DescribeMacro{\step*}
206 % \DescribeMacro{\conclude*}
207 % |\assume*|, |\step*| and |\conclude*|) and using a
208 % {\em custom number} instead of a {\ em label} as the first argument.
209 % Note that because of this, derivation line references are not possible
210 % and should be done manually as well.
211 %
212 % \begin{Example}[gobble=7,frame=single,label=Manual numbering]
213 % \begin{flagderiv}
214 % \introduce*{$(1)$}{x: \Nat}{Introduction of $x$}
215 % \assume*{$(2)$}{P(x)}{Assumption}
216 % \skipsteps*{\dots}{}
217 % \step*{$(n - 2)$}{Q(x)}{}
218 % \conclude*{$(n - 1)$}{P(x) \implies Q(x)}
219 % {$\implies$-intro on $(2)$ and $(n - 2)$}
220 % \conclude*{$(n)$}{\forall x \in \Nat: P(x) \implies Q(x)}
221 % {$\forall$-intro on $(1)$ and $(n - 1)$}
222 % \end{flagderiv}
223 % \end{Example}
224 %
225 % Note that the |\skipsteps*| used in the previous example is
226 % explained in section~\ref{sec:usage:skipsteps}.
227 %
228 % \subsection{Concluding multiple assumptions/introductions\label{sec:usage:multi}}
229 % Sometimes it is useful to make a conclusion from multiple open
230 % assumptions and/or introductions at once. This can be done by supplying
231 % an optional {\em number} to the |\conclude| command. Usage is
232 % illustrated in the example below.
233 %
234 % \begin{Example}[gobble=7,frame=single,label=Multiple conclusion]
235 % \begin{flagderiv}
236 % \introduce{}{x: \Nat}{}
237 % \assume{}{P(x)}{}
238 % \step{}{Q(x)}{}
239 % \conclude[2]{}{\forall x \in \Nat: (P(x) \implies Q(x))}{}
240 % \end{flagderiv}
241 % \end{Example}
242 %
243 % \subsection{Skipping steps\label{sec:usage:skipsteps}}
244 % When writing example derivations or abbreviating those where
245 % obvious/trivial steps may be skipped, one can use the
246 % \DescribeMacro{\skipsteps}
247 % |\skipsteps|\marg{number}\marg{formula}\marg{comment} command for
248 % auto-numbered derivations. This commands takes the {\em number} of
249 % steps to skip as the first argument, a {\em formula} as the second and
250 % a {\em comment} as the third, like a normal step.
251 % \vspace{3em}
252 %
253 % \begin{Example}[gobble=7,frame=single,label=Skipping 5 steps]
254 % \begin{flagderiv}
255 % \assume{as}{P \implies Q}{}
256 % \step{lem-p}{P \lor \neg P}{LEM}
257 % \skipsteps{5}{\dots}
258 % {Prove $\neg P \lor Q$ for $P$ and $\neg P$}
259 % \step{or-elm}{\neg P \lor Q}{$\lor$-elim on \ref{lem-p}}
260 % \end{flagderiv}
261 % \end{Example}
262 %
263 % For skipping an unknown number of steps in a manual numbered
264 % \DescribeMacro{\skipsteps*}
265 % derivation, the command |\skipsteps*|\marg{formula}\marg{comment} can
266 % be used. Here the number of steps to skip must be omitted, since there
267 % is no counting involved. See for example the $\implies$-intro rule:
268 %
269 % \begin{Example}[gobble=7,frame=single,label=Skipping steps]
270 % \begin{flagderiv}
271 % \assume*{$(1)$}{P}{Assumption}
272 % \skipsteps*{\dots}{Derive $Q$}
273 % \step*{$(n - 1)$}{Q}{}
274 % \conclude*{$(n)$}{P \implies Q}
275 % {$\implies$-intro on $(1)$ to $(n - 1)$}
276 % \end{flagderiv}
277 % \end{Example}
278 %
279 % \subsection{Closing assumptions/introductions}
280 % Assumptions and introductions (contexts) are not always closed by a
281 % conclusion, it is sometimes useful to keep proven propositions within
282 % \DescribeMacro{\done}
283 % its context. The |\done| command (|\done|\oarg{number}) can be used to
284 % close a assumption and/or introduction without mentioning why. It takes
285 % an optional argument {\em number} to close multiple open assumptions
286 % and/or introductions. An example from the WTT (Weak Type Theory):
287 %
288 % \begin{Example}[gobble=7,frame=single,label=Closing assumptions/introductions]
289 % \begin{flagderiv}
290 % \introduce{}{n: \Nat}{}
291 % \introduce{}{d: \Nat}{}
292 % \step{}{\text{$d$ is a divisor of $n$} :=
293 % \exists_{k: \Nat} (n = d \cdot k)}{}
294 % \done
295 % \introduce{}{m: \Nat}{}
296 % \step{}{\text{$m$ is a multiple of $n$} :=
297 % \exists_{k: \Nat} (m = k \cdot n)}{}
298 % \done[2]
299 % \end{flagderiv}
300 % \end{Example}
301 %
302 % \vspace{-1em}
303 % The last |\done[2]| can be omitted since closing the \flags\ environment
304 % implicitly closes all open introductions and assumptions.
305 %
306 %
307 % \subsection{Spacing between lines}
308 % The spacing between derivation lines defaults to {\tt 8pt} but can be
309 % changed
310 % \DescribeMacro{derivskip}\index{setting}
311 % by adjusting the length (using |\setlength| on {\tt derivskip})
312 % before starting or during a \flags\ environment. See for example the
313 % more condensed proof:
314 %
315 % \begin{Example}[gobble=7,frame=single,label=Condensing a derivation]
316 % \setlength{\derivskip}{4pt}
317 % \begin{flagderiv}
318 % \assume{}{P}{}
319 % \assume{}{Q}{}
320 % \step{}{P}{}
321 % \conclude{}{Q \implies P}{}
322 % \conclude{}{P \implies Q \implies P}{}
323 % \end{flagderiv}
324 % \end{Example}
325 %
326 % Note that flag derivations will automatically be split across pages if
327 % it is too long and the |flagderiv| environment is used. See also the
328 % {\tt longtable} package. This does not happen for |flagderiv*|, which
329 % is a normal |tabular|.
330 %
331 % \subsection{The introduction symbol}
332 % \DescribeMacro{\introsymb}\index{changing}
333 % The way an introduction flag differs from an assumption flag is that it
334 % is prefixed with an {\em introduction symbol}. This symbol is by
335 % default set to $\mathbf{var}$ (|\mathbf{var}|) but can be changed
336 % to a different symbol, for example to $\leadsto$ (|\leadsto|) or
337 % just `Let'. This can be changed by redefining the |\introsymb|
338 % command before opening the \flags\ environment.
339 %
340 % \begin{Example}[gobble=7,frame=single,label=Changing the introduction symbol]
341 % \renewcommand{\introsymb}{\textbf{Let}}
342 % \begin{flagderiv}
343 % \introduce{intro-x}{x: \Nat}{Introduction}
344 % \introduce{intro-y}{y: \Nat}{Introduction}
345 % \skipsteps*{\ddots}{}
346 % \end{flagderiv}
347 % \end{Example}
348 %
349 % \subsection{Numbering and format}
350 % When the derivation lines are automatically numbered the numbers are
351 % formatted as ``({\em number})'' and so are the references. This format
352 % \DescribeMacro{fd@stepcount}
353 % \DescribeMacro{\thestepcount}\index{changing}
354 % can be changed by overriding the |\thestepcount| command using the
355 % {\tt fd@stepcount} counter before opening the \flags\ environment.
356 %
357 % \begin{Example}[gobble=7,frame=single,label=Changing the numbering format]
358 % \renewcommand{\thestepcount}{[\Roman{fd@stepcount}]}
359 % \begin{flagderiv}
360 % \step{ass}{P \implies Q}{}
361 % \step{lem}{P \lor \neg P}{LEM}
362 % \assume{ass-nP}{\neg P}{Assumption}
363 % \step{s0}{\neg P \lor \neg Q}{$\lor$-intro on \ref{ass-nP}}
364 % \done
365 % \assume{ass-nnP}{P}{Assumption}
366 % \step{s1}{Q}{$\implies$-elim on \ref{ass-nnP} and \ref{ass}}
367 % \step{s2}{\neg P \lor \neg Q}{$\lor$-intro on \ref{s1}}
368 % \done
369 % \step{or-el}{\neg P \lor Q}
370 % {$\lor$-elim on \ref{lem}, \ref{s0} and \ref{s2}}
371 % \end{flagderiv}
372 % \end{Example}
373 %
374 % \DescribeMacro{\thesteplabel}\index{changing}
375 % Since the manual numbered derivations use no counter, the format can be
376 % changed by overriding the |\thesteplabel| command which will take
377 % one argument, the {\em custom number}.
378 %
379 % \begin{Example}[gobble=7,frame=single,label=Changing the numbering format]
380 % \renewcommand{\thesteplabel}[1]{#1.}
381 % \begin{flagderiv}
382 % \assume*{1}{P}{Assumption}
383 % \skipsteps*{\dots}{Derive $Q$}
384 % \step*{n - 1}{Q}{}
385 % \conclude*{n}{P \implies Q}{$\implies$-intro on 1 to n - 1}
386 % \end{flagderiv}
387 % \end{Example}
388 %
389 % Note that since references are also manually done, the same format
390 % should be used there by the writer him/herself.
391 %
392 % \subsection{Inline comments}
393 % In general there are two ways to place the comments with respect to
394 % the formulas in derivations. The first is behind the formula (the
395 % default). The second way is to place them inline, that is, on a separate
396 % line before the formula.
397 %
398 % All \flags\ environments can be set globally to display the comments
399 % inline by passing the global option {\tt inlcmnts} to the \flags\
400 % package (e.g.\\|\usepackage[inlcmnts]{flagsderiv}|).
401 %
402 % \DescribeMacro{\inlcmnts}\index{usage}
403 % Giving the |\inlcmnts| command makes the environments after this
404 % command explicitly switch into inline-comment-mode (the default or
405 % \DescribeMacro{\noinlcmnts}\index{usage}
406 % global option is forgotten) after which giving |\noinlcmnts| will set
407 % it back to normal mode.
408 %
409 % \begin{Example}[gobble=7,frame=single,label=Inline comments]
410 % \inlcmnts
411 % \begin{flagderiv}
412 % \assume{as-P}{P}{Assume:}
413 % \assume{as-Q}{Q}{Assume:}
414 % \step{re-P}{P}{Rei \ref{as-P}:}
415 % \conclude{imp1}{Q \implies P}
416 % {$\implies$-intro on \ref{as-Q} and \ref{re-P}:}
417 % \conclude{imp2}{P \implies Q \implies P}
418 % {$\implies$-intro on \ref{as-P} and \ref{imp1}:}
419 % \end{flagderiv}
420 % \end{Example}
421 %
422 % When the comments are inserted inline, a certain format is used, namely
423 % to enclose the comment with braces. This is the default, but can be
424 % \DescribeMacro{\theinlcmnt}
425 % overridden by redefining the |\theinlcmnt| command.\index{override}
426 % \vspace{1em}
427 %
428 % \begin{Example}[gobble=7,frame=single,label=Changing inline comments format]
429 % \inlcmnts
430 % \renewcommand{\theinlcmnt}[1]{--#1--}
431 % \begin{flagderiv}
432 % \assume{ass-P}{P}{Assumption}
433 % \assume{ass-Q}{Q}{Assumption}
434 % \step{rei-P}{P}{Rei \ref{ass-P}}
435 % \end{flagderiv}
436 % \end{Example}
437 %
438 % \subsection{Namespaces for labels}
439 % In a document with a lot of auto-numbered derivations it is easy to lose
440 % overview of labels already used or it may be hard to keep thinking of
441 % new ones. To solve this a \flags\ environment can take a {\em namespace}
442 % as optional argument\index{namespacing}. This makes the lines referable
443 % as normal within the same derivation but also globally when the namespace
444 % and a colon is added outside the derivation. For example a derivation for
445 % Modus Tollens (MT):
446 %
447 % \begin{Example}[gobble=7,frame=single,label=Derivation label namespace]
448 % \begin{flagderiv}[mt]
449 % \step{s0}{P \implies Q}{}
450 % \assume{as-nQ}{\neg Q}{Assumption}
451 % \assume{as-P}{P}{Assumption}
452 % \step{s1}{Q}{$\implies$-elim on \ref{s0} and \ref{as-P}}
453 % \step{s2}{\bot}{$\bot$-intro on \ref{as-nQ} and \ref{s1}}
454 % \conclude{nP}{\neg P}{$\neg$-intro on \ref{as-P} and \ref{s2}}
455 % \conclude{nQ-nP}{\neg Q \implies \neg P}
456 % {$\implies$-intro on \ref{as-nQ} and \ref{nP}}
457 % \end{flagderiv}
458 %
459 % Note that step~\ref{mt:as-P} is not an intuitive step but necessary
460 % to get $\neg P$ under the assumption $\neg Q$.
461 % \end{Example}
462 %
463 % \subsection{Other options}
464 % \DescribeMacro{\caption}\index{usage}
465 % \DescribeMacro{\tablehead}\DescribeMacro{\tablefirsthead}
466 % A \flags\ environment actually wraps a {\tt longtable}. This means
467 % that at the start of an environment all {\tt longtable} options are
468 % available. This means the use of |\caption|, and setting heads
469 % (|\tablehead| and |\tablefirsthead|) and feet (|\endfoot|
470 % \DescribeMacro{\endfoot}\DescribeMacro{\endlastfoot}
471 % and |\endlastfoot|) but also changing the lengths, etc.
472 %
473 % \DescribeEnv{flagderiv*}
474 % Note that this does not hold for the slightly different |flagderiv*|
475 % environment, which acts exactly the same but is wrapped in a normal
476 % {\tt tabular} and thus can not be split across pages.
477 %
478 % \begin{Example}[gobble=7,frame=single,label=Captioned]
479 % \inlcmnts
480 % \begin{flagderiv}[reflex]
481 % \caption{The reflexivity of $\equiv_n$} \\
482 % \introduce*{(1)}{x \in \All}{Assume:}
483 % \skipsteps*{\dots \\ \dots}{}
484 % \step*{(n - 1)}{x \equiv_n x}{}
485 % \conclude*{(n)}{\forall x \in \All: x \equiv_n x}
486 % {$\forall$-intro on (1) and (n - 1):}
487 % \end{flagderiv}
488 % \end{Example}
489 %
490 % \DescribeMacro{\\}
491 % Additional it is possible to add custom newlines (|\\|) in all
492 % step formulas\footnote{This is not possible in introductions or
493 % assumptions, but they can often be split into multiple introductions or
494 % assumptions.} when the formula gets too long as demonstrated in the
495 % above example.
496 %
497 %
498 % \section{Examples\label{sec:ex}}
499 % The following are just a few real-life examples of flag-style proofs,
500 % where \flags\ provides an elegant means to include these proofs in
501 % \LaTeX-documents.
502 %
503 % \subsection{Examples from \flags}
504 % \subsection*{A derivation with auto-numbering and labels/references}
505 % \begin{flagderiv}
506 % \introduce{intro-xy}{x,y \in \mathbb{N}}{Introduction}
507 % \assume{assum:1}{x > 0}{Assumption}
508 % \assume{assum:2}{x < y}{Assumption}
509 % \step{y-pos}{y > 0}{Transitivity on \ref{assum:1} and \ref{assum:2}}
510 % \step{y3-pos}{y^3 > 0}{Arithmetic on \ref{y-pos}}
511 % \conclude{imp:1}{x < y \implies y^3 > 0}
512 % {$\implies$-intro on \ref{assum:2} and \ref{y3-pos}}
513 % \conclude{imp:2}{x > 0 \implies x < y \implies y^3 > 0}
514 % {$\implies$-intro on \ref{assum:1} and \ref{imp:1}}
515 % \conclude{}{\forall x, y \in \Nat: x > 0 \land x < y \implies y^3 > 0}
516 % {$\forall$-intro on \ref{intro-xy} and \ref{imp:2}}
517 % \end{flagderiv}
518 %
519 % \subsection*{A derivation with manual numbering}
520 % \begin{flagderiv}
521 % \assume*{(m)}{\neg P}{}
522 % \skipsteps{1}{\dots}{}
523 % \step*{(n - 2)}{False}{}
524 % \conclude*{(n - 1)}{\neg\neg P}
525 % {$\implies$-intro on (m) and (n - 2), and Negation}
526 % \step*{(n)}{P}{Double negation on (n - 1)}
527 % \end{flagderiv}
528 %
529 %
530 % \subsection{Predicate Calculus}
531 % \subsubsection*{Idempotence}
532 % \begin{flagderiv}[pc-idempotence]
533 % \assume{intro:PP}{P \land P}{}
534 % \step{and-elim:P}{P}{$\land$-elim on \ref{intro:PP}}
535 % \conclude{impl-intro:PP-P}{P \land P \implies P}
536 % {$\implies$-intro on \ref{intro:PP}
537 % and \ref{and-elim:P}}
538 % \assume{intro:P}{P}{}
539 % \step{and-intro:P}{P \land P}{$\land$-intro on \ref{intro:P}
540 % and \ref{intro:P}}
541 % \conclude{impl-intro:P-PP}{P \implies P \land P}
542 % {$\implies$-intro on \ref{intro:P}
543 % and \ref{and-intro:P}}
544 % \step{and-intro:result}{(P \land P \implies P) \land
545 % (P \implies P \land P)}
546 % {$\land$-intro on \ref{impl-intro:PP-P}
547 % and \ref{impl-intro:P-PP}}
548 % \step{idempotence}{P \land P \equiv P}
549 % {$\equiv$-intro on \ref{and-intro:result}}
550 % \end{flagderiv}
551 %
552 % \subsubsection*{De Morgan}
553 % \begin{flagderiv}[pc-demorgan]
554 % \assume{intro:NPQ}{\lnot (P \land Q)}{}
555 % \assume{intro:NNP}{\lnot\lnot P}{}
556 % \assume{intro:Q}{Q}{}
557 % \step{notnot-elim:P}{P}{$\lnot\lnot$-elim on \ref{intro:NNP}}
558 % \step{and-intro:PQ}{P \land Q}{$\land$-intro on \ref{intro:Q}
559 % and \ref{notnot-elim:P}}
560 % \step{false-intro:2}{\false}
561 % {$\false$-intro on \ref{and-intro:PQ}
562 % and \ref{intro:NPQ}}
563 % \conclude{not-intro:Q}{\lnot Q}{$\lnot$-intro on \ref{intro:Q}
564 % and \ref{false-intro:2}}
565 % \conclude{impl-intro:NNP-NQ}{\lnot\lnot P \implies \lnot Q}
566 % {$\implies$-intro on \ref{intro:NNP}
567 % and \ref{not-intro:Q}}
568 % \step{or-intro:NP-NQ}{\lnot P \lor \lnot Q}
569 % {$\lor$-intro on \ref{impl-intro:NNP-NQ}}
570 % \conclude{impl-intro:NPQ-NPNQ}{\lnot (P \land Q) \implies
571 % \lnot P \lor \lnot Q}
572 % {$\implies$-intro on \ref{intro:NPQ}
573 % and \ref{or-intro:NP-NQ}}
574 % \assume{intro:NPNQ}{\lnot P \land \lnot Q}{}
575 % \assume{intro:PQ}{P \lor Q}{}
576 % \step{or-elim:NP-Q}{\lnot P \implies Q}
577 % {$\lor$-elim on \ref{intro:PQ}}
578 % \step{and-elim:NP}{\lnot P}{$\land$-elim on \ref{intro:NPNQ}}
579 % \step{impl-elim:Q}{Q}{$\implies$-elim on \ref{or-elim:NP-Q}
580 % and \ref{and-elim:NP}}
581 % \step{and-elim:NQ}{\lnot Q}{$\land$-elim on \ref{intro:NPNQ}}
582 % \step{false-intro:1}{\false}{$\false$-intro on \ref{impl-elim:Q}
583 % and \ref{and-elim:NQ}}
584 % \conclude{impl-intro:PQ}{P \lor Q \implies \false}
585 % {$\implies$-intro on \ref{intro:PQ}
586 % and \ref{false-intro:1}}
587 % \step{not-intro:PQ}{\lnot (P \lor Q)}
588 % {$\lnot$-intro on \ref{impl-intro:PQ}}
589 % \conclude{impl-intro:NPNQ-NPQ}{\lnot P \land \lnot Q \implies
590 % \lnot (P \lor Q)}
591 % {$\implies$-intro on \ref{intro:NPNQ}
592 % and \ref{not-intro:PQ}}
593 % \step{and-intro:result}{(\lnot (P \land Q) \implies
594 % \lnot P \lor \lnot Q)
595 % \land\\
596 % (\lnot P \land \lnot Q \implies
597 % \lnot (P \lor Q))}
598 % {$\land$-intro on \ref{impl-intro:NPQ-NPNQ}
599 % and \ref{impl-intro:NPNQ-NPQ}}
600 % \step{demorgan}{\lnot (P \land Q) \equiv \lnot P \lor \lnot Q}
601 % {$\equiv$-intro on \ref{and-intro:result}}
602 % \end{flagderiv}
603 %
604 % \subsubsection*{Transitivity}
605 % \begin{flagderiv}[pc-transitivity]
606 % \introduce{intro:PQR}{P, Q, R}{}
607 % \assume{intro:PQQR}{(P \implies Q) \land (Q \implies R)}{}
608 % \assume{intro:P}{P}{}
609 % \step{and-elim:PQ}{P \implies Q}
610 % {$\land$-elim on \ref{intro:PQQR}}
611 % \step{impl-elim:Q}{Q}{$\implies$-elim on \ref{and-elim:PQ}
612 % and \ref{intro:P}}
613 % \step{and-elim:QR}{Q \implies R}
614 % {$\land$-elim on \ref{intro:PQQR}}
615 % \step{impl-elim:R}{R}{$\implies$-elim on \ref{and-elim:QR}
616 % and \ref{impl-elim:Q}}
617 % \conclude{impl-intro:PR}{P \implies R}
618 % {$\implies$-intro on \ref{intro:P}
619 % and \ref{impl-elim:R}}
620 % \conclude{impl-intro:PQQR-PR}{(P \implies Q) \land (Q \implies R)
621 % \implies (P \implies R)}
622 % {$\implies$-intro on \ref{intro:PQQR}
623 % and \ref{impl-intro:PR}}
624 % \conclude{transitivity}{(\forall P, Q, R::
625 % (P \implies Q) \land (Q \implies R)
626 % \implies (P \implies R)
627 % )}
628 % {$\forall$-intro on \ref{intro:PQR}
629 % and \ref{impl-intro:PQQR-PR}}
630 % \end{flagderiv}
631 %
632 % \subsection{Rewrite Systems}
633 % \subsubsection*{Mixed confluent $\biimplies$ Church-Rosser}
634 % {
635 % \renewcommand{\introsymb}{\text{Let}}
636 % \begin{flagderiv}
637 % \assume*{1}{\CRtext}{hyp}
638 % \introduce*{2}{a, b, c\in A, \text{such that}~a\OHA b\land a\THA c}{}
639 % \step*{3}{a\OHA b\land a\THA c}{rei (2)}
640 % \step*{4}{a\THA b\land a\THA c}{$\forall$-elimination on lemma~\ref{transclosure} and (3)}
641 % \step*{5}{(\exists d\in A:: b\THA d\land c\THA d)}{$\forall$-elimination on (1) and (4)}
642 % \conclude*{6}{\MCtext}{$\forall$-introduction on (2) and (5)}
643 % \conclude*{7}{\CRtext\implies\MCtext}{$\implies$-introduction on (1) and (6)}
644 % \assume*{8}{\MCtext}{}
645 % \assume*{9}{\text{Induction on the length of}~a\THA b}{}
646 % \skipsteps*{\IHbase}{}
647 % \introduce*{11}{a, b, c\in A, \text{such that}~a\NHA{0} b\land a\THA c}{}
648 % \step*{12}{a=b}{def $\NHA{0}$, (11)}
649 % \step*{13}{a\THA c}{$\land$-elimination on (11)}
650 % \step*{14}{b\THA c}{(12) applied on (13)}
651 % \step*{15}{c\THA c \land b\THA c}{}
652 % \step*{16}{(\exists d\in A:: b\THA d\land c\THA d)}{}
653 % \renewcommand{\thesteplabel}[1]{#1}
654 % \conclude*{}{\IHhyp}{}
655 % \step*{18}{\ensuremath{(\forall a, b, c\in A: a\NHA{n} b\land a\THA c:\\ \quad
656 % (\exists d\in A:: b\THA d\land c\THA d))}}{}
657 % \skipsteps*{\IHstep}{}
658 % \introduce*{20}{a, b, c\in A, \text{such that}~a\NHA{n+1} b\land a\THA c}{}
659 % \step*{21}{a\NHA{n+1} b}{$\land$-elimination on (20)}
660 % \step*{22}{a\NHA{n} b'\OHA b}{}
661 % \step*{23}{a\THA c}{$\land$-elimination on (20)}
662 % \step*{24}{a\NHA{n} b' \land a\THA c}{$\land$-introduction on (22) and (23)}
663 % \step*{25}{(\exists d'\in A:: b'\THA d'\land c\THA d')}{$\forall$-elimination on (18) and (24)}
664 % \step*{26}{d', \text{such that}~b'\THA d'\land c\THA d'}{$\exists$-elimination on (25)}
665 % \step*{27}{b'\OHA b \land b'\THA d'}{}
666 % \step*{28}{(\exists d\in A:: b\THA d\land d'\THA d)}{$\forall$-elimination on (8) and (27)}
667 % \step*{29}{d, \text{such that}~b\THA d\land d'\THA d}{$\exists$-elimination on (28)}
668 % \step*{30}{a\NHA{n} b'\OHA b\THA d \land a\THA c\THA d'\THA d}{}
669 % \step*{31}{b\THA d \land c\THA d}{}
670 % \step*{32}{(\exists d\in A:: b\THA d\land c\THA d)}{}
671 % \conclude*[2]{33}{\CRtext}{}
672 % \conclude*{34}{\MCtext\implies\CRtext}{$\implies$-introduction on (8) and (33)}
673 % \step*{35}{\MCtext\biimplies\CRtext}{$\biimplies$-introduction on (7) and (34)}
674 % \end{flagderiv}
675 % }
676 %
677 % \begin{lemma}
678 % \label{transclosure}
679 % \mbox{\ensuremath{(\forall a, b\in A: a\OHA b: a\THA b)}}
680 % \end{lemma}
681 %
682 % \StopEventually{}
683 %
684 % \newpage
685 % \section{Implementation}
686 %
687 % First some initial code is needed for processing of the options.
688 % Note that {\tt ifthen} is used throughout the package.
689 % \begin{macrocode}
690 \RequirePackage{ifthen}
691 \newboolean{@inlcmnts}
692 % \end{macrocode}
693 %
694 % Processing of the option ({\tt inlcmnts}) for enabling inline comments.
695 % \begin{macrocode}
696 \DeclareOption{inlcmnts}{\setboolean{@inlcmnts}{true}}
697 \ProcessOptions
698 % \end{macrocode}
699 %
700 % Loading of the required packages.
701 % Note that \flags\ needs to require a fix/override for the array package,
702 % until the fixed version is available in most distributions.
703 % \begin{macrocode}
704 \RequirePackage{array}
705 \RequirePackage{longtable}
706 \long\@namedef{NC@rewrite@*}#1#2{%
707 \count@#1\relax
708 \loop
709 \ifnum\count@>\z@
710 \advance\count@\m@ne
711 \@temptokena\expandafter{\the\@temptokena#2}%
712 \repeat
713 \NC@find}
714 % \end{macrocode}
715 %
716 % \subsection{Generic settings, counters and commands}
717 %
718 % \begin{macro}{fd@flagcount}
719 % \begin{macro}{fd@stepcount}
720 % The counters keeping the number of opened/nested flags and the number of
721 % derivation steps.
722 % \begin{macrocode}
723 \newcounter{fd@flagcount}
724 \newcounter{fd@stepcount}
725 % \end{macrocode}
726 % \end{macro}
727 % \end{macro}
728 %
729 % \begin{macro}{\derivskip}
730 % The default space ({\tt 8pt}) between lines in a derivation. This is
731 % overridable to define a different default length.
732 % \begin{macrocode}
733 \newlength{\derivskip}
734 \setlength{\derivskip}{8pt}
735 % \end{macrocode}
736 % \end{macro}
737 %
738 % \begin{macro}{\introsymb}
739 % The symbol used as variable introduction prefix. Overridable with
740 % |\renewcommand| to insert a different symbol, defaults to:
741 % |\textbf{var}|.
742 %
743 % Ex. |\renewcommand{\introsymb}{\textbf{Let}}|
744 % \begin{macrocode}
745 \newcommand{\introsymb}{\textbf{var}}
746 % \end{macrocode}
747 % \end{macro}
748 %
749 % \begin{macro}{\thestepcount}
750 % This is the command used to generate a step number label (used by
751 % auto-numbering). |\thestepcount| can be overridden to display labels
752 % differently, defaults to: ({\it number}). This exposes the internal
753 % |\thefd@stepcount| command.
754 %
755 % Ex. |\renewcommand{\thestepcount}{[\arabic{stepcount}]}|
756 % \begin{macrocode}
757 \newcommand{\thestepcount}{(\arabic{fd@stepcount})}
758 \renewcommand{\thefd@stepcount}{\thestepcount}
759 % \end{macrocode}
760 % \end{macro}
761 %
762 % \begin{macro}{\thesteplabel}
763 % Command used to generate a customized step label (used by manual numbering).
764 % |\thesteplabel| can be overridden to display manual numbers differently,
765 % this command has one argument: \marg{label}.
766 % The command does nothing by default (i.e\@. just returns the argument).
767 %
768 % Ex. |\renewcommand{\thesteplabel}[1]{[##1]}|
769 % \begin{macrocode}
770 \newcommand{\thesteplabel}[1]{#1}
771 % \end{macrocode}
772 % \end{macro}
773 %
774 % \begin{macro}{\theinlcmnt}
775 % The command used to format inline comments (if enabled). |\theinlcmnt|
776 % can be overridden to display it differently and has one argument:
777 % \marg{comment}. Defaults to: \{ {\em comment text} \}.
778 %
779 % Ex. |\renewcommand{\theinlcmnt}[1]{--#1--}|
780 % \begin{macrocode}
781 \newcommand{\theinlcmnt}[1]{\{ #1 \}}
782 % \end{macrocode}
783 % \end{macro}
784 %
785 % \begin{macro}{\inlcmnts}
786 % Command to switch inline comments explicitly on (and by that, overriding
787 % and forgetting the default determined by the absence or presence of the
788 % {\tt inlcmnts} package option).
789 %
790 % \begin{macrocode}
791 \newcommand{\inlcmnts}{\setboolean{@inlcmnts}{true}}
792 % \end{macrocode}
793 % \end{macro}
794 %
795 % \begin{macro}{\noinlcmnts}
796 % Command to switch inline comments explicitly off (and by that, overriding
797 % and forgetting the default determined by the absence or presence of the
798 % {\tt inlcmnts} package option).
799 %
800 % \begin{macrocode}
801 \newcommand{\noinlcmnts}{\setboolean{@inlcmnts}{false}}
802 % \end{macrocode}
803 % \end{macro}
804 %
805 % \subsection{The derivation environment}
806 %
807 % The following three sections describe the internal commands and constructs
808 % of the {\tt flagderiv} environment, after which the last section will
809 % explain how the environment works and how it is put together using the
810 % internal constructs.
811 %
812 % Note that for almost all commands there exists two versions, one used
813 % for manual numbered derivations and one for automatic numbered/labelled
814 % derivations (both forms can be mixed within the environment).
815 %
816 % \subsubsection{Labels}
817 %
818 % Derivation lines are labelled and can be referred to. This can be done
819 % with automatically numbered lines where the first argument is a normal
820 % \LaTeX\ label. However, to avoid clashing, the labels can be automatically
821 % prefixed with a namespace. The following two commands handle this prefixing.
822 %
823 % \begin{macro}{\@labelprefix}
824 % Command that specifies the label namespace prefix.
825 %
826 % \begin{macrocode}
827 \newcommand{\@labelprefix}{\relax}
828 % \end{macrocode}
829 % \end{macro}
830 % \begin{macro}{\@derlabel}
831 % Internal command to define a label using the prefix (if a label
832 % is defined, otherwise do nothing).
833 %
834 % \begin{macrocode}
835 \newcommand{\@derlabel}[1]{%
836 \ifthenelse{\equal{#1}{}}{}{\label{\@labelprefix#1}}%
837 }
838 % \end{macrocode}
839 % \end{macro}
840 %
841 % \subsubsection{Steps}
842 %
843 % A line of a derivation can be one of five types:
844 % \begin{enumerate}
845 % \item A simple and bare line, only internally accessible,
846 % \item a comment line,
847 % \item a derivation step (both automatically and manual numbered),
848 % \item a line to indicate skipping of steps,
849 % \item a flag (handled in the next section).
850 % \end{enumerate}
851 %
852 % This section deals with the first four types.
853 %
854 % \begin{macro}{\@derline}
855 % A simple derivation line that uses {\tt fd@flagcount} to remember
856 % the number of open flags. This command is used as:
857 % |\@derline|\marg{label}\marg{formula}\marg{comment}, with:
858 % \begin{description}
859 % \item[\marg{label}] a label which can be left empty, to refer back to in
860 % comments of other derivation lines,
861 % \item[\marg{formula}] the formula, and
862 % \item[\marg{comment}] a comment.
863 % \end{description}
864 %
865 % \begin{macrocode}
866 \newcommand{\@derline}[3]{%
867 \mbox{#1} &
868 \setlength{\extrarowheight}{\derivskip}%
869 % \end{macrocode}
870 % If the flag counter is still zero\dots
871 % \begin{macrocode}
872 \ifthenelse{\value{fd@flagcount}=0}%
873 % \end{macrocode}
874 % then this line is outside any flag,
875 % \begin{macrocode}
876 {\begin{array}[t]{@{}l}}%
877 % \end{macrocode}
878 % otherwise this is inside one or more flag contexts and the amount of
879 % open flagpoles equal to the number of open contexts should be inserted.
880 %
881 % \begin{macrocode}
882 {\begin{array}[t]{*{\value{fd@flagcount}}{|@{\hspace{2\arraycolsep}}}l}}
883 \ensuremath{#2}
884 \end{array} &
885 \mbox{#3} \\
886 }
887 % \end{macrocode}
888 % \end{macro}
889 %
890 % \begin{macro}{\@CMNTderline}
891 % Command to fold the comment on a separate line before the
892 % actual derivation line if the {\tt inlcmnts} option is set for this
893 % package, see also |\@derline| for the argument handling.
894 %
895 % \begin{macrocode}
896 \newcommand{\@CMNTderline}[3]{%
897 \ifthenelse{\boolean{@inlcmnts}}{%
898 % \end{macrocode}
899 % If the inline comments option is enabled, fold the comment before the
900 % actual line.
901 % \begin{macrocode}
902 \ifthenelse{\equal{#3}{}}{}{%
903 % \end{macrocode}
904 % There is comment, insert it inline.
905 % \begin{macrocode}
906 \@derline{}{\mbox{\theinlcmnt{#3}}}{}%
907 }
908 \@derline{#1}{#2}{}%
909 }{%
910 % \end{macrocode}
911 % If inline comments are not enabled, pass everything to |\@derline| directly.
912 % \begin{macrocode}
913 \@derline{#1}{#2}{#3}%
914 }%
915 }
916 % \end{macrocode}
917 % \end{macro}
918 %
919 % \begin{macro}{\@MANstep}
920 % \begin{macro}{\@AUTOstep}
921 % Command for the manual ({\tt MAN}) and automatically ({\tt AUTO})
922 % numbered version of a derivation step. See also |\@derline|.
923 %
924 % \begin{macrocode}
925 \newcommand{\@MANstep}[3]{\@CMNTderline{\thesteplabel{#1}}{#2}{#3}}
926 % \end{macrocode}
927 %
928 % \begin{macrocode}
929 \newcommand{\@AUTOstep}[3]{%
930 \refstepcounter{fd@stepcount}%
931 \@derlabel{#1}\@CMNTderline{\thestepcount}{#2}{#3}%
932 }
933 % \end{macrocode}
934 % \end{macro}
935 % \end{macro}
936 %
937 % \begin{macro}{\@MANskipsteps}
938 % \begin{macro}{\@AUTOskipsteps}
939 % Command for the manual ({\tt MAN}) and automatically ({\tt AUTO})
940 % numbered version of skipping derivation steps. See also |\@derline|.
941 %
942 % \begin{macrocode}
943 \newcommand{\@MANskipsteps}[2]{\@CMNTderline{}{#1}{#2}}
944 % \end{macrocode}
945 %
946 % \begin{macrocode}
947 \newcommand{\@AUTOskipsteps}[3]{%
948 \addtocounter{fd@stepcount}{#1}%
949 \@CMNTderline{}{#2}{#3}%
950 }
951 % \end{macrocode}
952 % \end{macro}
953 % \end{macro}
954 %
955 % \subsubsection{Flags}
956 %
957 % Flags are actually simple derivation lines with two extras: the formula
958 % is put into a flag box and the flag counter {\tt fd@flagcount} is incremented
959 % when one is opened. Next to flag commands there are also commands to
960 % to close (and by that decrementing the counter) flags.
961 %
962 % There exist three types of flags:
963 % \begin{enumerate}
964 % \item the simple and bare flag,
965 % \item the assumption flag (both manual and automatically numbered),
966 % \item the variable introduction flag (also manual and automatically numbered).
967 % \end{enumerate}
968 %
969 % \begin{macro}{\@flagbox}
970 % Creates a flag for (a box around) the given text/formula, takes
971 % \marg{formula} as an argument.
972 % \begin{macrocode}
973 \newcommand{\@flagbox}[1]{%
974 \setlength{\fboxsep}{0.75ex}%
975 \fbox{#1}%
976 }
977 % \end{macrocode}
978 % \end{macro}
979 %
980 % \begin{macro}{\@startflag}
981 % Starts a flag context by opening a flag and incrementing the counter.
982 % The command is used as:
983 % |\@startflag|\marg{label}\marg{formula}\marg{comment},
984 % see also |\@derline| for the meaning of these arguments.
985 %
986 % \begin{macrocode}
987 \newcommand{\@startflag}[3]{%
988 \@CMNTderline{#1}{\@flagbox{\ensuremath{#2}}}{#3}%
989 \addtocounter{fd@flagcount}{1}%
990 }
991 % \end{macrocode}
992 % \end{macro}
993 %
994 % \begin{macro}{\@endflag}
995 % Ends a flag by closing it and decrementing the counter. Takes the
996 % number of flags to close \marg{number} as an argument.
997 %
998 % \begin{macrocode}
999 \newcommand{\@endflag}[1]{\addtocounter{fd@flagcount}{-#1}}
1000 % \end{macrocode}
1001 % \end{macro}
1002 %
1003 % \begin{macro}{\@flagclose}
1004 % Wrapper command for closing a number of flags simultaneously taking \oarg{number}
1005 % as an optional argument, defaulting to 1. See also |\@endflag|.
1006 %
1007 % \begin{macrocode}
1008 \newcommand{\@flagclose}[1][1]{\@endflag{#1}}
1009 % \end{macrocode}
1010 % \end{macro}
1011 %
1012 % \begin{macro}{\@MANassume}
1013 % \begin{macro}{\@AUTOassume}
1014 % Command for the manual ({\tt MAN}) and automatic ({\tt AUTO})
1015 % numbered version of an assumption flag, see also |\@startflag|.
1016 %
1017 % \begin{macrocode}
1018 \newcommand{\@MANassume}[3]{\@startflag{\thesteplabel{#1}}{#2}{#3}}
1019 % \end{macrocode}
1020 %
1021 % \begin{macrocode}
1022 \newcommand{\@AUTOassume}[3]{
1023 \refstepcounter{fd@stepcount}%
1024 \@derlabel{#1}\@startflag{\thestepcount}{#2}{#3}%
1025 }
1026 % \end{macrocode}
1027 % \end{macro}
1028 % \end{macro}
1029 %
1030 % \begin{macro}{\@MANintroduction}
1031 % \begin{macro}{\@AUTOintroduction}
1032 % Command for the manual ({\tt MAN}) and automatically ({\tt AUTO})
1033 % numbered version of an introduction flag, see also |\@startflag|.
1034 %
1035 % \begin{macrocode}
1036 \newcommand{\@MANintroduction}[3]{%
1037 \@startflag{\thesteplabel{#1}}{\introsymb~#2}{#3}%
1038 }
1039 % \end{macrocode}
1040 %
1041 % \begin{macrocode}
1042 \newcommand{\@AUTOintroduction}[3]{
1043 \refstepcounter{fd@stepcount}%
1044 \@derlabel{#1}\@startflag{\thestepcount}{\introsymb~#2}{#3}%
1045 }
1046 % \end{macrocode}
1047 % \end{macro}
1048 % \end{macro}
1049 %
1050 % \begin{macro}{\@MANconclude}
1051 % \begin{macro}{\@AUTOconclude}
1052 % Command to conclude from one or more open flags in the manual ({\tt MAN})
1053 % and automatically ({\tt AUTO}) numbered version, see also |\@endflag|.
1054 % The command is used as:
1055 % |\@MANconclude|\oarg{number}\marg{label}\marg{formula}\marg{comment},
1056 % where the \oarg{number} indicates the number of flags to close,
1057 % defaulting to 1.
1058 %
1059 % \begin{macrocode}
1060 \newcommand{\@MANconclude}[4][1]{\@endflag{#1}\step*{#2}{#3}{#4}}
1061 % \end{macrocode}
1062 %
1063 % \begin{macrocode}
1064 \newcommand{\@AUTOconclude}[4][1]{\@endflag{#1}\step{#2}{#3}{#4}}
1065 % \end{macrocode}
1066 % \end{macro}
1067 % \end{macro}
1068 %
1069 % \subsubsection{The environment itself}
1070 %
1071 % \begin{environment}{flagderiv}
1072 % This section explains the main environment for flag style
1073 % derivations/proofs: {\tt flagderiv}. The command has an optional
1074 % argument \oarg{prefix}, used as label prefix so that labels can be
1075 % ``scoped'' with a namespace local to the derivation but still
1076 % accessible from the outside.
1077 %
1078 % Examples:\\
1079 % |\begin{flagderiv} ... \end{flagderiv}|\\
1080 % |\begin{flagderiv}[abs] ... \end{flagderiv}|
1081 %
1082 % \begin{macrocode}
1083 \newenvironment{flagderiv}[1][]{%
1084 % \end{macrocode}
1085 %
1086 % First, set the optional label prefix (if given) and reset the counters.
1087 %
1088 % \begin{macrocode}
1089 \ifthenelse{\equal{#1}{}}{%
1090 \renewcommand{\@labelprefix}{}%
1091 }{%
1092 \renewcommand{\@labelprefix}{#1:}%
1093 }%
1094 \setcounter{fd@flagcount}{0}%
1095 \setcounter{fd@stepcount}{0}%
1096 % \end{macrocode}
1097 %
1098 % Note: {\em All} of the following five commands have a star version which
1099 % allows manual numbering, instead of having auto-numbering, \LaTeX\ labels
1100 % and references.
1101 %
1102 % \begin{macro}{\assume}
1103 % \begin{macro}{\assume*}
1104 % Opens an assumption flag; command usage:\\[1em]
1105 % |\assume|\marg{label}\marg{formula}\marg{comment}\\
1106 % |\assume*|\marg{custom-number}\marg{formula}\marg{comment}
1107 %
1108 % Examples: \\
1109 % |\assume{assum:1}{x > 0}{Assumption}|\\
1110 % |\assume*{l}{\neg P}{}|
1111 %
1112 % \begin{macrocode}
1113 \newcommand{\assume}{\@ifstar{\@MANassume}{\@AUTOassume}}
1114 % \end{macrocode}
1115 % \end{macro}
1116 % \end{macro}
1117 %
1118 % \begin{macro}{\introduce}
1119 % \begin{macro}{\introduce*}
1120 % Opens an introduction flag. Command usage: \\[1em]
1121 % |\introduce|\marg{label}\marg{formula}\marg{comment} \\
1122 % |\introduce*|\marg{custom-number}\marg{formula}\marg{comment}
1123 %
1124 % Examples:\\
1125 % |\introduce{intro-x}{x \in \mathbb{N}}{Introduction}| \\
1126 % |\introduce*{l - 1}{P \in s_P}{}|
1127 %
1128 % \begin{macrocode}
1129 \newcommand{\introduce}{\@ifstar{\@MANintroduction}{\@AUTOintroduction}}
1130 % \end{macrocode}
1131 % \end{macro}
1132 % \end{macro}
1133 %
1134 % \begin{macro}{\conclude}
1135 % \begin{macro}{\conclude*}
1136 % Performs a conclusion/multiple conclusion from one or more
1137 % introductions and/or assumptions. The command usage:\\[1em]
1138 % |\conclude|\oarg{number}\marg{label}\marg{formula}\marg{comment}\\
1139 % |\conclude*|\oarg{number}\marg{custon-number}\marg{formula}\marg{comment}
1140 %
1141 % The optional argument \oarg{number} indicates how much flags should be
1142 % closed with this conclusion, this defaults to 1.
1143 %
1144 % Examples;\\
1145 % |\conclude[2]{concl:2}{x > 0 \implies ...}{$\implies$-intro on ...}|\\
1146 % |\conclude*{n - 1}{\neg\neg P}{$\implies$-intro on (l) ...}|
1147 %
1148 % \begin{macrocode}
1149 \newcommand{\conclude}{\@ifstar{\@MANconclude}{\@AUTOconclude}}
1150 % \end{macrocode}
1151 % \end{macro}
1152 % \end{macro}
1153 %
1154 % \begin{macro}{\step}
1155 % \begin{macro}{\step*}
1156 % Performs a derivation step, command usage:\\[1em]
1157 % |\step|\marg{label}\marg{formula}\marg{comment}\\
1158 % |\step*|\marg{custom-number}\marg{formula}\marg{comment}
1159 %
1160 % Examples:\\
1161 % |\step{x-elim}{x > 0}{$\forall$-elem on \ref{assum:1}}|\\
1162 % |\step*{n - 1}{x > 0}{$\forall$-elem on (n - 3)}|
1163 %
1164 % Note: |\\| (line breaks) may be inserted for splitting
1165 % large formulas.
1166 %
1167 % \begin{macrocode}
1168 \newcommand{\step}{\@ifstar{\@MANstep}{\@AUTOstep}}
1169 % \end{macrocode}
1170 % \end{macro}
1171 % \end{macro}
1172 %
1173 % \begin{macro}{\skipsteps}
1174 % \begin{macro}{\skipsteps*}
1175 % Skips a number of steps (for usage in examples), usage:\\[1em]
1176 % |\skipsteps|\marg{number}\marg{formula}\marg{comments}\\
1177 % |\skipsteps*|\marg{formula}\marg{comments}.
1178 %
1179 % Examples:\\
1180 % |\skipsteps{3}{\vdots}{Etcetera, etcetera}|\\
1181 % |\skipsteps*{\vdots}{Etcetera, etcetera}|
1182 %
1183 % \begin{macrocode}
1184 \newcommand{\skipsteps}{\@ifstar{\@MANskipsteps}{\@AUTOskipsteps}}
1185 % \end{macrocode}
1186 % \end{macro}
1187 % \end{macro}
1188 %
1189 % \begin{macro}{\done}
1190 % Closes a number of flags because contexts have been opened and
1191 % should be closed without conclusions. Command usage: \\[1em]
1192 % |\done|\oarg{number}
1193 %
1194 % This command takes a number of introductions/assumptions, \oarg{number},
1195 % to close as an optional argument, which defaults to 1.
1196 %
1197 % Examples:\\
1198 % |\done|\\
1199 % |\done[3]|
1200 %
1201 % \begin{macrocode}
1202 \newcommand{\done}{\@flagclose}
1203 % \end{macrocode}
1204 % \end{macro}
1205 %
1206 % Silently override |\ref| to work with the defined namespace.
1207 % \begin{macrocode}
1208 \let\origref\ref%
1209 \renewcommand{\ref}[1]{\origref{\@labelprefix##1}}%
1210 % \end{macrocode}
1211 %
1212 % The actual flagderiv environment is just a longtable (called
1213 % ``derivation'').
1214 %
1215 % \begin{macrocode}
1216 \renewcommand{\tablename}{Derivation}%
1217 \begin{longtable}[l]{rll}
1218 }{%
1219 \end{longtable}
1220 }
1221 % \end{macrocode}
1222 % \end{environment}
1223 %
1224 % \begin{environment}{flagderiv*}
1225 % The |flagderiv*| environment is almost the same as |flagderiv|
1226 % with the only difference that the resulting derivation will and
1227 % can not be split across pages.
1228 %
1229 % Example:\\
1230 % |\begin{flagderiv*} ... \end{flagderiv*}|\\
1231 %
1232 % \begin{macrocode}
1233 \newenvironment{flagderiv*}[1][]{%
1234 \ifthenelse{\equal{#1}{}}{%
1235 \renewcommand{\@labelprefix}{}%
1236 }{%
1237 \renewcommand{\@labelprefix}{#1:}%
1238 }%
1239 \setcounter{fd@flagcount}{0}%
1240 \setcounter{fd@stepcount}{0}%
1241 \newcommand{\assume}{\@ifstar{\@MANassume}{\@AUTOassume}}
1242 \newcommand{\introduce}{\@ifstar{\@MANintroduction}{\@AUTOintroduction}}
1243 \newcommand{\conclude}{\@ifstar{\@MANconclude}{\@AUTOconclude}}
1244 \newcommand{\step}{\@ifstar{\@MANstep}{\@AUTOstep}}
1245 \newcommand{\skipsteps}{\@ifstar{\@MANskipsteps}{\@AUTOskipsteps}}
1246 \newcommand{\done}{\@flagclose}
1247 \let\origref\ref%
1248 \renewcommand{\ref}[1]{\origref{\@labelprefix##1}}%
1249 \renewcommand{\tablename}{Derivation}
1250 \begin{tabular}{rll}
1251 }{%
1252 \end{tabular}
1253 }
1254 % \end{macrocode}
1255 % \end{environment}
1256 %
1257 % \PrintIndex
1258 % \PrintChanges
1259 %
1260 % \Finale
1261 \endinput