1. Introduction
FirstOrder Logic (FOL) is the language of classical logic most widely used in various areas of mathematics and computer science. Firstorder logic uses quantified variables over nonlogical objects and allows the use of sentences that contain variables. The firstorder language of graph theory is defined in the usual way with variables ranging over the vertexset and the edge relation as the primitive relation. However, not many graph properties can be expressed using this logic: such fundamental properties as Connectivity, Acyclicity, Bipartiteness, Planarity, Eulerian, and Hamiltonian Path are not firstorder definable on finite graphs [114, 160]. Therefore developing a comprehensive firstorder theory on graphs with more expressive power is an important problem. A possible approach towards such a theory is to transpose to graphs Tarski’s axiomatic approach to Euclidean geometry [157, 158, 147].
Tarski developed a FirstOrder Logic theory of Euclidean geometry using only “points” as the “primitive geometric objects” in contrast to other theories of Euclidean geometry of Hilbert and Birkhoff, where points, lines, planes, etc., are all primitive “geometrical objects”. In Tarski’s theory, there are two primitive geometrical relations (predicats): the ternary relation of “betweenness” and the quaternary relation of “equidistance” or “congruence of segments”. The elegance of Tarski’s axiomatic theory of geometry is that the axiom system admits elimination of quantifiers: that is, every formula is provably equivalent (on the basis of the axioms) to a Boolean combination of basic formulas. The theory is complete: every assertion is either provable or refutable; the theory is decidable – there is a mechanical procedure for determining whether or not any given assertion is provable and also there is a constructive consistency proof for the theory. Tarski’s axioms are an axiom set for the substantial fragment of Euclidean geometry that is formulable in firstorder logic with identity, and requiring no set theory [157, 158, 147].
The main goal of this article is the FirstOrder Logic axiomatization of Metric Graph Theory using the notion of Betweenness, in a similar vein as Tarski’s FirstOrder Logic approach to Euclidean geometry. The natural betweenness on graphs is the metric betweenness (or shortest path betweenness) resulting from the standard path metric of connected graphs and defined using the ternary relation on the vertex set of a graph meaning that “the vertex lies on some shortest path of between the vertices and ”. We abbreviate the Fist Order Logic with Betweenness of graphs by FOLB.
The main subject of Metric Graph Theory (MGT) is the investigation and characterization of graph classes whose metric satisfies main properties of classical metric geometries like Euclidean geometry (and more generally, the  and geometries), hyperbolic spaces, hypercubes, trees. Such central properties are convexity of balls, Helly property for balls, geometry of geodesic or metric triangles, isometric and lowdistortion embeddings, the retractions, the fourpoint conditions, uniqueness or existence of medians, etc. The main classes of graphs central to MGT are median graphs, Helly graphs, partial cubes and –graphs, bridged graphs, graphs with convex balls, Gromov hyperbolic graphs, modular and weakly modular graphs. Other classes surprisingly arise from combinatorics and geometry: basis graphs of matroids, even matroids, tope graphs of oriented matroids, dual polar spaces. For a survey of classes arising in MGT, see the survey [14]). For a theory of weakly modular graphs and their subclasses, see the paper [50] and for partial cubes and graphs, see the books [80] and [99].
In this paper, we show that all these graph classes occurring in MGT are definable in FOLB. On the other hand, we show that chordal graphs, dismantlable graphs, Eulerian graphs, planar graphs, and partial Johnson graphs are not definable in FOLB. Chordal graphs form a subclass of bridged graphs, dismantlable graphs form a superclass of bridged and Helly graphs, partial Johnson graphs generalize partial cubes. Since often the FOLBdefinability of a graph class is based not on its initial definition but on a characterization, which is not the principal or nicest one, when we introduce a graph class we define it, briefly motivate its importance, and present the used characterization. Then we refer to mentioned above papers and books or to other references for a more detailed treatment of each class. Notice that many of the classes from metric graph theory contain all trees but not all cycles; they are often defined by forbidding isometric subgraphs and cycles of given lengths. Consequently, these classes cannot be defined in the standard First Order Logic on graphs: indeed, the proof establishing that is not FOLdefinable immediately implies that such classes are not FOLdefinable.
The paper is organized as follows. In Section 2 we present the main basic definitions about graphs and First Order Logic. We also recall the EhrenfeuchtFraïssé games as the tool of proving that some queries are not definable in FOL for graphs. In Section 3 we introduce the First Order Logic with Betweenness for graphs and give the first examples of queries which are definable in this logic. In Section 4 we show that weakly modular graphs and their main subclasses and superclasses occurring in Metric Graph Theory are FOLBdefinable. In Section 5 we show FOLBdefinability of partial cubes and some of their subclasses and superclasses. Section 6 is devoted to FOLBdefinability of Gromov hyperbolic graphs. In Section 7, we establish that some classes of graphs are not FOLBdefinable. In Section 8, we explain how such FOLB characterization lead to polynomial time recognition algorithms.
2. Preliminaries
In this section, we recall the main definitions about graphs and the firstorder logic. In the three subsections about firstorder logic we closely follow the paper [114] by Kolaitis (we also use the book by Libkin [118]).
2.1. Graphs
A graph consists of a set of vertices and a set of edges . All graphs considered in this paper are finite, undirected, connected, and contain no multiple edges nor loops. For two distinct vertices we write (respectively, ) when there is an (respectively, there is no) edge connecting with , that is, when . For vertices , we write (respectively, ) or (respectively, ) when (respectively, ), for each , where . As maps between graphs and we always consider simplicial maps, that is functions of the form such that if in then or in . A –path of length is a sequence of vertices with . If then we call a 2path of . If for , then is called a simple –path. A –cycle is a path . For a subset the subgraph of induced by is the graph such that if and only if ( is sometimes called a full subgraph of ). A square (respectively, triangle , pentagon ) is an induced –cycle (respectively, –cycle , cycle ).
The distance between two vertices and of a graph is the length of a shortest –path. For a vertex of and an integer , we denote by (or by ) the ball in (and the subgraph induced by this ball) of radius centered at , that is, More generally, the –ball around a set is the set (or the subgraph induced by) where . As usual, denotes the set of neighbors of a vertex in . A graph is isometrically embeddable into a graph if there exists a mapping such that for all vertices . More generally, for an integer , a graph is scale embeddable into a graph if there exists a mapping such that for all vertices . A retraction of a graph is an idempotent nonexpansive mapping of into itself, that is, with for all . The subgraph of induced by the image of under is referred to as a retract of .
The interval between and consists of all vertices on shortest –paths, that is, of all vertices (metrically) between and : If , then is called a 2interval. A 2interval is called thick if contains two nonadjacent vertices . A graph is called thick if all 2intervals of are thick. A subgraph of (or the corresponding vertexset ) is called convex if it includes the interval of between any pair of its vertices. The smallest convex subgraph containing a given subgraph is called the convex hull of and is denoted by conv. A halfspace is a convex set of whose complement is convex. An induced subgraph (or the corresponding vertexset of ) of a graph is gated if for every vertex outside there exists a vertex in (the gate of ) such that for any of . Gated sets are convex and the intersection of two gated sets is gated. By Zorn’s lemma there exists a smallest gated subgraph containing a given subgraph , called the gated hull of .
Let , be an arbitrary family of graphs. The Cartesian product is a graph whose vertices are all functions , and two vertices are adjacent if there exists an index such that and for all . Note that a Cartesian product of infinitely many nontrivial graphs is disconnected. Therefore, in this case the connected components of the Cartesian product are called weak Cartesian products. The direct product of graphs , is a graph having the same set of vertices as the Cartesian product and two vertices are adjacent if or for all .
We continue with the definition of some graphs. The complete graph on vertices is denote by and the complete bipartite graph with parts of size and by . The wheel is a graph obtained by connecting a single vertex – the central vertex – to all vertices of the –cycle ; the almost wheel is the graph obtained from by deleting a spoke (i.e., an edge between the central vertex and a vertex of the –cycle). Analogously and are the graphs obtained from and by removing one edge. An –octahedron (or, a hyperoctahedron, for short) is the complete graph on vertices minus a perfect matching. A hypercube of dimension is a graph having the subsets of a set of size as vertices and two such sets are adjacent in if and only if . A halved cube has the vertices of a hypercube corresponding to subsets of of even cardinality as vertices and two such vertices are adjacent in if and only if their distance in
is 2 (analogously one can define a halved cube on finite subsets of odd cardinality). For a positive integer
, the Johnson graph has the subsets of of size as vertices and two such vertices are adjacent in if and only if their distance in is . All Johnson graphs with even are isometric subgraphs of the halved cube and the halved cube is scale 2 embedded in the hypercube . The hypercube can be viewed as the Cartesian product of copies of . The Hamming graph is a Cartesian product of the complete graphs .2.2. FirstOrder Logic (FOL)
In this subsection we recall the main definitions from FirstOrder Logic. A vocabulary consists of a set of constant symbols and a set of relation symbols (called also predicates) of specified arities. Given a vocabulary , the variables and the constant symbols are the terms. The set of formulas is defined inductively as follows:

