Z -Toolkit Z specification language is based on formal system: –Propositional and predicate calculus –Set theory –Relations and –Functions Thus Z offers.

Slides:



Advertisements
Similar presentations
Chapter 2 Revision of Mathematical Notations and Techniques
Advertisements

Lecture adapted from CS3511,Discrete Methods Kees van Deemter
Linked Lists Contents 1.LinkedList implements the Interface List 2.Doubly Linked List implementation of common methods a.boolean add( Object x) -- append.
If R = {(x,y)| y = 3x + 2}, then R -1 = (1) x = 3y + 2 (2) y = (x – 2)/3 (3) {(x,y)| y = 3x + 2} (4) {(x,y)| y = (x – 2)/3} (5) {(x,y)| y – 2 = 3x} (6)
Chapter Matrices Matrix Arithmetic
Primitive Recursive Functions (Chapter 3)
Functions A function, f, is a mechanism that relates (or maps) one set of elements to another set. –More specifically, f, is a special type of relation.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
0 PROGRAMMING IN HASKELL Chapter 10 - Declaring Types and Classes.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Binary Operations.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
1 Amazing fact #3: -calculus is Turing-complete! But the -calculus is too weak, right? No multiple arguments! No numbers or arithmetic! No booleans or.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Discussion #25 1/13 Discussion #25 Set Topics & Applications.
Schemas. Nature of a schema: scope of names in a Z specification Names that are not confined inside schemas. Need to declare and called as global declaration.
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Sequences. What is sequence? A sequence is an ordered collection of objects. We use sequences to model collections in which order or multiplicity is important.
Sets. Copyright © Peter Cappello Definition Visualize a dictionary as a directed graph. Nodes represent words If word w is defined in terms of word.
Sets.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Express the repeating decimal as the ratio of two integers without your calculator. Warm-Up.
Programovací jazyky F# a OCaml Chapter 5. Hiding recursion using function-as-values.
ECSE Software Engineering 1I HO 3 © HY 2012 Lecture 3 Formal Methods through an Introduction to Z Formal Methods A notation for formal specification.
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
1 2.6 – Limits Involving Infinity. 2 Definition The notation means that the values of f (x) can be made arbitrarily large (as large as we please) by taking.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
What is a language? An alphabet is a well defined set of characters. The character ∑ is typically used to represent an alphabet. A string : a finite.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Sets Goal: Introduce the basic terminology of set theory.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Copyright © Cengage Learning. All rights reserved. CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF ELEMENTARY NUMBER THEORY AND METHODS OF PROOF.
Calculus I Ms. Plata Fortunately, several rules have been developed for finding derivatives without having to use the definition directly. Why?
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
Theory of computation Introduction theory of computation: It comprises the fundamental mathematical properties of computer hardware, software,
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
CSE 202 – Formal Languages and Automata Theory 1 REGULAR EXPRESSION.
Section 2.5. Cardinality Definition: A set that is either finite or has the same cardinality as the set of positive integers (Z + ) is called countable.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Functional Programming
Functional Programming
String is a synonym for the type [Char].
Conditional Expressions
Functional Programming
Formal Methods in SE Lecture 21.
Theory of Computation Lecture #
Data Structures and Algorithms
A lightening tour in 45 minutes
COP4020 Programming Languages
Advanced Algorithms Analysis and Design
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
CSCE 314: Programming Languages Dr. Dylan Shell
Chapter 6: Formal Relational Query Languages
C Language B. DHIVYA 17PCA140 II MCA.
Presentation transcript:

Z -Toolkit Z specification language is based on formal system: –Propositional and predicate calculus –Set theory –Relations and –Functions Thus Z offers a set of facilities to include (or express) these concepts ---- we call the set of facilities the Z toolkit.

Numbers and Operations in Z Z - language has 3 built-in number types –N : natural numbers (e.g. 0,1,2, , ) –N 1 : positive integers (e.g. 1,2,3, - - -, ) –Int : integers (e.g , -2,-1,0,1,2, - - -, ) Axiomatically expressed : (let IP represent power set) for positive integers for positive integers N 1 : IP N (“type” declaration) N 1 : IP N (“type” declaration) N 1 = N \ {0} (relation definition) N 1 = N \ {0} (relation definition) for natural numbers for natural numbers N : IP Int N : IP Int N = Int \ { - - -, -4, -3, -2, -1} N = Int \ { - - -, -4, -3, -2, -1} Rick ?

