Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 מפרטים פורמאליים 236368 תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:http://webcourse.cs.technion.ac.il/236368.

Similar presentations


Presentation on theme: "1 מפרטים פורמאליים 236368 תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:http://webcourse.cs.technion.ac.il/236368."— Presentation transcript:

1 1 מפרטים פורמאליים 236368 תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:http://webcourse.cs.technion.ac.il/236368 שקפים:גרסא מצונזרת (ללא תשובות) לפני התרגול גרסא מלאה אחריו תרגילי בית:הגשה בזוגות מניסיון שנים קודמות, מומלץ ששני השותפים יהיו מעורבים בפתרון, מי שלא יפתור תרגילי בית יתקשה במבחן נדרש רישום פורמאלי ומדויק יש לפרט את כל מה שהנכם מניחים לצורך הפיתרון יתכן תרגיל רטוב אחד בוחן:לא יתקיים בוחן מומלץ בחום לפתור בחנים משנים קודמות כדי למנוע הפתעות במבחן שאלות:במהלך התרגול, נא לעצור אותי עם משהוא לא מובן פלפונים:נא לכבות פלפונים

2 2 I/O Assertions Content What are I/O Assertions? What do I/O Assertions mean? Translating verbal properties into logic expression. Annotated programs. Using “logical” and “auxiliary” variables. Examples. Assertion – טענה יכולה להיות נכונה או שגויה

3 3 An I/O specification defines the set of admissible initial states, and for each initial state, the final states reachable by terminating computations. Termination must be specified separately. Used mainly to specify transformational programs. We can express I/O specifications by attaching a logical expression about the system variables, both at the beginning and at the end of the program’s execution. The assertion at the beginning defines the admissible initial values of the variables, and the one at the end defines a relationship between the final values and the initial ones. What are I/O Assertions

4 4 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 assertion are added after the “START” and before the “END” statements. What are I/O Assertions (cont.) זוהי לוגיקה ולכן מדובר בשוויון ולא בהצבה Hoare נלמד במבוא לאימות תוכנה (לא לדאוג, לא נעסוק באימות) יתרון מודולאריות S1 S2 שקול ל S1;S2 שקול ל S כאשר S הוא S1 שלאחריו מתבצע S2

5 5 What do I/O assertions mean Initial assertions are assumption 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 guaranty that if something happens (the program ends) then the condition is true.

6 6 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? do we mean the mathematical un-bounded version or the bounded version of a computer program?

7 7 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 ‘;’

8 8 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 represent 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

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

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

11 11 דוגמאות – דוגמא מספר 2 יש להגדיר בעזרת לוגיקה את הפרדיקט prime(x)

12 12 דוגמאות – דוגמא מספר 3 יש להגדיר בעזרת לוגיקה וסימוני קבוצות, את קבוצת כל המספרים הראשוניים שאינם גדולים מ x primes_upto(x) איך פותרים את אותה הבעיה בעזרת לוגיקה בלבד?

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

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

15 15 דוגמאות – דוגמא מספר 5 (המשך) תיאור אלטרנטיבי יהיה:

16 16 דוגמאות – דוגמא מספר 6 (מההרצאה) מיון מהן הבעיות במפרט זה ? (1) (2) (3) (4)

17 17 דוגמאות – דוגמא מספר 7 (מההרצאה) מה נותנת ההגדרה הבאה ?

18 18 דוגמאות – שעשועי לוגיקה הגדר בעזרת לוגיקה את המשפט: "לכל אדם יש אב" בצורה דומה נגדיר בעזרת לוגיקה את המשפט: "לכל אדם יש אם אנושית" איך נגדיר כי לכל אדם אב ואם אנושיים הנשואים זה לזו.


Download ppt "1 מפרטים פורמאליים 236368 תרגול מספר 1 מהות הקורס:כח ביטוי. בעיות מעשיות (ולא הוכחות) מתרגל אחראי:שחר דג מתרגלת:אמיליה כץ אתר:http://webcourse.cs.technion.ac.il/236368."

Similar presentations


Ads by Google