Presentation is loading. Please wait.

Presentation is loading. Please wait.

Formal Specifications for Complex Systems (236368) Tutorial #1

Similar presentations


Presentation on theme: "Formal Specifications for Complex Systems (236368) Tutorial #1"— Presentation transcript:

1 Formal Specifications for Complex Systems (236368) Tutorial #1
Course site : T.A : Nimrod Partush

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

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

4 דוגמאות לוגיקה – דוגמא מספר 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 לא ניתן להשתמש ב  במקום ב  Emilia Katz, Shahar Dag

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

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

7 יכולה להיות נכונה או שגויה
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 Dag

8 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 כלשהי Emilia Katz, Shahar Dag

9 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 Dag

10 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? Emilia Katz, Shahar Dag

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

12 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 Dag

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

14 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 Dag

15 דוגמאות 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 } Emilia Katz, Shahar Dag

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


Download ppt "Formal Specifications for Complex Systems (236368) Tutorial #1"

Similar presentations


Ads by Google