Introduction to VDM Copyright, 2003 © Jerzy R. Nawrocki Models and Analysis of Software.

Slides:



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

IntroductionIntroduction Copyright, 2000 © Jerzy R. Nawrocki Models and Analysis.
Discrete Mathematics Lecture 3
Models of Concurrency Manna, Pnueli.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Study Guides Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM Mycatstudy.com.
Thinking Mathematically
Math 3121 Abstract Algebra I
Denoting the beginning
Discrete Mathematics Lecture 4 Harper Langston New York University.
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
CSE115/ENGR160 Discrete Mathematics 02/10/11 Ming-Hsuan Yang UC Merced 1.
Discrete Math 6A Max Welling. Recap 1. Proposition: statement that is true or false. 2. Logical operators: NOT, AND, OR, XOR, ,  3. Compound proposition:
Properties of the Integers: Mathematical Induction
The Integers and Division
Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,
CSCI 1900 Discrete Structures
Definitions from the Text, sections 1.1 – 1.4
Slide 5-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.
Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM
(CSC 102) Discrete Structures Lecture 10.
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.
Number Theory.  A prime number is a natural number greater than 1 that has exactly two factors (or divisors), itself and 1.  Prime numbers less than.
Model-Based Specification CIS 376 Bruce R. Maxim UM-Dearborn.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Mathematical Preliminaries (Hein 1.1 and 1.2) Sets are collections in which order of elements and duplication of elements do not matter. – {1,a,1,1} =
Real Number System.
Sets --- A set is a collection of objects. Sets are denoted by A, B, C, … --- The objects in the set are called the elements of the set. The elements are.
Introduction to Z Copyright, 2002 © Jerzy R. Nawrocki Models and Analysis of Software.
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Mar 3, 2006.
The Real Number System Section P.1. Set, Unions, and Intersections Part 1.
Copyright © 2009 Pearson Education, Inc. Chapter 5 Section 1 - Slide 1 Chapter 1 Number Theory and the Real Number System.
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (1)
CompSci 102 Discrete Math for Computer Science
Section 2.1. Section Summary Definition of sets Describing Sets Roster Method Set-Builder Notation Some Important Sets in Mathematics Empty Set and Universal.
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Basic Definitions of Set Theory Lecture 23 Section 5.1 Wed, Mar 8, 2006.
Slide Copyright © 2009 Pearson Education, Inc. Unit 1 Number Theory MM-150 SURVEY OF MATHEMATICS – Jody Harris.
Basic Definitions of Set Theory Lecture 24 Section 5.1 Fri, Mar 2, 2007.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
Introduction to Quality Management Copyright, 2000 © Jerzy R. Nawrocki Quality.
CSCI 115 Chapter 1 Fundamentals. CSCI 115 §1.1 Sets and Subsets.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
Chapter P Prerequisites: Fundamental Concepts of Algebra Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 P.6 Rational Expressions.
1 CMSC 250 Chapter 3, Number Theory. 2 CMSC 250 Introductory number theory l A good proof should have: –a statement of what is to be proven –"Proof:"
Basic Definitions of Set Theory Lecture 23 Section 5.1 Mon, Feb 21, 2005.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
Module #9 – Number Theory 6/11/20161 Chapter 3 Algorithms, Integers and Matrices.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Slide Copyright © 2009 Pearson Education, Inc. Slide Copyright © 2009 Pearson Education, Inc. Chapter 1 Number Theory and the Real Number System.
Algebra 2 Properties of Real Numbers Lesson 1-2 Goals Goal To graph and order real numbers. To Identity properties of real numbers. Rubric Level 1 –
1.1 – SETS AND SYMBOLS. Goals SWBAT understand basic set notation and set symbols SWBAT solve simple sentences with a given domain SWBAT graph sets of.
The Relation Induced by a Partition
Math 3121 Abstract Algebra I
VDM: Vienna Development Method
Set, Combinatorics, Probability & Number Theory
1.1 Sets and Subsets.
VDM - Part II Models and Analysis of Software Lecture 4
R.1 R.2 R.3 R.4 R.5 R.6 R.7 R.1 Sets Basic Definitions ▪ Operations on Sets Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Mathematical Induction Recursion
CS100: Discrete structures
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Algebra 1 Section 1.1.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Copyright © Zeph Grunschlag,
Divisibility and Modular Arithmetic
Foundations of Discrete Mathematics
books WARM-uP Lesson 1 Independent work Exit card
Presentation transcript:

