SEMANTICS (Q1,'05)

[ semantics | relevance | roles | structure | schedule | exercises | project | exam | re-exam | materials | classes | webboard ]

SEMANTICS REEXAM (AUGUST 2006)

  • Period: [ Wednesday 02/08 @ 12:00 -- Friday 04/08 @ 12:00 ]

  • The exam features 4 (four) exercises of weight: (18-30%):
    • 1. Static and dynamic semantics for a stack-variable language [30%];
    • 2. Static semantic of an expression language with binders [25%];
    • 3. Termination proof of non-recursive CCS via structural induction [27%];
    • 4. Implementation of a dynamic semantics (one datatype and one function) [18%].

  • Individual exam:
    • This exam is your personal exam and its grade will be your personal grade. Discussing the problems with anyone else or copying parts of solutions is cheating and any evidence of it will mean that you fail this exam and may be reported to the Faculty of Science(!)

  • Grading:
    Be sure to motivate, explain, and argue for the reasoning behind your solutions! Be concise and to the point (not necessarily "the more explanation the better"); include only issues relevant to the problem at hand (irrelevant issues may subtract points).

    All this is what wins you the points (i.e. there are no/very few points for unmotivated solutions "out-of-the-blue", correct or not).

    The actual grading is done relative to the course objectives; i.e., that you demonstrate the ability:

    • to describe formally the meaning of a wide range of programming constructs;
    • to explain fundamental concepts, techniques, and results regarding formal semantics of programming languages;
    • to implement semantic descriptions in familiar programming languages;
    • to analyze the meaning of a wide range of programming constructs;
    • to compare semantic descriptions;
    • to reason about semantic descriptions;
    • to prove consequences of semantic descriptions; and
    • to apply all above skills to concrete programs (to understand and prove properties of programs).

    ...whereever relevant.

  • Handing-in:
    Submit your solution (in Danish or English) to the exam assignments by copying it into your delivery directory (which is a directory owned by you for the duration of the exam and which is located here):
        /users/courses/dSem/re-exam/<<username>>/        (e.g. /users/courses/dSem/re-exam/brabrand/ )
    
    no later than (Friday 04/08 @ 12:00) at which point the delivery directories will be closed (and handed over to me). You may not change the permissions of the directory.

    Handing in must be according to the following convention:

    You place the files exactly as shown below:

        /users/courses/dSem/re-exam/<<username>>/exam.pdf (xor "exam.doc")
                                             /phi-datatype.sml             // cf. exercise 4
                                             /phi-evalPhi.sml              // cf. exercise 4
    

  • If you write the SOS rules by hand (which is fine as long as you write them very(!) clearly), then you need to scan them into PDF (the University printers can do this).

  • Alternatively, you may hand in a hardcopy (by handing it in to the department secretary Karen Kjær Møller at her office Ada-128) no later than (Friday 04/08 @ 12:00); however, you still have to deliver the ML program (datatype + function) file as specified above (also before the deadline).

  • Your report must have your name and your student-id on the front page. If you use Word, do not use non-standard fonts (e.g., special non-standard mathematical fonts).

    Violations of any of the above rules will subtract points.

  • Damage control:
    If you run out of time or cannot solve an exercise, identify and restrict your solution to a suitable subset (make this clear in your hand-in). This will, of course, reduce your grade (but at least you will get some points instead of none for no solution). In particular; for the programming exercise: submit your (ML) program even if it may not be fully operational (you may still get points for the things that would work with a bit of "tweaking"). You need not have a full ML program (we only ask for the datatype definition phi and for the small-step SOS function evalPhi).


EXERCISE 0 (IMPORTANT INFORMATION)

  • Read the information at the top of this document thorougly, as it is likely to indirectly improve your grade (in making sure you do not lose points by missing important information)!


EXERCISE 1 (STATIC AND DYNAMIC SEMANTICS FOR A STACK-VARIABLE LANGUAGE)

Consider the following stack-variable language, SVL:

  • -) The syntax of a SVL program is given by the syntactic category, P (which is in turn defined in terms of SVL expressions as given by the syntactic category, E):
        P   :   (run E)           // evaluate expression E (with an initially empty stack)
        
        E   :   con n             // push constant integer n onto the stack (n natural number)
            |   inc n             // increase top element on stack by constant n (n natural number)
            |   dec n             // decrease top element on stack by constant n (n natural number)
            |   neg               // integer negatation: invert the sign of the top element on the stack
            |   get x             // push value of x onto stack (implicitly 0 if x has never been assigned)
            |   put x             // pop top element from stack and assign it to variable x
            |   (ifnz E else E')  // pop top element from stack, evaluate E if it was non-zero (E', if not)
            |   (whnz E)          // pop top element from stack, evaluate E if it was non-zero...
                                  // ...after evaluation of E, reevaluate the whole expression: "whnz E"
            |   (seq E ; E')      // sequential evaluation: evaluate E, then evaluate E'
    


  • a) Write an SVL program P that adds the values held in the variables x and y.

  • b1) Give the signatures (for all relations you plan to use in assignment "b2" below):

  • b2) Give a reasonable static semantics for the SVL language, making sure that:
    • -) for all P programs (run E), the evaluation of E starting with the empty stack always results in a stack of height 1 (for "the result");
    • -) for all P programs, inc, neg, get, ifnz-else, and whnz are never executed with a stack height of less than one (for popping the top element on the stack); and
    • -) branching along either control-flow path of the ifnz-else-construction (i.e. evaluating either E or E') always produces the same resulting stack height.
    • -) figure out a reasonable static requirement for the whnz-construction.

      [ Hint: You may, for instance, use (possibly among other things) an expression well-formedness relation, |-wfe, relating an expression, E, an assumed initial stack height, n, and a resulting stack height, m (e.g., "|-wfe E:n:m") ]

  • c1) Give the configurations, terminal configurations, and signature of the transition relation (for all transition systems you plan to use in assignment "c2" below). Also, in case you are using any intermediate syntax, introduce it explicitly by giving the new grammar for P and E with the intermediate syntax added (if you are using any).

  • c2) Give a reasonable small-step structural operational dynamic semantics for the SVL language as informally described (in gray color) above.

    [ Hint: For configurations, you may wish to use (possibly among other things) <M,E,W> (where M is a memory, E is an expression, and W (omega) is an integer sequence (stack) belonging to Z* ]

    [ Hint': Also, you may wish to use the syntactic conventions that "ε" (epsilon) describes the empty integer sequence (empty stack), and "n::w" describes the concatenation of integer n and integer sequence W (omega) ]

[ 30% ]


EXERCISE 2 (STATIC SEMANTIC OF AN EXPRESSION LANGUAGE WITH BINDERS)

Consider the following parameterized summation and multiplication language, SUMUL (in the following we are only interested in its static semantics):

  • -) The syntax of a SUMUL program is given by the syntactic category, E:
        E   :   n                  // integer constant
            |   T   |   F          // boolean "true" and "false"
            |   x                  // integer variable
            |   (E =!= E')         // integer non-equality (E and E' must be integer expressions)
            |   (E ==> E')         // boolean implication (E and E' must be boolean expressions)
            |   (E ? E' : E'')     // if-then-else expression: evaluate E to a boolean value (b, say);
                                   // then, if b is true, eval E' (otherwise evaluate E'')
            |   (SUM [i:0..E] E')  // parameterized summation: evaluate E to an integer value (n, say);
                                   // then evaluate E' successively (with i bound to first 0, then 1, ..., n);
                                   // (the result is zero plus the summation of all evaluations of E')
            |   (MUL [i:0..E] E')  // parameterized multiplication: evaluate E to an integer value (n, say);
                                   // then evaluate E' successively (with i bound to first 0, then 1, ..., n);
                                   // (the result is one times the multiplication of all evaluations of E')
    


  • a) Specify the defining variables (DV: E -> P(VAR)) and free variables (FV: E -> P(VAR)) of all expressions (where P(VAR) denotes the powerset of the set of all variables, VAR).

  • b) Specify a binary symbolic well-formedness relation |-sym which is a subset of P(VAR) * E:

    • V |-sym E      iff      E has no undefined variable references (assuming all variables in V are defined).

  • Note: A SUMUL program (expression w/o free variables) E is then said to be symbolically well-formed    iff    Ø |-sym E.

  • c) Specify a binary typing relation |-typ which is a subset of E * {int,bool}:

    • |-typ E : τ      iff      E is a well-typed expression (with type τ) in accordance with the above informal specification.

  • Note: A SUMUL program (expression w/o free variables) E is then said to be valid    iff    Ø |-sym E and there exists a type τ such that |-typ E : τ.

[ 25% ]


EXERCISE 3 (TERMINATION PROOF OF NON-RECURSIVE CCS VIA STRUCTURAL INDUCTION)

Proof of termination for CCS w/o recursion (CCS without recursion):
  • Syntax: Let the syntax of CCS w/o recursion (i.e., without "the K rule" or [DEF]) be given by:
    
    P   :   0    |    α.P    |    P + P'    |    P | P'    |    P[f]    |    P \ L
    
  • Semantics: Recall the semantics (repeated w/o [DEF] here for your convenience):


  • a) Give the SOS rules for the inactive process "0" (aka. "nil") and binary infix summation "P+Q" (aka. "binary infix choice"):

  • Definition: Let the "size" of a CCS Process be given by the following inductive definition (|.|: PROC -> N):

    
    |0| := 0    ,    |α.P| := |P| + 1    ,    |P+Q| := |P| + |Q| + 1    ,    
    |P|Q| := |P| + |Q| + 1    ,    |P[f]| := |P| + 1    ,    |P\L| := |P| + 1
    

  • b) Give the sizes of the following processes (incl. how the sizes are calculated):

    • 1) a.0+b.0 (i.e. give: |a.0+b.0|)
    • 2) (a.0+b.(0|0))|(c.0[a/c]\a)

  • c) Give the proof structure for assignment "d" below:

  • Note: Do not use any other proof principle than (or variant of) conventional strutural induction (as on the curriculum and demonstrated in the lectures):

  • d) Prove the following property by structural induction:
    
    ∀ P in PROC, α in ACT, Q in PROC:     P -α-> Q     ==>     |P| > |Q|
    

  • Note' (for your information): That this property is satisfied means that any CCS w/o recursion process will terminate since the "size" measure can be used as a so-called "termination function" on derivation sequences. The requirement for a termination function is that it is a strictly decreasing injection into the non-negative natural numbers (for any sequence). The "size" of a given expression initially starts out at some non-negative integer value v, and then strictly decreases with each evaluation step.

    It is (of course) impossible to construct a (strictly decreasing) termination function for the full-scale CCS language due to the recursive [DEF] rule and construction (no termination function would strictly decrease). This note was not an exercise, but purely for your information (why the above property is a proof of termination).

