2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.1 CSC 4504 : Langages formels et applications (La méthode Event-B)

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

LEUCEMIA MIELOIDE AGUDA TIPO 0
2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Refinement.1 CSC 4504 : Langages formels et applications (La méthode Event-B)
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Bellwork If you roll a die, what is the probability that you roll a 2 or an odd number? P(2 or odd) 2. Is this an example of mutually exclusive, overlapping,
Chapter 6 Writing a Program
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Chapter 40 - Physiology and Pathophysiology of Diuretic Action Copyright © 2013 Elsevier Inc. All rights reserved.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Chapters 1 & 2 Theorem & Postulate Review Answers
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING Think Distributive property backwards Work down, Show all steps ax + ay = a(x + y)
Addition Facts
BAI CM20144 Applications I: Mathematics for Applications Mark Wood
Who Wants To Be A Millionaire? Decimal Edition Question 1.
1 Data Link Protocols By Erik Reeber. 2 Goals Use SPIN to model-check successively more complex protocols Using the protocols in Tannenbaums 3 rd Edition.
ZMQS ZMQS
Reductions Complexity ©D.Moshkovitz.
Richmond House, Liverpool (1) 26 th January 2004.
BT Wholesale October Creating your own telephone network WHOLESALE CALLS LINE ASSOCIATED.
Test on Input, Output, Processing, & Storage Devices
ABC Technology Project
O X Click on Number next to person for a question.
© S Haughton more than 3?
Progam.-(6)* Write a program to Display series of Leaner, Even and odd using by LOOP command and Direct Offset address. Design by : sir Masood.
Determining if a Triangle is Possible
Twenty Questions Subject: Twenty Questions
2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applicationsEvent-B/Intro.1 CSC 4504 : Langages formels et applications (La méthode Event-B) J.
2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/OddEven.1 CSC 4504 : Langages formels et applications (La méthode Event-B)
2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/DataStructures.1 CSC 4504 : Langages formels et applications (La méthode Event-B)
2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/Purse.1 CSC 4504 : Langages formels et applications (La méthode Event-B) J.
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Squares and Square Root WALK. Solve each problem REVIEW:
SYSTEMS OF EQUATIONS.
Energy & Green Urbanism Markku Lappalainen Aalto University.
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
This, that, these, those Number your paper from 1-10.
While Loop Lesson CS1313 Spring while Loop Outline 1.while Loop Outline 2.while Loop Example #1 3.while Loop Example #2 4.while Loop Example #3.
Control Structures Selections Repetitions/iterations
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
1 First EMRAS II Technical Meeting IAEA Headquarters, Vienna, 19–23 January 2009.
Event 4: Mental Math 7th/8th grade Math Meet ‘11.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/Introduction.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
Number bonds to 10,
We will resume in: 25 Minutes.
Bottoms Up Factoring. Start with the X-box 3-9 Product Sum
1 Unit 1 Kinematics Chapter 1 Day
Number Bonds to = = = = = = = = = = = 20.
1 Section 1.5 Rules of Inference. 2 Definitions Theorem: a statement that can be shown to be true Proof: demonstration of truth of theorem –consists of.
2009 Quinín Freire 1 THE MAGIC OF LEARNING Where do animals live?
2012: J Paul GibsonTSP: MSC SAI Mathematical FoundationsMAT7003.Computability- Answers.1 MAT 7003 : Mathematical Foundations (for Software Engineering)
Presentation transcript:

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.1 CSC 4504 : Langages formels et applications (La méthode Event-B) J Paul Gibson, A207 PurseCode

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.2 Java implementation of Purse requirements public class Purse { int numberCoinTypes; int [] CoinTypes; int [] Coins; …. } Why do we say that the Java code is less formal than the Event-B model? Do you think the code is correct? ( Available on web – Purse.java)

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.3 Java implementation of Purse requirements Purse (int nct, int largest, int maxnumber){ System.out.print("Constructing Random Purse with "+nct+" coin types, largest possible coin value "+largest); System.out.println(", and \n(initially) no more than "+maxnumber+ " coins of same type in the purse" ); numberCoinTypes = nct; CoinTypes = new int [nct]; Coins = new int [nct]; for (int i=0; i<numberCoinTypes; i++) Coins[i] =(int) (Math.random()*maxnumber+1); for (int i=0; i<numberCoinTypes; i++) { int temp = 0; do { temp = (int) (Math.random()*largest+1); } while ((isCoin(temp))); CoinTypes [i] = temp; } } //Purse constructor

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.4 Java implementation of Purse requirements public int howManyCoins(int c){ for (int i=0; i<numberCoinTypes; i++) if (c == CoinTypes [i]) return Coins[i]; return 0; } public void addCoin (int c){ for (int i=0; i<numberCoinTypes; i++) if (CoinTypes[i] == c) Coins[i]++; } public void removeCoin (int c){ for (int i=0; i<numberCoinTypes; i++) if (CoinTypes[i] == c && Coins[i]>0) Coins[i]--; }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.5 Java implementation of Purse requirements // add a random coin public void addCoin (){ Coins[ (int) (Math.random()* numberCoinTypes)]++; } // randomly remove a coin public void removeCoin (){ if (total()==0) return; int temp = (int) (Math.random()* numberCoinTypes); if (Coins[temp] >0) Coins[temp]--; else removeCoin(); }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.6 Java implementation of Purse requirements // add a random coin public void addCoin (){ Coins[ (int) (Math.random()* numberCoinTypes)]++; } // randomly remove a coin public void removeCoin (){ if (total()==0) return; int temp = (int) (Math.random()* numberCoinTypes); if (Coins[temp] >0) Coins[temp]--; else removeCoin(); }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.7 Java implementation of Purse requirements // NOT USED IN PORGRAM BUT TIES INTO SPECIFICATION public boolean hasSubPurse(Purse p2){ for (int i=0; i<numberCoinTypes; i++){ if (Coins[i]< p2.howManyCoins(Coins[i]) ) return false; } return true; }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.8 Java implementation of Purse requirements public boolean paySum(int sum, Purse p){ if (sum>total()) return false; if (isCoin(sum) && howManyCoins(sum) >0 ){ p.removeCoin(sum); System.out.print(" "+ sum ); return true;} else { for (int i = 0; i<numberCoinTypes; i++){ if (howManyCoins(CoinTypes[i]) >0){ p.removeCoin(CoinTypes[i]); if ( sum-CoinTypes[i]>0 && p.paySum(sum-CoinTypes[i], p)){ System.out.print(" "+ CoinTypes[i]); return true;} else p.addCoin(CoinTypes[i]); } return false; }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.9 Java implementation of Purse requirements public int total(){ int t =0; for (int i=0; i<numberCoinTypes; i++) t = t+ CoinTypes[i]* Coins[i]; return t; } public boolean isCoin(int c){ for (int i=0; i<numberCoinTypes; i++) if (CoinTypes[i] == c) return true; return false; }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.10 Java implementation of Purse requirements public String toString (){ String result =""; for (int i=0; i<numberCoinTypes; i++) result = result + CoinTypes[i]+"->"+ Coins[i]+ " "; result =result+":: Total = "+ total(); return result; }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.11 Java implementation of Purse requirements public static void main(String[] args) { System.out.println("Test Purse Class"); Purse p = new Purse (4, 20, 3); System.out.println(p); int s = (int) (Math.random()*50)+1; System.out.println("\nTrying to pay "+ s); if (p.paySum(s, p)) System.out.println("\nPaid sum required\n"); else System.out.println("\nCan't pay sum required\n"); System.out.println(p); }

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.12 Java implementation of Purse requirements Execution 1: Test Purse Class Constructing Random Purse with 4 coin types, largest possible coin value 20, and (initially) no more than 3 coins of same type in the purse 20->1 7->3 8->2 9->2 :: Total = 75 Trying to pay 4 Can't pay sum required 20->1 7->3 8->2 9->2 :: Total = 75

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.13 Java implementation of Purse requirements Execution 2: Test Purse Class Constructing Random Purse with 4 coin types, largest possible coin value 20, and (initially) no more than 3 coins of same type in the purse 18->1 15->3 6->2 13->2 :: Total = 101 Trying to pay Paid sum required 18->0 15->3 6->1 13->0 :: Total = 51

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.14 Java implementation of Purse requirements Execution 3: Test Purse Class Constructing Random Purse with 4 coin types, largest possible coin value 20, and (initially) no more than 3 coins of same type in the purse 19->1 5->3 18->2 11->3 :: Total = 103 Trying to pay Paid sum required 19->1 5->1 18->2 11->3 :: Total = 93

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.15 Question: does Java code help you better understand the requirements? Question: can it help you to write the requirements in Event-B? Challenge: try to hide a bug in code (in a 2 nd version). Also make changes to code (in a 3rd version) that dont add a bug. Ask a colleague to say which version is bugged. HINT: To make it harde make sure that both new versions pass my simple test code. How easy is it to verify the Java Code?

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.16 Purse specification in Event-B Purse_ctx0 : all proof obligations discharged TO DO: Add theorems to validate add and remove functions

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.17 Purse specification in Event-B Purse_ctx1 : not all proof obligations discharged TO DO: Try to prove the unproved theorems (2,3 and 4)

2009: J Paul GibsonT&MSP-CSC 4504 : Langages formels et applications Event-B/PurseCode.18 Purse specification in Event-B Purse_mch0 : all proof obligations discharged TO DO: Think about how one could specify the pay_sum event by stating what is required rather than how to do it