given terms and a ary predicate , then is a formula;;

for each formulas , , and are formulas;

if is a formula and is a variable, then and are formulas.
Atomic formulas are those constructed according to the first rule. A general firstorder formula is build up from atomic formulas using Boolean connectives and the two quantifiers. Given a vocabulary , a structure is a tuple consisting of

a nonempty set , called the universe;

for each constant , an element of ;

for each ary predicate in , a ary relation .
A finite structure is a structure whose universe is finite.
Let and be two structures. An isomorphism between and is a mapping that satisfies the following conditions:

is a onetoone and onto function;

for every constant symbol , we have ;

for each relation symbol , of arity and any tuple from , we have if and only if .
Given two structures and , is a substructure of if , each is the restriction of to (which means that ) and . If is a structure and is a subset of , then the substructure of generated by is the structure having the set as its universe and having the restrictions of the relations on as its relations. A partial isomorphism from to is an isomorphism from a substructure of to a substructure of . Given a structure , a variable , and , the structure is the same as except that .
Example 1.
A (undirected) graph is a structure with the vertexset as the universe and the vocabulary with one binary relation symbol , where is interpreted as the edge relation. The subgraph of induced by a set of vertices of is the substructure of generated by .
Let be a structure with universe . The value of each term is an element of the universe , inductively defined as follows:

