2 Height and sub-formulas
2.1 Yet another construction of the set of propositional formulas
We give one more construction of \(\mathcal{F}(\mathcal{V})\), again as a subset of \(\mathcal{V}^*\). To avoid confusion, we will denote that subset by \(\mathcal{F}\) and then prove that \(\mathcal{F} = \mathcal{F}(\mathcal{V})\).
Let \((\mathcal{F}_n)_{n \in \mathbb{N}}\) be the sequence of subsets of \(\mathcal{V}^*\) defined as follows:
- \(\mathcal{F}_0 := \mathcal{B}\) (basic propositions).
- \(\mathcal{F}_{n + 1} :=\) \[\mathcal{F}_n \cup \{ \neg F\ \mathrm{where}\ F \in \mathcal{F}_n \} \cup \{ F \diamond F'\ \mathrm{where}\ F, F' \in \mathcal{F}_n\ \mathrm{and}\ \diamond \in \{ \Rightarrow, \wedge, \vee, \Leftrightarrow \} \}.\]
Then we set \[\mathcal{F} := \bigcup_{n \in \mathbb{N}} \mathcal{F}_n.\]
The construction of \(\mathcal{F}\) as \(\cup_{n \in \mathbb{N}} \mathcal{F}_n\) is often referred to as a construction “from below”, as opposed to the construction “from above” of \(\mathcal{F}(\mathcal{V})\) seen in Lecture 1. Note that for all natural number \(n\), we have \(\mathcal{F}_n \subset \mathcal{F}_{n+1}\) and that the union defining \(\mathcal{F}_{n+1}\) is a disjoint union (exercise!).
We then claim that \(\mathcal{F} = \mathcal{F}(\mathcal{V})\), the latter being the set of propositional formulas constructed in Lecture 1. This is a good exercise, where you have to prove a double inclusion and use induction on \(n\) to prove one of them.
2.2 Height
The height is supposed to measure the complexity of a formula: basic propositions have height \(0\) and the higher the height of a compound formula, the more complex it is. Given a propositional formula \(F\), we define the height of \(F\) as \[\mathrm{ht}(F) := \min \{n \in \mathbb{N}\ |\ F \in \mathcal{F}_n \}.\]
This defines a function \(\mathrm{ht} : \mathcal{F} \to \mathbb{N}\) satisfying \(\mathrm{ht}(F) = 0\) if \(F = P_i\) for some \(i\) and \(h(F) = n + 1\) if \(F \in \mathcal{F}_{n+1}\) but \(F \not\in \mathcal{F}_n\).
Note that \(F \in \mathcal{F}_{\mathrm{ht}(F)}\) but \(F \not\in \mathcal{F}_{\mathrm{ht}(F)-1}\) and that this characterises \(\mathrm{ht}(F)\).
The upshot of the construction of the set of propositional formulas as a union indexed by the natural numbers is that we can use induction on the height to prove properties about propositional formulas.
However, the definition of \(\mathrm{ht}\) is not excessively convenient for practical computations or implementation in a functional programming language. The next construction remedies that and is more direct: the induction is performed directly on the well-formed formula \(F\) (this is a consequence of the fact that the type \(\mathrm{Wff}\) is defined inductively).
2.3 Computational approach to the height
Recall that \(\mathcal{F} = \mathcal{F}(\mathcal{V}) = \mathrm{Wff}\). Using \(\mathrm{Wff}\), we can construct the height function by pattern matching on constructors of well-formed formulas, which is done as follows (we will be using the same notation \(\mathrm{ht}\) as above, to denote the height function).
Given a well-formed formula \(F : \mathrm{Wff}\), we set:
- \(\mathrm{ht}(P_i) := 0\) if \(F = P_i\) for some natural number \(i\).
- \(\mathrm{ht}(\neg G) := 1 + \mathrm{ht}(G)\) if \(F = \neg G\) for some well-formed formula \(G\).
- \(\mathrm{ht}(G \diamond G') := 1 + \max(\mathrm{ht}(G), \mathrm{ht}(G'))\) if \(F = G \diamond G'\) for some well-formed formulas \(G, G'\) and some binary connective \(\diamond \in \{ \Rightarrow, \wedge, \vee, \Leftrightarrow \}\).
Note that the height function is defined recursively. More precisely, it is defined via primitive recursion. This just means that the number of constructors in the expression for the argument of the function diminishes by exactly one at each step (see how \(P, \neg\) and \(\diamond\) disappear when passing from the left-hand side to the right-hand side).
It is not entirely straightforward to check that the two definitions of the height function coincide when \(\mathrm{Wff}\) and \(\mathcal{F}(\mathcal{V})\) are identified. In this course, we will favour the second definition and see the height as a function \(\mathrm{ht} : \mathrm{Wff} \to \mathbb{N}\). As seen in examples, the quantity \(\mathrm{ht}(F)\) then computes out nicely.
2.4 Sub-formulas
Similarly to the height, we can define the collection of sub-formulas of a given formula \(F\) in two different ways, depending on whether we think of \(F\) as an element of \(\mathcal{F}(\mathcal{V})\) or \(\mathrm{Wff}\).
2.4.1 Set-theoretic approach
We define a function \(\mathrm{sf} : \mathcal{F} \to \mathcal{P}(\mathcal{F})\) from the set of propositional formulas to the power set of that set.
Using that \(\mathcal{F} = \cup_{n \in \mathbb{N}} \mathcal{F}_n\), we first define a sequence of functions \((\mathrm{sf}_n)_{n \in \mathbb{N}}\) such that \(\mathrm{sf}_n : \mathcal{F}_n \to \mathcal{P}(\mathcal{F})\) satisfying, for all natural number \(n\), the equality \(\mathrm{sf}_{n + 1}|_{\mathcal{F}_n} = \mathrm{sf}_n\), and then set \(\mathrm{sf}(F) := \mathrm{sf}_{\mathrm{ht}(F)}(F)\). The resulting (well-defined!) function \(\mathrm{sf}|\) satisfies, for all natural number \(n\), the condition \(\mathrm{sf}|_{\mathcal{F}_n} = \mathrm{sf}_n\).
- For all natural number \(i\), we set \(\mathrm{sf}_0(P_i) := \{ P_i \}\).
- For all natural number \(n\) and all propositional formula \(F \in F_{n + 1}\), we set
- \(\mathrm{sf}_{n + 1} (F) := \mathrm{sf}_{n} (F)\) if \(F \in F_n \subset F_{n+1}\).
- \(\mathrm{sf}_{n + 1} (F) := \{ \neg G \} \cup \mathrm{sf}_{n} (G)\) if \(F = \neg G\) with \(G \in F_n\).
- \(\mathrm{sf}_{n + 1} (F) := \{ G \diamond G' \} \cup \mathrm{sf}_{n} (G) \cup \mathrm{sf}_{n} (G')\) if \(F = G \diamond G'\) with \(G, G' \in F_n\) and \(\diamond \in \{\Rightarrow, \wedge, \vee, \Leftrightarrow\}\).
Note that if \(\mathrm{sf}(G) \cap \mathrm{sf}(G') \not= \emptyset\), then any element at the intersection will only be listed once in the subset \(\mathrm{sf}(G \diamond G')\). This will not be the case in the approach below, where we use lists of well-formed formulas instead of the power set.
2.4.2 Type-theoretic approach
We now define a function \(\mathrm{strict\_sf} : \mathrm{Wff} \to \mathrm{List\ Wff}\) from well-formed formulas to lists of well-formed formulas. The goal is to send a well-formed formula \(F\) to the list of formulas strictly contained in \(F\). As in the definition of the height function, there are essentially three cases to consider.
- \(\mathrm{strict\_sf}(P_i) := \mathrm{nil}\)
- \(\mathrm{strict\_sf}(\neg G) := G :: \mathrm{strict\_sf}(G)\).
- \(\mathrm{strict\_sf}(G \diamond G') := ( G :: \mathrm{strict\_sf}(G) ) \mathbin{+\!+} ( G' :: \mathrm{strict\_sf}(G') )\).
In the formulas above, the empty list is denoted by \(\mathrm{nil}\) and the function \(\mathrm{cons} : \mathrm{Wff} \times \mathrm{List\ Wff} \to \mathrm{List\ Wff}\) (= the constructor for so-called linked lists) is denoted by \(\_::\_\) (with infix notation). The binary operator \(\mathbin{+\!+}\) denotes the concatenation of lists.
With these conventions, the function \(\mathrm{strict\_sf}\) is defined by pattern matching on \(F\) and it is a (primitive) recursive function. Then we define a function \(\mathrm{sf} : \mathrm{Wff} \to \mathrm{List} \mathrm{Wff}\) by prepending \(F\) to \(\mathrm{strict\_sf}(F)\).
\(\mathrm{sf}(F) := [F] \mathbin{+\!+} \mathrm{strict\_sf}(F)\).
In a forthcoming lecture, we will implement the function \(\mathrm{sf}\) in Rocq.
2.5 Height and sub-formulas in the tree representation of a formula
As an exercise, take \(F := (P_1 \vee P_2) \wedge \neg P_3\) and compute \(\mathrm{ht}(F)\) and \(\mathrm{sf}(F)\). Represent \(F\) as a tree whose leafs (at the bottom) are the atomic sub-formulas \(P_1, P_2, P_3\) of \(F\), whose nodes are the connectives \(\vee, \wedge\) and \(\neg\) appearing in \(F\), and whose sub-trees are labelled by (or in bijection with) sub-formulas of \(F\) (the whole tree corresponding to \([F]\)). Note that the height of the formula \(F\) corresponds to how “tall” the tree is.