ArticleslgStudy

computer science

Denotational semantics

Denotational semantics is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Denotational semantics rather than just read about it. In short: In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called denotations) that describe the meanings of expressions from the languages. Other approaches providing formal semantics of programming languages include axiomatic semantics and operational se…

Key takeaways

  • Denotational semantics belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Denotational semantics to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Denotational semantics from memory before moving on to harder problems.

Reference excerpt

In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called denotations) that describe the meanings of expressions from the languages. Other approaches providing formal semantics of programming languages include axiomatic semantics and operational semantics. Broadly speaking, denotational semantics is concerned with finding mathematical objects called domains that represent what programs do. For example, programs (or program phrases) might be represented by partial functions or by games between the environment and the system. An important tenet of denotational semantics is that semantics should be compositional: the denotation of a program phrase should be built out of the denotations of its subphrases.

Historical development Denotational semantics originated in the work of Christopher Strachey and Dana Scott published in the early 1970s. As originally developed by Strachey and Scott, denotational semantics provided the meaning of a computer program as a function that mapped input into output. To give meanings to recursively defined programs, Scott proposed working with continuous functions between domains, specifically complete partial orders. As described below, work has continued in investigating appropriate denotational semantics for aspects of programming languages such as sequentiality, concurrency, non-determinism and local state. Denotational semantics has been developed for modern programming languages that use capabilities like concurrency and exceptions, e.g., Concurrent ML, CSP, and Haskell. The semantics of these languages is compositional in that the meaning of a phrase depends on the meanings of its subphrases. For example, the meaning of the applicative expression f(E1,E2) is defined in terms of semantics of its subphrases f, E1 and E2. In a modern programming language, E1 and E2 can be evaluated concurrently and the execution of one of them might affect the other by interacting through shared objects causing their meanings to be defined in terms of each other. Also, E1 or E2 might throw an exception which could terminate the execution of the other one. The sections below describe special cases of the semantics of these modern programming languages.

Meanings of recursive programs Denotational semantics is ascribed to a program phrase as a function from an environment (holding current values of its free variables) to its denotation. For example, the phrase n*m produces a denotation when provided with an environment that has binding for its two free variables: n and m. If in the environment n has the value 3 and m has the value 5, then the denotation is 15. A function can be represented as a set of ordered pairs of argument and corresponding result values. For example, the set {(0,1), (4,3)} denotes a function with result 1 for argument 0, result 3 for the argument 4, and undefined otherwise. Consider for example the factorial function, which might be defined recursively as:

To provide a meaning for this recursive definition, the denotation is built up as the limit of approximations, where each approximation limits the number of calls to factorial. At the beginning, we start with no calls - hence nothing is defined. In the next approximation, we can add the ordered pair (0,1), because this doesn't require calling factorial again. Similarly we can add (1,1), (2,2), etc., adding one pair each successive approximation because computing factorial(n) requires n+1 calls. In the limit we get a total function from ℕ to ℕ defined everywhere in its domain. Formally we model each approximation as a partial function ℕ⇀ℕ. Our approximation is then repeatedly applying a function implementing "make a more defined partial factorial function", i.e. F:(ℕ⇀ℕ)→(ℕ⇀ℕ), starting with the empty function (empty set). F could be defined in code as follows (using Map<int,int> for ℕ⇀ℕ):

Then we can introduce the notation Fn to indicate F applied n times.

F0({}) is the totally undefined partial function, represented as the set {}; F1({}) is the partial function represented as the set {(0,1)}: it is defined at 0, to be 1, and undefined elsewhere; F5({}) is the partial function represented as the set {(0,1), (1,1), (2,2), (3,6), (4,24)}: it is defined for arguments 0,1,2,3,4. This iterative process builds a sequence of partial functions from ℕ to ℕ. Partial functions form a chain-complete partial order using ⊆ as the ordering. Furthermore, this iterative process of better approximations of the factorial function forms an expansive (also called progressive) mapping because each Fi≤Fi+1 using ⊆ as the ordering. So by a fixed-point theorem (specifically Bourbaki–Witt theorem), there exists a fixed point for this iterative process. In this case, the fixed point is the least upper bound of this chain, which is the full factorial function, which can be expressed as the union

⋃i∈ℕFi({}). The fixed point we found is the least fixed point of F, because our iteration started with the smallest element in the domain (the empty set). To prove this we need a more complex fixed point theorem such as the Knaster–Tarski theorem.

Denotational semantics of non-deterministic programs The concept of power domains has been developed to give a denotational semantics to non-deterministic sequential programs. Writing P for a power-domain constructor, the domain P(D) is the domain of non-deterministic computations of type denoted by D. There are difficulties with fairness and unboundedness in domain-theoretic models of non-determinism.

Denotational semantics of concurrency Many researchers have argued that the domain-theoretic models given above do not suffice for the more general case of concurrent computation. For this reason various new models have been introduced. In the early 1980s, people began using the style of denotational semantics to give semantics for concurrent languages. Examples include Will Clinger's work with the actor model; Glynn Winskel's work with event structures and Petri nets; and the work by Francez, Hoare, Lehmann, and de Roever (1979) on trace semantics for CSP. All these lines of inquiry remain under investigation (see e.g. the various denotational models for CSP). Recently, Winskel and others have proposed the category of profunctors as a domain theory for concurrency.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Denotational semantics

Start with the simplest possible case. Write down what Denotational semantics claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Denotational semantics before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Denotational semantics ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Denotational semantics

In research
Denotational semantics appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Denotational semantics in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Denotational semantics is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1970 in computing, Christopher Strachey, Dana Scott, so understanding it makes those chapters shorter.
In everyday life
Look for Denotational semantics outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Denotational semantics” →

How to study Denotational semantics in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Denotational semantics means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Denotational semantics out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Denotational semantics in simple terms?

In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called denotations) that describe the meanings of expressions from the langua…

Why does Denotational semantics matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Denotational semantics?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Denotational semantics.

Tags

  • 1970 in computing
  • Christopher Strachey
  • Dana Scott
  • Denotational semantics
  • Formal specification languages
  • Logic in computer science
  • Models of computation
  • Programming language semantics

Keep exploring