Introduction to VDM Copyright, 2003 © Jerzy R. Nawrocki Models and Analysis of Software Lecture 3 Models and Analysis of Software Lecture 3

J. Nawrocki, Models... (3) IntroductionIntroduction VDM = Vienna Development Method, IBM Laboratory 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. Math & text notations. VDM VDM = Very Difficult Method

J. Nawrocki, Models... (3) IntroductionIntroduction add (a, b: N ) result: N post result = a + b add (a, b: N ) result: N post result = a + b Simple example It’s trivial!

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) IdentifiersIdentifiers add (a, b: N ) result: N post result = a + b add (a, b: N ) result: N post result = a + b Letter (Letter | Digit | Greek_letter | Underscore)* Letter case is significant. First_element First_Element Value_6  First_element First_Element Value_6 

J. Nawrocki, Models... (3) CommentsComments -- adding two numbers add (a, b: N ) result: N post result = a + b -- adding two numbers add (a, b: N ) result: N post result = a + b annotations Author: J.R. Nawrocki Written on: March 6, 2002 end annotations add (a, b: N ) result: N post result = a + b annotations Author: J.R. Nawrocki Written on: March 6, 2002 end annotations add (a, b: N ) result: N post result = a + b I prefer double hyphen.

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) Integer numbers Integer types N N Natural numbers (0, 1, 2,..) N1N1 N1N1 Positive integers (1, 2,..) Z Z Integers (.., -2, -1, 0, 1, 2,..)

J. Nawrocki, Models... (3) Operators Integer numbers a + b3 + 2 = 5 a - b5 - 2 = 3 a  b3  2 = 6 a / b6 / 4 = 1.5 a div b11 div 4 = 2 a mod b11 mod 4 = 3 a  b2  3 = 8 abs aabs -3 = 3 a + b3 + 2 = 5 a - b5 - 2 = 3 a  b3  2 = 6 a / b6 / 4 = 1.5 a div b11 div 4 = 2 a mod b11 mod 4 = 3 a  b2  3 = 8 abs aabs -3 = 3 Looks like Pascal except for ‘  ’.

J. Nawrocki, Models... (3) Example Integer numbers f(0) = 0 f(1) = 1 f(2) = 3 -- f(n) = n f (n: N ) res: N post res = (n+1)  n / 2 -- f(n) = n f (n: N ) res: N post res = (n+1)  n / 2

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) Boolean values a = b a  b a < b a  b a > b a  b a = b a  b a < b a  b a > b a  b Relations true false true false Constants  anot a a  ba and b a  ba or b a  ba implies b a  ba equivalent to b  anot a a  ba and b a  ba or b a  ba implies b a  ba equivalent to b Boolean operators B B Boolean values

J. Nawrocki, Models... (3) Example Boolean values Is_CD(12, 16, 4)= true -- CD = Common Divisor -- Is k a CD for a and b? Is_CD (a, b, k: N ) res: B post res  (a mod k = 0  b mod k = 0) -- CD = Common Divisor -- Is k a CD for a and b? Is_CD (a, b, k: N ) res: B post res  (a mod k = 0  b mod k = 0)

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) Quantifiers PredicatesPredicates   For all (universal q.)   Exists (existential q.) !! !! Exists one (unique q.)

J. Nawrocki, Models... (3) -- A prime number, n, is -- divisible only by 1 and n. IsPrime (n: N 1 ) res: B post res   k  N 1  (1 < k  k < n)  n mod k  0 -- A prime number, n, is -- divisible only by 1 and n. IsPrime (n: N 1 ) res: B post res   k  N 1  (1 < k  k < n)  n mod k  0 Example PredicatesPredicates That’s really different from Pascal!

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) General form Implicit functions function_name (Ids 1 : T 1,.., Ids k : T k ) Id_r: T pre B post B’ function_name (Ids 1 : T 1,.., Ids k : T k ) Id_r: T pre B post B’ Optional pre-condition

