Skip to main content

Temporal Logic: LTL and CTL, how to express "eventually" and "always"

Linear Temporal Logic (LTL) and branching-time temporal logic (CTL): formal semantics, temporal operators, liveness and safety properties.

What do you think about this article?

Temporal Logic: LTL and CTL, how to express "eventually" and "always"
Formal Methodsfedericocalo.dev

At a Glance

Linear Temporal Logic (LTL) and branching-time temporal logic (CTL): formal semantics, temporal operators, liveness and safety properties.

Classical propositional logic cannot express properties that change over time: you cannot write "this request will eventually receive a response" or "the system never deadlocks". Temporal logics add operators for the future, past, and inevitability. Two dialects dominate practice: LTL (Linear Temporal Logic) and CTL (Computation Tree Logic). LTL reasons about a single execution path (the "ideal trace" of behavior), while CTL reasons about all paths simultaneously using path quantifiers. This distinction is foundational to modern model checking: with LTL and CTL, you formally declare the behavior you want from a concurrent system and automatically verify that an implementation satisfies it.

Historical context and formalization

Amir Pnueli introduced Linear Temporal Logic in 1977 to solve a concrete problem: how to rigorously reason about infinite behaviors of interactive programs (operating systems, communication protocols)? Classical logic asserts facts true or false in one state; Pnueli declared properties over infinite sequences of states. In 1981, Edmund M. Clarke and E. Allen Emerson developed CTL and the first practical model checking algorithm (on finite automata and CTL formulas): exhaustive search over a model's state space to verify a temporal property. Joseph Sifakis worked in parallel on CTL*. Their contribution earned the 2007 Turing Award "for their invention of automated techniques for the verification that systems operate correctly." By the 1990s and 2000s, model checking became industrial: hardware verification at Intel, communication protocols, critical software. Tools like Spin (LTL, Gerard Holzmann 1989) and NuSMV (CTL, Pistore et al. 1998) remain standard today.

Outline of the series

This article in the Formal Methods series explores temporal logics as the foundation for property specification. You will learn:

  1. Limitations of classical propositional logic for temporal properties
  2. Basic temporal operators: X (next), F (future), G (globally), U (until), R (release)
  3. Formal definition of LTL on linear traces
  4. Formal definition of CTL on Kripke structures
  5. Critical differences between LTL and CTL: expressiveness and decidability
  6. Safety and liveness properties: how to recognize and formalize them

Limits of classical logic and why temporal logics exist

Classical propositional logic is atemporal: a formula Φ is true or false in an isolated state. Examples:

  • request → response asserts "if there is a request, there is a response" in the same instant.
  • You cannot express: "after a request, a response will eventually arrive".
  • You cannot express: "a resource remains free until it is acquired".

In concurrent and reactive systems, behavior unfolds over time as an infinite sequence of states (a "trace" s₀, s₁, s₂, ...). Temporal logics add operators that refer to future (and possibly past) states from an observation point. Two principal approaches exist:

  • LTL (Linear Temporal Logic): reasons about a single "timeline". Formula φ is true on a trace if φ holds in that sequence of states.
  • CTL (Computation Tree Logic): reasons about a tree of executions. The model has multiple possible paths (nondeterminism); φ is true on the model if the paths satisfying φ are exactly those we want (with "for all paths" ∀ or "exists a path" ∃ quantifiers).

Basic temporal operators

Both logics use the same base operators, interpreted differently at the level of traces vs. trees:

  • X φ (neXt): φ holds in the immediately next state.
  • F φ (Finally/Future): φ holds in some future state (including the present).
  • G φ (Globally/Always): φ holds in all future states (including the present).
  • φ U ψ (Until): φ holds until ψ becomes true (ψ must occur in finite time).
  • φ R ψ (Release): ψ holds until φ becomes true (or ψ holds forever if φ never occurs). Dual of Until.

Recurring specification patterns. In practice, properties organize into semantic patterns that recur across nearly all protocols:

  • Safety ("bad things never happen"): G ¬bad. Examples: AG ¬crash, AG ¬(lock₁ ∧ lock₂) (mutual exclusion). If violated, counterexample is finite.
  • Liveness ("good things eventually happen"): F good or GF good (infinitely often). Examples: AF success, GF grant (fairness). Counterexample is infinite (bad cycle).
  • Response ("if X then eventually Y"): G (X → F Y). Example: G (request → F response) (every request receives response).
  • Precedence ("Y only after X"): ¬Y U (X ∨ ¬X) (Y never occurs before X), or G (Y → F⁻¹ X) (in LTL with past). Example: ¬write U initialize (write only after system initializes).
  • Fairness ("no process starvation"): GF enabled → GF executed. If an action remains enabled infinitely often, it must execute infinitely often. Distinguishes starvation (bad) from fairness (good).

