Semantics Q1 2007 S EMANTICS (Q1,’07) Week 1 Jacob Andersen PhD student [email protected].
-
Upload
dennis-blankenship -
Category
Documents
-
view
214 -
download
0
Transcript of Semantics Q1 2007 S EMANTICS (Q1,’07) Week 1 Jacob Andersen PhD student [email protected].
Semantics Q1 2007
Week 1 - Outline• Introduction
• Welcome and introduction• Short-film about teaching (20')...• Course Presentation [ homepage ]
• Prerequisitional (discrete) Mathematics• Relations• Inference Systems• Transition Systems• The Language “L”
Semantics Q1 2007
Introduction• Semantics
– Merriam-Webster:– Example:
• “I would like a cup of coffee.”• “Colourless green ideas sleep furiously.”
• Question:Would you fly the space shuttle if you had writtenthe guidance software???
• In this course we shall explore formal ways of reasoning about the meaning / behaviour of computer programs.
Main Entry: se·man·tics Pronunciation: si-'man-tiksFunction: noun plural but singular or plural in construction1 : the study of meanings
Semantics Q1 2007
Short-film about teaching...
Semantics Q1 2007
Course Introduction I
SOLO 2, 3, 4
Verbs identifies skills / competences
Actor
Semantics Q1 2007
Course Introduction II
• No-one can force new skills into your head– You do not learn how to ride a bike by observing others (!!)
• Expected weekly time consumption:
Lecture 3
Reading 1
Exercise class 3
Hand-in 2
Sum 13
Fitting the pieces together
Lecture 3
Reading 1
Reflecting / Solving exercises
4
Exercise class 3
Hand-in 2
Sum 13
Semantics Q1 2007
Course Introduction III
• Course RetrospectiondSem ’05:
Semantics Q1 2007
Learning vs. Breaks• #Breaks, |Breaks|, ...?
Conclusion:more (shorter) breaks
Semantics Q1 2007
RELATIONSAND
INFERENCE SYSTEMS
Semantics Q1 2007
Relations I• Example1: “even” relation:
• Written as: as a short-hand for:… and as: as a short-hand for:
• Example2: “equals” relation:• Written as: as a short-hand for:
… and as: as a short-hand for:
• Example3: “DFA transition” relation:• Written as: as a short-hand for:
… and as: as a short-hand for:
|_even Z
|_even 4
|_even 5
4 |_even
5 |_even
2 3 (2,3) ‘=’
‘=’ Z Z
(2,2) ‘=’2 = 2
‘’ Q Q
q q’ (q, , q’) ‘’
(p, , p’) ‘’p p’
Semantics Q1 2007
Relations II• In general, a k-ary relation, L, over the
setsS1, S2, … , Sk
is a subsetL S1 S2 … Sk
• k is called the “arity” of L, and “L S1 S2 … Sk” is the “signature”.
Semantics Q1 2007
Inference System• Inference System:
• Inductive (recursive) specification of relations• Consists of axioms and rules
• Example:• Axiom:
• “0 (zero) is even”!
• Rule:• “If n is even, then m is even (where m = n+2)”
|_even 0
|_even n
|_even m
m = n+2
|_even Z
Semantics Q1 2007
Terminology
• Meaning:• Inductive:
“If n is even, then m is even (provided m = n+2)”; or• Deductive:
“m is even, if n is even (provided m = n+2)”
|_even n
|_even m
m = n+2
premise(s)
conclusion
side-condition(s)
Question:
Why have both premises and side-conditions??
Note: The “ “ is actually just another way of writing a “” !
Semantics Q1 2007
Abbreviation• Often, rules are abbreviated:
• Rule:• “If n is even, then m is even (provided m = n+2)”;
or• “m is even, if n is even (provided m = n+2)”
• Abbreviated rule:• “If n is even, then n+2 is even”; or• “n+2 is even, if n is even”
|_even n
|_even n+2
|_even n
|_even m
m = n+2
Even so, this is what we mean
Warning:Be careful !
Semantics Q1 2007
Relation Membership (Even)?• Axiom:
• “0 (zero) is even”!
• Rule:• “If n is even, then n+2 is even”
• Is 6 even?!?
• The inference tree proves that:
|_even 0
|_even 2
|_even 4
|_even 6
|_even 0
|_even n
|_even n+2
[rule1]
[rule1]
[rule1][axiom1]
inference tree
|_even 6
Semantics Q1 2007
Example: “less-than-or-equal-to”• Relation:
• Is ”1 2” ?!?• Yes, because there exists an inference tree:
» In fact, it has two inference trees:
0 0 n mn m+1
[rule1][axiom1]
‘’ N N
n mn+1 m+1
[rule2]
0 00 11 2
[rule2]
[rule1][axiom1] 0 0
1 11 2
[rule1]
[rule2][axiom1]
Semantics Q1 2007
Activation Exercise 1• Activation Exercise:
• 1. Specify the signature of the relation: '<<'» x << y "y is-double-that-of x"
• 2. Specify the relation via an inference system» i.e. axioms and rules
• 3. Prove that indeed:» 3 << 6 "6 is-double-that-of 3"
Semantics Q1 2007
Activation Exercise 2• Activation Exercise:
• 1. Specify the signature of the relation: '//'» x // y "x is-half-that-of y"
• 2. Specify the relation via an inference system» i.e. axioms and rules
• 3. Prove that indeed:» 3 // 6 "3 is-half-that-of 6"
Syntactically differentSemantically the same relation
Semantics Q1 2007
Relation Definition (Interpretation)• Actually, an inference system:
…is a demand specification for a relation:
• The three relations:• R = {0, 2, 4, 6, …} (aka., 2N)• R’ = {0, 2, 4, 5, 6, 7, 8, …}• R’’ = {…, -2, -1, 0, 1, 2, …} (aka., Z)
…all satisfy the (above) specification!
|_R 0|_R n
|_R n+2
[rule1][axiom1]
|_R Z
(0 ‘|_R’) ( n ‘|_R’ n+2 ‘|_R’)
Semantics Q1 2007
Inductive Interpretation• A inference system:
• …induces a function:
• Definition:• ‘lfp’ (least fixed point) ~ least solution:
|_R 0|_R n
|_R n+2
[rule1][axiom1]
FR: P(Z) P(Z)
|_R Z
FR(R) = {0} { n+2 | n R }
F(Ø) = {0} F2(Ø) = F({0}) = {0,2} F3(Ø) = F2({0}) = F({0,2}) = {0,2,4} …
|_even := lfp(FR) = FRn(Ø)n
|_R P(Z)
From rel. to rel.
2N =
Fn(Ø) ~ “Anything that can be proved in ‘n’ steps”
Semantics Q1 2007
TRANSITION SYSTEMS
Semantics Q1 2007
Definition: Transition System• A Transition System is (just) a structure:
is a set of configurations is a binary relation
(called the transition relation)
– We will write instead of
• Other times we might use the following notations:
,
’ (,’)
’ |_ ’ ’ , , …
Semantics Q1 2007
• The transition may be illustrated as:
• In this course, we will be (mostly) using:
• For instance:
A Transition ’
’
= system configuration = < program , data >
< “x:=y ; y:=0” , [x=3,y=7] > < “y:=0” , [x=7,y=7] >
...and have "" describe "one step of computation"
Semantics Q1 2007
Def: Terminal Transition System• A Terminal Transition System is a structure:
is the set of configurations is the transition relation• T is a set of final configurations
– …satisfying:
– i.e. “all configurations in ‘T’ really are terminal”.
, , T
t T : : t
Semantics Q1 2007
E.g.: Finite Automaton• A Non-det Finite Automaton (NFA) is a 5tuple:
• Q finite set of states finite set of input
symbols
• q0 Q initial state
• F Q set of acceptance states : Q P(Q) state transition relation
M = Q , , q0 , F ,
toss
toss
heads
tails
0 1 2
Q = { 0,1,2 } = { = { toss,heads,tails } (0,toss) {1,2} ,q0 = 0 (1,heads) {0} ,F = { 0 } (2,tails) {0} }
Semantics Q1 2007
E.g.: NFA Transition System (1)
• Define Term. Trans. Syst. by:
• Configurations:
• Transition relation:
– i.e., we have whenever
• Final Configurations:
M := Q *
M , M , TM
TM := { <q,> | q F }
M := { ( <q,aw> , <q’,w> ) | q,q’Q, a, w*, q’(q,a) }
“State component”“Data component”
q’ (q,a)<q,aw> M <q’,w>
Recall:
M = Q , , q0 , F , Given
Semantics Q1 2007
E.g.: NFA Trans. Sys. (Cont’d)
• Define behavior of M:
toss
toss
heads
tails
0 1 2
<0, toss;heads;toss;tails> M <1, heads;toss;tails> M
<0, toss;tails> M
<2, tails> M
<0, > TM
L(M) := { w * | T : <q0,w> * }
Semantics Q1 2007
Def: Labelled Transition System• A Labelled Transition System is a structure:
is the set of configurations
• A is the set of actions (= labels)
A is the transition relation
– Note: we will write instead of
, A ,
’a (, a, ’) ‘’
Semantics Q1 2007
• The labelled transition may be illustrated as:
– The labels(/actions) add the opportunity of describing transitions:
– Internally (e.g., information about what went on internally)– Externally (e.g., information about communication /w env)– …or both.
A Labelled Transition ’
’a
a
Semantics Q1 2007
E.g.: NFA Transition System (2)• Given Finite Automaton:
• Define Labelled Terminal Transition System:
• Configurations:
• Labels:
• Transition relation:
• Final configurations:
M := Q
M , AM , M , TM
TM := F
M := {(q,a,q’)|q’(q,a)}
AM :=
M = Q , , q0 , F ,
X
???
“Relaxed”v
Semantics Q1 2007
E.g.: NFA Trans. Sys. (Cont’d)
• Behavior:
• Define ”*” as the reflexive transitive closure of ””on sequences of labels:
toss
toss
heads
tails
0 1 2
0 M 1 M 0 M 2 M 0
L(M) := { w A* | qT : q0 * qw
toss
heads
toss
tails
L(M) := { a a’ … a’’ A* | qT : q0 q’ … qa a’ a’’
Semantics Q1 2007
NFA: Machine 1 vs. Machine 2• The two transition systems are very different:
• Machine 1:– ”I transitioned from <q,aw> to <q’,w>”
Implicit: ”…by consuming part of (internal) data component”
• Machine 2:– ”I transitioned from q to q’
…by inputing an ’a’ symbol from the (external) environment!”
<q,aw> M <q’,w>
q M q’a
Semantics Q1 2007
More Examples…• More Examples in [Plotkin, p. 22 – 26]:
– Three Counter Machine (***)– Context-Free Grammars (**)– Petri Nets (*)
• They illustrate expressive power of transition systems
– no new points...except formalizing input / output behavior (also later here…)
• Read these yourself…
Semantics Q1 2007
THE LANGUAGE “L”
Semantics Q1 2007
The Language ”L”• Basic Syntactic Sets:
• Truthvalues:– Set ranged over by: t , t’, t0, …
• Numbers:– Set ranged over by: m, n, …
• Variables:– Set ranged over by: v, v’, …
T = {tt, ff}
N = {0, 1, 2, …}
VAR = {a, b, c, …, z}
Meta-variables
Semantics Q1 2007
The Language ”L”• Derived Syntactic Sets:
• Arithmetic Expressions (e Exp):
• Boolean Expressions (b BExp):
• Commands (c Com):
e ::= n | v | e + e’ | e – e’ | e e’
b ::= t | e = e’ | b or b’ | ~ b
c ::= nil | v := e | c ; c’ | if b then c else c’ | while b do c
Semantics Q1 2007
• Consider program:• It can be (ambiguously) understood:
• Note:
Abstract- vs. Concrete Syntaxwhile b do c ; c’
while b do c ; c’ while b do c ; c’
…either as: …or as:
“Concrete syntax”
while
b c
;
c’
while
b
c
;
c’
“Abstract syntax”
Parsing: “Concrete syntax” “Abstract syntax”
Semantics Q1 2007
Next week
• Use everything…:• Inference Systems, Transition Systems, Syntax, …
• …to:– describe– explain– analyse– compare
…semantics of Expressions:
Semantics Q1 2007
"Three minutes paper"• Please spend three minutes writing down the
most important things that you have learned today (now).
After 1 dayAfter 1 week
After 3 weeksAfter 2 weeks
Right away
Semantics Q1 2007
Exercises...
[ homepage ]
Semantics Q1 2007
See you next week…
Questions?
Semantics Q1 2007