Reading: MCS 7,7.1
We started by briefly reviewing hashing; I have added this discussion to the previous lecture's notes
An inductively defined set is a set where the elements are constructed by a finite number of applications of a given set of rules.
Examples:
thus the elements of \(\mathbb{N}\) are \(\{Z, SZ, SSZ, SSSZ, \dots\}\). \(S\) stands for successor. You can then define \(1\) as \(SZ\), \(2\) as \(SSZ\), and so on.
thus if \(\Sigma = \{0,1\}\), then the elements of \(\Sigma^*\) are \(\{ε, ε0, ε1, ε00, ε01, \dots, ε1010101, \dots\}\). we usually leave off the \(ε\) at the beginning of strings of length 1 or more.
thus the elements of \(T\) are things like the picture to the right (click for tex), which might be written textually as \(node(3,node(0,nil,nil),node(1,node(2,nil,nil),nil))\)
Compact way of writing down inductively defined sets: BNF (Backus Naur Form)
Only the name of the set and the rules are written down; they are separated by a "::=", and the rules are separated by vertical bar (\(|\)).
Examples (from above):
\(n \in \mathbb{N} ::= 0 \mid Sn\)
\(x \in \Sigma^* ::= \epsilon \mid xa\) where \(a \in \Sigma\)
\(t \in T ::= nil \mid node(a,t_1,t_2)\) where \(a \in Z\)
(basic mathematical expresssions) \[\begin{aligned}e \in E &::= n \mid e_1 + e_2 \mid e_1 * e_2 \mid - e \mid e_1 / e_2 \\ n \in \mathbb{Z}\end{aligned}\]
Here, the variables to the left of the \(\in\) indicate metavariables. When the same characters appear in the rules on the right-hand side of the \(::=\), they indicate an arbitrary element of the set being defined. For example, the \(e_1\) and \(e_2\) in the \(e_1 + e_2\) rule could be arbitrary elements of the set \(E\), but \(+\) is just the symbol \(+\).
If \(X\) is an inductively defined set, you can define a function from \(X\) to \(Y\) by defining the function on each of the types of elements of \(X\); i.e. for each of the rules. In the inductive rules (i.e. the ones containing the metavariable being defined), you can assume the function is already defined on the subterms.
Examples:
\(add2 : \mathbb{N} → \mathbb{N}\) is given by \(add2(0) ::= SS0\) and \(add2 (Sn) ::= S(add2(n))\).
\(plus : \mathbb{N} \times \mathbb{N} → \mathbb{N}\) given by \(plus (0,n) ::= n\) and \(plus (Sn, n') ::= S(plus(n,n'))\). Note that we don't need to use induction on both of the inputs.
\(len : Σ^* → \mathbb{N}\) is given by \(len(ε) ::= 0\) and \(len(xa) ::= 1 + len(x)\).
\(cat : Σ^* \times Σ^* → Σ^*\) is given by \(cat(ε,ε) ::= ε\), \(cat(xa,ε) ::= xa\), \(cat(ε,xa) ::= xa\) and \(cat(xa,yb) ::= cat(xa,y)b\).