Chapter 2 inductive definitions
Inductive definitions cannot be dispensed in the study of programming languages.
TLDR
Basic framework of inductive definitions.
Examples of inductive definitions.
Inductive definition = A set of Rules for deriving Judgments/Assertions of a variety of forms.
- Judgment: A statement about one or more Abstract binding tree (ABT)s of some Sort.
- The rules specify necessary and sufficient conditions for the validity of a judgment. -> Fully determine its meaning.
Judgments
TLDR: Judgment/Assertion about an Abstract binding tree (ABT).
Many forms of judgments:
Personal notes
- The notation is familiar.
- is maybe similar to Big-step/Natural operational semantics.
- is not a boolean (Boolean Blindness).
- and have the same structure but totally different meaning.
Judgment: A statement that one or more Abstract binding tree (ABT)s have a property (unary relation) or stand in some relation to one another.
- The property/relation Judgment form.
- The judgment that an object or objects have that property or stand in that relation An Instance of an inference rule.
Judgment form = Predicate.
The objects constituting an instance are its subjects. Judgment form instance's subject.
The Judgment asserting that a Judgment form holds of the Abstract binding tree (ABT) is written as or . Instance of the judgment form.
A general Judgment form can be written as or .
When it is not important to stress the subject of the judgment, we write to stand for an unspecified judgment, that is, an instance of some judgment form.
Inference rules
An Inductive definition of a Judgment form consists of a collection of Rules of the form:
in which and , , , are all judgment of the form being defined.
The judgments above the line: Premises.
The judgment below the line: Conclusion.
No Premise Axiom.
Otherwise, a Proper rule.
If all premises hold The conclusion hold.
The reverse does not hold.
Example - Inductive definition of the judgment form
- Example - Inductive definition of the judgment form
- Example - Inductive definition of the judgment form
A notational convention for specifying an infinite family of Rules by a finite number of patterns, or Rule schemes.
A collection of Rules is considered to define the strongest Judgment form that is closed under, or respects, those rules.
Closed under the rules = The rules are sufficient to show the validity of a judgment: holds if there is a way to obtain it using the given rules.
Strongest judgment form = The rules are also necessary: holds only if there is a way to obtain it by applying the rules.
The sufficiency of the rules means that we may show that holds by deriving it by composing rules.
Their necessity means that we may reason about it using rule induction.
Derivations
To prove an inductively defined Judgment, it's sufficient to show a Derivation of it.
Derivation of a Judgment: A finite composition of rules, starting with axioms and ending with that judgment.
A Derivation of is evidence for the validity of an inductively defined judgment .
Derivations are visualized as trees with the conclusion at the bottom and with the children of a node corresponding to a rule appearing above it as evidence for the premises of that rule.
Formalization:
An inference rule: .
Derivations of its premises: .
is a derivation of .
Two main methods for finding derivations:
Forward chaining/Bottom-up construction.
Start with the axioms and work towards the desired conclusion.
Idea: Forward chaining search maintains a set of derivable judgments and continually extends this set by adding to it the conclusion of any rules all of whose premises are in that set.
Assume that all rules are considered at every stag:
Forward chaining would eventually find a derivation of any derivable judgment. Complete.
Forward chaining cannot decide when to stop & conclude that a judgment is not derivable.
Need to understand the global properties of the rules.
Do not take into account the end goal when deciding how to proceed at each step. Undirected.
Backward chaining/Top-down construction.
Start with the desired conclusion and work backwards towards the axioms. Goal-directed.
Initialization: The process begins with a queue containing only the final goal (the judgment to be derived).
The loop:
- A goal is removed from the queue.
- The system searches for rules where the conclusion matches that goal.
- The premises of those matching rules are added to the queue as new sub-goals.
Success: The process terminates successfully when the queue is empty (all goals and sub-goals are satisfied).
Same issues as Forward chaining.
Rule induction
An Inductive definition specifies the strongest Judgment form closed under a collection of rules.
We can reason about them using Rule induction.
The principle of Rule induction states that to show that a property a holds whenever a is Derivable, it is enough to show that is closed under, or respects, the rules defining the judgment form .
More precisely, the property respects the rule:
if holds whenever do.
The assumptions are called the Inductive hypothesis, and is called the Inductive conclusion of the inference.
To show that whenever , it's sufficient to show that:
.
For every , if then .
The principle of Mathematical induction.
To show that whenever , it's sufficient to show that:
.
For every and , if and then .
The principle of Tree induction.
Iterated and simultaneous inductive definition
Iterated inductive definition: One inductive definition builds on top of another.
The premises of a rule may be instances of either a previously defined judgment form, or the judgment form being defined.
Example: The Judgment form.
Simultaneous inductive definition: A set of rules for deriving instances of several different judgment forms, any of which may appear as the premise of any rule.
Those judgment forms are defined at once.
Example: The and Judgment forms.
To show simultaneously that whenever and whenever odd, it is enough to show the following:
- . 2. For every , if then . 3. For every , if then .
Defining functions by rules
Functions can be defined by:
- Providing the definition of its graph relating inputs to outputs.
- Then showing that the relation uniquely determines the outputs for given inputs.
Example: The function with the intended meaning of being the sum of and .
Theorem. For every and , there exists a unique such that .
Proof
Two parts:
- Existence: If and , then there exists such that .
- Uniqueness: If , and , then is .
Exercises
Exercise 2.1
Problem statement. Give an inductive definition of the judgment , where , , and , with the meaning that is the larger of and . Prove that every and are related to a unique by this judgment.
Solution
- Definition
The judgment defines a function on and
Existence : For every and , there exists a such that .
- If or , applying or suffices to show holds in these cases.
- If and , then with , it's sufficient to show that holds in the case and . By the induction hypothesis, this is trivial.
Uniqueness : For every and , if there exists and such that and , then .
- If or , applying or is the only way to obtain such a . Therefore, holds in these cases.
- If and , then applying for the case and is the only way to obtain such a . By the induction hypothesis, this is trivial.
Exercise 2.2
Problem statement. Consider the following rules, which define the judgment stating that the binary tree has height .
Prove that the judgment defines a function from trees to natural numbers.
Solution
- Existence : For every , there exists such that .
- For , this is trivial that , so holds.
- For such that and .
By the induction hypothesis, there exists and such that and .
By Exercise 2.1, there exists such that .
By definition, .
- Uniqueness : For every , if and , then .
Similar to .
Exercise 2.3
Problem statement. Given an inductive definition of ordered variadic trees whose nodes have a finite, but variable, number of children with a specified left-to-right ordering among them. Your solution should consist of a simultaneous definition of two judgments:
- , stating that is a variadic tree.
- , stating that is a "forest" (finite sequence) of variadic trees.
Solution
Exercise 2.4
Problem statement. Give an inductive definition of the height of a variadic tree of the kind defined in Exercise 2.3.
- Your definition should make use of an auxiliary judgment defining the height of a forest of variadic trees.
- It will be defined simultaneously with the height of a variadic tree.
Show that the two judgments so defined each define a function.
Solution (incomplete)
- Definition
Exercise 2.5
Problem statement. Give an inductive definition of the binary natural numbers, which are either:
- Zero
- Twice a binary number
- One more than twice a binary number
The size of such a representation is logarithmic, rather than linear, in the natural number it represents.
Solution
Exercise 2.6
Problem statement. Give an inductive definition of addition of binary natural numbers as defined in Exercise 2.5.
- Hint: Proceed by analyzing both arguments to the addition, and make use of an auxiliary function to compute the successor of a binary number.
- Hint: Alternatively, define both the sum and the sum-plus-one of two binary numbers mutually recursively.
Solution (incomplete)
- Definition