Examples in prose and notation:

  • "The system never deadlocks": G ¬deadlock
  • "After a request, a response eventually arrives": request → F response (if request is true in one state, then F response holds from that point)
  • "A resource remains free until acquired": free U acquired
  • "The error state is eventually reachable (liveness)": F error

LTL formalized: semantics on linear traces

A trace is an infinite sequence of states σ = s₀, s₁, s₂, .... Each state sᵢ is a truth assignment over propositions (which propositions are true in that moment). Formally, a trace is a function σ: ℕ → 2^P, where P is the set of propositions.

LTL semantics: A formula φ is satisfied by a trace σ (written σ ⊨ φ) iff:

σ ⊨ p                iff  p ∈ σ(0)                      (p is true in initial state)
σ ⊨ ¬φ               iff  σ ⊭ φ
σ ⊨ φ ∧ ψ            iff  σ ⊨ φ  AND  σ ⊨ ψ
σ ⊨ X φ              iff  σ[1:] ⊨ φ                    (σ[1:] is trace from second state)
σ ⊨ F φ              iff  ∃i ≥ 0 : σ[i:] ⊨ φ           (some future state)
σ ⊨ G φ              iff  ∀i ≥ 0 : σ[i:] ⊨ φ           (all future states)
σ ⊨ φ U ψ            iff  ∃i ≥ 0 : (σ[i:] ⊨ ψ) ∧ (∀0 ≤ j < i : σ[j:] ⊨ φ)
                           (φ holds until first state where ψ holds)

Concrete example: Trace of a communication protocol:

s₀: idle
s₁: idle
s₂: request
s₃: wait
s₄: response
s₅: idle
s₆: ...

Verify request → F response on this trace:

  • σ ⊨ request → F response iff whenever request ∈ s_i, then F response holds from s_i
  • In states s₀, s₁, s₅, request is false, so the implication holds (vacuously).
  • In s₂, request is true. Does F response hold from s₂? I.e., does response ∈ s_j for some j ≥ 2? Yes, response ∈ s₄. So the implication holds in s₂.
  • Conclusion: the trace satisfies the property.

CTL formalized: semantics on Kripke structures

A Kripke structure models not a single trace, but all possible executions of a system. It is a directed graph:

M = (S, →, s₀, L)
S     = set of states
→     = transition relation (s → s' if we can go from s to s')
s₀    = initial state
L     = labeling function S → 2^P (which propositions are true in each state)

A path (trace) in a Kripke structure is an infinite sequence π = s₀, s₁, s₂, ... where sᵢ → sᵢ₊₁ for each i.

CTL semantics: Adds path quantifiers A (for All paths) and E (Exists path):

M, s ⊨ A φ           iff  for all paths π starting from s, π ⊨ φ
M, s ⊨ E φ           iff  there exists a path π starting from s such that π ⊨ φ

In CTL, operators X, F, G, U are always preceded by a quantifier:

AX φ    = on all paths, the next state satisfies φ
EX φ    = there exists a path where the next state satisfies φ
AF φ    = on all paths, φ eventually holds
EF φ    = there exists a path where φ eventually holds
AG φ    = on all paths, φ always holds
EG φ    = there exists a path where φ always holds

Concrete execution trace: step-by-step on a Kripke structure. Consider this system: a client-server protocol where the client can decide to request, the server responds, or the system enters a faulted state. Model:

Kripke structure: M = (S, →, s₀, L)

S = {idle, requesting, processing, done, faulted}
→:
  idle →request→ requesting
  idle →fault→ faulted
  requesting →process→ processing
  processing →complete→ done
  done →reset→ idle
  faulted →reset→ idle

L(idle) = {ready}
L(requesting) = {pending}
L(processing) = {working}
L(done) = {success}
L(faulted) = {error}

Verify CTL property: AG ¬error (system never enters a faulted state on any path)

Verification steps:

Examine path: idle →request→ requesting →process→ processing →complete→ done →reset→ idle → ... (good loop)

  • Step 1 (idle): error ∈ L(idle)? No. ¬error holds? Yes. Continue.
  • Step 2 (requesting): error ∈ L(requesting)? No. ¬error? Yes. Continue.
  • Step 3 (processing): error ∈ L(processing)? No. ¬error? Yes. Continue.
  • Step 4 (done): error ∈ L(done)? No. ¬error? Yes. Continue.
  • Loop.

