# Linear temporal logic to Büchi automaton

In formal verification, finite state model checking needs to find a Büchi automaton (BA) equivalent to a given linear temporal logic (LTL) formula, i.e., such that the LTL formula and the BA recognize the same ω-language. There are algorithms that translate an LTL formula to a BA. This transformation is normally done in two steps. The first step produces a generalized Büchi automaton (GBA) from a LTL formula. The second step translates this GBA into a BA, which involves a relatively easy construction. Since LTL is strictly less expressive than BA, the reverse construction is not always possible.
The algorithms for transforming LTL to GBA differ in their construction strategies but they all have a common underlying principle, i.e., each state in the constructed automaton represents a set of LTL formulas that are expected to be satisfied by the remaining input word after occurrence of the state during a run.

## Transformation from LTL to GBA

Here, two algorithms are presented for the construction. The first one provides a declarative and easy-to-understand construction. The second one provides an algorithmic and efficient construction. Both the algorithms assume that the input formula f is constructed using the set of propositional variables AP and f is in negation normal form. For each LTL formula f' without ¬ as top symbol, let neg(f') = ¬f' and neg(¬f') = f'. For a special case f'=true, let neg(true) = false.

### Declarative construction

Before describing the construction, we need to present a few auxiliary definitions. For an LTL formula f, Let cl( f ) be the smallest set of formulas that satisfies the following conditions:
| true ∈ cl( f ) f ∈ cl( f ) if f$_1$ ∈ cl( f ) then neg(f$_1$) ∈ cl( f ) if X f$_1$ ∈ cl( f ) then f$_1$ ∈ cl( f ) | if f$_1$ ∧ f$_2$ ∈ cl( f ) then f$_1$,f$_2$ ∈ cl( f ) if f$_1$ ∨ f$_2$ ∈ cl( f ) then f$_1$,f$_2$ ∈ cl( f ) if f$_1$ U f$_2$ ∈ cl( f ) then f$_1$,f$_2$ ∈ cl( f ) if f$_1$ R f$_2$ ∈ cl( f ) then f$_1$,f$_2$ ∈ cl( f ) |
cl( f ) is closure of sub-formulas of f under neg. Note that cl( f ) may contain formulas that are not in negation normal form. The subsets of cl( f ) are going to serve as states of the equivalent GBA. We aim to construct the GBA such that if a state corresponds to a subset M ⊆ cl( f ) then the GBA has an accepting run starting from the state for a word if and only if the word satisfies every formula in M and violates every formula in cl( f ) \ M. For this reason, we will not consider each formula set M that is clearly inconsistent or subsumed by a strict superset M' such that M and M' are equiv-satisfiable. A set M ⊆ cl( f ) is maximally consistent if it satisfies the following conditions:
| true ∈ M f$_1$ ∈ M iff ¬f$_1$ ∉ M | f$_1$ ∧ f$_2$ ∈ M iff f$_1$ ∈ M and f$_2$ ∈ M f$_1$ ∨ f$_2$ ∈ M iff f$_1$ ∈ M or f$_2$ ∈ M |
Let cs( f ) be the set of maximally consistent subsets of cl( f ). We are going to use only cs( f ) as the states of GBA.

#### GBA construction