for a constant symbol , set ;

for a variable , set ;

for a term , where is a ary function symbol and are terms, set .
The satisfaction relation (which means that satisfies or that models F) between a structure and formula is defined by induction over the structure of :

if and only if ;

if and only if and ;

if and only if or ;

if and only if ;

if and only if there exists such that ;

if and only if for all ;

if and only if .
A firstorder formula over signature is satisfiable if for some structure . If is not satisfiable it is called unsatisfiable. is called valid if for every structure .
Following the terminology of [114, 118], we continue with the concept of query, one of the most fundamental concepts in finite model theory. Let be a vocabulary. A class of structures is a collection of structures that is closed under isomorphisms. A ary query on is a mapping with domain such that is preserved under isomorphisms and is a ary relation on for all . A Boolean query on is a mapping that is preserved under isomorphisms. Consequently, can be identified with the subclass of . For example, the query on graphs is the Boolean query such that if and only if the graph is connected. Queries are mathematical objects that formalize the concept of a “property” of structures and makes it possible to define what means for such a “property” to be expressible in some logic.
Let be a (firstorder) logic and a class of structures. A ary query on is definable if there exists a formula of with as free variables and such that for every , . A Boolean query on is definable if there exists an formula such that for every , if and only if . Let denotes the collection of all definable queries on .
The expressive power of a logic on a class of finite structures is defined by the collection of definable queries on , i.e., is to determine which queries on are definable and which are not. To show that a query is definable, it suffices to find some formula that defines it on every structure in . In contrast, showing that is not definable entails showing that no formula of defines the property. One of the main tools in proving that a query is not definable in firstorder logic of finite graphs is the method of EhrenfeuchtFraïssé games, defined in the next subsection.
2.3. EhrenfeuchtFraïssé games
Let be a positive integer, a vocabulary, and and two structures. The move EhrenfeuchtFraïssé game on and is played between two players, called the Spoiler and the Duplicator. Each run of the game has moves. In each move, the Spoiler plays first and picks an element from the universe of or from the universe of ; the Duplicator then responds by picking an element of the other structure (i.e., if Spoiler picked an element from , then the Duplicator picks and element from , and vice versa). Let and be the two elements picked by the Spoiler and the Duplicator in their th move, .

The Duplicator wins the run if the mapping and is a partial isomorphism from to , which means that it is an isomorphism between the substructure of restricted to and the substructure of restricted to . otherwise, the Spoiler wins the run .

The Duplicator wins the move EhrenfeuchtFraïssé game on and if the Duplicator can win every run of the game, i.e., if (s)he has a winning strategy for the EhrenfeuchtFraïssé game. Otherwise, the Spoiler wins the move EhrenfeuchtFraïssé game.