Exists a "bad" path: idle →fault→ faulted → ... On this path, error ∈ L(faulted), so ¬error is false. Thus, it is not true that AG ¬error (on **all** paths, error never happens). The property is violated.

Key observation: CTL requires the property to hold on **all** paths. If even one path violates it, the model fails. LTL, by contrast, verifies a single trace (ideal execution) and checks that no trace violates the property.

Example on a simple structure (3 states, nondeterminism):

Kripke:
s₀ -(a)→ s₁ -(b)→ s₂
 ↓ (c)
s₃ -(a)→ s₁

Labeling:
L(s₀) = {start}
L(s₁) = {busy}
L(s₂) = {done}
L(s₃) = {}

Verify some properties:

  • AG ¬(busy ∧ done): "on all paths, busy and done never hold simultaneously". Check: s₂ has only "done", s₁ has only "busy", none have both. ✓
  • EF done: "there exists a path where done eventually holds". Yes: s₀ -(a)→ s₁ -(b)→ s₂ (done ∈ s₂). ✓
  • AF done: "on all paths, done eventually holds". False! Path s₀ -(c)→ s₃ -(a)→ s₁ -(a)→ ... might cycle without reaching s₂. ✗

Critical differences between LTL and CTL: incommensurable expressiveness

1. Expressiveness and incommensurability:

LTL and CTL are incommensurable: neither is more expressive than the other. There are properties expressible in CTL but not LTL, and vice versa.

Formula expressible in CTL but not LTL: Consider AG EF p (from every reachable state, there always exists a path leading to state where p holds). This formula speaks of branching: from each state, there must exist a path reaching p. LTL lacks the "exists-path" operator (E), so cannot express this. The closest in LTL is GF p (infinitely often p), which is much weaker.

Formula expressible in LTL but not CTL: Consider F (p ∧ F q) (eventually p occurs, and from that point eventually q). This speaks of linear sequences without path quantifiers. To express in CTL, you write AF (p ∧ AF q), which asserts something stronger: on all paths, first p then q. If the system has nondeterministic choices, the meaning changes: LTL allows some paths reaching (p and then q), while CTL demands all paths do so. Thus F (p ∧ F q) is not translatable to CTL without losing semantics.

Didactic consequence: When specifying a property, you cannot say "use CTL or LTL interchangeably". The choice is semantic. CTL suits systems with explicit choices and meaningful nondeterminism (scheduling, protocols with backtrack). LTL suits properties of "linear" behavior (ideal sequences of actions).

CTL* as unification: The logic CTL* allows path quantifiers (A, E) followed by arbitrary LTL formulas. Syntax:

A φ             (on all paths, φ holds)
E φ             (there exists a path where φ holds)
where φ is any LTL formula (with X, F, G, U)

CTL* is strictly more expressive than both LTL and CTL: it contains both as subsets. But it costs complexity: CTL* model checking is EXPTIME-complete (vs. polynomial for CTL). This is why industrial practice prefers CTL (fast) or LTL (expressive) depending on context, using CTL* only when necessary.

2. Decidability and complexity:

  • CTL model checking: O(|M| × |φ|), where |M| is the Kripke size and |φ| is the formula length. Polynomial!
  • LTL model checking: O(|M| × 2^|φ|). The formula converts to an automaton, the translation is exponential. But remains tractable in practice (formulas are small).

3. When to choose which?

  • CTL if the model has explicit nondeterministic choices (system may pick among paths) and you want to reason about "which path the system **must** take to satisfy the property".
  • LTL if you reason about a single "ideal execution" and want to verify no way exists to violate it.

Safety and liveness properties

Safety ("bad things never happen"): A property asserting "something bad never occurs".

  • Form: G ¬bad or equivalently ¬F bad
  • Examples: G ¬crash, G ¬(lock₁ ∧ lock₂) (mutual exclusion), G (request → ¬X X ¬response).
  • Characteristic: if violated, the counterexample is finite (badness occurs at a specific point).

Liveness ("good things eventually happen"): A property asserting "something good occurs eventually".

  • Form: F good or GF good (infinitely often)
  • Examples: F response (a response will arrive), GF granted (access granted infinitely often = fairness).
  • Characteristic: the counterexample is infinite (system remains in a "bad" region or enters a cycle not including "good").

Mixed properties: G (request → F response) combines safety and liveness: it is bad to not respond to a request (safety), and good to eventually respond (liveness).

