1 מפרטים פורמאליים תירגול מספר 13 מפרטים פורמאליים - תירגול שחר דג LARCH הרמה הראשונה - הרחבת ההגדרה הבסיסית דוגמא – set Initial and Final algebras הרמה.

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
© M. Winter COSC 4P41 – Functional Programming Testing vs Proving Testing –uses a set of “typical” examples, –symbolic testing, –may find errors,
(CSC 102) Discrete Structures Lecture 14.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
ISBN Chapter 3 Describing Syntax and Semantics.
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
Lecture 2: Fundamental Concepts
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
1 Lecture 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
Using Templates Object-Oriented Programming Using C++ Second Edition 11.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Describing Syntax and Semantics
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
 2006 Pearson Education, Inc. All rights reserved Generics.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
1 Understanding Inheritance COSC 156 C++ Programming Lecture 8.
Reading and Writing Mathematical Proofs
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
MATH 224 – Discrete Mathematics
Pushdown Automata (PDAs)
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Chapter 18 Java Collections Framework
April 14, 2015Applied Discrete Mathematics Week 10: Equivalence Relations 1 Properties of Relations Definition: A relation R on a set A is called transitive.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Copyright © Cengage Learning. All rights reserved.
1 Using Templates COSC 1567 C++ Programming Lecture 10.
Data Structures & Algorithms
Emilia Katz, Shahar Dag 1 Formal Specifications for Complex Systems (236368) Tutorial #13 Algebraic Specification and Larch.
Protocols Software Engineering II Wirfs Brock et al, Designing Object-Oriented Software, Prentice Hall, Mitchell, R., and McKim, Design by Contract,
INM175 Topic 8 1 Module INM175 Discrete Mathematics Topic 8 Algebraic Theories.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.
Class Invariants Class invariants are logical conditions to ensure the correct working of a class. Class invariants must hold true when an object is created,
Conditional Expressions
User-Written Functions
Input Space Partition Testing CS 4501 / 6501 Software Testing
GC211Data Structure Lecture2 Sara Alhajjam.
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
The Larch Shared Language
CS212: Object Oriented Analysis and Design
Specifying Object Interfaces
Mini Language Interpreter Programming Languages (CS 550)
Axiomatic semantics Points to discuss: The assignment statement
Denotational Semantics (Denotational Semantics)
Semantics In Text: Chapter 3.
CSCE 314: Programming Languages Dr. Dylan Shell
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
From now on: Combinatorial Circuits:
Sub-system interfaces
Testing vs Proving Testing uses a set of “typical” examples,
Algebraic Specification Software Specification Lecture 34
Presentation transcript:

1 מפרטים פורמאליים תירגול מספר 13 מפרטים פורמאליים - תירגול שחר דג LARCH הרמה הראשונה - הרחבת ההגדרה הבסיסית דוגמא – set Initial and Final algebras הרמה השנייה - שפת ממשק (interface language) דוגמא – ממשק דמוי פסקל ל set

2 מפרטים פורמאליים - תירגול שחר דג מבנה עקרוני trait_name : trait includes trait1 rename_list, trait2 rename_list, … introduces operator_list asserts predicate_list var_type generated by operator_list var_type partitioned by observer_list implies converts // see the slide for details traitתכונה, התנהגות exemptingחוץ מ

3 מפרטים פורמאליים - תירגול שחר דג includes includes trait1 rename_list, trait2 rename_list, … where: rename _list is a list of the form new_name for old_name, … meaning: creating a union of traits lets us combine behaviors the rename list is the way to bring all components to unique naming space when it is clear that all the time we will rename some names, we can define them as arguments of the trait

4 מפרטים פורמאליים - תירגול שחר דג includes (example) reflective : trait introduces: __ ↔ __: T, T → bool asserts ∀ x:T x↔x transitive : trait introduces: __ R __: T, T → bool asserts ∀ x, y, z:T (x R y ∧ y R z) ⇒ x R z preorder: trait includes reflective ( ≤ for ↔ ) transitive ( ≤ for R )

5 מפרטים פורמאליים - תירגול שחר דג generated by sort generated by constructor1, constructor2, … meaning: all possible elements of the sort, can only be generated by a combination of the listed constructors. for example in the stack trait (shown in class) we can add S generated by new, push we can see that every operation that changes a stack only adds a finite number of elements, this means that we can’t create infinite stack we can use the generated by, for proving by induction. generated by divides the operations into generators (the operation that are listed in the clause) and extensions (all the rest)

6 מפרטים פורמאליים - תירגול שחר דג The Stack (from lecture) Stack : trait introduces push: ST x E --> ST pop: ST --> ST top: ST --> E new: --> ST asserts for s  ST and i  E pop( push( s, i )) = s top( push( s, i )) = i [ pop( new ) = undefined ] [ top( new ) = undefined ] ST generated by new, push

7 מפרטים פורמאליים - תירגול שחר דג partitioned by sort partitioned by observer1, observer2, … meaning: any two values in the sort that can’t be distinguished by the observers in the list are considered equal this is similar for the final algebra approach (but only relative to the defined observers). for example the operator ∈ can distinguish sets.