Numbers and Operations in Z Numerical operators –Defined as functions may use “lambda” notation –Binary operators defined with underscores on either side e.g. _ op _ e.g. _ op _ –Addition operator, +, (example) _ + _ : N x N N should be included in the signature part of schema _ + _ : N x N N should be included in the signature part of schema _ + _ = ג m,n : N succ n m in the predicate part of the schema Or m + n = succ n m in the predicate part of schema _ + _ : N x N N _ + _ : N x N N m + n = succ n m (where succ is successor ) m + n = succ n m (where succ is successor ) total function

Numbers and Operations in Z Let’s look at the great than or equal, =<, operator over N. _ = N (note : is a relation) _ = N (note : is a relation) _ =< _ = succ* (reflexive transitive closure of succ function) _ =< _ = succ* (reflexive transitive closure of succ function) succ* = succ 0 U succ 1 U succ 2 U succ* = succ 0 U succ 1 U succ 2 U succ 0 = id N = {(0,0), (1,1), } succ 0 = id N = {(0,0), (1,1), } succ 1 = { (0,1), (1,2), (2,3), } succ 1 = { (0,1), (1,2), (2,3), } succ 2 = { (0,2), (1,3), (2,4), } succ 2 = { (0,2), (1,3), (2,4), } succ 3 = { (0,3), (1,4), (2,5), } succ 3 = { (0,3), (1,4), (2,5), } etc. etc. So, succ* contains all the pairs that satisfy the =< relation The operator =< is thus defined in terms of a relation Look at 2 =< 5 as an example; now look at above predicate. should _ =< _ be “equal to” or is an “element of” succ* ? should _ =< _ be “equal to” or is an “element of” succ* ?

Sets and Operators on Sets in Z A Generic Definition is a definition that applies to sets of any type. –In schema representation: use [ ] use [ ] use double line,, on the top use double line,, on the top e.g. (union, difference, intersection ) e.g. (union, difference, intersection ) [ T ] [ T ] _ U _, _ \ _, _ _ : IP T x IP T IP T _ U _, _ \ _, _ _ : IP T x IP T IP T s1, s2 : IP T s1, s2 : IP T s1 U s2 = { x : T I x s1 \/ x s2 } s1 U s2 = { x : T I x s1 \/ x s2 } s1 \ s2 = { x : T I x s1 /\ x s2 } s1 \ s2 = { x : T I x s1 /\ x s2 } s1 s2 = { x : T I x s1 /\ x s2 } s1 s2 = { x : T I x s1 /\ x s2 }

“Inventing” an Operator Modified Example 9.1 in text: S1 and S2 be two sets. –Specify a SCARD operator that returns the cardinality of the set S1\S2. [ T ] [ T ] _ SCARD _ : IP T x IP T N _ SCARD _ : IP T x IP T N \/ S1, S2 : IP T S1 SCARD S2 = # (S1\S2) \/ S1, S2 : IP T S1 SCARD S2 = # (S1\S2)

More Sets and Operators on Sets in Z Subsets and proper subsets may be defined similarly as with unions and intersections, except subsets are defined as a “relation” between power sets, not a function. Generalized union and generalized intersection is defined as follows: [ S] [ S] U _, _ : IP ( IP S) IP S U _, _ : IP ( IP S) IP S \/ A : IP S ( IP S ) \/ A : IP S ( IP S ) U A = { x : S I a A x a } U A = { x : S I a A x a } A = { x : S I a A x a } A = { x : S I a A x a } So, for S = {1,2,3}, IP S = { { }, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} }. And { {2,3}, {1,2,3} } = {2,3}

