Denotational Semantics - PowerPoint PPT Presentation

About This Presentation
Title:

Denotational Semantics

Description:

Need to create a lifted domain from the Integers. ... Think of a recursive definition of a function as really naming two functions, ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 8
Provided by: josephn6
Learn more at: https://www.cise.ufl.edu
Category:

less

Transcript and Presenter's Notes

Title: Denotational Semantics


1
Denotational Semantics
  • The meaning of a program is given by specifying
    the function (from input to output) that
    corresponds to the program.
  • The denotational semantic definition, thus maps
    syntactical things into functions PProgram?Inp
    ut?Output
  • We need to specify each of these
  • Syntactic domains (describing program syntax
    elements that are assigned common valuation
    functions)
  • Semantic domains (that are used to express
    meanings of programs and their components).
  • Semantic functions (that map syntax into
    semantics)

2
Elements for The Expression Language
  • Syntactic DomainsE Expression N NumberD
    Digit
  • Semantic Domainsv Integer ...,-2,-1,0,1,2,...
    Operations Integer ? Integer ?
    Integer -Integer ? Integer ? Integer Integer
    ? Integer ? Integer
  • Semantic FunctionsE Expression ?
    IntegerEE1 E2 EE1 EE2EE1
    E2 EE1 EE2EE1 - E2
    EE1 - EE2E( E ) EEEN
    NNN Number ? IntegerNND
    10NN NDNND DDD Digit ?
    IntegerD0 0, D1 1, ... D9
    9

3
Adding an Environment to the Expression Language
  • Need to create a lifted domain from the Integers.
    A lifted domain has all the elements of some
    partially ordered domain together with a unique
    bottom element (?), that is less than any other
    element in the original domain. We call the
    lifted integers Integer?.
  • New Semantic DomainsEnv Environment
    Identifier ? Integer?
  • Modified Semantic FunctionsE Expression ?
    Environment ? Integer?EE1 E2(Env)
    EE1(Env) EE2 (Env) EE1
    E2(Env) EE1(Env) EE2(Env) EE1 -
    E2(Env) EE1(Env) - EE2(Env) E( E
    )(Env) EE(Env)EI(Env) Env(I)
    EN(Env) NNNote that E is now a
    higher-order function (when given an Expression,
    it yields a function mapping an Environment to an
    Integer). Such functions can be constructed from
    normal functions by Currying. This is useful in
    this context, because it lets us explain what the
    meaning of an expression is, no matter what the
    environment in which we evaluate that expression.

4
Adding Statements
  • New Syntactic DomainsL Statement-listS
    StatementI IdentifierL Letter
  • New Semantic FunctionsP Program ?
    EnvironmentPL LL(Env0))L
    Statement-list?Environment?EnvironmentLL1
    L2 LL2 ?LL1LS SSS
    Statement ? Environment ? EnvironmentSI
    E(Env) EnvI EE(Env)

5
Mathematics of Functional Programming
  • We can define a functionby extension (by
    providing the graph of the function, namely, the
    set of ordered pairs that represent the
    functions mapping) orby comprehension (by
    providing a rule that tells us how to calculate
    the value of the function at any point).
  • Consider the normal definition of the factorial
    function f(n) if n 0 then 1 else ng(n-1)
  • Think of a recursive definition of a function as
    really naming two functions, the function used in
    the body, and the function being defined f(n)
    if n 0 then 1 else nf(n-1)
  • Now f has two arguments, n, and g. Think of
    defining a higher order function H H(g)(n) if
    n 0 then 1 else ng(n-1)
  • The factorial function f is a fixed-point of H,
    that is, a value of H such that H(g) g.
    Why? H(f)(n) if n 0 then 1 else nf(n-1)
    f(n)

6
Least-Fixed-Points
  • If we think of a function being represented by
    extension, then we can talk about a partial
    ordering of all functions, with the bottom
    element being the empty set ?.
  • Think of the function that just maps 0 to 1,
    (0,1), and the function that in addition maps 1
    to 1, (0,1),(1,1), and the function that
    further maps 2 to 2, (0,1),(1,1),(2,2), and the
    function that further maps 3 to 6,
    (0,1),(1,1),(2,2),(3,6).We are constructing a
    sequence of functions, f0, f1, f2, f3, that begin
    a sequence of functions that represent the
    factorial function.
  • If we defined a function f that was just like f,
    but in addition mapped negative values to -1, f
    would still satisfy the definition of the
    factorial function, however, f would be a larger
    function in the natural lattice order of the
    function definitions because it contains every
    pair in f, but it also contains many other
    pairs.Thats why we say the factorial function
    is the least-fixed-point of the definition of
    H(f).

7
Adding Control Flow
  • Defining if statements is relatively
    straightforwardSif E then L1 else
    L2(Env) if EE(Env) gt 0 then LL1(Env)
    else LL1(Env)
  • While and other repetitive statements, however
    present somewhat of a problem Swhile E do
    L od(Env) if EE(Env) ? 0 then Env
    else SL while E do L od(Env)
  • The recursive nature of the while is typically
    handled by defining the meaning as the
    least-fixed-point of the specified semantic
    function.
Write a Comment
User Comments (0)
About PowerShow.com