P h i l

advertisement
Philadelphia University
Lecturer
Coordinator
Internal Examiner
Faculty of Information Technology
Department of Computer Science
Marking scheme
MSc. Course
: Prof. S. Ghoul
: Prof. S. Ghoul
: Dr.N. Emam
Formal Methods (750750)
Mid-Term Exam
December 4, 2012 Time: 2H
2012-2012.1
I. Basic Notions
1.
Reading [2], answer the following:
1.a Specify, in one line, the relation between formal methods and formal specifications.
(5 m)
Formal specification is part of a more general collection of techniques that are known as formal methods
5
1.b In the basic mathematical model, the author presents the functions signatures as function: domain  range. Later, he
fixed the different possible kinds of function. What are these kinds and why are they important.
(5m)
Constructors, generators, and operations. They are important in axioms specification
23
1.c In the same context, Sommerville [3] has presented, in page 09, others kinds of function. Match between the two
definitions and conclude, in one line, about the righteous one.
(5m)
Constructors
Generators
Operations
Constructors 1
Inspection 1
Constructors
Generators are not particularly useful. So, [3] is sufficient 3
Operations
2. In [3], a syntax for signature and presentation was introduced, in Figure 27.7.
(5 m)
2.a Develop a complete signature of the List, by converting the above syntax to that introduced in [1].
Sort List;
1+ 4
Operations
Create:
 List;
Cons : List x Elem  List
Head : List
 Elem
Length:
 Integer
Tail : List
 List
Signature
Declare L: List; v: Elem; 3
Axioms
2
Head (create) == Undefined exception (empty list);
Head (Cons (L, v)) == if L= create then v else Head (L);
Length (Create) == 0;
Length (Cons (L, v)) == Length (L) + 1;
Tail (Create) == Create;
Tail (Cons(L, v)) == if L=create then create else Cons(Tail(L),v)
(5m)
2.b Develop a complete presentation of the List, by converting the above syntax to that introduced in [1].
See the precedent answer.
Master degree course
Formal Methods
Mid-Term Exam
4/12/2012
1/3
P
r
e
s
e
n
t
a
t
i
o
n
(5m)
2.c Rewrite the presentation introduced in page 12 [1] using the syntax introduced in [3].
Sorts Stack, Nat, Bool;
1
Comments
true, false
 Bool;
zero
 Nat;
succ (Nat)
 Nat;
newstack
 Stack;
push (Stack, Nat)  Stack;
isnewstack (Stack)  Bool;
pop (Stack)
 Stack;
top (Stack)
 Nat;
isnewstack (newstack)
isnewstack (push(s,n))
isnewstack (pop (s))
top (newstack)
top (push(s,n))
top (pop (s))
3
== true;
== false;
== false
== zero;
== n;
== top(s)
1
2.d Using the Labeled BNF Grammar formalism [5], specify the main parts (components) of the specification
syntax introduced in Figure 27.6 [3].
(5m)
The LBNF rules have the following form:
Ident ”.” Ident ”::=” (Ident | String)* ”;” ;
So, the syntax of a signature may be as it follows:
Lsign. <Signature> :: = <Specification Name> 1
“sort” <Sort names>
1
("imports" <List of Specification names>)* 2
(<informal Description>)
<Operation signatures>
1
< Axioms>
…..
3. The paper [4] presents the modularity concept for which we found a formal specification in [1].
3.a The Figure 27.7 [3] presents a specification of List. Rewrite this specification using the module concept syntax
introduced in [1].
(5m)
Master degree course
Formal Methods
module List; 2
import Integer; Elem
export all;
module Integer; 3
sort List;
… //2.a
end module List;
sort integer;
…
end module Integer;
Mid-Term Exam
4/12/2012
export all;
1/3
(5m)
3.b Translate the above module to a generic specification.
scheme ListScheme
[
requirement Elem; 2
export all;
3
sort Elem;
end requirement Elem;
];
module List;
…
end module List;
end scheme ListScheme
instantiate ListScheme;
with Elem as Nat, 1
end instantiate ListScheme;
module List;
import Integer;
export all;
Sort List;
Operations 2
Create:
Cons : List x Nat
Head : List
Length:
Tail : List
 List;
 List
 Nat
 Integer
 List
Declare L: List; v: Nat;
Axioms
…
end module List;
2
(5m)
3.c Create an instance from the above generic specification, fixing Elem to Nat (Natural data type).
See above
III. Unfamiliar Problems Solving
Objectives. The aim of the questions in this part is to evaluate you can make progress towards the solution of unfamiliar problems,
and can set out reasoning and explanation in a clear and coherent manner
(5m)
4. Study, in few lines, the possibility of specifying a function with several signatures and semantics.
This means that a function may be defined by different versions. Each version has a syntax and a semantics. Several PL
allow that: C++ (signature is an id), Logic (deduction rules defined by several alternatives). So, it is possible to define a
function by several signatures and semantics. But the problem is how to select the appropriated version according to the
context.
Master degree course
Formal Methods
Mid-Term Exam
4/12/2012
1/3
Download