Denotational Semantics

Denotational Semantics

Advanced Seminar Softwareengineering - Denotational semantics Klemens Muthmann Tutor Steffen Zschaler 1. INTRODUCTION 2.2 What is the meaning of denotational se- This text gives some basic knowledge about denotational mantics semantics. It is intended as a rough but hopefully broad To get an impression of what denotational semantics is you overview of the topic. have to analyze know what the two words ’denotational’ and ’semantics’ stand for. While reading it, one might acquire the needed background knowledge. To get this knowledge it might be necessary to consult additional material. Everytime this is needed a hint 2.2.1 Semantics will be given. What someone wants if he talks about semantics is to assign a meaning to an otherwise meaningless expression. Lets The reader of the text should definitely know about the give an example. I could say: “Das Ergebnis von vier plus concepts of syntax. He should have heard about semantics. vier ist acht.” and because I am german I would know the meaning of this sentence. But a person only speaking english needs me to give him the semantics which actually would be 2. WHATIS DENOTATIONAL SEMANTICS ’4 + 4 = 8’. Of course this is only another notation and strictly speaking we still have syntax here. Semantics are There are three main formalisms for defining the seman- what something means in your head or in the circuits of a tics of programing languages. These formalisms are the ax- computer but somewhere we need to make a point. This iomatic semantics, the operational semantics and the de- point should be made, when everyone who needs to, knows notational semantics. The axiomatic and the operational about what is meant by the expression. The rest I will leave semantics are also called definitional semantics. The deno- to the philosophers. tational semantics is the one you will read about now. It tries to translate mathematical objects into programs. 2.2.2 Denotational The word ’denotational’ comes from ’to denote’ but there is 2.1 What is it needed for? not much more you can take from this. Denotational semantics is needed by programmers and mostly by compiler and compiler-compiler builders. The seman- But what are they denoting? Well if you want to analyze tics of many programming languages were and are only in- the semantics of a computable program such a program in formally specified in natural language. Because of natural the simplest case takes some input, processes it and produces language being sometimes abigous, this leads to problems some output. If one of these three steps is missing you have a while implementing these languages. Formal notations, like very boring program either doing nothing, producing always the BNF-Notation, make the syntax of code easy to describe. the same or not giving any information. Formal notations of the semantics would also make the prov- ing of the correctness more easy. Denotational semantics So you get - with some borrowing from axiomatic notation gives a mathematical formalism to specify the meaning of - something which Allison (All89) notes the following way: syntax and thus solves these issues. {I}P rogram{O} Allision (All89) describes briefly how to implement a parser Well but if you rewrite this to P rogram(I) = O you get a for denotational semantics. He shows practical implemen- very familiar notation, which can be abstracted to f(x) = y. tations of compiler-compilers for a subset of PASCAL and So a program is nothing else than an algorithm for a mathe- PROLOG. matical function. The problem with mathematical functions is that they are usually infinite mappings of input to output, Denotational semantics worth for programmers is limited which is not usable by computers. since the rules are very complex applied to a specific pro- gram. It is however conceivable to run proves of programs. To express that a program is only a partial mapping and This way you can guarantee the correctness of critical pro- not the whole function, which is expressed by its semantics, grams or program parts and find difficult bugs in complex we can say that the total mathematical function denotes the programs. partial function of the algorithm implemented by a program. 1 A program is a partial function denoted by a total func- represents this computation you simply would write: tion from input to output. Now you know why it is called f(x) = (x + x)2 denotational semantics. But for λ-calculus there is no difference between x and 2. This can be driven even further. A program consists of They are only symbols without any meaning1. To do the statements and expressions and the like. Each of these are abstraction step above you have to bind the desired variable also simple mappings or functions. They map from one state to a λ. So that the term: of the program, before the execution of the statement to 2 another after the execution. What a state is is not important (x + x) now and will be explained later. You should only understand can be abstract the following way: that everything, that you write down while you are writing a 2 program is - in terms of denotational semantics - a function λx.(x + x) and even functions are composed of other functions. or λ2.(2 + 2)x 3. THE λ CALCULUS Before delving now into the depths of denotational semantics Looks a little weird but you will get familiar with this soon. you should know about another concept, very often used to write down its rules. As meta language for denotational se- The term (3) is called application and means that some ar- mantics, the basics of the lambda calculus will be presented gument is applied to a λ-term. For instance: here. But note that lambda calculus is, though the most f2 ≡ (λx.(x + x)2)2 widely spread, only one meta language for denotational se- mantics. applies 2 to f. Now let us see some other examples of valid λ terms: Informally saying lambda calculus is a very simple but also very powerful method of writing down functions. c x (xc)(λx.(xc)) (y(λx.(xc))) ((λv.(vc))y) More formally spoken it is a formal model similar to func- tional programming languages. This relation is similar to Such terms, which you can define yourselves, are the axioms that of the Turing Machine’s to imperative programming of the calculus. languages. 3.1 Currying Well but what is a calculus? A calculus consists according A problem you get with the basic λ-calculus is that you can (aut) to out of the following two parts: not define functions of more than one variable. • A language for the calculus, which means: Consider – an alphabet of the basic symbols plus(x, y) = x + y – a definition of the well-formed expressions which is only expressible with two nested λ-terms. • A deduction framework, consisting of: plus = λx.(λy.x + y) – axioms out of the well formed expressions of the But was does this mean? To calculate the sum of 2 and 3 language (terms) with the function plus you can directly add the two numbers or you can construct a function p1 which returns a function – deduction rules for transforming expressions p2 that adds a variable to a constant. Now you can call p1 with the argument 2 and get a function that adds something The language formulated as abstract syntax in BNF looks to 2. The second function called with 3 now adds 2 and 3 the following way as presented in (Feh89): produces the desired output 5. Λ ::=C| (1) plus : N × N 7→ N V| (2) p1 : N 7→ (N 7→ N) ΛΛ| (3) λV.Λ (4) p1(2) = p2(y) = 2 + y The C is an arbitrary constant (c,d,e. ), V a variable (x, y, z, . .) p2(3) = 5 and Λ an arbitrary λ-term (M,N,L,. ). This concept is called currying after Haskel B. Curry and was invented by the mathematician Sch¨onfinkel. The term (4) is called abstraction. This abstraction can be understood the following way. The function More formally spoken currying works the following way: 2 f = (2 + 2) (A × B) 7→ C ≡ A 7→ (B 7→ C) is the constant function with the value 16. It is very con- 1To simplify notation we will assume that literals such as crete because there is only one value as solution of the com- 2 will have the usual meaning but strictly spoken they are putation. To express a more general function which also only meaningless symbols in λ calculus. 2 Such functions that do return other functions are called names of variables in λ calculus are only symbols and can higher-order functions. They are seen very often while work- be changed without changing the semantics of the λ-term. ing with denotational semantics. But for the λ-calculus this is a little bit annoying so for simplicity we define: Consider: λx1.(λx2.(... (λxn.M))) ≡ λx1 x2 . λxn.M (λy.(λx.x y))x if you apply β-reduction to this lambda term the count 3.2 Bound and free variables of free variables in the remaining term drops from 1 to 0. λ-expressions contain two types of variables. One type is Abruptly x is occurring two times inside the λ-term. This bound by λ’s and the other is free. The free variables are should not happen because the x outside the brackets is not like global ones in programming languages, while the bound the same as the one inside. are the parameters of a function. Using α-conversion each variable that is used two times in Consider one λ-term is renamed to show their different meanings.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us