First Order Logic
$\renewcommand{\implies}{\rightarrow}$ $\newcommand{\Val}[1]{\mathsf{Val}_{\mathcal{M}}{\left(#1\right)}}$ $\renewcommand{\iff}{\leftrightarrow}$
Motivation - Why Do We Need Yet Another Logic?
Earlier, we defined the language of propositional logic. Every logic acts on some base object. In propositional logic, the base object was atomic propositions, which were statements that could either be true or false and did not contain any logical connectives. In this set of notes we show that propositional logic is not sufficient to express a large amount of reasoning we are used to. The primary reason is that the base object of reasoning, the proposition, is not granular enough. This phenomenon is clearly described by the following example from middle school mathematics.
$$ \begin{align} 3 + 2 &= 5 \\ 5 &> 1 \\ \hline \therefore 3 + 2 &> 1 \end{align} $$
We are given a premise which consists of two inequalities (1) and (2), from which we can conclude (3). We have 3 propositions $p, q$ and $r$.
$$ \begin{align*} p: &\quad 3 + 2 &= 5 \\ q: &\quad 5 &> 1 \\ \hline r: &\quad 3 + 2 &> 1 \end{align*} $$
They are atomic as we cannot further break them down into simpler propositions using our logical connectives $\land, \lor, \neg, \implies, \iff$. Our premises form the set $\{p, q\}$, and the conclusion is $r$, but as stated $\{p, q\} \not \models r$. The parse tree is just 3 independent propositions. There is no way to propagate meaning from $p$ and $q$ to $r$.
What went wrong?
We know that $r$ is true from colloquial mathematical reasoning (which, as we will show, is based on at least first order logic, if not higher orders). To deduce the conclusion, what we really have to do is “break up” the atomic propositions. $3+2=5$ is not a generic statement that is true or false, but rather a statement about
- Constants $3, 2$ and $5$ from some domain.
- Functions, like addition, applied to these constants, and
- Predicates (like equality, or greater than) about the constants that are either true or false.
The syntax of propositional logic is not rich enough to express this reasoning. This is why we need a new kind of logic that has richer syntax and semantics.
Syntax Of First Order Logic (FOL)
To describe first order logic, once again, we need to first describe what a well-formed sentence in FOL looks like. As discussed earlier, syntax is given by an alphabet and grammar (rules for sticking symbols together, defined recursively).
Unlike in propositional logic, however, we do not define a single first-order language but rather a whole class of languages. The well-formed strings of FOL contain two kinds of symbols - (1) Logical symbols common to all first-order languages, (2) Non-logical symbols that vary from language to language.
Logical Symbols
This builds on propositional logic in that it shares some of the symbols.
- The connectives $\land$, $\lor$, $\neg$, $\implies$, and $\iff$.
- The quantifiers $\forall$ and $\exists$ (these are new, and in semantics we will see what they mean).
- Variable symbols $x_1, x_2, \ldots$. Earlier, variables were atomic propositions that were either true or false. Now these variables will be elements of some set called the domain. This will become clear shortly.
- The equality symbol $=$ that allows us to declare that two domain elements are equal.
- Parentheses and commas for grouping.
All FOL languages will have these symbols.
Non-Logical Symbols
- a set of constant symbols,
- a set of function symbols, and
- a set of predicate symbols.
In addition, each function and predicate symbol in a first-order language is associated with a positive integer which we call its arity. Functions and predicates of arity 1 are called unary functions and predicates respectively; those of arity 2 are called binary and so on.
We should state that when we say function here, we will almost always mean a map that takes an $n$-tuple of domain elements and maps to some $m$-tuple of domain elements, where $m,n \ge 1$.
Examples Of Signatures
-
ZFC Set Theory: The signature contains only a single binary predicate $\{\in\}$ and nothing else. No constants or functions. Later we will spend an entire post re-deriving this theory.
-
Graph theory: A signature for graph theory is $\{E\}$, a single binary predicate $E$.
These signatures might not seem intuitive or meaningful yet. We have all seen graphs. We usually write it as $G = (V, E)$ where $E : V \times V \rightarrow \{\top, \bot\}$ tells us if an edge exists or not. But where are the vertices? Why are they not part of the signature? The vertices in the case of graph theory will be domain elements that need to be defined only when we are assigning meaning.
In general, domain elements might be numbers, sets, or other types of objects, depending on the language and its interpretation. The constants in the signature represent specific elements in the domain.
Grammar Rules
Grammar refers to the set of rules that allow us to stitch symbols together to make well-formed sentences. Again, we reiterate that we use the phrases sentence and formula interchangeably. A sentence in this logic is made of terms. That is, the parse tree of a sentence has terms as leaves. And terms are made up of variables or constants. So the parse tree of a term has variables or constants as leaves.
Consider the following signature where $(\cdot)$ denotes the arity.
$$ \Sigma = \bigl( \underbrace{\lbrace 0\rbrace}_{\text{constants}}, \underbrace{\lbrace S^{(1)}, +^{(2)}\rbrace}_{\text{functions}}, \underbrace{\lbrace >^{(2)}\rbrace}_{\text{predicates}} \bigr) $$
This signature is able to express the middle school problem we started with. Now, to make notation a little less cluttered, we use labels.
$$
\begin{align*}
1 &:= S(0) \\
2 &:= S(S(0)) \\
& \ldots \\
5 &= S(S(S(S(S(0)))))
\end{align*}
$$
Thus, the terms in the premises are given by the following parse trees according to the definition.
We can now express the opening argument as a single formula.
$$ \bigl((3 + 2 = 5) \land (5 > 1)\bigr) \implies (3 + 2 > 1) $$
Its parse tree shows the first premise in green, the second premise in blue, and the conclusion in red. The numeral nodes abbreviate the terms built from $S$ and $0$ defined above.
A sentence/formula can be either atomic or compound.
In the example above, both premises $3 + 2 = 5$ and $5 > 1$, and the conclusion $3 + 2 > 1$ are atomic formulae.
Semantics
The signature of a first-order language specifies which symbols are used to represent constants, functions, and predicates. These do not, however, give meaning to symbols. In propositional logic, meaning was straightforward. Give truth assignments to atomic propositions in the leaves of the parse tree, and propagate upwards. The rules of propagating were given by truth tables. Now we will need a bit more machinery.
TODO: do not like this definition
Continuing with the example, the domain is defined as follows. The function $S$ denotes the successor function, mapping $0$ to $S(0)$, $S(0)$ to $S(S(0))$, and so on.
$$ \mathcal{D}=\lbrace 0,S(0),S(S(0)),\ldots\rbrace $$ Now this is annoying to read. So we will use nice labels like you have seen in maths textbooks and write $\mathcal{D}$ as $$ \mathcal{D}=\lbrace 0,1,2,\ldots\rbrace $$
This domain $\mathcal{D}$ is often referred to as the natural numbers, so we can write $\mathcal{D}=\Naturals$.
Define the binary function $+ : \mathcal{D}^2\to\mathcal{D}$ for all $a,b\in\mathcal{D}$ as follows.
$$ \begin{align*} a+0 &= a, \\ a+S(b) &= S(a+b). \end{align*} $$
Finally, the greater than predicate is also defined as we would expect.
$$ a>b\quad\iff\quad a\in\lbrace S(b),S(S(b)),\ldots\rbrace\qquad(a,b\in\mathcal{D}). $$
Now observe that we have assigned meaning to all the functions and predicates in the signature. We have defined a domain. We are now able to propagate meaning up the parse tree. Evaluation is always this - we assign meaning to the leaves and use rules for propagating up the tree.
This is all a very tedious way to say the same thing as propositional logic. Evaluate the leaves, which are terms. Then propagate upwards with the above rules. The truth table rules still apply, but there are some extra rules for $\forall$ and $\exists$, and these statements are about elements in the domain.
Some Notation And Definitions
Once again we need to define a satisfying assignment and tautologies. But before that let us introduce more notation (crikey).
Sometimes I will be lazy and just write $\phi(\mathcal{M}) = \top$ also. All three of the following mean the same thing. $$ \mathcal{M} \models \phi, \quad \Val{\phi} = \top, \quad \phi(\mathcal{M}) = \top $$
Now, from here we can build theories and models.
Examples of Tautologies in FOL
For any signature with the unary predicate $P$, the sentence
$$ (\forall x_1 \neg P(x_1) \to \neg \exists x_1 P(x_1)) $$
is valid.
Models and Theories
Now entailment or logical consequence is not as simple to visualise as in propositional logic, but there is nothing special going on here. Recall that we said in propositional logic that $\Gamma \models \Omega$ if every truth assignment $v$ that satisfied every sentence in $\Gamma$ also satisfied every sentence in $\Omega$. The exact same thing is happening again. We write $\Gamma \models \Omega$ if every structure $\mathcal{M}$ that satisfies every $\phi \in \Gamma$ also satisfies every $\psi \in \Omega$.
We will do some example theories like Group Theory and Peano Arithmetic at the end of the post. For now we proceed to deduction rules.
Formal Proofs In FOL (Deduction Rules)
We have entailment, but that is once again the business of going over all $\mathcal{M}$ and checking if the formula holds. This is no good to us. So we will come up with a proof system, and then prove it is complete and sound just like we did with the propositional proof system. In fact we will keep all the deduction rules we defined earlier, and add 6 new ones. Before we can state them, we need to understand what bound variables and free variables mean, and we will define the idea of scope. Assume I have the following formula $$\phi:=\forall y\psi=\forall y\forall x((x>0)\land(y>1))$$
where $\psi:=\forall x\theta$ and $\theta:=(x>0)\land(y>1)$.
The scope of a quantifier is the formula immediately following it. In $\phi$, $\forall y$ has scope $\psi$, and $\forall x$ has scope $\theta$. In $\psi$, the occurrence of the variable $x$ is bound by $\forall x$, while the occurrence of $y$ is free. In $\phi$, $\forall y$ binds $y$ as well, so $\phi$ is a sentence.
We can now define substitution using free occurrences. For a formula $\phi$, variable $v$, and term $t$, write $\phi[v/t]$ for the result of replacing the free occurrences of $v$ in $\phi$ with $t$. For a formula $\phi$ and terms $t,u$, write $\phi[t/^{\ast}u]$ for the result of replacing any chosen occurrences of $t$ in $\phi$ with $u$. For example, if $\phi:=(v>0)$ and $t:=1$, then $\phi[v/1]=(1>0)$.
Suppose the premise is $\forall x\phi$, where $\psi:=(x>0)$, $\theta:=\exists y(y>x)$, and $\phi:=\psi\lor\theta$. The two occurrences of $x$ are free in $\phi$ and bound by the outer $\forall x$ in $\forall x\phi$.
-
Take $t:=S(x)$. Substituting $x/t$ in $\phi$ gives $\phi[x/t]=(S(x)>0)\lor\exists y(y>S(x))$. This is legal because neither inserted occurrence of $x$ becomes bound by $\exists y$.
-
Take $t:=y$. Substituting $x/t$ in $\phi$ would give $(y>0)\lor\exists y(y>y)$. This is not legal because the $x$ replaced inside $\theta$ lies in the scope of $\exists y$, which would bind the inserted $y$.
An undischarged assumption is an assumption at the start of a subproof that remains open at the current proof line.
Suppose $\phi:=\forall x((v>0)\land(x>0))$ has been derived, with $v$ absent from every premise and undischarged assumption. In $\phi$, the occurrence of $v$ is free, while the occurrence of $x$ is bound by $\forall x$. Universal Introduction gives $\forall y\phi[v/y]=\forall y\forall x((y>0)\land(x>0))$.
If $1>0$ appears in a proof, take $t:=1$ and infer $\exists x(x>0)$ by replacing $1$ with $x$.
$\exists x((x>0)\land(x>1))\vdash\exists y(y>0)$.
$$ \begin{array}{rll} 1. & \exists x((x>0)\land(x>1)) & \mathsf{PR} \\ \begin{array}{r} 2. \\ 3. \\ 4. \end{array} & \qquad\begin{array}{|l} (v>0)\land(v>1) \\ v>0 \\ \exists y(y>0) \end{array} & \begin{array}{l} \mathsf{AS} \\ \land\mathsf{E}\ 2 \\ \exists\mathsf{I}\ 3 \end{array} \\ 5. & \exists y(y>0) & \exists\mathsf{E}\ 1, 2\text{-}4 \end{array} $$
Examples of Using Our System
In the proofs below, $v$ is a fresh variable.