[ 27% ]


EXERCISE 4 (IMPLEMENTATION OF DYNAMIC SEMANTICS)

  • Consider the following subset of the language Φ (Phi) (exercise 3 from week 4) without variables and binders:
    φ   :   T             // "true"
        |   F             // "false"
        |   ¬ φ           // negation
        |   φ & φ         // conjunction
        |   φ => φ        // implication
    
  • a) Give an ML datatype for the syntax of the Phi subset (submit ONLY the source for the datatype phi).

  • b) Give small-step SOS rules for the Phi subset with as lazy a semantics as possible (where the transition relation "-->" is a subset of Φ * Φ).

  • c) Give the implementation for the rules following your SOS (in part b) as directly as at all possible (submit ONLY the source for the function evalPhi).

[ 18% ]


EXERCISE 0 (CONT'D)

  • Re-read the information at the top of this document thorougly, as it is likely to indirectly improve your grade (in making sure you do not lose points by missing important information)!
  • In particular, remember to motivate, explain, and argue for the reasoning behind your solutions (also in questions where this is not explicitly stated)!


CURRICULUM ("PENSUM")

Lectures: [ slides: 1 | 2 | 3 | 4 | 5 | 6 | 7 ]
Reading: [ SOS (Chap.1-3, p.1-78) ] + [ CCS (Chap.1-5, p.1-63) ] + [ Note on Induction ]
Exercises: [ exercises: 1 | 2 | 3 | 4 | 5 | 6 ] + [ project ]

August 2006

Mo Tu We Th Fr Sa Su
   01 02 03 04 05 06


Claus Brabrand (June 14, 2006)