Scarlet Serenade

Types and Programming Languages | Definition Styles

We will use the untyped arithmetic expression as example.

BNF Definition

One way to describe our grammar is using BNF. Parentheses are not mentioned in the grammar of terms, which defines only their abstract syntax.

t ::= true
      false
      if t then t else t
      0
      succ t
      pred t
      iszero t

The symbol t in the right-hand sides of the rules of this grammar is called a metavariable. It is a place-holder for some particular term.

- "meta" means that it is not a variable of the object language - the language whose syntax we are currently describing but rather of the metalanguage - the notation in which the description is given.

Definition: The term metatheory means the collection of true statements that we can make about some particular logical system (or programming language) and, by extension, the study of such statements.

Inductive Definition

The set of terms is the smallest set such that

- true, false, 0
- if then
- if and then

This can also be written as the natural deduction style:

Each rule is read "If we have established the statements in the premise(s) listed above the line, then we may derive the conclusion below the line."
Rules with no premises (like the first three above) are often called axioms.

To be completely pedantic, what we are calling inference rules are actually rule schemas, since their premises and conclusions may include metavariables.

- for example, you can replace the metavariable by all phrases from the appropriate syntactic category

Like the BNF grammar, this definition says nothing about the use of parentheses to mark compound subterms. Formally, what's really going on is that we are defining as a set of trees.

Concrete Definition

For each natural number , define a set as follows:

Finally, let

Equivalence between Inductive Definition and Concrete Definition

Use to represent the one defined by inductive definition and to represent the one defined by concrete definition.

was defined as the smallest set satisfying certain conditions. so our proof consists of two pars:

  • satisfies these conditions
  1. the constants are trivial

  2. if then , then by definition of , we have , similarly, we see that and

  3. if and , similarly

  • is the smallest set, in other words, any set satisfying the conditions has as a subset

suppose that some set satisfies the conditions, we will argue by complete induction on , that every , from which it clearly follows

Suppose that for all , we are to show that . By the definition of , there are two cases to consider

  1. : it's trivial
  2. : . Since is defined as the union of three smaller sets, an element must come from one of these sets:
    • if is constant, then it's trivial
    • if has the form for some , then by the induction hypothesis, and by condition (2)
    • if has the form , for the same reason in (ii),

Thus, we have shown that each . By the definition of S as the union of all the , this gives , completing the argument.