# Why can't reachability be expressed in first order logic?

I’m wondering why we can’t express graph reachability in first order logic in pretty much exactly the same way we express it in second order existential logic. For SOL, one definition is :

1 . L is a linear order on a subset of the vertices :

\begin{align} \psi_1 = &\forall u \neg L(u,u) \\ &\wedge \forall u\forall v (L(u,v) \Rightarrow \neg L(v,u)) \\ & \wedge \forall u\forall v \forall w(L(u,v) \wedge L(v,w) \Rightarrow L(u,w)) \end{align}

2 . Any two consecutive vertices in the order must be joined by an edge in G:

\begin{align} \psi_2 = &\forall u\forall v ((L(u,v) \ \wedge \forall w(\neg L(u,w) \vee \neg L(w,v))) \\ & \Rightarrow E(u,v)). \end{align}

3 . The first vertex in the order is x and the last is y and x, y are in the order:

\begin{align} \psi_3 = &(\forall u\ \neg L(u,x)) \wedge (\forall v\ \neg L(y,v)) \ \wedge L(x,y) \end{align}

and finally the expression for reachability is

4 . $\phi(x,y) =\exists L (x=y) \vee (\psi_1 \wedge \psi_2 \wedge \psi_3))$

But why can’t we use the same thing in first order logic (i.e. no existential quantification over L) :

$\phi(x,y) =(x=y) \vee (\psi_1 \wedge \psi_2 \wedge \psi_3))$

This would be interpreted over the vocabulary with models M having two binary relations : E (edge) and L (reachable), and the universe of all nodes. Surely any model which satisfies the expression 5 above will have its L relation expressing a linear ordering of the nodes, with any two consecutive elements being adjacent in E – in other words, it will be the “Reachable” relation, (and the model will map the free variables x and y to nodes N1 and N2, with (N1,N2) in L, meaning N2 is reachable from N1).

Why doesn’t this work? Specifically, would the proof of non expressibility of reachability fail for it?

The proof of non expressibility of reachability in FOL goes like this :

Assume that an FOL expression p, with free variables x and y exists, expressing reachability.

We have $s_1 \equiv \forall x \forall y \ p$ stating that all nodes are reachable from all nodes, i.e. the graph is strongly connected.

Then we add two sentences about E, $s_2$ (saying that every node of the graph has outdegree one), and $s_3$ (that every node has indegree one). The conjunction of the above three sentences

$s_4 = s_1 \wedge \ s_2 \wedge \ s_3$,

then states that the graph is strongly connected and all nodes have indegree and outdegree one – i.e. it’s a cycle.

Since there are finite cycles with as many nodes as desired, s4 has arbitrary large finite models. Therefore by Lowenheim-Skolem theorem, it also has an infinite model. But infinite cycles do not exist, and so our assumption that there exists a p expressing reachability is contradicted.

If our FOL expression (5) is taken as the p expression in the proof, all the steps of the proof can be carried out the same, and we will be led to the same result, namely that (5) does not express reachability. But why not? It certainly has all the elements..

#### Solutions Collecting From Web of "Why can't reachability be expressed in first order logic?"

The issue here is with the terminology. You can express reachability in first-order logic; for example you can express it in the language of set theory by quantifying over paths in the graph, and set theory is a first-order theory.

You cannot express reachability in the particular language where the only relations available are the incidence relation on the graph and equality, and where quantification is only permitted over elements of the graph. So the issue actually has very little to do with “first order logic”, and everything to do with the particular language that is being allowed. Tradition says that this situation is phrased as “reachability cannot be expressed in first order logic”, even though that phrase could be interpreted in other ways.

Ignoring terminological issues, it can be genuinely useful to know that reachability cannot be expressed without quantifying over sets or paths in some way. For example, that fact means that if your graph is stored in an SQL database in a natural way then it will be more difficult to code an SQL query that tells whether an arbitrary pair of nodes has a path than it would be if that relation could be phrased in the limited language mentioned above.

By the way,here is how you show there is no formula $\phi(a,b)$ expressing reachability. Take the language of graph theory mentioned above and add two new constants $C$ and $D$. Take the infinite set of axioms “there is no path of length $1$ from $C$ to $D$”, “there is no path of length two from $C$ to $D$”, … Then any finite set of these axioms is consistent with $\phi(a,b)$, as can be seen by looking at a graph with an infinitely long path and taking $C$ and $D$ to be far enough apart. Thus by the compactness theorem the set of all those axioms is consistent with $\phi(C,D)$. But if all those axioms are true in a graph, there is no path from $C$ to $D$ in that graph, so $\phi$ did not express that property correctly.