We write to denote that the Duplicator wins the move EhrenfeuchtFraïssé game on and .
From this definition follows that is an equivalence relation on the class of all structures. For a formal definition of the winning strategy for the Duplicator, see for example [114, Definition 3.4]. EhrenfeuchtFraïssé games characterize definability in firstorder logic. To describe this connection, we need the following definition.
Let be a firstorder formula over a vocabulary . The quantifier rank of , denoted by , is defined inductively in the following way:

if is atomic, then ;

if is of the form , then ;

if is of the form or of the form , then ;

if is of the form or of the form , then .
For a positive integer and two structures and , denotes that and satisfy the same firstorder sentences of quantifier rank ; is an equivalence relation on the class of all structures. The main result of Ehrenfeucht and Fraïssé asserts that the equivalence relations and coincide:
Theorem 2 ([87, 90]).
Let be a positive integer and let and be two structures. Then the following two conditions are equivalent:

, i.e., and have the same firstorder sentences of quantifier rank ;

, i.e., the Duplicator wins the move EhrenfeuchtFraïssé game on and .
Moreover, has finitely many equivalence classes and each equivalence class is definable by a firstorder sentence of quantified rank .
For a proof of this theorem, see [114]. A consequence of this theorem is the following result:
Theorem 3.
Let be a class of structures and be a Boolean query on . Then the following statements are equivalent:

is firstorder definable on ;

there exists a positive integer such that, for every , if and the Duplicator wins the move EhrenfeuchtFraïssé game on and , then .
This theorem provides the following method for studying firstorder definability of Boolean queries on classes of structures. Let be a structure and be a Boolean query on . To show that is not firstorder definable on , it suffices to show that for every positive integer there are such that

and ;

the Duplicator wins the move EhrenfeuchtFraïssé game on and .
The method is also complete, i.e., if is not firstorder definable on , then for every positive integer such structures and exist.
2.4. What can be expressed and what cannot be expressed in FOL for graphs
Recall that an undirected graph is a structure with the universe and the vocabulary with one binary relation symbol (interpreted as the edge relation) such that and . We start with a few queries on graphs, which are firstorder definable:
Example 4.
Let be a graph with vertexset . The Boolean query meaning “ contains as an induced subgraph” is definable by the firstorder formula
This implies that the query meaning “ contains at least one of the graphs as an induced subgraph” is also firstorder definable.
Analogously, the binary query “there exists a path of length from to ” is definable by the first order formula
Using the formulas , one can show that the binary query meaning that “the distance between and is at most ” is definable by the first order formula
The binary query meaning that “the distance between and is at most ” can then be defined as the first order formula
Using the last queries, one can easily show that the Boolean queries and meaning “ contains as an isometric subgraph” and “ contains at least one of the graphs as an isometric subgraph” are also firstorder definable. For example, if is a graph with the vertexset , then is definable by the formula
On the other hand, the most queries on graphs are not firstorder definable, in particular the following wellknown queries:

The query is the Boolean query such that iff is an acyclic graph;

The query is the Boolean query such that iff is a bipartite graph;

The query is the Boolean query such that iff is a connected graph;

The query is the Boolean query such that iff has an even number of vertices.
All these results can be obtained via EhrenfeuchtFraïssé games [114, 118].
3. First Order Logic with Betweenness (FOLB)
In this section, we introduce the firstorder logic with betweenness. Betweenness was first formulated in geometry and nowadays has a rich history. Euclid, Pasch, Hilbert, Peano, and Tarski studied betweeness in Euclidean geometry axiomatically. Menger [122] and Blumenthal [41] investigated metric betweeness, i.e., betweenness in general metric spaces. Inspired by the work of Pasch, Pitcher and Smiley [135] and Sholander [148, 149, 150] were the first to investigate betweenness in the discrete setting: in lattices, partial orders, trees, and median semilattices. In graphs, the study of metric betweenness was initiated by Mulder [125]. Prenowitz and Jantosciak [141] were the first to investigate the notion of betweenness in the setting of abstract convexity by introducing the concept of join space. Hedliková represented the betweenness relation as a ternary relation and introduced the concept of ternary space; the betweenness relation in a ternary space unifies the metric, order and lattice betweenness. Finally, this led to the equivalent concept of geometric interval space [162].
3.1. Betweenness and interval spaces
Let be any finite set. For each pair of points in , let be a subset of , called the interval between and . Then is a (finite) interval space [162] if and only if

;

