1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site:

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.
Situation Calculus for Action Descriptions We talked about STRIPS representations for actions. Another common representation is called the Situation Calculus.
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.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
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.
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.
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
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
Formal Specifications for Complex Systems (236368) Tutorial #6 appendix Statecharts vs. Raphsody 7 (theory vs. practice)
תורת הקבוצות חלק ב'. קבוצה בת מניה הגדרה: קבוצה אינסופית X היא ניתנת למניה אם יש התאמה חד-חד ערכית בין X לבין .
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
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.
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.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
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.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
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
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
Formal Specifications for Complex Systems (236368) Tutorial #1
Formal Methods in Software Engineering 1
Mathematical Structures for Computer Science Chapter 1
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
Program correctness Axiomatic semantics
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site:

Emilia Katz, Shahar Dag2 General Information 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 Dag3 Today: Logic – reminder I/O specifications Hoare Logic

Emilia Katz, Shahar Dag4 Reminder – FOL See reminder on Logic and Set Theory on course web-page Now: a couple of examples

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

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

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

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

Emilia Katz, Shahar Dag10 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 Dag11 דוגמאות Assertions – דוגמא מספר 1 מה הוא אוסף התוכניות שמקימות את המפרט: { true } S { false } כל התוכניות שלא עוצרות אף פעם (כל התוכניות שאין להן אף חישוב עוצר) למה? תוכנית שעוצרת לא יכולה לקיים את המפרט, כי false לא מתקיים באף מצב. אם התוכנית אינה עוצרת, היא מקיימת את המפרט באופן ריק.

Emilia Katz, Shahar Dag12 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? Y is the largest integer divided by x None stopping Now it is OK do we mean the mathematical un-bounded version or the bounded version of a computer program?

Emilia Katz, Shahar Dag13 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 Dag14 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 Dag15 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 Dag16 דוגמאות Assertions – דוגמא מספר 2 יש לתת מפרט שיביע מניעה הדדית בין שני קטעים קריטיים (cs1, cs2) בתוכנית המקבילית הבאה (רמז: העזר ב auxiliary variables) P1 in1 := T err := err  in2 CS1 in1 := F P2 in2 := T err := err  in1 in2 := F CS2 P :: P1 || P2 { in1 = in2 = err = F } P { err = F } התוספות לא משפיעות על מהלך התוכנית חישוב שמפר מניעה הדדית מפר את המפרט

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