advertisement

COSC 4P42 – Formal Methods in Software Engineering COSC 4P42 Formal Methods in Software Engineering • Course: – Lecture: Wed & Fri, 11:00am - 12:30pm, Winter 2015, Room: TH244 – Lab: Fri, 8:00am - 9:30am, Winter 2015, Room: MCD205 • Instructor: Michael Winter – Office J323 – Office Hours: Tue 1:00pm - 3:00pm, Wed 9:00am-11:00am – email: [email protected] • Webpage: www.cosc.brocku.ca/~mwinter/Courses/4P42/ © M. Winter 1.1 COSC 4P42 – Formal Methods in Software Engineering • Course Description (Brock Calendar): Specification and correctness of software. Topics include algebraic specifications, semantics of programming languages, Hoare/dynamic logic, specification languages, program transformation. • Prerequisites: 3.5 COSC credits and MATH 1P67 or permission of the instructor • course procedures – cheating on tests/exam © M. Winter 1.2 COSC 4P42 – Formal Methods in Software Engineering Textbooks • Main Text – None (course material is on the web page). • Supplemental Texts – The Formal Semantics of Programming Languages: An Introduction, G. Winskel, The MIT Press (1993), ISBN 0-26223169-7 (hc), 0-262-73103-7 (pb) – The Design of Well-Structured and Correct Programs, S. Alagic & M.A. Arbib, Springer-Verlag (1978), ISBN 0-387-90299-6 – Fundamentals of Algebraic Specifications 1: Equations and Initial Semantics, H. Ehrig & B. Mahr, Springer-Verlag (1985), ISBN 0387-13718-1 © M. Winter 1.3 COSC 4P42 – Formal Methods in Software Engineering Course Work • Marking Scheme – Lab Tests (3x20%) – Final Exam (Lab D205) 60% 40% • Important Dates Test Length Date (D205)/Time 1 2 3 Exam 60 mins 60 mins 60 mins 90 mins Jan 30 (8:00am-9:00am) Feb 27 (8:00am-9:00am) Mar 20 (8:00am-9:00am) Apr 06 (8:00am-9:30am) © M. Winter 1.4 COSC 4P42 – Formal Methods in Software Engineering Course Outline Week Date Lecture Topic Lab Topic 1 Jan 07, 09 Introduction No lab 2 Jan 14, 16 First-order logic - Syntax and Semantics Introduction to Isabelle 3 Jan 21, 23 First-order logic - Natural Deduction Natural Deduction in Isabelle 4 Jan 28, 30 5 Feb 04, 06 6 Feb 11, 13 7* Feb 25, 27 8 Mar 04, 06 9 10 11 12 First-order logic - Soundness of Natural Test 1 (Jan 30) Deduction Introduction of the Programming Logic IMP and Hoare logic in Isabelle Hoare Logic Programming Language IMP - Syntax and Hoare logic in Isabelle Operational Semantics Programming Language IMP - Hoare Logic Programming Language IMP - Soundness of Hoare logic Algebraic Specifications - Motivation, Syntax and Mar 11, 13 Semantics Algebraic Specifications - Homomorphisms, Mar 18, 20 Initial and Terminal Models Algebraic Specifications - Homomorphisms, Mar 25, 27 Initial and Terminal Models Apr 01, 06** Selected topics, Review Test 2 (Feb 27) Introduction to ML Using ML as a specification language in Isabelle Test 3 (Mar 20) Review, Questions, Exam preparation Exam (April 06) * February 16-20 is Reading Week, no classes ** April 03 is Good Friday, no classes. Make up on April 06. © M. Winter 1.5 COSC 4P42 – Formal Methods in Software Engineering • A mark of at least 40% on the final exam is required to achieve a passing grade in this course. No electronic devices and especially no calculators will be allowed in the examination room. • Consideration regarding illness for test or exam dates will only be considered if accompanied with the completed Departmental Medical Excuse form. © M. Winter 1.6 COSC 4P42 – Formal Methods in Software Engineering Motivation Assume you are a project coordinator in a software company. The latest project your team is working on has the following constraints: • avoid integer multiplication (there are issues with the hardware); • the operation square(n)=n2 will frequently be used in the program. You present this problem to a member of your team. He comes up with the following piece of code: © M. Winter 1.7 COSC 4P42 – Formal Methods in Software Engineering A program r := 0; s := 1; i := 0; while i < n r := s := i := do r+s; s+2; i+1; od The program above computes n2 in the variable r. © M. Winter 1.8 COSC 4P42 – Formal Methods in Software Engineering Testing Input n= i r s 3 0 0 1 1 1 3 2 4 5 3 9 7 0 0 1 1 1 3 2 4 5 3 9 7 4 16 9 5 25 11 6 36 13 6 © M. Winter 1.9 COSC 4P42 – Formal Methods in Software Engineering Problems with Testing Testing may unveil errors in the code, but • You may only test finitely many examples. • Testing cannot verify that the code is bug-free. “Correctness cannot be established through testing. Testing can only delete errors, but never exclude errors.” Are you satisfied with the testing procedure? Yes?!?, but what if this program • controls a machine producing toys worth $10,000 an hour? • controls a rocket sending a new television satellite into orbit? An error in the code might cause a big financial loss for our company!!! © M. Winter 1.10 COSC 4P42 – Formal Methods in Software Engineering A proof The programmer says: “My program obviously computes −1 2 + 1 =0 Here is the proof that this is equal to n2. […]” © M. Winter 1.11 COSC 4P42 – Formal Methods in Software Engineering Further Problems? Are you satisfied with this proof? Yes?!?, but what if this program • controls the reentry of a space shuttle? • controls the rollercoaster you are sitting in? • controls the cooling system of the nuclear plant next door? The previous argument still contains the informal step: −1 “My program obviously computes 2 + 1“ =0 This could be wrong!!!!! © M. Winter 1.12 COSC 4P42 – Formal Methods in Software Engineering Formal Methods An alternative approach is based on so-called formal methods in software engineering. These methods try to either mathematically prove programs to be correct or to construct programs correctly step by step. Both attempts Require some formal system/calculus , i.e., a system that is based on a fixed set of simple rules. In this course we will focus on program verification. The idea/procedure of program verification can be summarized by: • Provide a specification of the behaviour of the program in a formal system/logic. Common tools are: – Propositional Logic (hardware verification) – First-order Logic (properties of imperative programs) – Higher-order Logic (properties of functional programs) – Algebraic Specifications (specification of datatypes) © M. Winter 1.13 COSC 4P42 – Formal Methods in Software Engineering Formal Software Verification • Provide a formal semantics of the programming language used. Common approaches are: – Operational Semantics (abstract machine) – Denotational Semantics (input/output behaviour as a function) – Axiomatic Semantics (program logic) • Use a specialized logic to verify the implementation with respect to the specification. Common logics are: – Specific Modal Logics such as Dynamic Logic – Hoare Logic – Extended Calculus of Constructions © M. Winter 1.14 COSC 4P42 – Formal Methods in Software Engineering Formal Software Verification Important considerations when dealing with a formal system: • Soundness/Correctness . This property states that every property that can be obtained using the formal system/calculus is semantically true in some sense. – Slogan: “What you can prove is also true.” • Completeness. This property is the opposite implication of correctness. It states that for every true sentence there is also a proof in the formal system/calculus. – Slogan: “What is true can also be proven.” • Expressive power. – Slogan: “Can I formulate all my properties in the language?” • Decidability. If a formal system is decidable, then all proofs can be found automatically by a program. – Slogan: “Can a computer do my work?” © M. Winter 1.15