1 Formal Specifications for Complex Systems (236368) Tutorial #5 I/O specifications; Hoare Logic; OCL.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Semantics Static semantics Dynamic semantics attribute grammars
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Predicate Transformers
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Object Constraint Language.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
1 מפרטים פורמאליים תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Describing Syntax and Semantics
Proving Program Correctness The Axiomatic Approach.
1 Formal Specifications for Complex Systems (236368) Tutorial #7 OCL Object Constraint Language.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Program Correctness. 2 Program Verification An object is a finite state machine: –Its attribute values are its state. –Its methods optionally: Transition.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
Object Constraint Language
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site:
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
An association between class Flight and class Person, indicating that a certain group of persons are the passengers on a flight, will have multiplicity.
Formal Specifications for Complex Systems (236368) Tutorial #1
The Object Constraint Language
Formal Methods in Software Engineering 1
Mathematical Structures for Computer Science Chapter 1
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Slides by Steve Armstrong LeTourneau University Longview, TX
Logic for Computer Security Protocols
The Object Constraint Language
Predicate Transformers
Program correctness Axiomatic semantics
Object Constraint Language (OCL)
Programming Languages and Compilers (CS 421)
Formal Methods in Software Engineering 1
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

1 Formal Specifications for Complex Systems (236368) Tutorial #5 I/O specifications; Hoare Logic; OCL

Emilia Katz, Shahar Dag2 I/O Assertions Content What are I/O Assertions? What do I/O Assertions mean? Annotated programs. Using “logical” and “auxiliary” variables. Examples. Assertion – טענה יכולה להיות נכונה או שגויה

Emilia Katz, Shahar Dag3 Some notations are used: (1)x=0, and x’=x+1 for some program S (2) (3) The last 2 examples are called “Hoare assertion”. In flowcharts the assertions are added after the “START” and before the “END” statements. What are I/O Assertions זוהי לוגיקה ולכן מדובר בשוויון ולא בהצבה Hoare נלמד במבוא לאימות תוכנה (לא לדאוג, לא נעסוק באימות) יתרון מודולאריות S1 S2 שקול ל S1;S2 שקול ל S כאשר S הוא S1 שלאחריו מתבצע S2

Emilia Katz, Shahar Dag4 What do I/O assertions mean Initial assertions are assumptions made by the program, to be satisfied by the environment. Final assertions are requirements to be satisfied by the program, if and when it terminates. Every terminating computation that satisfies the initial assertion when it starts, must satisfy the final assertion if it terminates. Non-terminating computations and computations not satisfying the initial assertion, satisfy the I/O specification “vacuously”. This is called partial correctness and it is a kind of safety property. Partial correctness is safety since it guaranties that if something happens (the program ends) then the condition is true.

Emilia Katz, Shahar Dag5 Expressing properties with I/O assertions We restrict ourselves to first-order logic and common mathematical notation. Sometimes certain (well known / standard) predicates can be left undefined ( for example integer(x) ). Look at the following specification (4) What does it specify? Which programs satisfy this specification? It seems that we can express a requirement which can't be implemented. What if we replace integer() with some bounded representation? do we mean the mathematical un-bounded version or the bounded version of a computer program?

Emilia Katz, Shahar Dag6 דוגמאות – דוגמא מספר 1 מה הוא אוסף התוכניות שמקימות את המפרט: { true } S { false }

Emilia Katz, Shahar Dag7 Annotated programs Sometimes a program skeleton is provided, with assertions between statements. Each assertion, called a local invariant and it is supposed to hold whenever the program’s control is at this location. The assertions immediately before and after a statement (usually a place- holder for un-implemented code) are its I/O specification. The implementation can be shown to satisfy the original specification by using a proof method for correctness based on axioms and proof rules. (but in this course we are not going to prove correctness) For example Is an instance of the axiom And an example of a proof rule the meaning of ‘;’

Emilia Katz, Shahar Dag8 Using logical variables Variables that appear only in the assertions are called “logical variables” (also called “ rigid variables ” or “ specification variables ”). (Sometimes in order to specify a property, we need variables not present in the program.) Their value doesn’t change during the execution of the program. A logical value just represents some value, and can be quantified (with  or  ) We saw logical variables in: Logical variables appear only in the assertions We do not assign values to logical variables

Emilia Katz, Shahar Dag9 Using auxiliary variables We may add to a program “auxiliary variables” (new variables) and statements that assign them values, to support the specification. For example: we might add a Boolean variable flag (initialized to false ) to remember that a certain event has occurred, together with an assignment flag := true at the point where the event occurs. Auxiliary variables get their values only in the added assignment statements, which don’t affect the original system variables. The only references to auxiliary variables must be in the added assignment and in assertions within the annotation of the program.

Emilia Katz, Shahar Dag10 דוגמאות – דוגמא מספר 2 יש לתת מפרט שיביע מניעה הדדית בין שני קטעים קריטיים (cs1, cs2) בתוכנית המקבילית הבאה (רמז: העזר ב auxiliary variables) P1 CS1 P2 CS2 P :: P1 || P2

Emilia Katz, Shahar Dag11 דוגמאות – דוגמא מספר 3 תן מפרט קלט/פלט לפרוצדורה P המקבלת מספר טבעי n ומחזירה מספר טבעי m ומערך a[1..m] המכיל את כל המספרים הראשוניים שאינם גדולים מ n (אבל לא מכיל אף מספר אחר). כל מספר יופיע במערך בדיוק פעם אחת.

Emilia Katz, Shahar Dag12 OCL Added to UML class diagrams or state-charts Example system specification: LoyaltyProgram system Given: UML class diagram (see additional file)

Emilia Katz, Shahar Dag13 OCL – operations on collections This is the unusual part of notation Collections: Bag, Set, Sequence Bag Set Sequence AsBag AsSet AsSequence Example: Bag{1,1,2,5}.AsSet() =

Emilia Katz, Shahar Dag14 Operations on Collections - examples Set{account1,account2,account3,account4}.select(balance>100) –Meaning: Set{1,2,3,4,5}.includes(6) = Set{1,2,3,4,5}.including(6) = Excludes, excluding – symmetric operations Set{{1,2},{2,3},{5,6}}.collect =

Emilia Katz, Shahar Dag15 OCL => Natural Language (1) 1. context Customer inv title = (if isMale = true then ‘Mr.’ else ‘Ms.’ Endif) Translation: 2. context LoyaltyProgram inv serviceLevel-> includesAll(membership.actualLevel) Translation:

Emilia Katz, Shahar Dag16 OCL => Natural Language (2) 3. context LoyaltyAccount inv points>0 implies transaction->exists(points>0) Translation: 4. context ProgramPartner inv self.deliveredServices.transactions-> select(oclType=Burning)->collect(points)->sum <= self.deliveredServices.transactions-> select(oclType=Earning)->collect(points)->sum Translation:

Emilia Katz, Shahar Dag17 Natural Language => OCL(1) 1. Customers must have a minimum age of 18 years 2. The CustomerCard’s “valid from” date must be earlier then the “valid to” date

Emilia Katz, Shahar Dag18 Natural Language => OCL(2) 3. The printed name on the customer card must be a title followed by the registered name of the customer 4. The number of service levels is exactly 2

Emilia Katz, Shahar Dag19 Pre- and Post-Conditions in OCL 1. For isEmpty() operation of LoyaltyAccount (returns true iff there are no points in the account) 2. The Burn(integer i) operation of LoyaltyAccount

Emilia Katz, Shahar Dag20 Built-in OCL Types OclType –Customer.name() = –Customer.attributes() = OclAny Example - s:Set –s.oclType() = –s.oclIsKindOf(Collection) = –s.oclIsTypeOf(Collection) =