Denotational semantics
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[1][2] or by games[3] 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 developmentDenotational semantics originated in the work of Christopher Strachey and Dana Scott published in the early 1970s.[1][2] As originally developed by Strachey and Scott, denotational semantics provided the meaning of a computer program as a function that mapped input into output.[2] 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,[4] CSP,[5] and Haskell.[6] 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 Meanings of recursive programsDenotational 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 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: int factorial(int n) { if (n == 0) then return 1; else return n * factorial(n-1); }
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. , starting with the empty function (empty set). F could be defined in code as follows (using int factorial_nonrecursive(Map<int,int> factorial_less_defined, int n)
{
if (n == 0) then return 1;
else if (fprev = lookup(factorial_less_defined, n-1)) then
return n * fprev;
else
return NOT_DEFINED;
}
Map<int,int> F(Map<int,int> factorial_less_defined)
{
Map<int,int> new_factorial = Map.empty();
for (int n in all<int>()) {
if (f = factorial_nonrecursive(factorial_less_defined, n) != NOT_DEFINED)
new_factorial.put(n, f);
}
return new_factorial;
}
Then we can introduce the notation Fn to indicate F applied n times.
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 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 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 programsThe 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.[7] Denotational semantics of concurrencyMany 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;[8] and the work by Francez, Hoare, Lehmann, and de Roever (1979) on trace semantics for CSP.[9] All these lines of inquiry remain under investigation (see e.g. the various denotational models for CSP[5]). Recently, Winskel and others have proposed the category of profunctors as a domain theory for concurrency.[10][11] Denotational semantics of stateState (such as a heap) and simple imperative features can be straightforwardly modeled in the denotational semantics described above. The key idea is to consider a command as a partial function on some domain of states. The meaning of " Things become more difficult in modelling programs with local variables. One approach is to no longer work with domains, but instead to interpret types as functors from some category of worlds to a category of domains. Programs are then denoted by natural continuous functions between these functors.[12][13] Denotations of data typesMany programming languages allow users to define recursive data types. For example, the type of lists of numbers can be specified by datatype list = Cons of nat * list | Empty
This section deals only with functional data structures that cannot change. Conventional imperative programming languages would typically allow the elements of such a recursive list to be changed. For another example: the type of denotations of the untyped lambda calculus is datatype D = D of (D → D)
The problem of solving domain equations is concerned with finding domains that model these kinds of datatypes. One approach, roughly speaking, is to consider the collection of all domains as a domain itself, and then solve the recursive definition there. Polymorphic data types are data types that are defined with a parameter. For example, the type of α datatype α list = Cons of α * α list | Empty
Lists of natural numbers, then, are of type Some researchers have developed domain theoretic models of polymorphism. Other researchers have also modeled parametric polymorphism within constructive set theories. A recent research area has involved denotational semantics for object and class based programming languages.[14] Denotational semantics for programs of restricted complexityFollowing the development of programming languages based on linear logic, denotational semantics have been given to languages for linear usage (see e.g. proof nets, coherence spaces) and also polynomial time complexity.[15] Denotational semantics of sequentialityThe problem of full abstraction for the sequential programming language PCF was, for a long time, a big open question in denotational semantics. The difficulty with PCF is that it is a very sequential language. For example, there is no way to define the parallel-or function in PCF. It is for this reason that the approach using domains, as introduced above, yields a denotational semantics that is not fully abstract. This open question was mostly resolved in the 1990s with the development of game semantics and also with techniques involving logical relations.[16] For more details, see the page on PCF. Denotational semantics as source-to-source translationIt is often useful to translate one programming language into another. For example, a concurrent programming language might be translated into a process calculus; a high-level programming language might be translated into byte-code. (Indeed, conventional denotational semantics can be seen as the interpretation of programming languages into the internal language of the category of domains.) In this context, notions from denotational semantics, such as full abstraction, help to satisfy security concerns.[17][18] AbstractionIt is often considered important to connect denotational semantics with operational semantics. This is especially important when the denotational semantics is rather mathematical and abstract, and the operational semantics is more concrete or closer to the computational intuitions. The following properties of a denotational semantics are often of interest.
For semantics in the traditional style, adequacy and full abstraction may be understood roughly as the requirement that "operational equivalence coincides with denotational equality". For denotational semantics in more intensional models, such as the actor model and process calculi, there are different notions of equivalence within each model, and so the concepts of adequacy and of full abstraction are a matter of debate, and harder to pin down. Also the mathematical structure of operational semantics and denotational semantics can become very close. Additional desirable properties we may wish to hold between operational and denotational semantics are:
CompositionalityAn important aspect of denotational semantics of programming languages is compositionality, by which the denotation of a program is constructed from denotations of its parts. For example, consider the expression "7 + 4". Compositionality in this case is to provide a meaning for "7 + 4" in terms of the meanings of "7", "4" and "+". A basic denotational semantics in domain theory is compositional because it is given as follows. We start by considering program fragments, i.e. programs with free variables. A typing context assigns a type to each free variable. For instance, in the expression (x + y) might be considered in a typing context (x:
Now, the meaning of the compound expression (7+4) is determined by composing the three functions 〚⊢7: In fact, this is a general scheme for compositional denotational semantics. There is nothing specific about domains and continuous functions here. One can work with a different category instead. For example, in game semantics, the category of games has games as objects and strategies as morphisms: we can interpret types as games, and programs as strategies. For a simple language without general recursion, we can make do with the category of sets and functions. For a language with side-effects, we can work in the Kleisli category for a monad. For a language with state, we can work in a functor category. Milner has advocated modelling location and interaction by working in a category with interfaces as objects and bigraphs as morphisms.[20] Semantics versus implementationAccording to Dana Scott (1980):[21]
According to Clinger (1981):[22]: 79
Connections to other areas of computer scienceSome work in denotational semantics has interpreted types as domains in the sense of domain theory, which can be seen as a branch of model theory, leading to connections with type theory and category theory. Within computer science, there are connections with abstract interpretation, program verification, and model checking. References
Further reading
External linksThe Wikibook Haskell has a page on the topic of: Denotational semantics
|