A brief review of Lecture 19.
If the recursive step of $S$ includes multiple rules for constructing new elements from existing elements, then
③ assume $P$ for the existing elements in every rule, and
④ prove $P$ for the new element in every rule.
Ordinary induction is just structural induction applied to the recursively defined set of natural numbers!
$\rule{P(\Node); \forall L, R\in S. (P(L)\wedge P(R))\rightarrow P(\Tree(\Node,L,R))}{\forall x \in S. P(x)}$
How do we get $P(\Tree(\Node,\Node,\Tree(\Node, \Node,\Node)))$ from $P(\Node)$ and $\forall L,R\in S. (P(L)\wedge P(R))\rightarrow P(\Tree(\Node,L,R))$?
1. | First, we have $\forall L,R\in S. (P(L)\wedge P(R))\rightarrow P(\Tree(\Node,L,R))$ | |
2. | Next, we have $P(\Node)$. | $P(\Node)$ |
3. | Intro $\wedge$ on 2 gives us $P(\Node)\wedge P(\Node)$. | $P(\Node)\wedge P(\Node)$ |
4. | Elim $\forall$ on 1 gives us $(P(\Node)\wedge P(\Node))\rightarrow P(\Tree(\Node, \Node, \Node))$. | $\ \Downarrow_{\ (P(\Node)\wedge P(\Node))\rightarrow P(\Tree(\Node, \Node,\Node))}$ |
5. | Modus Ponens on 3 and 4 gives us $P(\Tree(\Node, \Node,\Node))$. | $P(\Tree(\Node, \Node,\Node))$ |
6. | Intro $\wedge$ on 2 and 5 gives us $P(\Node)\wedge P(\Tree(\Node, \Node,\Node))$. | $P(\Node)\wedge P(\Tree(\Node, \Node,\Node))$ |
7. | Elim $\forall$ on 1 gives us $(P(\Node)\wedge P(\Tree(\Node, \Node,\Node))\rightarrow P(\Tree(\Node,\Node,\Tree(\Node, \Node, \Node)))$. | $\ \Downarrow_{\ (P(\Node)\wedge P(\Tree(\Node, \Node,\Node))\rightarrow P(\Tree(\Node,\Node,\Tree(\Node, \Node, \Node)))}$ |
8. | Modus Ponens on 6 and 7 gives us $P(\Tree(\Node,\Node,\Tree(\Node, \Node, \Node)))$. | $P(\Tree(\Node,\Node,\Tree(\Node, \Node, \Node)))$ |
Definition, examples, applications.
This just defines a recursive function definition for computing
the meaning of a regular expression:
grep
, a Unix program that searches for patterns in a set of files.grep "311" *.md
searches for the string “311” in all Markdown files in the current directory.Syntax, semantics, and examples.
Context-free grammars are a more powerful formalism that lets us specify all of these example languages (i.e., sets of strings)!
Only nonterminals can appear on the left-hand side of a production rule.
A CFG over $\Sigma $ represents a set of strings over $\Sigma $.
Compute (or generate) a string from this set as follows:
A CFG represents the set of all strings over $\Sigma$ that can be generated in this way.
grep
to everyday programming.