8 מפרטים פורמאליים - תירגול שחר דג implies implies additional_claims defines additional claims the claim is derived from the already defined claims once proved, the new claim can serve for reasoning about additional claims implies converts operation_list this means that the listed operations are well defined (and non ambiguous) for all possible values implies converts operation_list exempting special_cases exclude special cases, such as singular points where the operation is not defined errors are handled separately.

9 מפרטים פורמאליים - תירגול שחר דג Example – the set settrait : trait introduces {}: → set _ ∈ _ : E, set → bool insert: E, set → set delete: E, set → set size: set → int _ ∪ _ : set, set → set _ ⋂ _ : set, set → set asserts // continued on next page

10 מפרטים פורמאליים - תירגול שחר דג Example – the set (cont.) // continues previous page asserts ∀ e, e1 : E, s, s1 : S ¬( e ∈ {} ); e ∈ insert(e1, s) == e = e1 ⋁ e ∈ s; size( {} ) == 0; size( insert(e, s)) == if e ∈ s then size(s) else size(s) + 1; delete( e, {} ) == {}; delete(e, insert(e1, s)) == if e=e1 then delete(e, s) else insert(e1, delete(e, s)); s ∪ {} == s; s ∪ insert( e, s1 ) == insert( e, s ∪ s1 ); s ⋂ {} == {}; s ⋂ insert( e, s1 ) == if e ∈ s then insert( e, s ⋂ s1 ) else s ⋂ s1;

11 מפרטים פורמאליים - תירגול שחר דג Initial and Final algebras because: delete(5, insert(7, insert(5, {}))) == // the else of (2) insert(7, delete(5, insert(5, {}))) ==// the then (2) insert(7, delete(5, {})) ==// (1) insert(7, {}) we can view traits as defining a logical theory (first order logic) every thing is defined in the traits we know only what the trait defines & all the consequences from it in the set definition we have: (1) delete( e, {} ) == {}; (2) delete(e, insert(e1, s)) == if e=e1 then delete(e, s) else insert(e1, delete(e, s)); we can conclude that: delete(5, insert(7, insert(5, {}))) = insert(7, {})

12 מפרטים פורמאליים - תירגול שחר דג Initial and Final algebras (cont.) Larch keeps this open for the user of the trait is the following true ? insert(7, insert(5, {})) = insert(5, insert(7, {})) in the initial algebra approach, they are different since they cannot be proven equal from the axioms of set in the final algebra approach, they are equal since they cannot be distinguished by the axioms of set (you can’t contradict it)

13 מפרטים פורמאליים - תירגול שחר דג דוגמא ממבחן - set בהינתן set והפעולות האריתמטיות (כמו שראינו) וגם סימני היחס (>, >=, <,...) יש להגדיר: max- האיבר המקסימאלי בקבוצה second- האיבר השני בגודלו

14 מפרטים פורמאליים - תירגול שחר דג דוגמא ממבחן – set (המשך) ניסיון ראשון לפיתרון max (פיתרון של סטודנט) max: S → E max(s) = e. e ∈S ∧ ¬∃a∈S ∧ a>e האם זה הוא פיתרון טוב?

15 מפרטים פורמאליים - תירגול שחר דג דוגמא ממבחן – set (המשך) עכשיו לפתור את second כבר צריך להיות קל second: S → E

16 מפרטים פורמאליים - תירגול שחר דג Larch Interface Language - LCL it is the second layer of a Larch specification we will only show some of the main features of LCL termination requirement is implicit may use any sorts and operations defined in LSL traits the mapping of types to sorts is done when introducing the used traits, by renaming the sorts to the correct types: uses trait (type for sort, …) objects are places where values are stored the state of the program is a mapping from objects to values

17 מפרטים פורמאליים - תירגול שחר דג LCL – The general form uses traits procedure header requires P modifies L ensures Q P is the usual precondition of an input / output assertion, in the terms of formal parameters from the header. restrictions on the input appear in P if we want to prevent a call with illegal values, we will put a restriction in P L is the list of changeable objects Q is the usual post condition, relating final values to initial ones. the values after the operation will be primed (‘) version of the values before the operation. error conditions appear in Q. we will handle exceptions & generate error messages

18 מפרטים פורמאליים - תירגול שחר דג LCL – some observations the specification divides the responsibility between the user and the implementer of the functions. the users must establish the requires clause (the pre condition) (otherwise the behavior is not constrained) the function must not change any object not in the modifies list. the function must terminate. the function must establish the ensures conditions at its final stage.

19 מפרטים פורמאליים - תירגול שחר דג Example uses settrait procedure set-init(var s : set) modifies s ensures s’ = {} procedure set-insert(var s : set; e : integer) requires size( insert( e, s ) ) ≤ 100 modifies s ensures s’ = insert( e, s ) procedure set-rem(var s : set; var f : bool; e : integer) modifies s, f ensures s’ = delete( e, s ) ∧ f’ = ( e ∈ s) function choose(s : set; var e : integer) : bool modifies e, choose ensures if size( s ) > 0 then ( choose’ ∧ (e’ ∈ s) else (¬choose’ ∧ (e’ = e))

20 מפרטים פורמאליים - תירגול שחר דג Example (cont.) the example is written in a Pascal like syntax set-init corresponds to the trait operation {} set-inserts corresponds to the trait insert operation with the restriction that the result should be no longer then 100 set-rem combines the delete & the membership function from the set trait choose however does not correspond to any trait operation and chooses a set element arbitrarily.