Trade-off reasoning

I chose to present LTL before CTL (simple to complex, linear before branching) rather than vice versa, because LTL is didactically more direct: you reason on a sequence, not a tree of paths. CTL adds complexity with quantifiers but gains computational efficiency for model checking. In industrial practice, CTL is often preferred because the model checker is polynomial, while LTL requires automaton conversion. Those working with well-defined sequences prefer LTL; those verifying concurrent systems with explicit choices prefer CTL. CTL* unifies both, but its complexity falls to LTL's level (exponential).

Advanced connections

Finite automata on infinite words (Büchi automata): Every LTL formula translates to a Büchi automaton (automaton accepting infinite words by visiting accepting states infinitely often). The translation is exponential but makes satisfiability (SAT) equivalent to automaton emptiness testing.

Modal mu-calculus (Lμ): Even more expressive logic based on fixed points (least and greatest). CTL is a subset of mu-calculus. All formalisms (LTL, CTL, mu-calculus) are equivalent in expressive power for properties on infinite structures, but differ in complexity and practicality.

SAT and SMT solving: Modern model checkers (such as smvConfig, mCRL2) use SAT/SMT solvers instead of exhaustive search to handle huge state spaces (bounded model checking: search for counterexamples of bounded length).

Pitfalls and common errors

  • Confusing LTL with "propositions in the future". LTL talks about infinite sequences, not probability. F p means "p **certainly** occurs at some future point", not "p occurs with probability > 0".
  • Underestimating path quantifier power. EX p and AX p are completely different. The first says "there exists an execution where next state has p"; the second "all executions have p in next state".
  • Using F for "within N steps". F p has no time limit. If you want "p within 5 steps", translate as p ∨ X(p ∨ X(p ∨ ...)) (5 times), or use LTL bounds F[0,5] p (LTL extension).
  • Forgetting traces are infinite. Some systems terminate (final states remain). Then "infinite" means the last state repeated forever.
  • Misinterpreting counterexamples. If a model checker says "AG p is false", the counterexample is a path where p becomes false. Read the path step by step to see where the property breaks.

Advanced exercises

  1. Formalize a property: Write in CTL and LTL: "If a request arrives, it must be processed in one instant and a response must return within 3 instants." (Hint: use sequences of X, or bounded LTL if available.)
  2. Distinguish safety from liveness: For each formula, classify: (a) AG ¬error, (b) AF success, (c) GF fairness, (d) A(p U q).
  3. Verify on simple structure: Build a 4-state Kripke (e.g., traffic light: red, yellow, green, broken). Manually verify: AG ¬(red ∧ green), EF broken, AF green.
  4. LTL to automaton translation: Convert F p to a Büchi automaton (draw states and transitions).
  5. Complexity: Calculate model checking complexity for a 10-symbol CTL formula on a 1000-state Kripke. How long would it take (order of magnitude)?

Essential bibliography

  • Jiacun Wang, William C. Tepfenhart, Formal Methods in Computer Science, CRC Press, 2019. (Chapters 7-8 on LTL and CTL).
  • Edmund M. Clarke, Orna Grumberg, Doron Peled, Model Checking, MIT Press, 1999. (Bible of the discipline).
  • Christel Baier, Joost-Pieter Katoen, Principles of Model Checking, MIT Press, 2008. (Modern, 966 pages, covers LTL/CTL/mu-calculus).
  • Amir Pnueli, "The temporal logic of programs", 18th Annual Symposium on Foundations of Computer Science, 1977. (Foundational paper on LTL).
  • Edmund M. Clarke, E. Allen Emerson, "Design and synthesis of synchronization skeletons using branching-time temporal logic", Logics of Programs, LNCS 131, 1981. (Foundational paper on CTL).
  • Gerard J. Holzmann, The SPIN Model Checker: Primer and Reference Manual, Addison-Wesley, 2003. (Practical guide to Spin, LTL tool).

Technical prerequisites

  • Propositional logic: ∧, ∨, ¬, →, ↔.
  • Notion of transition structure and trace (introduced in previous article of the series, 1722).
  • Basic set theory: relations, functions, infinite sequences.
  • Familiarity with finite automata (optional, but useful for understanding Büchi automata).
  • Python: networkx to model Kripke; itertools for sequences.

Related resources

Article published 2026-10-04, graduate level.

Commenti

Caricamento commenti...

Sign in to comment

Discuss this article in the community

Join the Telegram group to discuss with other developers, ask questions and share your experiences.

Did you like this article?

Explore other content on the blog or discover my projects