VDM - Part II Models and Analysis of Software Lecture 4

Slides:



Advertisements
Similar presentations
IntroductionIntroduction Copyright, 2003 © Jerzy R. Nawrocki Models and Analysis.
Advertisements

IntroductionIntroduction Copyright, 2000 © Jerzy R. Nawrocki Models and Analysis.
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
1 Recitation 7. Developing loops Introduction. This recitation concerns developing loops using their invariants and bound functions. Your recitation instructor.
Introduction to Programming (in C++) Data types and visibility Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC.
ML Introduction.1 Standard ML Introduction. ML Introduction.2 Includes: Most of the examples Most of the questions Most of the answers... Recommended.
Sequences for system modelling. At the end of this lecture you should be able to: provide a definition of a VDM sequence; identify situations in which.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
1 CS 162 Introduction to Computer Science Chapter 5 ASCII to Integer Conversion Herbert G. Mayer, PSU Status 11/9/2014.
RequisitePro (2) Copyright, 2001 © Jerzy R. Nawrocki Requirements Engineering.
Sequences At the end of this lecture you should be able to: provide a definition of a VDM sequence; utilize and interpret sequence notation; make appropriate.
1 CS October 2008 The while loop and assertions Read chapter 7 on loops. The lectures on the ProgramLive CD can be a big help. Quotes for the Day:
Standard SRS Copyright, 2001 © Jerzy R. Nawrocki Requirements Engineering Lecture.
Java Methods. Topics  Declaring fields vs. local variables  Primitive data types  Strings  Compound Assignment  Conversions from one value to another.
Introduction to Programming (in C++) Algorithms on sequences. Reasoning about loops: Invariants. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept.
An introduction to specification in VDM-SL At the end of this lecture you should be able to: write a formal specification of a system in VDM-SL; correlate.
VDM-SL Case Study Learning Outcomes At the end of this lecture you should be able to: Analyse and informally specify a complete system using UML class.
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Introduction to VDM Copyright, 2003 © Jerzy R. Nawrocki Models and Analysis of Software.
Introduction to Z Copyright, 2002 © Jerzy R. Nawrocki Models and Analysis of Software.
Chapter 9: Functional Programming in a Typed Language.
Overview of the Haskell 98 Programming Language
PZ03EX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03EX - ML Programming Language Design and Implementation.
Composite Objects Learning Outcomes At the end of this lecture you should be able to: Identify when it is appropriate to use a composite object type Use.
An introduction to specification in VDM-SL At the end of this lecture you should be able to: write a formal specification of a system in VDM-SL; correlate.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Requirements Specification Copyright, 2001 © Jerzy R. Nawrocki Requirements Engineering.
Programming Fundamentals 3 rd lecture Szabolcs Papp.
1 CS April 2010 while loops Reading: today: Ch. 7 and ProgramLive sections. For next time: Ch Prelim 2. Thursday evening, 7:30PM Watch.
DiscussionsDiscussions Copyright, 2001 © Jerzy R. Nawrocki Requirements Engineering.
Introduction to Quality Management Copyright, 2000 © Jerzy R. Nawrocki Quality.
1 Notation and Specification of Concurrency n Concurrency Topics  1. Sequential programming notation  2. Expressing concurrency with co and process 
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
1 CS April 2010 while loops Reading: today: Ch. 7 and ProgramLive sections. For next time: Ch Prelim 2. Thursday evening, 7:30PM Watch.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
6-Jul-16 Haskell II Functions and patterns. Data Types Int + - * / ^ even odd Float + - * / ^ sin cos pi truncate Char ord chr isSpace isUpper … Bool.
Lecture #5 מבוא מורחב.
Formal Methods in SE Lecture 21.
Requirements Engineering Lecture 2
VDM: Vienna Development Method
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Theory of Computation Lecture 4: Programs and Computable Functions II
CS 100: Roadmap to Computing
Python: Control Structures
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Functions and patterns
A lightening tour in 45 minutes
Material in the textbook on pages
ML Programming Language Design and Implementation (4th Edition)
Discrete Structures for Computer Science
CS October 2008 The while loop and assertions
Lecture #5 מבוא מורחב.
Structured COBOL Programming
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CSE-321 Programming Languages Introduction to Functional Programming
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Copyright © Zeph Grunschlag,
Compiler Construction
Functions and patterns
Functions and patterns
Requirements Engineering Lecture 6
Compiler Construction
CS October 2010 Read: Sec and chapter 7 on loops. The lectures on the ProgramLive CD can be a big help. Some anagrams A decimal point I'm.
Presentation transcript:

