content/methods/induction/induction.tex
1% Part: methods2% Chapter: induction 34\documentclass[../../../include/open-logic-section]{subfiles}56\begin{document}78\olchapter{mth}{ind}{Induction}910\olimport{introduction}1112\olimport{induction-on-N}1314\olimport{strong-induction}1516\olimport{inductive-definitions}1718\olimport{structural-induction}1920\olimport{relations}2122\OLEndChapterHook2324\end{document}
content/methods/induction/introduction.tex
1% Part: methods2% Chapter: induction3% Section: introduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{int}1011\olsection{Introduction}1213Induction is an important proof technique which is used, in different14forms, in almost all areas of logic, theoretical computer science, and15mathematics. It is needed to prove many of the results in logic.1617Induction is often contrasted with deduction, and characterized as the18inference from the particular to the general. For instance, if we19observe many green emeralds, and nothing that we would call an emerald20that's not green, we might conclude that all emeralds are green. This21is an inductive inference, in that it proceeds from many particular22cases (this emerald is green, that emerald is green, etc.) to a23general claim (all emeralds are green). \emph{Mathematical} induction24is also an inference that concludes a general claim, but it is of a25very different kind than this ``simple induction.''2627Very roughly, an inductive proof in mathematics concludes that all28mathematical objects of a certain sort have a certain property. In29the simplest case, the mathematical objects an inductive proof is30concerned with are natural numbers. In that case an inductive proof31is used to establish that all natural numbers have some property, and32it does this by showing that33\begin{enumerate}34 \item $0$ has the property, and35 \item whenever a number~$k$ has the property, so does~$k+1$.36\end{enumerate}37Induction on natural numbers can then also often be used to prove38general claims about mathematical objects that can be assigned numbers. For39instance, finite sets each have a finite number~$n$ of elements, and40if we can use induction to show that every number~$n$ has the property41``all finite sets of size~$n$ are \dots'' then we will have shown42something about all finite sets.4344Induction can also be generalized to mathematical objects that are45\emph{inductively defined}. For instance, expressions of a formal46language such as those of first-order logic are defined inductively.47\emph{Structural induction} is a way to prove results about all such48expressions. Structural induction, in particular, is very49useful---and widely used---in logic.5051\end{document}
content/methods/induction/induction-on-N.tex
1% Part: methods2% Chapter: induction3% Section: induction-on-N45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{inN}1011\olsection{Induction on~$\Nat$}1213In its simplest form, induction is a technique used to prove results14for all natural numbers. It uses the fact that by starting from $0$15and repeatedly adding~$1$ we eventually reach every natural number. So16to prove that something is true for every number, we can (1)~establish17that it is true for $0$ and (2)~show that whenever it is true for a18number~$n$, it is also true for the next number~$n+1$. If we19abbreviate ``number~$n$ has property $P$'' by $P(n)$ (and ``number~$k$20has property $P$'' by $P(k)$, etc.), then a proof by induction that21$P(n)$ for all $n \in \Nat$ consists of:22\begin{enumerate}23\item a proof of $P(0)$, and24\item a proof that, for any~$k$, if $P(k)$ then $P(k+1)$.25\end{enumerate}26To make this crystal clear, suppose we have both (1) and~(2). Then27(1) tells us that $P(0)$ is true. If we also have~(2), we know in28particular that if $P(0)$ then $P(0+1)$, i.e., $P(1)$. This follows29from the general statement ``for any~$k$, if $P(k)$ then $P(k+1)$'' by30putting~$0$ for~$k$. So by modus ponens, we have that~$P(1)$. From (2)31again, now taking $1$ for~$n$, we have: if $P(1)$ then~$P(2)$. Since32we've just established~$P(1)$, by modus ponens, we have~$P(2)$. And so33on. For any number~$n$, after doing this $n$~times, we eventually34arrive at~$P(n)$. So (1) and~(2) together establish~$P(n)$ for any $n35\in \Nat$.3637Let's look at an example. Suppose we want to find out how many38different sums we can throw with $n$ dice. Although it might seem39silly, let's start with $0$ dice. If you have no dice there's only one40possible sum you can ``throw'': no dots at all, which sums to~$0$. So41the number of different possible throws is~$1$. If you have only one42die, i.e., $n=1$, there are six possible values, $1$ through~$6$. With43two dice, we can throw any sum from $2$ through $12$, that's $11$44possibilities. With three dice, we can throw any number from $3$ to45$18$, i.e., $16$ different possibilities. $1$, $6$, $11$, $16$: looks46like a pattern: maybe the answer is $5n+1$? Of course, $5n+1$ is the47maximum possible, because there are only $5n+1$ numbers between $n$,48the lowest value you can throw with $n$ dice (all $1$'s) and $6n$, the49highest you can throw (all $6$'s).5051\begin{thm}52 With $n$ dice one can throw all $5n+1$ possible values between $n$53 and $6n$.54\end{thm}5556\begin{proof}57Let $P(n)$ be the claim: ``It is possible to throw any number between58$n$ and~$6n$ using $n$~dice.'' To use induction, we prove:59\begin{enumerate}60\item The \emph{induction basis} $P(1)$, i.e., with just one die,61 you can throw any number between $1$ and $6$.62\item The \emph{induction step}, for all $k$, if $P(k)$ then~$P(k+1)$.63\end{enumerate}6465(1) Is proved by inspecting a $6$-sided die. It has all 6 sides, and66every number between $1$ and~$6$ shows up one on of the sides. So it67is possible to throw any number between $1$ and~$6$ using a single68die.6970To prove (2), we assume the antecedent of the conditional, i.e.,71$P(k)$. This assumption is called the \emph{inductive hypothesis}. We72use it to prove~$P(k+1)$. The hard part is to find a way of thinking73about the possible values of a throw of $k+1$ dice in terms of the74possible values of throws of $k$~dice plus of throws of the extra75$k+1$-st die---this is what we have to do, though, if we want to use76the inductive hypothesis.7778The inductive hypothesis says we can get any number between $k$79and~$6k$ using $k$~dice. If we throw a~$1$ with our $(k+1)$-st die,80this adds $1$ to the total. So we can throw any value between $k+1$81and $6k+1$ by throwing $k$~dice and then rolling a~$1$ with the82$(k+1)$-st die. What's left? The values $6k+2$ through $6k+6$. We83can get these by rolling $k$ $6$s and then a number between $2$ and84$6$ with our $(k+1)$-st die. Together, this means that with $k+1$ dice85we can throw any of the numbers between $k+1$ and $6(k+1)$, i.e.,86we've proved~$P(k+1)$ using the assumption~$P(k)$, the inductive87hypothesis.88\end{proof}8990Very often we use induction when we want to prove something about a91series of objects (numbers, sets, etc.) that is itself defined92``inductively,'' i.e., by defining the $(n+1)$-st object in terms of93the $n$-th. For instance, we can define the sum~$s_n$ of the natural94numbers up to~$n$ by95\begin{align*}96 s_0 & = 0\\97 s_{n+1} & = s_n + (n+1)98\end{align*}99This definition gives:100\begin{align*}101 s_0 & = 0,\\102 s_1 & = s_0 + 1 && = 1,\\103 s_2 & = s_1 + 2 && = 1 + 2 = 3\\104 s_3 & = s_2 + 3 && = 1 + 2 + 3 = 6, \text{ etc.}105\end{align*}106Now we can prove, by induction, that $s_n = n(n+1)/2$.107108\begin{prop}109 $s_n = n(n+1)/2$.110\end{prop}111112\begin{proof}113 We have to prove (1) that $s_0 = 0\cdot(0 + 1)/2$ and (2) if $s_k =114 k(k+1)/2$ then $s_{k+1} = (k+1)(k+2)/2$. (1) is obvious. To prove115 (2), we assume the inductive hypothesis: $s_k = k(k+1)/2$. Using it,116 we have to show that $s_{k+1} = (k+1)(k+2)/2$.117118 What is $s_{k+1}$? By the definition, $s_{k+1} = s_k + (k+1)$. By119 inductive hypothesis, $s_k = k(k+1)/2$. We can substitute this into120 the previous equation, and then just need a bit of arithmetic of121 fractions:122 \begin{align*}123 s_{k+1} & = \frac{k(k+1)}{2} + (k+1) = {}\\124 & = \frac{k(k+1)}{2} + \frac{2(k+1)}{2} = {}\\125 & = \frac{k(k+1) + 2(k+1)}{2} = {}\\126 & = \frac{(k+2)(k+1)}{2}.127 \end{align*}128\end{proof}129130The important lesson here is that if you're proving something about131some inductively defined sequence $a_n$, induction is the obvious way132to go. And even if it isn't (as in the case of the possibilities of133dice throws), you can use induction if you can somehow relate the case134for~$k+1$ to the case for~$k$.135136\end{document}
content/methods/induction/strong-induction.tex
1% Part: methods2% Chapter: induction3% Section: strong-induction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{str}1011\olsection{Strong Induction}1213In the principle of induction discussed above, we prove $P(0)$ and14also if $P(k)$, then $P(k+1)$. In the second part, we assume that15$P(k)$ is true and use this assumption to prove $P(k+1)$.16Equivalently, of course, we could assume $P(k-1)$ and use it to prove17$P(k)$---the important part is that we be able to carry out the18inference from any number to its successor; that we can prove the19claim in question for any number under the assumption it holds for its20predecessor.2122There is a variant of the principle of induction in which we don't23just assume that the claim holds for the predecessor $k-1$ of $k$, but24for all numbers smaller than~$k$, and use this assumption to establish25the claim for~$k$. This also gives us the claim $P(n)$ for all~$n \in26\Nat$. For once we have established $P(0)$, we have thereby27established that $P$ holds for all numbers less than~$1$. And if we28know that if $P(l)$ for all $l<k$, then $P(k)$, we know this in29particular for $k=1$. So we can conclude $P(1)$. With this we have30proved $P(0)$ and $P(1)$, i.e., $P(l)$ for all $l<2$, and since31we have also the conditional, if $P(l)$ for all $l<2$, then $P(2)$, we32can conclude~$P(2)$, and so on.3334In fact, if we can establish the general conditional ``for all $k$, if35$P(l)$ for all $l<k$, then $P(k)$,'' we do not have to establish36$P(0)$ anymore, since it follows from it. For remember that a general37claim like ``for all $l<k$, $P(l)$'' is true if there are no $l<k$.38This is a case of vacuous quantification: ``all $A$s are $B$s'' is39true if there are no $A$s, $\lforall[x][(!A(x) \lif !B(x))]$ is true40if no $x$ satisfies~$!A(x)$. In this case, the formalized version41would be ``$\lforall[l][(l < k \lif P(l))]$''---and that is true if42there are no $l < k$. And if $k=0$ that's exactly the case: no $l<0$,43hence ``for all $l<0$, $P(0)$'' is true, whatever $P$ is. A proof of44``if $P(l)$ for all $l<k$, then $P(k)$'' thus automatically45establishes~$P(0)$.4647This variant is useful if establishing the claim for~$k$ can't be made48to just rely on the claim for $k-1$ but may require the assumption49that it is true for one or more $l<k$. 5051\end{document}
content/methods/induction/inductive-definitions.tex
1% Part: methods2% Chapter: induction3% Section: inductive-definitions45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{idf}1011\olsection{Inductive Definitions}1213In logic we very often define kinds of objects \emph{inductively},14i.e., by specifying rules for what counts as an object of the kind to15be defined which explain how to get new objects of that kind from old16objects of that kind. For instance, we often define special kinds of17sequences of symbols, such as the terms and !!{formula}s of a18language, by induction. For a simple example, consider strings19consisting of letters $\mathrm{a}$, $\mathrm{b}$, $\mathrm{c}$,20$\mathrm{d}$, the symbol~$\circ$, and brackets $[$ and $]$, such as21``$[[\mathrm{c} \circ \mathrm{d}][$'', ``$[\mathrm{a}[]\circ]$'',22``$\mathrm{a}$'' or ``$[[\mathrm{a} \circ \mathrm{b}]\circ23\mathrm{d}]$''. You probably feel that there's something24``wrong'' with the first two strings: the brackets don't25``balance'' at all in the first, and you might feel that the26``$\circ$'' should ``connect'' expressions that themselves make27sense. The third and fourth string look better: for every ``$[$''28there's a closing ``$]$'' (if there are any at all), and for any29$\circ$ we can find ``nice'' expressions on either side,30surrounded by a pair of parentheses.3132We would like to precisely specify what counts as a ``nice term.''33First of all, every letter by itself is nice. Anything that's not34just a letter by itself should be of the form ``$[t \circ s]$'' where35$s$ and $t$ are themselves nice. Conversely, if $t$ and $s$ are nice,36then we can form a new nice term by putting a $\circ$ between them and37surround them by a pair of brackets. We might use these operations38to \emph{define} the set of nice terms. This is an \emph{inductive39 definition}.4041\begin{defn}[Nice terms]42 The set of \emph{nice terms} is inductively defined as follows:43 \begin{enumerate}44 \item Any letter $\mathrm{a}$, $\mathrm{b}$, $\mathrm{c}$,45 $\mathrm{d}$ is a nice term.46 \item If $s_1$ and $s_2$ are nice terms, then so47 is $[s_1 \circ s_2]$.48 \item Nothing else is a nice term.49 \end{enumerate}50\end{defn}5152This definition tells us that something counts as a nice term iff it53can be constructed according to the two conditions (1) and~(2) in some54finite number of steps. In the first step, we construct all nice terms55just consisting of letters by themselves, i.e.,56\[57\mathrm{a}, \mathrm{b}, \mathrm{c}, \mathrm{d}58\]59In the second step, we apply (2) to the terms we've constructed. We'll get60\[61[\mathrm{a} \circ \mathrm{a}], [\mathrm{a} \circ \mathrm{b}],62[\mathrm{b} \circ \mathrm{a}], \dots, [\mathrm{d} \circ \mathrm{d}]63\]64for all combinations of two letters. In the third step, we apply (2)65again, to any two nice terms we've constructed so far. We get new nice66term such as $[\mathrm{a} \circ [\mathrm{a} \circ67 \mathrm{a}]]$---where $t$ is $\mathrm{a}$ from step~1 and $s$ is68$[\mathrm{a} \circ \mathrm{a}]$ from step~2---and $[[\mathrm{b} \circ69 \mathrm{c}] \circ [\mathrm{d} \circ \mathrm{b}]]$ constructed out70of the two terms $[\mathrm{b} \circ \mathrm{c}]$ and $[\mathrm{d}71 \circ \mathrm{b}]$ from step~2. And so on. Clause (3) rules out72that anything not constructed in this way sneaks into the set of nice73terms.7475Note that we have not yet proved that every sequence of symbols that76``feels'' nice is nice according to this definition. However, it77should be clear that everything we can construct does in fact ``feel78nice'': brackets are balanced, and $\circ$ connects parts that are79themselves nice.8081The key feature of inductive definitions is that if you want to prove82something about all nice terms, the definition tells you which cases83you must consider. For instance, if you are told that $t$ is a nice84term, the inductive definition tells you what $t$ can look like: $t$85can be a letter, or it can be $[s_1 \circ s_2]$ for some pair of86nice terms $s_1$ and~$s_2$. Because of clause (3), those are the only87possibilities.8889When proving claims about all of an inductively defined set, the90strong form of induction becomes particularly important. For instance,91suppose we want to prove that for every nice term of length~$n$, the92number of $[$ in it is~$< n/2$. This can be seen as a claim about93all~$n$: for every $n$, the number of $[$ in any nice term of94length~$n$ is $< n/2$.9596\begin{prop}97 For any $n$, the number of $[$ in a nice term of length~$n$ is98 $< n/2$.99\end{prop}100101\begin{proof}102To prove this result by (strong) induction, we have to show that the103following conditional claim is true:104\begin{quote}105 If for every $l < k$, any nice term of length~$l$ has $< l/2$106 $[$'s, then any nice term of length~$k$ has $< k/2$ $[$'s.107\end{quote}108To show this conditional, assume that its antecedent is true, i.e.,109assume that for any $l<k$, nice terms of length~$l$ contain $< l/2$110$[$'s. We call this assumption the inductive hypothesis. We want to111show the same is true for nice terms of length~$k$.112113So suppose $t$ is a nice term of length~$k$. Because nice terms are114inductively defined, we have two cases: (1)~$t$ is a letter by115itself, or (2)~$t$ is $[s_1 \circ s_2]$ for some nice terms $s_1$ and~$s_2$.116\begin{enumerate}117\item $t$ is a letter. Then $k = 1$, and the number of $[$ in $t$118is~$0$. Since $0 < 1/2$, the claim holds.119\item $t$ is $[s_1 \circ s_2]$ for some nice terms $s_1$ and~$s_2$.120 Let's let $l_1$ be the length of~$s_1$ and $l_2$ be the length121 of~$s_2$. Then the length~$k$ of $t$ is $l_1+l_2+3$ (the lengths of122 $s_1$ and $s_2$ plus three symbols $[$, $\circ$, $]$). Since123 $l_1+l_2+3$ is always greater than $l_1$, $l_1 < k$. Similarly, $l_2124 < k$. That means that the induction hypothesis applies to the terms125 $s_1$ and~$s_2$: the number~$m_1$ of $[$ in $s_1$ is $< l_1/2$, and126 the number~$m_2$ of $[$ in~$s_2$ is $< l_2/2$.127128 The number of $[$ in $t$ is the number of $[$ in~$s_1$, plus the129 number of $[$ in~$s_2$, plus~$1$, i.e., it is $m_1 + m_2 + 1$. Since $m_1130 < l_1/2$ and $m_2 < l_2/2$ we have:131 \[132 m_1 + m_2 + 1 < \frac{l_1}{2} + \frac{l_2}{2} + 1 = \frac{l_1+l_2+2}{2} < \frac{l_1+l_2+3}{2} = k/2.133 \]134\end{enumerate}135In each case, we've shown that the number of $[$ in $t$ is $< k/2$ (on136the basis of the inductive hypothesis). By strong induction, the137proposition follows.138\end{proof}139140\begin{prob}141 Define the set of supernice terms by142 \begin{enumerate}143 \item Any letter $\mathrm{a}$, $\mathrm{b}$, $\mathrm{c}$,144 $\mathrm{d}$ is a supernice term.145 \item If $s$ is a supernice term, then so is $[s]$.146 \item If $s_1$ and $s_2$ are supernice terms, then so147 is $[s_1 \circ s_2]$.148 \item Nothing else is a supernice term.149 \end{enumerate}150 Show that the number of $[$ in a supernice term~$t$ of length~$n$ is151 $\le n/2 +1$.152\end{prob}153154\end{document}
content/methods/induction/structural-induction.tex
1% Part: methods2% Chapter: induction3% Section: structural-induction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{sti}1011\olsection{Structural Induction}1213So far we have used induction to establish results about all natural14numbers. But a corresponding principle can be used directly to prove15results about all !!{element}s of an inductively defined set. This16often called \emph{structural} induction, because it depends on the17structure of the inductively defined objects.1819Generally, an inductive definition is given by (a)~a list of20``initial'' !!{element}s of the set and (b)~a list of operations which21produce new !!{element}s of the set from old ones. In the case of nice22terms, for instance, the initial objects are the letters. We only have23one operation: the operations are24\begin{align*}25 o(s_1, s_2) = & [s_1 \circ s_2]26\end{align*}27You can even think of the natural numbers~$\Nat$ themselves as being28given by an inductive definition: the initial object is~$0$, and the29operation is the successor function~$x + 1$.3031In order to prove something about all elements of an inductively32defined set, i.e., that every !!{element} of the set has a33property~$P$, we must:34\begin{enumerate}35\item Prove that the initial objects have~$P$36\item Prove that for each operation~$o$, if the arguments have~$P$,37 so does the result.38\end{enumerate}39For instance, in order to prove something about all nice terms, we40would prove that it is true about all letters, and that it is true41about $[s_1 \circ s_2]$ provided it is true of $s_1$ and $s_2$42individually.4344\begin{prop}45 The number of $[$ equals the number of $]$ in any nice term~$t$.46\end{prop}4748\begin{proof}49We use structural induction. Nice terms are inductively defined, with50letters as initial objects and the operation $o$ for constructing new51nice terms out of old ones.52\begin{enumerate}53\item The claim is true for every letter, since the number of $[$ in a54 letter by itself is~$0$ and the number of $]$ in it is also~$0$.55\item Suppose the number of $[$ in $s_1$ equals the number of $]$, and56 the same is true for $s_2$. The number of $[$ in $o(s_1, s_2)$, i.e., in57 $[s_1 \circ s_2]$, is the sum of the number of $[$ in $s_1$ and58 $s_2$ plus one. The number of $]$ in $o(s_1, s_2)$ is the sum of the number59 of $]$ in $s_1$ and $s_2$ plus one. Thus, the number of $[$ in $o(s_1, s_2)$60 equals the number of $]$ in $o(s_1,s_2)$.61\end{enumerate}62\end{proof}6364\begin{prob}65 Prove by structural induction that no nice term starts with~$]$.66\end{prob}6768Let's give another proof by structural induction: a proper initial69segment of a string~$t$ of symbols is any string~$s$ that agrees with70$t$ symbol by symbol, read from the left, but $t$ is longer. So,71e.g., $[a \circ {}$ is a proper initial segment of $[a \circ b]$, but72neither are $[b \circ {}$ (they disagree at the second symbol) nor $[a73\circ b]$ (they are the same length).7475\begin{prop}\ollabel{prop:initial}76 Every proper initial segment of a nice term~$t$ has more $[$'s than77 $]$'s.78\end{prop}7980\begin{proof}81 By induction on~$t$:82 \begin{enumerate}83 \item $t$ is a letter by itself: Then $t$ has no proper initial segments.84 \item $t = [s_1 \circ s_2]$ for some nice terms $s_1$ and~$s_2$. If $r$ is85 a proper initial segment of $t$, there are a number of86 possibilities:87 \begin{enumerate}88 \item $r$ is just $[$: Then $r$ has one more $[$ than it does~$]$.89 \item $r$ is $[r_1$ where $r_1$ is a proper initial segment90 of~$s_1$: Since $s_1$ is a nice term, by induction hypothesis, $r_1$91 has more $[$ than $]$ and the same is true for $[r_1$.92 \item $r$ is $[s_1$ or $[s_1 \circ {}$: By the previous result, the93 number of $[$ and $]$ in~$s_1$ are equal; so the number of $[$94 in $[s_1$ or $[s_1 \circ {}$ is one more than the number of~$]$.95 \item $r$ is $[s_1 \circ r_2$ where $r_2$ is a proper initial segment96 of~$s_2$: By induction hypothesis, $r_2$ contains more $[$ than97 $]$. By the previous result, the number of $[$ and of98 $]$ in~$s_1$ are equal. So the number of $[$ in $[s_1 \circ r_2$99 is greater than the number of~$]$.100 \item $r$ is $[s_1 \circ s_2$: By the previous result, the number of101 $[$ and $]$ in $s_1$ are equal, and the same for~$s_2$. So there102 is one more $[$ in $[s_1 \circ s_2$ than there are~$]$.103 \end{enumerate}104 \end{enumerate}105\end{proof}106107\end{document}
content/methods/induction/relations.tex
1% Part: methods2% Chapter: induction3% Section: relations45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{mth}{ind}{rel}1011\olsection{Relations and Functions}1213When we have defined a set of objects (such as the natural numbers or14the nice terms) inductively, we can also define \emph{relations on}15these objects by induction. For instance, consider the following16idea: a nice term~$t_1$ is a subterm of a nice term~$t_2$ if it occurs as17a part of it. Let's use a symbol for it: $t_1 \sqsubseteq t_2$. Every18nice term is a subterm of itself, of course: $t \sqsubseteq t$. We can19give an inductive definition of this relation as follows:2021\begin{defn}22 The relation of a nice term~$t_1$ being a subterm of~$t_2$, $t_123 \sqsubseteq t_2$, is defined by induction on~$t_2$ as follows:24 \begin{enumerate}25 \item If $t_2$ is a letter, then $t_1 \sqsubseteq t_2$ iff $t_1 = t_2$.26 \item If $t_2$ is $[s_1 \circ s_2]$, then $t_1 \sqsubseteq t_2$ iff $t_1 =27 t_2$, $t_1 \sqsubseteq s_1$, or $t_1 \sqsubseteq s_2$.28 \end{enumerate}29\end{defn}3031This definition, for instance, will tell us that $\mathrm{a}32\sqsubseteq [\mathrm{b} \circ \mathrm{a}]$. For (2) says that33$\mathrm{a} \sqsubseteq [\mathrm{b} \circ \mathrm{a}]$ iff $\mathrm{a}34= [\mathrm{b} \circ \mathrm{a}]$, or $\mathrm{a} \sqsubseteq b$, or35$\mathrm{a} \sqsubseteq \mathrm{a}$. The first two are false:36$\mathrm{a}$ clearly isn't identical to $[\mathrm{b} \circ37 \mathrm{a}]$, and by~(1), $\mathrm{a} \sqsubseteq \mathrm{b}$ iff38$\mathrm{a} = \mathrm{b}$, which is also false. However, also by~(1),39$\mathrm{a} \sqsubseteq \mathrm{a}$ iff $\mathrm{a} = \mathrm{a}$,40which is true.4142It's important to note that the success of this definition depends on43a fact that we haven't proved yet: every nice term~$t$ is either a44letter by itself, or there are \emph{uniquely determined} nice terms45$s_1$ and $s_2$ such that $t = [s_1 \circ s_2]$. ``Uniquely46determined'' here means that if $t = [s_1 \circ s_2]$ it isn't47\emph{also} $= [r_1 \circ r_2]$ with $s_1 \neq r_1$ or $s_2 \neq r_2$.48If this were the case, then clause~(2) may come in conflict with49itself: reading $t_2$ as $[s_1 \circ s_2]$ we might get $t_150\sqsubseteq t_2$, but if we read $t_2$ as $[r_1 \circ r_2]$ we might51get not $t_1 \sqsubseteq t_2$. Before we prove that this can't52happen, let's look at an example where it \emph{can} happen.5354\begin{defn}55 Define \emph{bracketless terms} inductively by56 \begin{enumerate}57 \item Every letter is a bracketless term.58 \item If $s_1$ and $s_2$ are bracketless terms, then $s_1 \circ s_2$ is59 a bracketless term.60 \item Nothing else is a bracketless term.61 \end{enumerate}62\end{defn}6364Bracketless terms are, e.g., $\mathrm{a}$, $\mathrm{b} \circ65\mathrm{d}$, $\mathrm{b} \circ \mathrm{a} \circ \mathrm{b}$. Now if we66defined ``subterm'' for bracketless terms the way we did above, the67second clause would read68\begin{center}69 If $t_2 = s_1 \circ s_2$, then $t_1 \sqsubseteq t_2$ iff $t_1 = t_2$, $t_170 \sqsubseteq s_1$, or $t_1 \sqsubseteq s_2$.71\end{center}7273Now $\mathrm{b} \circ \mathrm{a} \circ \mathrm{b}$ is of the form $s_174\circ s_2$ with 75\begin{align*}76 s_1 & = \mathrm{b} \text{ and} & s_2 & = \mathrm{a} \circ \mathrm{b}.77\intertext{It is also of the form $r_1 \circ r_2$ with}78 r_1 & = \mathrm{b} \circ \mathrm{a} \text{ and} & r_2 &= \mathrm{b}.79\end{align*}80Now is $\mathrm{a} \circ \mathrm{b}$ a subterm of $\mathrm{b} \circ81\mathrm{a} \circ \mathrm{b}$? The answer is yes if we go by the first82reading, and no if we go by the second.8384The property that the way a nice term is built up from other nice85terms is unique is called \emph{unique readability}. Since inductive86definitions of relations for such inductively defined objects are87important, we have to prove that it holds.8889\begin{prop}90 Suppose $t$ is a nice term. Then either $t$ is a letter by itself,91 or there are uniquely determined nice terms $s_1$, $s_2$ such that~$t =92 [s_1 \circ s_2]$.93\end{prop}9495\begin{proof}96 If $t$ is a letter by itself, the condition is satisfied. So assume97 $t$ isn't a letter by itself. We can tell from the inductive98 definition that then $t$ must be of the form $[s_1 \circ s_2]$ for some99 nice terms $s_1$ and~$s_2$. It remains to show that these are uniquely100 determined, i.e., if $t = [r_1 \circ r_2]$, then $s_1 = r_1$ and $s_2 = r_2$.101102 So suppose $t = [s_1 \circ s_2]$ and also $t = [r_1 \circ r_2]$ for nice terms103 $s_1$, $s_2$, $r_1$, $r_2$. We have to show that $s_1 = r_1$ and $s_2 = r_2$.104 First, $s_1$ and $r_1$ must be identical, for otherwise one is a proper105 initial segment of the other. But by \olref[sti]{prop:initial}, that106 is impossible if $s_1$ and~$r_1$ are both nice terms. But if $s_1 = r_1$,107 then clearly also $s_2 = r_2$.108\end{proof}109110We can also define functions inductively: e.g., we can define the111function~$f$ that maps any nice term to the maximum depth of nested112$[\dots]$ in it as follows:113114\begin{defn}115 \ollabel{defn:depth} The \emph{depth} of a nice term, $f(t)$, is116 defined inductively as follows:117 \[118 f(t) = \begin{cases}119 0 & \text{ if $t$ is a letter}\\120 \max(f(s_1), f(s_2)) + 1 & \text{ if $t = [s_1 \circ s_2]$.}121 \end{cases}122 \]123\end{defn}124125For instance126\begin{align*}127 f([\mathrm{a} \circ \mathrm{b}]) & = 128 \max(f(\mathrm{a}),f(\mathrm{b})) + 1 = \\ 129 &= \max(0, 0) + 1 = 1, \text{ and}\\130 f([[\mathrm{a} \circ \mathrm{b}] \circ \mathrm{c}]) & = 131 \max(f([\mathrm{a} \circ \mathrm{b}]), f(\mathrm{c})) + 1 = \\ 132 & = \max(1,0) + 1 = 2.133\end{align*}134135Here, of course, we assume that $s_1$ an $s_2$ are nice terms, and make136use of the fact that every nice term is either a letter or of the form137$[s_1 \circ s_2]$. It is again important that it can be of this form in138only one way. To see why, consider again the bracketless terms we139defined earlier. The corresponding ``definition'' would be:140\[141 g(t) = 142 \begin{cases}143 0 & \text{ if $t$ is a letter}\\144 \max(g(s_1), g(s_2)) + 1 & \text{ if $t = s_1 \circ s_2$.}145 \end{cases}146\]147Now consider the bracketless term $\mathrm{a} \circ \mathrm{b} \circ148\mathrm{c} \circ \mathrm{d}$. It can be read in more than one way,149e.g., as $s_1 \circ s_2$ with 150\begin{align*}151 s_1 & = \mathrm{a} \text{ and} & 152 s_2 & = \mathrm{b} \circ \mathrm{c} \circ \mathrm{d},153\intertext{or as $r_1 \circ r_2$ with}154 r_1 & = \mathrm{a} \circ b \text{ and} & 155 r_2 &= \mathrm{c} \circ \mathrm{d}.156\end{align*}157Calculating $g$ according to the first way of reading it would give158\begin{align*}159 g(s_1 \circ s_2) & =160 \max(g(\mathrm{a}), g(\mathrm{b} \circ \mathrm{c} \circ \mathrm{d})) + 1 =\\ & =161 \max(0,2) + 1 = 3162 \intertext{while according to the other reading we get}163 g(r_1 \circ r_2) & =164 \max(g(\mathrm{a} \circ \mathrm{b}), g(\mathrm{c} \circ \mathrm{d})) + 1=\\ &165 = \max(1,1) + 1 = 2166\end{align*}167But a function must always yield a unique value; so our ``definition''168of~$g$ doesn't define a function at all.169170\begin{prob}171 Give an inductive definition of the function $l$, where $l(t)$ is172 the number of symbols in the nice term~$t$.173\end{prob}174175\begin{prob}176 Prove by structural induction on nice terms $t$ that $f(t) < l(t)$ (where177 $l(t)$ is the number of symbols in~$t$ and $f(t)$ is the depth of178 $t$ as defined in \olref[mth][ind][rel]{defn:depth}).179\end{prob}180181\end{document}