I have just started reading Logic and Structure (5th edition) by Dirk Van Dalen. In the second chapter there is "Theorem 2.1.6 (Definition by Recursion)". I have no problem understanding nor proving it. My problem is with the examples that the book claims are applications of this technique. To give context, I will quote the theorem:
(Theorem 2.1.6) Let mappings $H_\square : A^2 \rightarrow A$ and $H_\neg : A \rightarrow A$ be given and let $H_{at}$ be a mapping from the set of atoms into A, then there exists exactly one mapping $F : PROP \rightarrow A$ such that:
$\begin{cases} F(\varphi) = H_{at}(\varphi ) \quad \text{for } \varphi \text{ atomic} \\ F((\varphi \square \psi)) = H_\square(F(\varphi), F(\psi)) \\ F((\neg \varphi))=H_\neg(F(\varphi )) \end{cases}$
The book then, as an example of this technique (theorem), defines the rank function as follows:
$ \begin{cases} r(\varphi)=0\quad \text{for atomic } \varphi ,\\ r((\varphi \square \psi))=max(r(\varphi),r(\psi))+1,\\ r((\neg \varphi))=r(\varphi)+1. \end{cases} $
This is where I get confused. I can't see how the theorem is used in this definition. Does the function $r$ in this definition, correspond to the function $H$ in the theorem? If yes, shouldn't it be of type $\mathbb{N}^2 \rightarrow \mathbb{N}$ instead of $PROP \rightarrow \mathbb{N}$ in $r((\varphi\square\psi))$? (given $A$ is $\mathbb{N}$ in this case). Does $r$ correspond to $F$? If it's the case, why do we need the theorem? The theorem guarantees the existence of such unique function, but here, we directly construct it. How would this definition be invalid if we hadn't proven the theorem? In my opinion, if we were to use the theorem to define $r$, we would have to do something like:
If we define:
$ \begin{cases} H_{at}(\varphi)=0 \quad \text{for atomic } \varphi,\\ H_\square(n_1, n_2) = max(n_1, n_2) + 1 \quad \text{for } n_1,n_2 \in \mathbb{N},\\ H_\neg(n) = n + 1 \quad \text{for } n \in \mathbb{N}. \end{cases} $
Then, according to 2.1.6, there exists a unique function $F : PROP \rightarrow \mathbb{N}$ satisfying the conditions explained above. We name this function $r$.
The book also defines the set of subformulas of a proposition as an example of this technique:
$\begin{cases} Sub(\varphi) = \{\varphi\} \quad \text{for atomic } \varphi \\ Sub((\varphi \square \psi))=Sub(\varphi)\cup Sub(\psi) \cup\{\varphi\square\psi\} \\ Sub(\neg\varphi)=Sub(\varphi)\cup\{\neg\varphi\}. \end{cases}$
I think the relation between this definition and the theorem is even more problematic. How are we going to define $H_\square$, so that we can have $Sub((\varphi \square \psi)) = H_\square(Sub(\varphi), Sub(\psi))$ to be equal to $Sub(\varphi)\cup Sub(\psi) \cup\{\varphi\square\psi\}$? In particular the $\{\varphi\cup\psi\}$ part. $H_\square$ takes two sets of subforumulas, it doesn't know which formula's subformulas they are. Maybe we must get $\varphi$ from $Sub(\varphi)$ by taking the element with the highest rank? Then we must prove such element is unique (not that it's hard to prove, but it should at least be pointed out). If it's the case, I should reconsider self-studying this book as there is so much detail omitted.