VDM - Part II Models and Analysis of Software Lecture 4 Jerzy Nawrocki Models and Analysis of Software Lecture 4 VDM - Part II Jerzy.Nawrocki@put.poznan.pl www.cs.put.poznan.pl/jnawrocki/mse/models/ Copyright, 2003 © Jerzy R. Nawrocki Models & Analysis of Software, Lecture 4

From the previous lecture.. Jerzy Nawrocki From the previous lecture.. Introduction to VDM VDM = Very Difficult Method Model-based: basic types (integer, real, ..) and compound types (sets, sequences, ..) Implicit specification (what?) and explicit one (how?). No explicit support for concurrency and time. J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

From the previous lecture.. Jerzy Nawrocki From the previous lecture.. Quantifiers That’s really different from Pascal! -- A prime number, n, is -- divisible only by 1 and n. IsPrime (n: N1) res: B post res  k  N1  (1 < k  k < n)  n mod k  0 J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

From the previous lecture.. Jerzy Nawrocki From the previous lecture.. Pre-conditions Quotient (-6, 2) = 3 Quotient (a, b: Z) res: N pre b  0 post res = (abs a) div (abs b) J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

From the previous lecture.. Jerzy Nawrocki From the previous lecture.. Sequences (I) -- CDs = sequence of Common Divisors CDs (a, b: N1) res: N1+ post res = [k | k  N1  a mod k = 0  b mod k = 0] J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Characters and strings Jerzy Nawrocki Plan of the lecture From the previous lecture.. Characters and strings Type invariants Records Miscellaneous J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Characters and strings char - alfanumeric characters char* - possibly empty sequence of char char+ - nonempty sequence of char 'a' - a character literal "ABBA" - a string of chars (text) "S. Covey" = ['S', '.', ' ', 'C', 'o', 'v', 'e', 'y'] "S. Covey"(1)= 'S' J. Nawrocki, Models & ...

