summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fitch/fitchdoc.tex
blob: 1889721dd09599e50cd3ca342d79c18a569bc06b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
%% fitchdoc.tex
%% Macros for Fitch-style natural deduction (documentation)
%% Copyright 2002-2023 Peter Selinger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Richard Zach <rzach@ucalgary.ca>
%
% This work consists of the files fitch.sty and fitchdoc.tex.

% Original Author: Peter Selinger, Dalhousie University
% Created: Jan 14, 2002
% Modified: Sep 4, 2023
% Version: 0.6
% Copyright: (C) 2002-2023 Peter Selinger
% Filename: fitch.sty
% Documentation: fitchdoc.tex
% https://github.com/OpenLogicProject/fitch/

\documentclass{ltxdoc}

\usepackage{fitch,graphicx,showexpl,fullpage}

\lstset{%
  basicstyle=\ttfamily\small,
  commentstyle=\itshape\ttfamily\small,
  showspaces=false,
  showstringspaces=false,
  breaklines=true,
  breakautoindent=true,
  captionpos=t
}

\title{\texttt{fitch.sty}: Fitch-style natural deduction macros}

\author{Peter Selinger\\Dalhousie University\thanks{The current
maintainer of this package is \href{https://richardzach.org}{Richard
Zach}. The package repository is at
\url{https://github.com/OpenLogicProject/fitch/}, where you can also
report any \href{https://github.com/OpenLogicProject/fitch/issues}{issues} with it.}}

\date{Version 0.6\\ September 4, 2023}

\begin{document}
\maketitle

\section{Overview}

This document describes how to use the {\tt fitch.sty} macros for
typesetting Fitch-style natural deduction derivations. To load the macros,
simply put \verb!\usepackage{fitch}! into the preamble of your
{\LaTeX} file. 

Here is a natural deduction derivation, together with the code that
produced it:

\begin{LTXexample}
\[
\begin{nd}
  \hypo {1}  {P\vee Q}
  \hypo {2}  {\neg Q}
  \open
  \hypo {3} {P}
  \have {4} {P}        \r{3}
  \close
  \open
  \hypo {aa} {Q}
  \have {6} {\neg Q}   \r{2}
  \have {7} {\bot}     \ne{aa,6}
  \have {8} {P}        \be{7}
  \close
  \have {9} {P}        \oe{1,3-4,aa-8}
\end{nd}
\]
\end{LTXexample}

A derivation consists of \emph{lines}, and each line contains a {\em
line number} and a \emph{formula}. Some lines also carry a {\em
justification}. Moreover, each line is either a \emph{hypothesis} or a
\emph{derived formula}. Generally, derived formulas carry a
justification, whereas hypotheses do not; however, the macros do not
enforce this.

\DescribeEnv{nd}
Derivations are typeset inside the \verb!nd! environment, which must be
used in math mode. 

\DescribeMacro{\hypo}\DescribeMacro{\have}
The commands \verb!\hypo! and \verb!\have! are used
to typeset one line of the derivation; \verb!\hypo! is used for
hypotheses, and \verb!\have! for derived formulas. Both commands take
a label and a formula as an argument. Note that the labels used to
identify lines in the derivation need not be actual line numbers; for
instance, in the above example, we used the label $aa$ instead of $5$.
In the output, lines are automatically numbered consecutively. Labels
may not contain any punctuation characters or spaces.

\DescribeMacro{\open}\DescribeMacro{\close}
Subderivations are opened and closed with the commands \verb!\open! and
\verb!\close!. Finally, the following commands are provided for
annotating lines with justifications:

\medskip
\hfill
\begin{tabular}{@{}ll@{}}
  \verb!\r!  & reiteration \\
  \verb!\ii! & implication introduction \\
  \verb!\ie! & implication elimination \\
  \verb!\ai! & and introduction \\
  \verb!\ae! & and elimination \\
\end{tabular} 
\hfill
\begin{tabular}{ll}
  \verb!\oi! & or introduction \\
  \verb!\oe! & or elimination \\
  \verb!\ni! & not introduction \\
  \verb!\ne! & not elimination \\
  \verb!\be! & bottom elimination \\
\end{tabular} 
\hfill
\begin{tabular}{@{}ll@{}}
  \verb!\nne! & double negation elimination \\
  \verb!\Ai! & forall introduction \\
  \verb!\Ae! & forall elimination \\
  \verb!\Ei! & exists introduction \\
  \verb!\Ee! & exists elimination \\
\end{tabular} 
\hfill
\medskip

Each such command takes a \emph{reference list} as an argument. A
reference list is a string made from labels, commas, and hyphens, for
instance \verb!1,3a-3b,4a-4d!.

\section{Details}

\subsection{Guards}

Some natural deduction derivations with quantifiers use \emph{guards}, as in
the following example:

\begin{LTXexample}
\[
\begin{nd}
  \hypo {1} {\exists x\forall y.P(x,y)}
  \open[v]
  \open[u]
  \hypo {2} {\forall y.P(u,y)}
  \have {3} {P(u,v)}                     \Ae{2}
  \have {4} {\exists x.P(x,v)}           \Ei{3}
  \close
  \have {5} {\exists x.P(x,v)}           \Ee{1,2-5}
  \close
  \have {6} {\forall y\exists x.P(x,y)}  \Ai{2-5}
\end{nd}
\]
\end{LTXexample}

The guards $v$ and $u$ in line 2 were typeset by giving optional
arguments to the \verb!\open! commands of the respective
subderivations. 

\DescribeMacro{\guard}
For most purposes, the above way of specifying guards is sufficient.
However, there is another method, which allows a more flexible
placement of guards: before any line, you can give the command
\verb!\guard{u}! to add a guard $u$ to the top-level subderivation at
that line, or \verb!\guard[n]{u}! to add a guard to the $n$th
enclosing subderivation at that line. Thus, the above example could
have also been typeset by inserting the two commands \verb!\guard{u}! and
\verb!\guard[2]{v}! just after the second \verb!\open! statement.

% For backward compatibility, there is a third way of specifying guards
% by giving an optional second argument to the \verb!\hypo! and
% \verb!\have! commands. The use of this feature is discouraged.

\subsection{Generic justifications}

Non-standard justifications can be created with the \verb!\by!
command. This command takes two arguments: a name and a reference
list. For instance, the command \verb!\by{De Morgan}{lab3,lab4}! might
produce the output ``\mbox{De Morgan, 3, 4}''. Note that the justification
is typeset in text mode. A comma is automatically inserted between the
name and the reference list, unless the reference list is empty.

\subsection{Label and reference list details}

Labels may not contain commas, periods, semicolons, hyphens,
parenthesis, or spaces. In a reference list, spaces are ignored (even
within a label!), whereas commas, periods, semicolons, parenthesis,
and hyphens are copied to the output. All other characters are
interpreted as part of a label. Attempting to reference a label which
has not been previously defined by any \verb!\hypo! or \verb!\have!
command produces an error message of the form:

\begin{verbatim}
  ! Package fitch Error: Undefined line reference: lab17.
\end{verbatim}

\subsection{Referencing line numbers in the text}
\label{subsec-ndref}

\DescribeMacro{\ndref}
Labels defined in an \verb!nd! environment can be referenced in the
text with the \verb!\ndref! command. This command takes a reference
list as an argument, and produces the corresponding output. However,
it is only possible to reference labels \emph{after} the corresponding
derivation has been typeset. There is currently no convenient way of
defining forward references. Also, if a label is used more than once,
\verb!\ndref! will always refer to the most recent time it was used.

\subsection{Scope}

The commands \verb!\hypo!, \verb!\have!, \verb!\open!, \verb!\close!,
\verb!\r!, \verb!\ii!, and so forth are only available inside an
\verb!nd! environment. These commands may have a different meaning
elsewhere in the same document. The only commands provided by the
\verb!fitch.sty!  package which are visible outside an \verb!nd!
environment are the command \verb!\ndref! described in
Section~\ref{subsec-ndref}, and the command \verb!\nddim! and the
dimension \verb!\ndindent! described in Section~\ref{subsec-nddim}.

\subsection{Breaking it across pages}\label{subsec-break}

\DescribeMacro{\ndresume}
The \verb!nd! environment is derived from the {\LaTeX} \verb!array!
environment, and thus it does not break across pages automatically. 
However, if a derivation is too long to fit on a single page, it is
possible to split it manually into physically independent, but
logically consecutive subparts. For this purpose, the \verb!ndresume!
environment is provided to continue a previously interrupted
derivation. Here is an example:

\begin{LTXexample}
$
\begin{nd}
  \hypo {1}  {P\vee Q}
  \hypo {2}  {\neg Q}
  \open
  \hypo {3} {P}
  \have {4} {P}      \r{3}
  \close
  \open
  \hypo {aa} {Q}
  \have {6} {\neg Q} \r{2}
\end{nd}
$

Derivations can be interrupted and 
resumed at any point.

$
\begin{ndresume}
  \have {7} {\bot}  \ne{aa,6}
  \have {8} {P}     \be{7}
  \close
  \have {9} {P}     \oe{1,3-4,aa-8}
\end{ndresume}
$
\end{LTXexample}

\subsection{Custom line numbers}

One often needs to write derivation schemas, rather than derivations.
This often requires the use of symbolic constants such as $n$, $n+1$,
etc, instead of actual line numbers. The \verb!\have! and \verb!\hypo!
commands have an optional first argument which is a symbolic constant.
For instance, \verb!\have[n]! will cause the current line to be
numbered with the symbolic constant $n$. Subsequent lines are
automatically numbered $n+1$ etc. An initial offset can be given as a
second optional argument, as in \verb!\have[n][-1]!, which will cause
the current line to be numbered $n-1$, the following line $n$, etc. In
an explicit offset is given, the symbolic constant can also be absent:
for instance, the command \verb!\have[][7]! resets the current line
number to $7$. The following example illustrates this behavior:

\begin{LTXexample}
\[
\begin{nd}
  \hypo          {1} {P\vee Q}
  \open
  \hypo          {2} {P}
  \have [\vdots] {3} {\vdots}
  \have [n][-1]  {4} {A\wedge B}
  \close
  \open
  \hypo          {5} {Q}
  \have [\vdots] {6} {\vdots}
  \have [m]      {7} {A\wedge B}
  \close
  \have          {8} {A\wedge B}  \oe{1,2-(4),5-7}
  \have [\vdots] {9} {\vdots}
  \have [][100] {10} {A}          \ae{8}
\end{nd}
\]
\end{LTXexample}

Note that in the justification for line $m+1$, parentheses had to be
put around the label $4$. There is currently no way of doing this
automatically. 

{\bf Exercise.} How does one typeset an empty line number?

{\bf Solution.} Since \verb!\have[]! has a special meaning as explained
above, we need to use \verb!\have[~]! instead.

\subsection{Continuation lines}\label{subsec-continuation}

Sometimes one has to typeset a very long formula that does not fit on
a single line. As of version 0.5 of the {\tt fitch.sty} macros, it is
possible to break a formula into several lines using \verb!\\! as a
line separator. Continuation lines are automatically indented, as
shown in the following example.

\begin{LTXexample}
\[
\begin{nd}
  \hypo{1}  {A\wedge B}
  \hypo{2}  {A\wedge B\rightarrow{} \\
             C\wedge D}
  \have{3}  {C\wedge D}  \ie{1,2}
  \have{4}  {A\wedge B\wedge{} \\
             C\wedge D}  \ai{1,3}
\end{nd}
\]
\end{LTXexample}

\DescribeMacro{\hypocont}
\DescribeMacro{\havecont}
Alternatively, the \verb!\havecont! and \verb!\hypocont!  commands can
be used to specify each continuation line separately, as the following
example illustrates.

\begin{LTXexample}
\[
\begin{nd}
  \hypo{1}  {A\wedge B}
  \hypo{2}  {A\wedge B\rightarrow{}}
  \hypocont {C\wedge D}
  \have{3}  {C\wedge D}         \ie{1,2}
  \have{4}  {A\wedge B\wedge{}} \ai{1,3}
  \havecont {C\wedge D}
\end{nd}
\]
\end{LTXexample}

This latter style gives slightly more flexibility in the placement of
justifications, since each line and continuation line can have its own
justification and its own guard (via the \verb!\guard! command).  It
also allows a derivation to be interrupted between a line and its
continuation, as discussed in Section~\ref{subsec-break}.

\subsection{Customizing dimensions}\label{subsec-nddim}

\DescribeMacro{\nddim}
The relative sizes of the various elements of a natural deduction
proof are preset to reasonable values depending on the size of the
currently selected font. However, it will sometimes be necessary to
customize these dimensions. This can be achieved with the
\verb!\nddim! command. The syntax of the command is as follows:
\begin{center}
  \cmd{\nddim}\marg{height}\marg{topheight}\marg{depth}\marg{labelsep}
  \marg{indent}\marg{hsep}\marg{justsep}\marg{linethickness},
\end{center}
where each of the eight parameters is a dimension. The meaning of the
first seven parameters is shown in the
following illustrations; \emph{linethickness} is simply the thickness
of the lines.
\[\includegraphics{fitchdoc-dimen}\]
The default dimensions are:
\begin{center}
\verb!\nddim{4.5ex}{3.5ex}{1.5ex}{1em}{1.6em}{.5em}{2.5em}{.2mm}!.
\end{center}
\DescribeMacro{\ndindent}
In addition, the dimension \verb!\ndindent!, controls
the amount of extra indentation used on continuation lines as
discussed in Section~\ref{subsec-continuation}. It can be changed and
is \verb!1ex!  by default.

\subsection{Other comments}

The goal was to design a flexible package which would not impose any
constraints on the form of derivations, while making typesetting easy.
With this package, it is in fact possible to typeset incomplete,
ill-formed, or invalid derivations. Sometimes it is pedagogically necessary
to do so.

There are no arbitrary limits on the size or nesting depth of a derivation,
except for the obvious requirement of fitting horizontally on the
printed page.

\section{Copyright and license}

This document and the accompanying \verb!fitch.sty! macros
are {\copyright} 2002--2023 by Peter Selinger and distributed under
the terms of the \href{https://www.latex-project.org/lppl/}{LPPL}.

\end{document}