An equivalent GBA to f is A= ({init}∪cs( f ), 2$^{AP}$, Δ,{init},F), where
* Δ = Δ$_1$ ∪ Δ$_2$
** (M, a, M') ∈ Δ$_1$ iff ( M' ∩AP ) ⊆ a ⊆ {p ∈ AP | ¬p ∉ M' } and:
*** X f$_1$ ∈ M iff f$_1$ ∈ M';
*** f$_1$ U f$_2$ ∈ M iff f$_2$ ∈ M or ( f$_1$ ∈ M and f$_1$ U f$_2$ ∈ M' );
*** f$_1$ R f$_2$ ∈ M iff f$_1$ ∧ f$_2$ ∈ M or ( f$_2$ ∈ M and f$_1$ R f$_2$ ∈ M' )
** Δ$_2$ = { (init, a, M') | ( M' ∩AP ) ⊆ a ⊆ {p ∈ AP | ¬p ∉ M' } and f ∈ M' }
* For each f$_1$ U f$_2$ ∈ cl( f ), {M ∈ cs( f ) | f$_2$ ∈ M or ¬(f$_1$ U f$_2$) ∈ M } ∈ F
The three conditions in definition of Δ$_1$ ensure that any run of A does not violate semantics of the temporal operators. Note that F is a set of sets of states. The sets in F are defined to capture a property of operator U that can not be verified by comparing two consecutive states in a run, i.e., if f$_1$ U f$_2$ is true in some state then eventually f$_2$ is true at some state later.
Let ω-word w= a$_1$, a$_2$,... over alphabet 2$^{AP}$. Let w$^i$ = a$_i$, a$_{i+1}$,... . Let M$_w$ = { f' ∈ cl(f) | w $\vDash$ f' }, which we call satisfying set. Due to the definition of cs(f), M$_w$ ∈ cs(f). We can define a sequence ρ$_w$ = init, M$_{w1}$, M$_{w2}$,... . Due to the definition of A, if w $\vDash$ f then ρ$_w$ must be an accepting run of A over w.
Conversely, lets assume A accepts w. Let ρ = init, M$_1$, M$_2$,... be a run of A over w. The following theorem completes the rest of the correctness proof.
Theorem 1: For all i > 0, M$_{wi}$ = M$_i$.
Proof: The proof is by induction on the structure of f' ∈ cl(f).
* Base cases:
** f' = true. By definitions, f' ∈ M$_{wi}$ and f' ∈ M$_i$.
** f' = p. By definition of A, p ∈ M$_i$ iff p ∈ a$_i$ iff p ∈ M$_{wi}$.
* Induction steps:
** f' = f$_1$ ∧ f$_2$. Due to the definition of consistent sets, f$_1$ ∧ f$_2$ ∈ M$_i$ iff f$_1$ ∈ M$_i$ and f$_2$ ∈ M$_i$. Due to induction hypothesis, f$_1$ ∈ M$_{wi}$ and f$_2$ ∈ M$_{wi}$. Due to definition of satisfying set, f$_1$ ∧ f$_2$ ∈ M$_{wi}$.
** f' = ¬f$_1$, f' = f$_1$ ∨ f$_2$, f' = X f$_1$ or f' = f$_1$ R f$_2$. The proofs are very similar to the last one.
** f' = f$_1$ U f$_2$. The proof of equality is divided in two entailment proofs.
*** If f$_1$ U f$_2$ ∈ M$_i$, then f$_1$ U f$_2$ ∈ M$_{wi}$. By the definition of the transitions of A, we can have the following two cases.
**** f$_2$ ∈ M$_i$. By induction hypothesis, f$_2$ ∈ M$_{wi}$. So, f$_1$ U f$_2$ ∈ M$_{wi}$.
**** f$_1$ ∈ M$_i$ and f$_1$ U f$_2$ ∈ M$_{i+1}$. And due to the acceptance condition of A, there is at least one index j ≥ i such that f$_2$ ∈ M$_j$. Let j' be the smallest of these indices. We prove the result by induction on k = {j',j'-1,...,i+1,i}. If k = j', then f$_2$ ∈ M$_k$, we apply same argument as in the case of f$_2$ ∈ M$_i$. If i ≤ k < j', then f$_2$ ∉ M$_k$, and so f$_1$ ∈ M$_k$ and f$_1$ U f$_2$ ∈ M$_{k+1}$. Due to induction hypothesis on f', we have f$_1$ ∈ M$_{wk}$. Due to induction hypothesis on indices, we also have f$_1$ U f$_2$ ∈ M$_{wk+1}$. Due to definition of the semantics of LTL, f$_1$ U f$_2$ ∈ M$_{wk}$.
*** If f$_1$ U f$_2$ ∈ M$_{wi}$, then f$_1$ U f$_2$ ∈ M$_i$. Due to the LTL semantics, we can have the following two cases.
**** f$_2$ ∈ M$_{wi}$. By induction hypothesis, f$_2$ ∈ M$_i$. So, f$_1$ U f$_2$ ∈ M$_i$.
**** f$_1$ ∈ M$_{wi}$ and f$_1$ U f$_2$ ∈ M$_{wi+1}$. Due to the LTL semantics, there is at least one index j ≥ i such that f$_2$ ∈ M$_j$. Let j' be the smallest of these indices. Proceed now as in proof of the converse entailment.
Due to the above theorem, M$_{w1}$ = M$_1$. Due to the definition of the transitions of A, f ∈ M$_1$. Therefore, f ∈ M$_{w1}$ and w $\vDash$ f.

### Gerth et al. algorithm

The following algorithm is due to Gerth, Peled, Vardi, and Wolper. A verified construction mechanism of this by Schimpf, Merz and Smaus is also available. The previous construction creates exponentially many states upfront and many of those states may be unreachable. The following algorithm avoids this upfront construction and has two steps. In the first step, it incrementally constructs a directed graph. In the second step, it builds a labeled generalized Büchi automaton (LGBA) by defining nodes of the graph as states and directed edges as transitions. This algorithm takes reachability into account and may produce a smaller automaton but the worst-case complexity remains the same.
The nodes of the graph are labeled by sets of formulas and are obtained by decomposing formulas according to their Boolean structure, and by expanding the temporal operators in order to separate what has to be true immediately from what has to be true from the next state onwards. For example, let us assume that an LTL formula f$_1$ U f$_2$ appears in the label of a node. f$_1$ U f$_2$ is equivalent to f$_2$ ∨ ( f$_1$ ∧ X(f$_1$ U f$_2$) ). The equivalent expansion suggests that f$_1$ U f$_2$ is true in one of the following two conditions.
* f$_1$ holds at the current time and (f$_1$ U f$_2$) holds at the next time step, or
* f$_2$ holds at the current time step
The two cases can be encoded by creating two states (nodes) of the automaton and the automaton may non-deterministically jump to either of them. In the first case, we have offloaded a part of burden of proof in the next time step therefore we also create another state (node) that will carry the obligation for next time step in its label.
We also need to consider temporal operator R that may cause such case split. f$_1$ R f$_2$ is equivalent to ( f$_1$ ∧ f$_2$) ∨ ( f$_2$ ∧ X(f$_1$ R f$_2$) ) and this equivalent expansion suggests that f$_1$ R f$_2$ is true in one of the following two conditions.
* f$_2$ holds at the current time and (f$_1$ R f$_2$) holds at the next time step, or
* ( f$_1$ ∧ f$_2$) holds at the current time step.
To avoid many cases in the following algorithm, let us define functions curr1, next1 and curr2 that encode the above equivalences in the following table.
| f | curr1(f) | next1(f) | curr2(f) |
| f$_1$ U f$_2$ | {f$_1$} | { f$_1$ U f$_2$ } | {f$_2$} |
| f$_1$ R f$_2$ | {f$_2$} | { f$_1$ R f$_2$ } | {f$_1$,f$_2$} |
| f$_1$ ∨ f$_2$ | {f$_2$} | ∅ | {f$_1$} |
We have also added disjunction case in the above table since it also causes a case split in the automaton.
Following are the two steps of the algorithm.

#### Step 1. create_graph

In the following box, we present the first part of the algorithm that builds a directed graph. create_graph is the entry function, which expects the input formula f in the negation normal form. It calls recursive function expand that builds the graph by populating global variables Nodes, Incoming, Now, and Next. The set Nodes stores the set of nodes in the graph. The map Incoming maps each node of Nodes to a subset of Nodes ∪ {init}, which defines the set of incoming edges. Incoming of a node may also contain a special symbol init that is used in the final automaton construction to decide the set of initial states. Now and Next map each node of Nodes to a set of LTL formulas. For a node q, Now(q) denotes the set of formulas that must be satisfied by the rest of the input word if the automaton is currently at node(state) q. Next(q) denotes the set of formulas that must be satisfied by the rest of the input word if the automaton is currently at the next node(state) after q.
The code of expand is labelled with line numbers for easy reference. Each call to expand aims to add a node and its successors nodes in the graph. The parameters of the call describes a potential new node.
* The first parameter curr contains the set of formulas that are yet to be expanded.
* The second parameter old contains the set of formulas that are already expanded.
* The third parameter next is the set of the formula using which successor node will be created.
* The fourth parameter incoming defines set of incoming edges when the node is added to the graph.
At line 1, the if condition checks if curr contains any formula to be expanded. If the curr is empty then at line 2 the if condition checks if there already exists a state q' with same set of expanded formulas. If that is the case, then we do not add a redundant node, but we add parameter incoming in Incoming(q') at line 3. Otherwise, we add a new node q using the parameters at lines 5–9 and we start expanding a successor node of q using next(q) as its unexpanded set of formulas at line 10.
In the case curr is not empty, then we have more formulas to expand and control jumps from line 1 to 12. At lines 12–14, a formula f from curr is selected and moved to old. Depending on structure of f, the rest of the function executes.
* If f is a literal, then expansion continues at line 20, but if old already contains neg(f) or f=false, then old contains an inconsistent formula and we discard this node by not making any recursive all at line 18.
* If f = f$_1$ ∧ f$_2$, then f$_1$ and f$_2$ are added to curr and a recursive call is made for further expansion at line 22.
* If f = X f$_1$, then f$_1$ is added to next for the successor of the current node under consideration at line 24.
* If f = f$_1$ ∨ f$_2$, f = f$_1$ U f$_2$, or f = f$_1$ R f$_2$ then the current node is divided into two nodes and for each node a recursive call is made.
For the recursive calls, curr and next are modified using functions curr1, next1, and curr2 that were defined in the above table.

#### Step 2. LGBA construction

Let (Nodes, Now, Incoming) = create_graph(f). An equivalent LGBA to f is A=(Nodes, 2$^{AP}$, L, Δ, Q$_0$, F), where
* L = { (q,a) | q ∈ Nodes and (Now(q) ∩ AP) ⊆ a ⊆ {p ∈ AP | ¬p ∉ Now(q) } }
* Δ = {(q,q')| q,q' ∈ Nodes and q ∈ Incoming(q') }
* Q$_0$ = { q ∈ Nodes | init ∈ Incoming(q) }
* For each sub-formula g = g$_1$ U g$_2$, let F$_g$ = { q ∈ Nodes | g$_2$ ∈ Now(q) or g ∉ Now(q) }, then F = { F$_g$ | g ∈ cl( f ) }
Note that node labels in the algorithmic construction do not contain negation of sub-formulas of f. In the declarative construction a node has the set of formulas that are expected to be true. The algorithmic construction ensures the correctness without the need of all the true formulas to be present in a node label.

## Tools

* Spot's LTL2TGBA - LTL2TGBA translator included in C++ library SPOT. Online translator available.
* LTL2BA - Fast LTL to BA translator via alternating automata. Online translator available.
* LTL3BA - An up-to-date improvement of LTL2BA.
* Owl's LTL2NBA - LTL2NBA translator included in Java library Owl. Online translator available.