Characters and strings Reversing a string -- Reversing a string of characters reverse(t: char*) res: char* post (t = [ ]  res = [ ])  (t  [ ]  res = (tl t) [hd t] reverse("top") = "pot" J. Nawrocki, Models & ...

Characters and strings Reversing a string -- Reversing a string of characters reverse(t: char*) res: char* post (t = [ ]  res = [ ])  (t  [ ]  res = reverse(tl t) [hd t] reverse("top") = "pot" Important modification J. Nawrocki, Models & ...

Characters and strings Integer to text conversion Can’t be simpler? d_seq= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] -- Integer to text conversion i2t(i: N) t: char+ post (i=0  t="0")  (i>0  t=i2t1(i)) i2t1(i: N) t: char* post (i=0  t= [ ])  (i>0  t=i2t1(i div 10) [d_seq(i mod 10 + 1)]) J. Nawrocki, Models & ...

Plan of the lecture Type invariants From the previous lecture.. Jerzy Nawrocki Plan of the lecture From the previous lecture.. Characters and strings Type invariants Records Miscellaneous J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Declaration of invariants Type invariants Declaration of invariants 0  b  b  1 resembles 0  b  1 Id = T inv Pattern  Boolean_condition Bit = N inv Bit  0  b  b  1 Bit = {b | b  N  0  b  b  1} J. Nawrocki, Models & ...

Defining prime numbers Type invariants Defining prime numbers More reusable and readable! Prime = N1 inv Prime   i N1  (1<i  i<a)  a mod i  0 is_prime(a: N1) res: B post res =  i N1  (1<i  i<a)  a mod i  0 Prime = N1 inv Prime  is_prime(a) J. Nawrocki, Models & ...

Here the defined type is used. Type invariants Using prime numbers -- Checking if every even number between a and b -- can be represented as a sum of 2 prime numbers goldbach(a,b: N1) res: B pre a  b post res =  i N1  (a  i  i  b  i mod 2 = 0)   x,y: Prime  i= x+y Here the defined type is used. J. Nawrocki, Models & ...

Plan of the lecture Records From the previous lecture.. Jerzy Nawrocki Plan of the lecture From the previous lecture.. Characters and strings Type invariants Records Miscellaneous J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Records Record definition ‘FamilyN’ Rec:: Field1 : T1 stands for ‘Family Name’ Rec:: Field1 : T1 Field2 : T2 . . . Fieldn : Tn Worker:: FamilyN: char+ FirstN: char+ Hours: N J. Nawrocki, Models & ...

Selecting the field ‘Hours’. Records Field selection Rec.Field WorkersFile = Worker* total_hours(w: WorkersFile) res: N post (w=[ ]  res = 0)  (w [ ]  res = (hd w).Hours + total_hours(tl w) Selecting the field ‘Hours’. J. Nawrocki, Models & ...

Plan of the lecture Miscellaneous From the previous lecture.. Jerzy Nawrocki Plan of the lecture From the previous lecture.. Characters and strings Type invariants Records Miscellaneous J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Unions T1 | T2 Enumerated types: Signal = RED | AMBER | GREEN J. Nawrocki, Models & ...

Optional types N N N nil - absence of a value Optional type: Optional type operator: Expression = nil  | nil or  [ ] N N N if next(P) = nil .. J. Nawrocki, Models & ...

Explicit functions N max: x x  max (x, y, z)  func_name: T1 x T2 x .. x Tn  T func_name(Id1, Id2, .., Idn)  E pre B max: x x  max (x, y, z)  if (y  x)  (z  x) then x elseif (x  y)  (z  y) then y else z N J. Nawrocki, Models & ...

Polymorphic functions max [ @num ]: @num x @num x @num  @num max (x, y, z)  if (y  x)  (z  x) then x elseif (x  y)  (z  y) then y else z result = max [ ] (1, 2, 3) N result = max [ ] (1.1, 2.2, 3.3) R J. Nawrocki, Models & ...

State N state Id of field_list inv invariant_definition init initialisation end state maximum of max: init mk_maximum(m)  m=0 end N J. Nawrocki, Models & ...

State R Another example state Id of field_list inv invariant_definition init initialisation end Another example state aircraft of speed: height: inv mk_aircraft(-,h)  (h  0.0) init mk_aircraft(s,h)  (s=0.0)  (h= 0.0) end R J. Nawrocki, Models & ...

Implicit operations N Op_name (Id1: T1, .., Idk:Tk) Idr: Tr ext Access_vars pre B post B’ Access_vars: rd or wr prefix MAX3() ext rd x, y, z: wr max: post (x  max)  (y  max)  (z  max)  (max  {x, y, z}) N J. Nawrocki, Models & ...

Implicit operations N Old state: variable MAX_NUM(n: ) ext wr max: post (n  max)  (max = max  max = n) N J. Nawrocki, Models & ...

Error definitions N PUT_YEAR(year: ) ext wr yr: pre year  1994 post yr = year errs yr2dXIX: 94  year  year  99  yr= year+1900 yr2dXX: year < 94  yr = year+2000 N J. Nawrocki, Models & ...

Explicit operations N o OPER_NAME: T1 x .. x Tn  T OPER_NAME (Id1, Id2, .., Idn)  Expression pre B MAX_NUM:  () MAX_NUM (n)  if max < n then max:= n else skip N o J. Nawrocki, Models & ...

Conditionals if B1 then ES1 elseif B2 then ES2 . . . elseif Bn then ESn else ES cases Es: P1  ES1 . . . Pn  ESn others  ES end J. Nawrocki, Models & ...

Iteration statements for Id= E1 to E2 by Inc do St for Id in Sq do St for Id in reverse Sq do St for all Id  E do St while B do St J. Nawrocki, Models & ...

Summary At last! Character string = sequence. Type invariants allow to define quite complicated types (e.g. prime numbers). Records allow do specify database-like computations. At last! J. Nawrocki, Models & ...

Jerzy Nawrocki Homework Specify a function digit 5 that returns a sequence of decimal digits of a number k (see functions digits3 and digits2). Specify an example of a function that would be an implementation of a JOIN operation in a relational database. Specify a polymorphic projection and selection operation. J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Jerzy Nawrocki Further readings A. Harry, Formal Methods Fact File, John Wiley & Sons, Chichester, 1996.  J. Nawrocki, Models & ... Models & Analysis of Software, Lecture 4

Quality assessment 1. What is your general impression? (1 - 6) 2. Was it too slow or too fast? 3. What important did you learn during the lecture? 4. What to improve and how? J. Nawrocki, Models & ...