;
Every interval space gives rise to a betweenness relation: we will say that a point is between the points and (notation ) if . The interval space is said to be geometric if it satisfies the following three conditions for all [27, 163]:

,

implies ,

and implies .
A particular instance of geometric interval space is any metric space : the intervals are the metric intervals .
For each point one defines the basepoint relation at as follows: if and only if . The next lemma summarizes an equivalent description of geometric interval spaces [162, Section 27]:
Lemma 1.
An interval space is geometric if and only if it satisfies the following conditions:

and implies ;

and implies and ;

for each point the basepoint relation is a partial order such that for any we have .
Let be any set together with a ternary relation . If and , then is said to be between and . The interval is defined as the set of all between and . A ternary space (which can be equally called a space with betweenness) is a set together with a ternary relation satisfying the following conditions [100]:

implies ;

and implies ;

and implies and .
From Lemma 1 it follows that a geometric interval space is exactly a ternary space satisfying the property that (i.e., ) for all .
An interval of an interval space is called an edge if and ; the edges then form the graph of the interval space .
Lemma 2 ([9]).
Let be a finite geometric interval space. Then the graph of is connected.
The graph of a finite geometric interval space can be regarded as a metric space, where the standard graphmetric accounts the lengths of shortest paths in the graph. We denote by the corresponding intervals in which have to be distinguished from the intervals in . An interval space is called graphic [9, 162] if the equality holds for all points of the space.
A simple sufficient condition for a finite interval space to be graphic was given in [9]. An interval space is said to satisfy the triangle condition if for any three points in with

and , the intervals are edges whenever at least one of them is an edge.
Theorem 5 ([9]).
A finite geometric interval space satisfying the axiom (ITC) is graphic.
Graphic interval spaces have been characterized by Mulder and Nebeský [126] (improving over the previous such characterizations obtained by Nebeský). Additionally, to axioms (I1)(I5) of a geometric interval space, they require two additional axioms introduced in [129]:

, and imply ;

, and imply .
Theorem 6 ([126]).
A finite geometric interval space is graphic if and only if it satisfies the axioms (I6) and (I7).
Observe that if is a subset of an interval space , we can define an interval structure on by taking the intersection of the interval in with for any pair . If is a graphic interval space, then endowed with this inherited interval structure is also a graphic interval space. Note however that may be different from the subgraph of induced by .
3.2. FOLB for graphs
Given a ternary predicate on a finite set , we define the binary predicate on as follows: .
A graphic interval structure is a structure where is a finite set and is a ternary predicate on satisfying the following axioms:







.
Observe that since satisfies (IB2), is an undirected graph seen as a structure (as defined in Section 2.4). By Lemma 2, is a connected graph. Since satisfies (IB1)–(IB7), by Theorem 6, for any , if and only if . When is true, it means that belongs to the interval .
When considering the class of structures satisfying axioms (IB1)–(IB7), we say that a query on is definable in first order logic with betweeness (FOLBdefinable) if it can be defined by a first order formula over .
Observe that by the definition of , any FOLdefinable query is also FOLBdefinable. In particular the queries and are FOLBdefinable.
3.3. What can be expressed in FOLB for graphs: first results
There are properties in FOLB that cannot be expressed using only FOL. Namely, we prove that and are FOLBdefinable, where is . Since in FOLB we consider only connected graphs, is a trivial query in FOLB.
A graph is bipartite if and only if for any edge and any vertex , the distances from to and to are different, and thus if and only if either or . Consequently, is definable by the following FOLBformula:
A tree is bipartite. In a bipartite connected graph, if is not a tree, there are two vertices such that has two neighbors in the interval . Indeed, consider a cycle and an arbitrary vertex . Let be the vertex of that is the furthest from . Since is bipartite, the two neighbors of on belong to the interval . Consequently, is definable by the following FOLBformula:
We will use the predicates , and , which are true if and only if the vertices , , and induce respectively a triangle, a square, or a pentagon of a graph . We will also use the predicate , which is true if and only of the intervals and intersects only in the vertex . can be written as the FOLBformula .
Given four vertices of , the following predicate express that and belong to a common shortest path going from to (reaching first and then ):
Three vertices of a graph define a metric triangle [64] if , , and . This can be expressed using the predicate
The size of a metric triangle is .
Given three vertices , a metric triangle is a quasimedian of if , , and , For any vertices , one can obtain a quasimedian of by taking furthest from , furthest from , and furthest from . It can be expressed by the following predicate: