Formal Specifications for Complex Systems (236368) Tutorial #1

Slides:



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

Completeness and Expressiveness. תזכורת למערכת ההוכחה של לוגיקה מסדר ראשון : אקסיומות 1. ) ) (( 2. )) ) (( )) ( ) ((( 3. ))) F( F( ( 4. ) v) ( ) v ((
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
Operating Systems, 122 Practical Session 8 Deadlocks 1.
מבוא למדעי המחשב לתעשייה וניהול
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
11111 Functional Program Verification CS 4311 A. M. Stavely, Toward Zero Defect Programming, Addison-Wesley, Y. Cheon and M. Vela, A Tutorial on.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
1 Formal Specifications for Complex Systems (236368) Tutorial #4 Refinement in Z: data refinement; operations refinement; their combinations.
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.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
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.
רקורסיות נושאי השיעור מהן רקורסיות פתרון רקורסיות : שיטת ההצבה שיטת איטרציות שיטת המסטר 14 יוני יוני יוני 1514 יוני יוני יוני 1514.
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
1 Formal Specifications for Complex Systems (236368) Tutorial #5 I/O specifications; Hoare Logic; OCL.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Formal Specifications for Complex Systems (236368) Tutorial #6 appendix Statecharts vs. Raphsody 7 (theory vs. practice)
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
1 מפרטים פורמאליים תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
4/17/2017 Section 3.6 Program Correctness ch3.6.
מודל הלמידה מדוגמאות Learning from Examples קלט: אוסף של דוגמאות פלט: קונסיסטנטי עם פונקציה f ב- C ז"א קונסיסטנטי עם S ז"א מודל הלמידה מדוגמאות Learning.
עקרון ההכלה וההדחה.
יחס סדר חלקי.
Describing Syntax and Semantics
1 מבוא למדעי המחשב סיבוכיות. 2 סיבוכיות - מוטיבציה סידרת פיבונאצ'י: long fibonacci (int n) { if (n == 1 || n == 2) return 1; else return (fibonacci(n-1)
MATH 224 – Discrete Mathematics
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
Methods of Proofs PREDICATE LOGIC The “Quantifiers” and are known as predicate quantifiers. " means for all and means there exists. Example 1: If we.
CS 363 Comparative Programming Languages Semantics.
פיתוח מערכות מידע Class diagrams Aggregation, Composition and Generalization.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Recursive Algorithms &
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.
Emilia Katz, Shahar Dag 1 Formal Specifications for Complex Systems (236368) Tutorial #13 Algebraic Specification and Larch.
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.
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
1 Section 8.2 Program Correctness (for imperative programs) A theory of program correctness needs wffs, axioms, and inference rules. Wffs (called Hoare.
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:
Section 1.7. Section Summary Mathematical Proofs Forms of Theorems Direct Proofs Indirect Proofs Proof of the Contrapositive Proof by Contradiction.
MATH 224 – Discrete Mathematics
Topics: jGRASP editor ideosyncrasies assert debugger.
Formal Methods in Software Engineering 1
מבוא למדעי המחשב סיבוכיות.
Mathematical Structures for Computer Science Chapter 1
ממשקים - interfaces איך לאפשר "הורשה מרובה".
Copyright © Cengage Learning. All rights reserved.
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Logic for Computer Security Protocols
Algorithm and Ambiguity
Functional Program Verification
Axiomatic Verification I
This Lecture Substitution model
Program correctness Axiomatic semantics
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : http://webcourse.cs.technion.ac.il/236368/ T.A. : Nimrod Partush (nimi@cs.technion.ac.il)

General Information Statements, not proofs The course is about: Formally expressing requirements Statements, not proofs Homework submission: In pairs From previous years experience, we recommend both partners to participate in every homework solution, in order to succeed in the exam Formal and exact writing of the solutions is required List all your assumptions (everything you had to assume for your solution) There might be one “wet” homework No midterm exam. 236368 Emilia Katz, Shahar Dag

Today: Logic – reminder I/O specifications Hoare Logic 236368 Emilia Katz, Shahar Dag

דוגמאות לוגיקה – דוגמא מספר 1 Define the predicate prime(x) using logic and the predicate integer(x): What about non-positive integers? integer(x)  y.(( integer(y)  1<y<x )  integer(x/y)) (x > 1)  ‘.’ works on the entire expression we put ( ) to avoid confusion לא ניתן להשתמש ב  במקום ב  236368 Emilia Katz, Shahar Dag

דוגמאות לוגיקה – דוגמא מספר 2 יש להגדיר בעזרת לוגיקה וסימוני קבוצות, את קבוצת כל המספרים הראשוניים שאינם גדולים מ x primes_upto(x) primes_upto(x) = { y :   prime(y)  y  x  y } איך פותרים את אותה הבעיה בעזרת לוגיקה בלבד? prime(y)  y  x 236368 Emilia Katz, Shahar Dag

דוגמאות לוגיקה – דוגמא מספר 3 human(), father() Are predicates הגדר בעזרת לוגיקה את המשפט: "לכל אדם יש אב" mother() is another predicate בצורה דומה נגדיר בעזרת לוגיקה את המשפט: "לכל אדם יש אם אנושית" הפתרון שלנו מחייב כי האב יהיה אנושי, אבל הדרישה המילולית כלל לא הזכירה זאת married() is yet another predicate איך נגדיר כי לכל אדם אב ואם אנושיים הנשואים זה לזו. 236368 Emilia Katz, Shahar Dag

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

What are I/O Assertions 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. זוהי לוגיקה ולכן מדובר בשוויון ולא בהצבה Hoare נלמד במבוא לאימות תוכנה (לא לדאוג, לא נעסוק באימות) יתרון מודולאריות: נניח, רוצים להוכיח {p}S{q} כאשר S הוא S1 שלאחריו מתבצע S2. אז מספיק להוכיח {p}S1{p1}, {p1}S2{q} עבור טענה p1 כלשהי 236368 Emilia Katz, Shahar Dag

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. 236368 Emilia Katz, Shahar Dag

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) do we mean the mathematical un-bounded version or the bounded version of a computer program? Y is the largest integer divided by x What does it specify? Which programs satisfy this specification? None stopping Now it is OK It seems that we can express a requirement which can't be implemented. What if we replace integer() with some bounded representation? 236368 Emilia Katz, Shahar Dag

דוגמאות Assertions – דוגמא מספר 1 מה הוא אוסף התוכניות שמקימות את המפרט: { true } S { false } כל התוכניות שלא עוצרות אף פעם (כל התוכניות שאין להן אף חישוב עוצר) 236368 Emilia Katz, Shahar Dag

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 ‘;’ 236368 Emilia Katz, Shahar Dag

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: (2) - (3) - X (4) - X Logical variables appear only in the assertions We do not assign values to logical variables 236368 Emilia Katz, Shahar Dag

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. 236368 Emilia Katz, Shahar Dag

דוגמאות Assertions – דוגמא מספר 2 יש לתת מפרט שיביע מניעה הדדית בין שני קטעים קריטיים (cs1, cs2) בתוכנית המקבילית הבאה (רמז: העזר ב auxiliary variables) P1 P2 התוספות לא משפיעות על מהלך התוכנית in1 := T err := err  in2 in2 := T err := err  in1 CS1 CS2 חישוב שמפר מניעה הדדית מפר את המפרט in1 := F in2 := F P :: P1 || P2 האם באמת פתרנו נכון? רק אם מה שהוספנו הוא חלק מהקטע הקריטי { in1 = in2 = err = F } P { err = F } 236368 Emilia Katz, Shahar Dag

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