J. Nawrocki, Models... (3) Example Implicit functions Quotient (-6, 2) = 3 Quotient (a, b: Z ) res: N pre b  0 post res = (abs a) div (abs b) Quotient (a, b: Z ) res: N pre b  0 post res = (abs a) div (abs b)

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) Non-integer numbers Non-integer types Q Q Rationals (2, 1/4, 3.8,..) R R Real numbers (2.0, 3.8,  2,..)

J. Nawrocki, Models... (3) Operators Non-integer numbers a + b = 3.2 a - b = 4.8 a  b3.1  2 = 6.2 a / b6.0 / 4 = 1.5 a  b2.0  3 = 8.0 abs aabs -3.1 = 3.1 floor afloor 3.9 = 3 a + b = 3.2 a - b = 4.8 a  b3.1  2 = 6.2 a / b6.0 / 4 = 1.5 a  b2.0  3 = 8.0 abs aabs -3.1 = 3.1 floor afloor 3.9 = 3 Where is div and mod ?

J. Nawrocki, Models... (3) Example Non-integer numbers -- CV = Cuboid Volume CV (a, b, h: R ) res: R post res = a  b  h -- CV = Cuboid Volume CV (a, b, h: R ) res: R post res = a  b  h h a b

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) SequencesSequences Type constructors T* General sequence (possibly empty) T+T+ T+T+ Non-empty sequence What is a sequence? [ 1, 5, 5, 1] First Second Third

J. Nawrocki, Models... (3) Operators SequencesSequences [ ]empty sequence hd Xhd [14, 15, 16] = 14 tl Xtl [14, 15, 16] = [15, 16] len Xlen [14, 15, 16] = 3 inds Xinds [14, 15, 16] = {1, 2, 3} elems Xelems [14, 15, 14] = {14, 15} X(n)[14, 15, 14](2) = 15 X(l,...,u)[14, 15, 16](2,...,3) = [15, 16] [ ]empty sequence hd Xhd [14, 15, 16] = 14 tl Xtl [14, 15, 16] = [15, 16] len Xlen [14, 15, 16] = 3 inds Xinds [14, 15, 16] = {1, 2, 3} elems Xelems [14, 15, 14] = {14, 15} X(n)[14, 15, 14](2) = 15 X(l,...,u)[14, 15, 16](2,...,3) = [15, 16]

J. Nawrocki, Models... (3) SequencesSequences s1 s2[6, 5] [2, 4, 9] = [6, 5, 2, 4, 9] Sequence concatenation

J. Nawrocki, Models... (3) Sequence comprehension SequencesSequences [ E | Id  S  Boolean_condition ] Expression Subset of R Selects a finite subset of S Evens_to_10 = [ 2  n | n  N 1  n < 6 ] Evens_to_10 = [ 2, 4, 6, 8, 10 ] Evens_to_10 = [ 2  n | n  N 1  n < 6 ] Evens_to_10 = [ 2, 4, 6, 8, 10 ]

J. Nawrocki, Models... (3) Example (I) SequencesSequences -- CDs = sequence of Common Divisors CDs (a, b: N 1 ) res: N 1 + post res = [k | k  N 1  a mod k = 0  b mod k = 0] -- CDs = sequence of Common Divisors CDs (a, b: N 1 ) res: N 1 + post res = [k | k  N 1  a mod k = 0  b mod k = 0]

J. Nawrocki, Models... (3) Example (II) SequencesSequences -- Max = maximum element of a sequence Max (s: N 1 + ) m: N 1 post (tl s = [ ]  m = hd s)  (tl s  [ ]  hd s  Max(tl s)  m = hd s)  (tl s  [ ]  hd s < Max(tl s)  m = Max(tl s)) -- Max = maximum element of a sequence Max (s: N 1 + ) m: N 1 post (tl s = [ ]  m = hd s)  (tl s  [ ]  hd s  Max(tl s)  m = hd s)  (tl s  [ ]  hd s < Max(tl s)  m = Max(tl s)) Recursion

