Semantics of Programming Languages
Pietro Di Gianantonio
Universita di Udine
18th June, 2009
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 1 / 49
Overview
A short introduction to semantics of programming:
objectives,some approaches,some examples.
Quite basic:
almost no previous knowledge is requiredtry to use only simple notions avoiding complex mathematics.
An introduction the notions presented in the second part of thecourse (with some repetitions)
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 2 / 49
Semantics of Programming Languages
Aims to formally describe the behaviour of programs, programsconstructors.
Useful:
to describe and specify a programming languages without ambiguities
as standard for syntax,fundamental for building compilers,
to reasons on programs: to proof that a program satisfies some givenrequirements; that is correct.
Formal methods used in some approaches to software engineering: formalsystem development, to produce reliable software.For example inside UML (unified modeling language)
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 3 / 49
Approaches to semantics
Different styles to describe the program behaviour:
Operational semantics. A formal, simple machine used to describesthe behaviour of the programs.
Structural operational semantics (SOS). A set of rules describing thebehaviour of programs.
Denotational semantics. To represent the behaviour of programsthrough a mathematical object.
Axiomatics semantics: the meaning of program is expressed in termsof preconditions and postconditions
They describe different aspects of program behaviour, have differentpurposes.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 4 / 49
Several aspects in programming languages
non termination,
store,
environment,
non determinism,
concurrency,
higher order functions,
exceptions,
continuations.
If a programming language is enriched with new features, it is necessary toenrich or modify the semantics to deal with the new aspects.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 5 / 49
A simple imperative language: IMP
a ::= n | X | a0 + a1 | . . .
b ::= true | false | a0 = a1 | b0 or b1 | . . .
c ::= skip | X := a | c0; c1 | if b then c0 else c1 fi | while b do c od
A minimal Turing-complete language:
no environment and aliasing,
no procedure definitions,
no recursive definition.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 6 / 49
Structured Operational Semantics
A set of rules describe program computation.They derive judgements in the form:
〈a, σ〉 ⇒ n
meaning: the evaluation of the expression a with the store (memory) σreturns the value (number) n.The evaluation of an expression depends only on store. The effect is togenerate a number (the store is left unchanged.)
And in the form:〈c , σ〉 ⇒ σ′
meaning: the computation of the command c in the store σ terminates,and the result of the computation is a store σ′.The computation of a command depends only on store. The effect ismodify the store (no value is returned.)
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 7 / 49
SOS rules
Rules have a natural deduction style.
〈n, σ〉 ⇒ n
〈a0, σ〉 ⇒ n0 〈a1, σ〉 ⇒ n1
〈a0 + a1, σ〉 ⇒ (n0 + n1)
〈b, σ〉 ⇒ true 〈c0, σ〉 ⇒ σ′
〈if b then c0 else c1 fi, σ〉 ⇒ σ′
There is one, or more, rules for each program constructor.
Most of the rule are intuitive.
Formalize the intended meaning of program constructors in a simpleand synthetic way.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 8 / 49
SOS at work, command evaluation
On the hypothesis that σ(X ) = σ(Y ) = 3, we can derive:
〈X , σ ⇒ 3〉 〈Y , σ ⇒ 3〉〈X = Y , σ ⇒ true〉
〈X , σ ⇒ 3〉 〈1, σ ⇒ 1〉〈X + 1, σ ⇒ 4〉
〈X := X + 1, σ ⇒ σ[4/X ]〉〈if X = Y then X := X + 1 else Y = 0 fi, σ〉 ⇒ σ[4/X ]
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 9 / 49
SOS at work, meta reasoning, examples:
If 〈a, σ〉 = n and 〈a, σ〉 = m then m = n.Proof By induction on the structure of a, showing that, for any a, σ,there is only one possible derivation;
while b do c od
andif b then c ; while b doc od else skip fi
are equivalent. That is, for any b, c and σ, the two commandsreturns the same store.Proof By case analysis. Exercise.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 10 / 49
Software tools
Formal reasoning on programs is quite lengthy: a formal proof of anintuitively obvious fact can take several pages.
Formal semantics is useful because:
Behavior of programs can be hide subtilities, especially whenconcurrency and aliasing are involved.What is the value of Y at the end of the commandX = 1; [Y = X − X ‖ X = 2]?
Complex code almost always contains mistakes.
Once the reasoning on program is formalize, it can be mechanized.
Software tools can greatly facilitate formal analysis of programs.
Guiding and checking the correctness of the formal analysis.
Automatizing the simple steps in the formal analysis.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 11 / 49
SOS pro
Simple, synthetic, intuitive.
Quite flexible:
Can easily accommodate various program feature: environments,higher-order types, concurrency.
The basic structure of rules remains unchanged when SOS is appliedto different programming languages.
We will consider concurrency, (and higher order types).
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 12 / 49
SOS contra
The semantics is syntax dependent.
The semantics is not compositional:the behaviour of program cannot be described starting from the behaviourof its subterms.
The semantics does not induce a suitable equivalence relation on programs.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 13 / 49
Denotational semantics
Aims:
a language independent semantics, to compare programs written indifferent programming languages
a semantics that is compositional, the behaviour of a program isobtained from the behaviour of its components
more abstract, inspire new methods for reasoning on programs.
Main idea, to describe the behaviour of a program through a suitablemathematical object.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 14 / 49
Denotational semantics for IMP
A command is described as a partial function from States to States(Σ ⇀ Σ).
CJ K : Σ ⇀ Σ
In turn,Σ = Loc→ Z
a state (store) assigns to each location an integer.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 15 / 49
Denotational semantics for IMP
The interpretation function, assigning to each expression and command itssemantics, is described by a set of equations, in the form
AJnK(σ) = n
AJao + a1K(σ) = (AJaoK(σ)) + (AJa1K(σ))
CJif b then c0 else c1 fiK(σ) =
{CJc0K(σ) = if BJbK(σ) = trueCJc1K(σ) = if BJbK(σ) = false
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 16 / 49
The difficult case: the while constructor
CJwhile b then c odK(σ)
=
{σ = if BJbK(σ) = falseCJwhile b then c odK(CJcK(σ)) = if BJbK(σ) = true
This is a recursive definition (normally formulated in different form).One needs to prove that the recursive definition has a solution and tocharacterize it.
In this case, we use:
the partial order of partial function on Σ
CJ K : Σ ⇀ Σ
and a variation of Knaster-Tarski theorem: any monotone andcontinuous function on chains complete orders has a minimalfixed-point.(Knaster-Tarski theorem: monotone functions on complete partial hasa minimal fixed-point)
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 17 / 49
In more detail
CJwhile b docodK
turns out to be the limit of the follwing list of partial functions:
CJ⊥KCJif b then c ;⊥ fiKCJif b then c ; if b then c;⊥ fi fiKCJif b then c ; if b then c; if b then c ;⊥ fi fi fiK. . .
where ⊥ is a always non terminating program
and if b then c fi is syntactic sugar for if b then c ; else skipfi(use syntactic sugar is a way to enrich the language without adding newsemantics definition)
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 18 / 49
Domain theory
Standard denotational semantics uses domain theory, a class of partialorders with some additional properties.
1 monotone increasing chains have limits,
2 any elements is the limits of a chain of finite elements,
3 finite elements are elements that can be described by a finite amountof informations (for example: a partial function defined on a finite setof points).
The order on object is the information order: a v b if b contains moreinformation of a.In the particular case of partial functions: a v b if b is define on morepoints, gives more outputs that a.
General domain theory is necessary to accommodate real languages,with environment, higher-order function, non concurrency.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 19 / 49
Alternatives versions of domain theory
There are a plethora of different kind of domains.
Scott-Domains – consistently complete dcpo
SFP-Domains
Continuous-Domains
Coherent spaces
Different property for the information order and for the finite elements.Different construction can be performed.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 20 / 49
Alternatives to domain theory
Different mathematical structure to interpret languages
Game semantics. A program described by the interaction of theprogram with its environment, (not as a function from input tooutput). A different paradigm.
Metric spaces and not-well-founded sets. Semantics of concurrentlanguages.
C ? algebras.
Category theory is used to derived general results, to give prescription onthe newly defined semantics structures.
Quite often, the underlining mathematics is quite (too) sophisticated.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 21 / 49
Concurrency
A simple concurrent program: IMP + program parallel composition,
c ::= . . . | c0 ‖ c1
informally the execution of the two commands c0 and c1 proceeds inparallel,or alternativelythe execution of the two commands can be interleaved.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 22 / 49
Concurrency
SOS for parallel language need a different set of judgement.
Judgments in the form〈c , σ〉 ⇒ σ′
Specify the input-output behaviour of c .To determine the evaluation of c0 ‖ c1 is not sufficient to know theinput-output behaviour of c0 and c1 given by thWe need to know also how the computation of c0 an c1 proceeds.This is can be specified by a different set of judgments.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 23 / 49
Small-step operational semantics
An alternative formulation of SOS
uses judgements are in the form:
〈c , σ〉 → 〈c ′, σ′〉
meaning, in one step of computation, the command c in the store σevolves in command c ′ and store σ′
and in the form:〈c , σ〉 → σ′
meaning, in one step of computation, the command c in the store σterminates and returns the store σ′
The rule for all constructor needs to be reformulated.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 24 / 49
Example: the new rules for composition
Big-step
〈co , σ〉 ⇒ σ′ 〈c1, σ′〉 ⇒ σ′′
〈c0; c1, σ〉 ⇒ σ′′
Small-step:
〈co , σ〉 → 〈c ′0, σ′〉〈c0; c1, σ〉 → 〈c ′0; c1, σ
′〉
〈co , σ〉 → σ′
〈c0; c1, σ〉 → 〈c1, σ′〉
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 25 / 49
Parallel composition
Just small step operational semantics:
〈co , σ〉 → 〈c ′0, σ′〉〈c0 ‖ c1, σ〉 → 〈c ′0 ‖ c1, σ
′〉
〈c1, σ〉 → 〈c ′1, σ′〉〈c0 ‖ c1, σ〉 → 〈c0 ‖ c ′1, σ
′〉
The reduction relation is non deterministic.
Non determinism is accommodated smoothly. There is no need to modifythe SOS approach.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 26 / 49
Communicating processes
The above parallel composition ‖ assumes a common store.Parallel process communicate through the store.Multiprocessors architecture: several processors sharing a commonmemory.
Multicomputer architecture: several computers communicating through anetwork.They need a different programming style.No common store, parallel processes communicate through messageexchange.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 27 / 49
Communicating processes
IMP + communication primitives became
c ::= skip | X := a | c0; c1 | if b then c0 else c1 fi | while b do c od |α!a | α?X | c0 ‖ c1
Where:
α range on a set of communication channels,
α!a is a command (process) that sends the value a along the channelα
α?X is the process that receives a value along the channel α andstores the received value on the location X .
In the parallel composition of two processes co ‖ c1, processes c0 andc1 cannot have a shared location.
The above calculus is similar to CSP: Communicating Sequential Processes
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 28 / 49
Pure CCS (Calculus of communicating systems
To analyze concurrency, it is convenient to study a language withoutimperative features, containing only basic concurrent constructors.
p ::= nil | empty action,α.p | α.p | communication along a channel,τ.p | silent action,p0 ‖ p1 | p0 + p1 | parallel and non-deterministic composition,X | recX = p recursive definition, infinitary processesp \ [α1, . . . , αn] action hiding, creates private channels.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 29 / 49
SOS semantics for CCS: Reductions Rules
Two main reductions rules:
((α.p0) + p1) ‖ ((α.q0) + q1) → p0 ‖ q0
((τ.p0) + p1) → p0
Together with a set of equations defining structurally congruent processes:
p0 + p1 ≡ p1 + p2 p0 + (p1 + p2) ≡ (p0 + p1) + p2
. . .rec X = p ≡ p[rec X = p/X ]. . .
and the rulep → q p ≡ p′ q ≡ q′
p′ → q′
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 30 / 49
Semantics for CCS: Label Transition System
An alternative description: to derive the communications that a processcan perform with the environment.Judgement in the form:
pα→ q
p communicates along the channel α and becomes the process q.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 31 / 49
LTS semantics, rules
Basic rules describing communicating features:
α.pα→ p
p0α→ q
p0 + p1α→ q
p0α→ q0 p1
α→ q1
p0 ‖ p1τ→ q0 ‖ q1
τ represents the silent action, a step of computation with nocommunication involved.
Also here it is necessary to add a rule stating that a process can besubstituted by a congruent one.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 32 / 49
Label Transitions Systems LTS
Denotational semantics for processes: a process is described by the(unorder, infinitary) tree of communications it can perform.For example, the process:
recX = α.nil + β.X ≡ α.nil + β.recX = α.nil + β.X
is represented by the (unordered) tree:
Xα
}}||||
|||| β
BBBB
BBBB
nil Xα
||||
|||| β
AAAA
AAAA
nil Xα
}}}}
}}}} β
@@@@
@@@
nil X
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 33 / 49
LTS semantics
Two process are equivalent if they generates equivalent infinitary trees.Two trees are equivalent if one can be transform into the other by (aninfinite numbers of) permutations, duplications, contractions of somesubtrees.Formally tree equivalence is captured by notion of bisimulation.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 34 / 49
Bisimulation
A symmetric relation R on processes is bisimulation ifFor any p, q, p′
pRq ∧ pτ→ p′
implies that there exits q′ such that
qτ→ q′ ∧ p′Rq′
Two processes are bisimilar (p ∼ q) if they are related by bisimulation.
Informally: two bisimilar processes generates equivalent (bisimilar) tree.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 35 / 49
Issues
A mathematical structures in which to interpret processes.More directed that the set of tree quotient by bisimualation.Several proposals: not-well founded set, metric spaces, final coalgebra.
Bisimilarity is a congruence relation:
p ∼ q ⇒ C [p] ∼ C [q]
Relate reductions semantics, and LTS semantics.
Move from a reductions system to a (good, congruent) LTS systems.To obtain a denotational semantics starting from a operationalsemantics
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 36 / 49
Category theory
Categories theory are quite often used in denotational semantics.A possible reason:too many different mathematical structures are used in semantics.
Category theory is able
to give a global framework in which to present general results.
to characterize the key properties that a (new) mathematicalstructures need to have.Prescriptive role.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 37 / 49
Category theory
Category theory can be seen as further generalization form thegeneralization provided by the notion of group, algebra, topological space.Definition. A category theory is formed by:
a set of objects, {A,B,C , . . . }for any pair of objects, a set of morphism, {f , g , h, . . . : A→ B}on morphism there is an operation of composition ◦,f : A→ B, g : B → C , g ◦ f : A→ C
that is associative: h ◦ (g ◦ f ) = (h ◦ g) ◦ f andhas identity elements: idA : A→ B, f ◦ idA = f , idB ◦ f = f .
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 38 / 49
Examples
sets and functions;
groups and groups morphisms (functions respecting groupoperations);
topological spaces and continuous functions;
elements of a partial order and arrows representing the orderrelations.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 39 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is
any singleton set;in Groups a final object is a group formed a single elements;in the category induced by a partial order, the final object, if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is the empty set;in Groups an initial object is a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is any singleton set;in Groups a final object is
a group formed a single elements;in the category induced by a partial order, the final object, if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is the empty set;in Groups an initial object is a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is any singleton set;in Groups a final object is a group formed a single elements;in the category induced by a partial order, the final object,
if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is the empty set;in Groups an initial object is a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is any singleton set;in Groups a final object is a group formed a single elements;in the category induced by a partial order, the final object, if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is
the empty set;in Groups an initial object is a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is any singleton set;in Groups a final object is a group formed a single elements;in the category induced by a partial order, the final object, if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is the empty set;in Groups an initial object is
a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Main ideas
To express properties, defining concepts in term of morphisms, withoutlooking at the internal structure of objects. Examples:
Final object: an object C is final if for any object A there is a singlemorphism from A to C
in Sets, a final object is any singleton set;in Groups a final object is a group formed a single elements;in the category induced by a partial order, the final object, if it exists,is the maximum element.
Initial object: an object C is initial if for any object A there is a singlemorphism from C to A.
in Sets, the initial object is the empty set;in Groups an initial object is a group formed a single elements (initialand final object coincide);in the category induced by a partial order, the initial object, if it exists,is the minimum element.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 40 / 49
Product
Cartesian product × can be defined categorically.The product of two objects A,B is an objects, denoted by A× B, suchthat:
there are two morphism π1 : (A× B)→ A and π2 : (A× B)→ B,called projections,
for any other object C and for any pair of morphism f : C → A andg : C → B,there exist a morphism 〈f , g〉 : C → (A× B) such that;f = π1 ◦ 〈f , g〉 and g = π2 ◦ 〈f , g〉,i.e. the following diagram commutes.
Cf
||xxxxxxxxxg
""FFFFFFFFF
〈f ,g〉��
A A× Bπ1oo π2 // B
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 41 / 49
Examples
In the following categories categorical product coincides with:
Sets: the cartesian product of two sets,
Groups: the product of two groups, with the correct operations andunit element,
Tops: the topological product, with the correct induced topology,
in the category induced by a partial order: the greatest lower of twopoints.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 42 / 49
Coproduct
Dually, the disjoint union + of sets is defined categorically as:The coproduct of two objects A,B is an objects, denoted by A + B, suchthat:
there are two morphism ι1 : A→ (A + B) and ι2 : B → (A + B),called injections,
for any other object C and for any pair of morphism f : A→ C andg : B → C ,there exist a morphism [f , g ]〉 : (A + B)→ C such that;f = [f , g ] ◦ ι1 and g = [f , g ] ◦ ι2,i.e. the following diagram commutes.
Aι1 //
f
""FFFFFFFFF A + B
[f ,g ]
��
Bπ2oo
g
||xxxxxxxxx
C
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 43 / 49
Algebras as morphisms
An algebra, that is a set together A with a list of operation on A.An algebra, on a set A can be defined as a morphism from a coproduct ofproducts of A into A.For example, to define a group structure on A, one needs to define
the zero element 0 that is a function {∗} → A
the inverse function −1, that is function A→ A
the addition function ·, that is function A→ (A + A)
All together they form a morphism [0, −1, ·] : (1 + A + (A× A))→ A
Here we do not consider the equality laws.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 44 / 49
Categorical generalization of the notion of algebra
The transformation from A to (1 + A + (A× A)),Defined a functor, from Set to Set.
A functor, F , from a category A to a category of B is a functions fromobjects of A to objects B and a function from maps of A to maps of B,preserving the categorical structure (identy and composition)
F (f ◦ g) = F (f ) ◦ F (g)
.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 45 / 49
Categorical generalization of the notion of algebra
Given an category A, and an endofuctor F : A→ A,
an F -algebra is given by an objct A and a morphism h : F (A)→ A;
a morphism between an F -algebra 〈A, h〉 and an F -algebra 〈A′, h′〉, isa map g : A→ A′ such that the following diagram commutes:
F (A)F (g) //
h
��
F (A′)
h′
��A
g // A′
F -algebras and F -algebra morphisms form a category.
When instantiated on the special case of F (A) = (1 + A + (A×A)), in theSet category, we obtained the standard notion of algebra and algebramorphism.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 46 / 49
Initial F -algebra
An F -algebra 〈A, h〉 is initial, if for any other algebra ∠B, j〉 there isexactly one F -algebra morphism from ∠A, h〉 to ∠B, j〉.
The initial algebra for the functor F (A) = (1 + A + (A× A)), in the Setcategory, is the free-algebra,
i.e. the set of terms that can be construct starting from three constants
0 a ground constant−1 a unary function constant.
· a binary function constant.
The syntax on a given signature can be characterize as the initial algebra.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 47 / 49
Duality
In category theory, any notion has its dual obtain by inverting the arrows.In this case
F -coalgebra
Final F -coalgebras.
When instantiated on Set (and on particular functors), final coalgebras arethe set on infinitary terms (trees), build on a given signatures.
Final coalgebra can represents the infinitary behaviour of process.i.e. as semantics models.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 48 / 49
Assignment
Deepen the study of one of the subjects presented in the course, solve onethe following exercises.
Propose an small-step SOS for IMP. Sketch a proof that small-stepand big-step SOS agree with each other.
Propose a denotational semantics for a repeat command
repeat c until b.
Determine whether the following pair of processes are bisimilar:
(rec X = α.X ) ‖ (rec Y = α.Y ) andrec X = ((α.X ) + (α.X ) + (τ.X )).τ.((α.nil) + (β.nil)) and (τ.α.nil) + (τ.β.nil)
prove your claims.
Reference. The formal semantics of programming languages. G. Winskel,MIT Press.
P. Di Gianantonio (Udine) FIT’09 – Novi Sad 18th June, 2009 49 / 49