Relations in Z A Relation in Z between two sets, S1 and S2, may be expressed as S1 S2 in the signature part of the schema. So, a relation would be R1 : S1 S2 Consider the composition operator, ;, defined generically [ T1, T2, T3 ] [ T1, T2, T3 ] _ ; _ : [(T1 T2) x (T2 T3)] (T1 T3) _ ; _ : [(T1 T2) x (T2 T3)] (T1 T3) R1 ; R2 = { t1: T1, t3 : T3 I t2: T2 R1 ; R2 = { t1: T1, t3 : T3 I t2: T2 (t1, t2) R1 /\ (t2, t3) R2 } (t1, t2) R1 /\ (t2, t3) R2 } R1 and R1 needs to be defined in Signature part?

Relations in Z Restrictions on domain and range of relations in Z [ T!, T2 ] [ T!, T2 ] _ _ : [ IP T1 x (T1 T2)] (T1 T2) _ _ : [ IP T1 x (T1 T2)] (T1 T2) _ _ : [(T1 T2 ) x IP T2] (T1 T2) _ _ : [(T1 T2 ) x IP T2] (T1 T2) \/ S : IP T1, R : T1 T2 \/ S : IP T1, R : T1 T2 S R = { t1 : T1, t2 :T2 I t1 S /\ (t1,t2) R (t1,t2) } S R = { t1 : T1, t2 :T2 I t1 S /\ (t1,t2) R (t1,t2) } \/ R : T1 T2, S : IP T2 \/ R : T1 T2, S : IP T2 R S = { t1: T1, t2 : T2 I (t1,t2) R /\ t2 S (t1,t2) } R S = { t1: T1, t2 : T2 I (t1,t2) R /\ t2 S (t1,t2) }

Relations in Z The “image” operator, where the image of a Relation restricted to the set S as the domain. [ T1, T2 ] [ T1, T2 ] _ ( _ ) : ( T1 T2) x IP T1 IP T2 _ ( _ ) : ( T1 T2) x IP T1 IP T2 \/ R : T1 T2, S : IP T1 \/ R : T1 T2, S : IP T1 R ( S ) = { t1: T1, t2 : T2 I t1 S /\ (t1,t2) R t2} R ( S ) = { t1: T1, t2 : T2 I t1 S /\ (t1,t2) R t2}

Functions in Z Since functions are just special relations, all the previous operators for sets and relations can be used Example with the “override” operator, – Recall that given two relations R and S each, over T1 x T2, R S = (dom S R) U S = [ (T1 \ dom S) R] U S R S = (dom S R) U S = [ (T1 \ dom S) R] U S [ T1, T2 ] [ T1, T2 ] _ _ : (T1 T2) x ( T1 T2) (T1 T2) _ _ : (T1 T2) x ( T1 T2) (T1 T2) \/ f, g : (T1 T2) \/ f, g : (T1 T2) f g = { {dom g} f } U g } f g = { {dom g} f } U g }

Sequences in Z There are 3 types of sequences in Z – a) a finite sequence ( note: most practical systems are finite) seq T = { f : N 1 T I dom f = 1, , #f }, where #f is the cardinality of sequence f. seq T = { f : N 1 T I dom f = 1, , #f }, where #f is the cardinality of sequence f. – b) non-empty finite sequence non-e-seq T = { f : seq T I #f >0 } non-e-seq T = { f : seq T I #f >0 } – c) injective sequence (sequence with no repetition) inj_seq T = { f: N 1 T I dom f = 1, - - -, #f } inj_seq T = { f: N 1 T I dom f = 1, - - -, #f } = seq T (N 1 T) = seq T (N 1 T) –Example : file_Q file_Q inQ, OutQ : seq Files inQ, OutQ : seq Files # inQ = #OutQ # inQ = #OutQ

Concatenaton of sequences in Z Two sequences may be concatenatec or a sequence and a single element may be concatenated. example”: [ T ] [ T ] _ Con _ : seq T x seq T seq T _ Con _ : seq T x seq T seq T \/ s1, s2 : seq T \/ s1, s2 : seq T s1 Con s2 = s1 U { i : dom s2 ( i + #s1, s2 i ) } s1 Con s2 = s1 U { i : dom s2 ( i + #s1, s2 i ) } S2 i represents the ith elements of seq, s2.