B (10) Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 1

Σχετικά έγγραφα
Matrices and vectors. Matrix and vector. a 11 a 12 a 1n a 21 a 22 a 2n A = b 1 b 2. b m. R m n, b = = ( a ij. a m1 a m2 a mn. def

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ. ΕΠΛ342: Βάσεις Δεδομένων. Χειμερινό Εξάμηνο Φροντιστήριο 10 ΛΥΣΕΙΣ. Επερωτήσεις SQL

Other Test Constructions: Likelihood Ratio & Bayes Tests

ΜΑΘΗΜΑ / ΤΑΞΗ : ΔΟΜΗΜΕΝΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ / Γ ΕΠΑΛ ΣΕΙΡΑ: ΗΜΕΡΟΜΗΝΙΑ: 27/01/2013

Jesse Maassen and Mark Lundstrom Purdue University November 25, 2013

SCHOOL OF MATHEMATICAL SCIENCES G11LMA Linear Mathematics Examination Solutions

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

forms This gives Remark 1. How to remember the above formulas: Substituting these into the equation we obtain with

Εργαστήριο βάσεων δεδομένων. MySQL Stored Procedures

The Simply Typed Lambda Calculus

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

Homework 8 Model Solution Section

ΕΠΛ 342 Βάσεις εδοµένων

Μαζέρας Αχιλλέας. Οι εντολές επανάληψης στην Pascal (While) Φυσικός Αυτοματιστής M.Sc. Νοέµβριος 2009

Ψηφιακή Επεξεργασία Εικόνας

ΠΛΗΡΟΦΟΡΙΚΗ Ι JAVA Τμήμα θεωρίας με Α.Μ. σε 3, 7, 8 & 9 22/11/07

ST5224: Advanced Statistical Theory II

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

Μοντελοποίηση προβληµάτων

ANSWERSHEET (TOPIC = DIFFERENTIAL CALCULUS) COLLECTION #2. h 0 h h 0 h h 0 ( ) g k = g 0 + g 1 + g g 2009 =?

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

Σχεδίαση Ψηφιακών Συστημάτων

ΕΠΛ 012. JavaScripts

Μοντελοποίηση Επιπέδου Πύλης. (Peter Ashenden, The Students Guide to VHDL)

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 10η: Basics of Game Theory part 2 Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

CORDIC Background (4A)

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

± 20% ± 5% ± 10% RENCO ELECTRONICS, INC.

Πίνακες. FORTRAN και Αντικειμενοστραφής Προγραμματισμός

Access Control Encryption Enforcing Information Flow with Cryptography

Απόκριση σε Μοναδιαία Ωστική Δύναμη (Unit Impulse) Απόκριση σε Δυνάμεις Αυθαίρετα Μεταβαλλόμενες με το Χρόνο. Απόστολος Σ.

Δομημένος Προγραμματισμός. Τμήμα Επιχειρηματικού Σχεδιασμού και Πληροφοριακών Συστημάτων

( Boats)) ( Tempsids, bid. sname. Boats. Boats. Boats. (Reserves)/ > Reserves. Interlake' Sailors) ...

CORDIC Background (2A)

C.S. 430 Assignment 6, Sample Solutions

IIT JEE (2013) (Trigonomtery 1) Solutions

Library, package και subprograms

How to register an account with the Hellenic Community of Sheffield.

ΕΠΙΧΕΙΡΗΣΙΑΚΗ ΑΛΛΗΛΟΓΡΑΦΙΑ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΑ ΣΤΗΝ ΑΓΓΛΙΚΗ ΓΛΩΣΣΑ

Κεφάλαιο 4 Σημασιολογία μιας Απλής Προστακτικής Γλώσσας

Second Order Partial Differential Equations

Δομές Δεδομένων (Data Structures)

σαπούνια & καλλυντικά Σειρά Marriott

, Evaluation of a library against injection attacks

Abstract Storage Devices

= λ 1 1 e. = λ 1 =12. has the properties e 1. e 3,V(Y

Αλγόριθμοι και πολυπλοκότητα NP-Completeness (2)

derivation of the Laplacian from rectangular to spherical coordinates

ΚΥΡΙΑ ΜΟΝΤΕΛΑ ΓΛΩΣΣΩΝ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ

These derivations are not part of the official forthcoming version of Vasilaky and Leonard

ΟΡΟΙ ΚΑΙ ΠΡΟΥΠΟΘΕΣΕΙΣ ΣΧΕΔΙΟΥ

Βασικές Έννοιες Δοµών Δεδοµένων

SPEEDO AQUABEAT. Specially Designed for Aquatic Athletes and Active People

Εισαγωγή στη Matlab 2 Εισαγωγή στην Αριθμητική Ανάλυση Διδάσκων: Γεώργιος Ακρίβης Βοηθός: Δημήτριος Ζαβαντής

08 : 2005/10/28(13:56) Web. Web. Web. Web. Web Visual BASIC. B B Visual BASIC (1) 4. Bezier

Fractional Colorings and Zykov Products of graphs

Inverse trigonometric functions & General Solution of Trigonometric Equations

Εργαστήριο Οργάνωσης Η/Υ. Δαδαλιάρης Αντώνιος

Ει αγωγή η Fortran.

Supporting Information for Substituent Effects on the Properties of Borafluorenes

ιαφάνειες παρουσίασης #5

Instruction Execution Times

Οι αδελφοί Montgolfier: Ψηφιακή αφήγηση The Montgolfier Βrothers Digital Story (προτείνεται να διδαχθεί στο Unit 4, Lesson 3, Αγγλικά Στ Δημοτικού)

2.153 Adaptive Control Lecture 7 Adaptive PID Control

MathCity.org Merging man and maths

Λύσεις Σειράς Ασκήσεων 5

Hellenic European Law Concordance

ΕΙΣΑΓΩΓΗ. Στόχοι του μαθήματος

Lecture 21: Properties and robustness of LSE

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Διάλεξη 14: Δομές Δεδομένων ΙΙI (Λίστες και Παραδείγματα)

Every set of first-order formulas is equivalent to an independent set

ΛΥΣΕΙΣ ΘΕΜΑΤΩΝ ΤΕΛΙΚΗΣ ΦΑΣΗΣ Οι παρακάτω λύσεις είναι απολύτως ενδεικτικές

Principles of Database Systems

«Σχεδιασμός Ολοκληρωμένων Κυκλωμάτων» Χειμερινό εξάμηνο Πακέτα και Συστατικά Στοιχεία (Υποκυκλώματα)

Οδηγίες χρήσης του R, μέρος 2 ο

ΗΜΥ 210 ΣΧΕΔΙΑΣΜΟΣ ΨΗΦΙΑΚΩΝ ΣΥΣΤΗΜΑΤΩΝ. Χειµερινό Εξάµηνο 2016 Συµπληρωµατική ΔΙΑΛΕΞΗ 14: Περιγραφή Ακολουθιακών Κυκλωµάτων στη VHDL

Κάθε γνήσιο αντίγραφο φέρει υπογραφή του συγγραφέα. / Each genuine copy is signed by the author.

Τεχνικό Τοπογραφικό Σχέδιο

«Σχεδιασμός Ολοκληρωμένων Κυκλωμάτων» Χειμερινό εξάμηνο Ακολουθιακός Κώδικας

Introduction. Setting up your PC for the first time. Visual Quick Set up Guide. Figure 1: Guide to ports and sockets. 2 P age

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Mock Exam 7. 1 Hong Kong Educational Publishing Company. Section A 1. Reference: HKDSE Math M Q2 (a) (1 + kx) n 1M + 1A = (1) =

ΤΕΧΝΙΚΕΣ ΑΥΞΗΣΗΣ ΤΗΣ ΑΠΟΔΟΣΗΣ ΤΩΝ ΥΠΟΛΟΓΙΣΤΩΝ I

ΑΣΚΗΣΗ 2: Σχεδίαση και προσομοίωση κυκλωμάτων καταχωρητών και μετρητών

Statistical Inference I Locally most powerful tests

A Lambda Model Characterizing Computational Behaviours of Terms

Histogram list, 11 RANDOM NUMBERS & HISTOGRAMS. r : RandomReal. ri : RandomInteger. rd : RandomInteger 1, 6

Εργαστήριο Οργάνωσης Η/Υ. Δαδαλιάρης Αντώνιος

Lecture 2. Soundness and completeness of propositional logic

Βασικά Στοιχεία της Java

Αβδέλαρου Κωνσταντίνα

ΘΕΜΑ Α ΦΑΣΗΣ. Υπολογιστικά Νέφη Ενδεικτικές Απαντήσεις

MATH423 String Theory Solutions 4. = 0 τ = f(s). (1) dτ ds = dxµ dτ f (s) (2) dτ 2 [f (s)] 2 + dxµ. dτ f (s) (3)

. visual basic. int sum(int a, int b){ return a+b;} : : :

Ευφυής Προγραμματισμός

Homomorphism of Intuitionistic Fuzzy Groups

Exercises 10. Find a fundamental matrix of the given system of equations. Also find the fundamental matrix Φ(t) satisfying Φ(0) = I. 1.

ΤΕΧΝΟΛΟΓΙΑ ΚΑΙ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΥΠΟΛΟΓΙΣΤΩΝ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ

alpha Language age (3/5) alpha Language Φροντιστήριο Syntax Directed Translation and

Transcript:

: B (10) 2010 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 1

B B Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 2 x : S S S S x := min(s) Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 3

allocated allocated MACHINE Allocate VARIABLES allocated INVARIANT allocated N 1 INITIALISATION allocated := Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 4 OPERATIONS choose(num) = PRE num N 1 num / allocated THEN allocated := allocated {num} ; num allocate = ANY nm WHERE nm N 1 allocated THEN num := nm allocated := allocated {nm} ; ans query(num) = PRE num N 1 THEN ans := bool(num allocated) allocate Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 5

REFINEMENT Allocate R REFINES Allocate VARIABLES allocated INITIALISATION allocated := Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 6 choose query OPERATIONS choose(num) =allocated := allocated {num}; num allocate = BEGIN num := min(n 1 allocated); allocated := allocated {num} ; ans query(num) = ans := bool(num allocated) allocate allocated Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 7

Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 8 Allocate Allocate R allocated = {6, 13} allocate Allocate 6, 13 Allocate R 1 6 13 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 9

... Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 10 1. BOOK 2. read 3. newbook newbook Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 11

MACHINE Books(BOOK ) VARIABLES read INVARIANT read BOOK INITIALISATION read := OPERATIONS bk newbook = PRE read BOOK THEN ANY bk1 WHERE bk1 BOOK read THEN bk := bk1 read := read {bk1} Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 12 iseq scheme scheme ran(scheme) =BOOK read Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 13

Atelier B B Book REFINEMENT Books R(BOOK ) REFINES Books VARIABLES scheme INVARIANT scheme iseq(book ) ran(scheme) =BOOK read INITIALISATION scheme : perm(book ) OPERATIONS bk newbook = BEGIN bk := first(scheme) scheme := tail(scheme) read scheme scheme perm(s) s s scheme BOOK Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 14 scheme BOOK read read := scheme BOOK ran(scheme) =BOOK read read = scheme newbook Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 15

newbook read = scheme =[x,...] newbook a newbook r read = {x} scheme =[...] Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 16 REFINEMENT Books R R(BOOK ) REFINES Books R VARIABLES counter, bookarr INVARIANT counter 0.. card(book ) bookarr 1.. card(book ) BOOK (0..counter bookarr)^scheme = bookarr INITIALISATION counter := 0 bookarr : 1.. card(book ) BOOK bookarr Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 17

newbook OPERATIONS bk newbook = BEGIN counter := counter +1; bk := bookarr(counter) (0..counter bookarr)^scheme = bookarr scheme counter counter 0 newbook scheme = bookarr Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 18 newbook newbook (read BOOK ) scheme first tail counter card(book ) bookarr(counter) scheme newbook Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 19

sset slist MACHINE StBox SETS STORY CONSTANTS max score PROPERTIES max score N 1 VARIABLES score, sset INVARIANT score N score max score sset : P(STORY ) INITIALISATION score := 0 sset := {} Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 20 OPERATIONS gives(sc) = PRE sc N 1 THEN score := min({score + sc, max score}) ; penalty = SELECT score > 0 THEN score := score 1 WHEN sset {} THEN ANY st WHERE st sset THEN sset := sset {st} ELSE skip ; select(st) = PRE score > 0 st STORY THEN CHOICE score := score 1 sset := sset {st} OR sset := sset {st} ; st tell = IF sset {} THEN ANY st1 WHERE st1 sset THEN st := st1 sset := sset {st1} Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 21

select score scorer sset slist 1 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 22 select free isfree free REFINEMENT SBox R REFINES SBox CONSTANTS free PROPERTIES free N 1 VARIABLES scorer, slist, isfree INVARIANT scorer N scorer = score slist iseq(story ) ran(slist) =sset isfree 0..free INITIALISATION scorer := 0 slist := [ ] isfree := 0 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 23

OPERATIONS gives(sc) = BEGIN scorer := min({scorer + sc, max score}) ; st tell = BEGIN st := first(slist) slist := tail(slist) ; penalty = IF slist []THEN slist := tail(slist) ELSIF scorer > 0 THEN scorer := scorer 1 ; select(st) = BEGIN IF st / ran(slist) THEN slist := slist st ; IF isfree = free THEN CHOICE isfree := 0 OR isfree := 0 scorer := scorer 1 ELSE isfree := isfree + 1;scoreR := scorer 1 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 24 free free IF IF isfree = free THEN isfree := 0 ELSE isfree := isfree + 1;scoreR := scorer 1 free Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 25

B Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 26 M M R M op m S m S m δ S r δ S r op r δ Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 27

Color MACHINE Colors SETS COLOR = {red, green, blue} VARIABLES colors INVARIANT colors COLOR INITIALISATION colors : P(COLOR {blue}) OPERATIONS add(cl) =PRE cl COLOR THEN colors := colors {cl} ; cc query = PRE colors THEN cc : colors ; change = LET clss BE clss = P(COLOR) {colors} IN colors : clss Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 28 Color colors COLOR colors {red, green} add colors query colors change LET clss = P(COLOR) {colors} clss COLOR colors change colors colors query Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 29

Color change add query colors REFINEMENT Colors R REFINES Colors VARIABLES color INVARIANT color COLOR color colors INITIALISATION color : COLOR {blue} OPERATIONS add(cl) =BEGIN color : {color,cl} ; cc query = cc := color ; change = LET cs BE cs = COLOR {color } IN color : cs Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 30 Color add add(cl) =BEGIN color : {color,cl} add color colors add color colors color : colors change change = LET cs BE cs = COLOR {color } IN color : cs change color colors cs colors color colors Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 31

M T I R T 1 J R T 1 T J T T 1 R M T 1 T T 1 J T Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 32 M R M s R s (s, s ) M R R M / J J(x, x ) M s R s I M J R M R T 1 R R s M T s J(s, s ) J T J T J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 33

T J J J [T ] J [T ] J T J [T ] J T J T [T ] J T J T J R T 1 T T 1 [T ] J T 1 [T ] J [T 1 ] [T ] J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 34 Colors ColorsR J color colors T = colors : P(COLOR {blue}) [T ] J J T color = blue [T ] J T colors color = blue color = red color = green T [T ] J [T ] J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 35

[colors : P(COLOR {blue})] (color colors) = ( colors. (colors P(COLOR {blue}) (color colors))) = colors. (colors P(COLOR {blue}) (color colors)) = colors. (colors (COLOR {blue}) color colors) COLOR {blue} colors color colors color blue color blue [T 1 ] [T ] J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 36 ColorsR T 1 = color : COLOR {blue} [T 1 ] [T ] J = [T 1 ](color blue) = [color : COLOR {blue}](color blue) = color. (color (COLOR {blue}) color blue) = true ColorsR Colors I T I I T Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 37

[T ] J T J T J T T [T ] I T [T ] J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 38 M R PRE P THEN S PRE P 1 THEN S 1 P 1 P 1 S 1 S [S 1 ] [S] J J I I J I J P [S 1 ] [S] J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 39

I J P [S 1 ] [S] J [S 1 ] [S] J S 1 S [S 1 ] [S] J S 1 S [S 1 ] [S] J Colors ColorsR I J colors COLOR color COLOR color colors add add(cl) =PRE cl COLOR THEN colors := colors {cl} add(cl) =BEGIN color : {color, cl} Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 40 I J P colors COLOR color COLOR color colors cl COLOR add [S 1 ] [S] J = [S 1 ] [S] (color colors) = [S 1 ] [colors := colors {cl}] (color colors) = [S 1 ] ( (color colors {cl})) = [S 1 ](color colors {cl}) = [color : {color, cl}](color colors {cl}) = x.(x {color, cl} color colors {cl}) = (color colors {cl}) (cl colors {cl}) = color colors {cl} I J P [S 1 ] [S] J J = color colors color colors color colors {cl} Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 41

M R P 1 PRE P THEN S PRE P 1 THEN S 1 P P 1 P 1 P P 1 M P R P 1 P P P P 1 P 1 I J P P 1 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 42 Colors ColorsR query ColorsR query green green Colors J Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 43

o o out out out out out) S 1 out out S 1 [out /out] out = out out 1 = out 1... out n = out n out out [S 1 [out /out]] [S] (out = out) Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 44 P 1 I J P [S 1 [out /out]] [S] (J out = out) I J P P 1 Colors ColorsR J color colors query cc query = PRE colors THEN cc : colors cc query = cc := color Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 45

[S 1 [cc /cc]] [S] (J cc = cc) = [S 1 [cc /cc]] [cc : colors] (J cc = cc) = [S 1 [cc /cc]] ( cc. (cc colors (J cc = cc))) = [S 1 [cc /cc]] ( cc. ( (cc colors) (J cc = cc))) = [S 1 [cc /cc]]( cc. ( (cc colors) (J cc = cc))) = [S 1 [cc /cc]]( cc. (cc colors J cc = cc)) = [cc := color ]( cc. (cc colors J cc = cc)) = J cc. (cc colors color = cc)) J color colors = J I J I P [S 1 [cc /cc]] [S] (J cc = cc) Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 46 SETS CONSTANTS PROPERTIES CONSTRAINTS CONSTRAINTS PROPERTIES PROPERTIES PROPERTIES Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 47

St 1,C 1,B 1 PROPERTIES St,C,B,Cn PROPERTIES CONSTRAINTS Cn St 1,C 1,St,C. B 1 B T 1 J T Cn B B 1 [T 1 ] [T ] J out op(in) =PRE P THEN S out op(in) =PRE P 1 THEN S 1 Cn B B 1 I J P [S 1 [out /out]] [S] (out = out) Cn B B 1 I J P P 1 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 48 Formal Methods: Software Development in B Qiu Zongyan (May 11, 2010) 49