J. Nawrocki, Models... (3) Example (III) SequencesSequences -- GCD = Greatest Common Divisor GCD (a,b: N 1 ) res: N 1 post res= Max (CDs (a, b)) -- GCD = Greatest Common Divisor GCD (a,b: N 1 ) res: N 1 post res= Max (CDs (a, b)) Is Max necessary? Can’t we make it simpler?

J. Nawrocki, Models... (3) Plan of the lecture Introduction Identifiers and comments Integer numbers Boolean values Predicates Implicit functions Non-integer numbers Sequences Sets

J. Nawrocki, Models... (3) B - Boolean (true, false) N 1 - positive integers (1, 2, 3,..) N - natural numbers (including 0) Z - integers Q - rationals R - reals B - Boolean (true, false) N 1 - positive integers (1, 2, 3,..) N - natural numbers (including 0) Z - integers Q - rationals R - reals SetsSets Basic sets x  BasicSet x  BasicSet Basic sets or basic types?

J. Nawrocki, Models... (3) T-seta finite set of values of type T SetsSets Finite sets N -seta finite set of natural numbers R -seta finite set of reals R -set-seta finite set of finite sets of reals N -seta finite set of natural numbers R -seta finite set of reals R -set-seta finite set of finite sets of reals

J. Nawrocki, Models... (3) {E | B 1, B 2,..., B n  Boolean_condition } SetsSets Set values { }empty set {0, 2, 4}explicit set value {2,..., 5}= {2, 3, 4, 5} {2  n | n  N  n<3}= {0, 2, 4} { }empty set {0, 2, 4}explicit set value {2,..., 5}= {2, 3, 4, 5} {2  n | n  N  n<3}= {0, 2, 4} {[a, b] | a  N, b  N  b = a  a  a  3} Only finite sets!

J. Nawrocki, Models... (3) SetsSets Finite set operators (I) x  Sbelongs to x  Sdoes not belong to card Scardinality of S S 1 = S 2 equals S 1  S 2 does not equal S 1  S 2 S 1 is a subset of S 2 S 1  S 2 S 1 is a proper subset of S 2 x  Sbelongs to x  Sdoes not belong to card Scardinality of S S 1 = S 2 equals S 1  S 2 does not equal S 1  S 2 S 1 is a subset of S 2 S 1  S 2 S 1 is a proper subset of S 2 Only finite sets!

J. Nawrocki, Models... (3) SetsSets Finite set operators (II) S 1  S 2 union S 1  S 2 intersection S 1 \ S 2 difference F S power set of S S 1  S 2 union S 1  S 2 intersection S 1 \ S 2 difference F S power set of S Only finite sets!

J. Nawrocki, Models... (3) SetsSets A set of decimal digits of a number k digit = {0,..., 9} digits1(k: N ) res: digit-set post res = {k mod 10}  digits1(k div 10) digit = {0,..., 9} digits1(k: N ) res: digit-set post res = {k mod 10}  digits1(k div 10) Does not work!

J. Nawrocki, Models... (3) SetsSets A set of decimal digits of a number k digits2(k: N ) res: digit-set post (k=0  res = { })  (k>0  res = {k mod 10}  digits2(k div 10)) digits2(k: N ) res: digit-set post (k=0  res = { })  (k>0  res = {k mod 10}  digits2(k div 10)) What if k=0? digits3(k: N ) res: digit-set post (k=0  res = { 0 })  (k>0  res = digits2(k)) digits3(k: N ) res: digit-set post (k=0  res = { 0 })  (k>0  res = digits2(k))

J. Nawrocki, Models... (3) SummarySummary VDM is a formal method. Its basic types are similar to those in Pascal, C,.. It contains quantifiers. Finite sequence is quite a powerful mechanism. VDM allows for recursion.

J. Nawrocki, Models... (3) Further readings A. Harry, Formal Methods Fact File, John Wiley & Sons, Chichester, 1996, pages 

J. Nawrocki, Models... (3) HomeworkHomework Write a shorter definition of GCD. Specify the factorial. Specify the least common multiply. Specify a function that checks if n is an automorphic number (i.e. if n appears in a decimal representation of its square). Specify a total of decimal digits of a given number n.

J. Nawrocki, Models... (3) 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?