100 likes | 269 Views
Software Engineering Lecture 8. Vladimir Safonov , Professor, head of laboratory St. Petersburg University Email: v_o_safonov@mail.ru WWW: http://user.rol.ru/~vsafonov. Program specification. Specification – the stage of software lifecycle , to follow by the requirements & goals stage
E N D
SoftwareEngineeringLecture8 Vladimir Safonov, Professor, head of laboratory St. Petersburg University Email: v_o_safonov@mail.ru WWW: http://user.rol.ru/~vsafonov
Program specification • Specification– the stage of software lifecycle, to follow by the requirements & goals stage • Specification – a formalized, external, preciseand complete description of the task to be solved by the program or its part in question • Simply: specification is WHAT, rather than HOW • Typical element of specification is a mathematical formula, e.g., fact(n) = 1 * 2 * … * n • Implementation of an algorithm, data representation, etc. are not elements of specification • Complete specification: taking into account all the alternatives, e.g., n = 0 forfact(n): fact(0) = 1 (C) Vladimir O. Safonov, 2004
Specification techniques • Natural language • HIPO diagrams(Hierarchical Input-Process-Output) • Decision tables • Program calculus (operator schemas) by R. Floyd – C.A.R. Hoare: P {S} Q A{S}B, B{T}C |- A{S;T} C • Denotational semantics (D. Scott, J.Donahue at al.): program is a transformer of predicates: P(x1, … xn) -> Q(x1, …, xn), wherexi – free (global) variables • Vienna Definition Method(VDM; IBM Research): program – system of mutually related finite-state automata • Algebraic (G.A. Goguen et al.): program – a collection of ADT, each of them specified as multi-sorted algebra • Petri nets – specifying asynchronous programs and computing systems (see: Kotov V. E. Petri nets.: Nauka, 1986) (C) Vladimir O. Safonov, 2004
Specification languages • VDM – specification using the concept of finite automaton (Ollongren A. Defining programming languages by interpretive automata. – Prentice Hall, 1977) • OBJ, CLEAR, SDL, LARCH –algebraic specification languages (please see OBJ description in J.A. Goguen’s papers) • CIP/L (“Wide Spectrum Multi-Layered Language) – Technical University, Munich, 1979 • References to VDM, Z, LARCH – please see: I. Sommerville’s textbook (C) Vladimir O. Safonov, 2004
OBJ3 (Prof. G. A. Goguen). Example (1/2)ftp://www.cs.ucsd.edu/pub/fac/goguen/obj3/University of California, San Diego obj NAT is sort Nat . op 0 : -> Nat . op s_ : Nat -> Nat [prec 1] . endo obj NATOPS is pr NAT . op 1 : -> Nat . eq 1 = s 0 . op _+_ : Nat Nat -> Nat [assoc comm prec 3] . vars M N : Nat . eq M + 0 = M . eq M + s N = s(M + N) . (C) Vladimir O. Safonov, 2004
OBJ3: Example (2/2) op _*_ : Nat Nat -> Nat [assoc comm prec 2] . eq M * 0 = 0 . eq M * s N = M * N + M . op _**_ : Nat Nat -> Nat [prec 4] . eq M ** 0 = 1 . eq M ** s N = (M ** N) * M . op _-_ : Nat Nat -> Nat . eq M - 0 = M . eq 0 - M = 0 . eq s M - s N = M - N .[ SKIP … ] [lemma1] cq (N * N)**(M %2) = N ** M if even M . [lemma2] cq N *(N **(M - s 0)) = N ** M if pos M . endo (C) Vladimir O. Safonov, 2004
A monograph on OBJ and algebraic specifications (C) Vladimir O. Safonov, 2004
Other approaches to specification • B Liskov. CLU (M.I.T.): GCD = proc (int M, N) signals (overflow) requires N > 0; effects GCD(M, N) = greatest common divisor of M, N - ср. с “Design-by-Contract” (Dr. B. Meyer, Eiffel) • M. Shaw. ALPHARD (Carnegie-Mellon Univ.) ADT specifications(forms) – by R. Floyd, C.A.R. Hoare. For each ADT,thepre- &post-conditions for each abstract operation, and also abstract invariant and concrete invariant are indicated – a predicate to hold on the abstract (concrete) data items participating in the ADT definition: e.g., SP > 0 (C) Vladimir O. Safonov, 2004
Automated program synthesis by specification (E. Tougu, S.S. Lavrov) • Task formulation: Given a specification of the application domainD (as a collection of equates)and a specification of the pre- and post-conditions: Pre {S} Post Goal: authoated synthesis of the programS • Tools intended to solve similar tasks (U.S.S.R): - PRIZ-> NUT (E. Tougu; please see his monograph: Conceptual programming, Moscow, Science Publishers, 1984) - SPORA (S. Lavrov; automated program synthesis system with the specification language DESCARTES, 1980s) (C) Vladimir O. Safonov, 2004
References • Agafonov V.N.Program specification. Concepts and their organization. – Novosibirsk: Science Publishers, 1988 • Mathematical logic in programming. -Moscow: World Publishers, 1991 • Requirements and Specifications on Program Development. - Moscow, World Publishers, 1984 (C) Vladimir O. Safonov, 2004