Computer Science School of Computing Clemson University Introduction to Mathematical Reasoning Jason Hallstrom and Murali Sitaraman Clemson University.

Slides:



Advertisements
Similar presentations
Introduction to Proofs
Advertisements

PROOF BY CONTRADICTION
School of Computing Clemson University Mathematical Reasoning  Goal: To prove correctness  Method: Use a reasoning table  Prove correctness on all valid.
Addressing the Challenges of Current Software. Questions to Address Why? What? Where? How?
MIPS Coding. Exercise 1 4/17/2015week04-3.ppt2 Suppose we have three arrays, A, B, C, all of size 10. Now we want to set C[i] = min(A[i], B[i]) for all.
Reasoning About Code; Hoare Logic, continued
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
Self-Reference - Induction Cmput Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.
Lecture 2: Fundamental Concepts
General Announcements Project Due Friday, 1/30 Labs start Wednesday & Thursday – Java review – Weiss 1.19, 1.20 – You may show up & hand in Workshops.
TR1413: INTRO TO DISCRETE MATHEMATICS LECTURE 2: MATHEMATICAL INDUCTION.
What is the best way to start? 1.Plug in n = 1. 2.Factor 6n 2 + 5n Let n be an integer. 4.Let n be an odd integer. 5.Let 6n 2 + 5n + 4 be an odd.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
Computer Science School of Computing Clemson University Mathematical Modeling Murali Sitaraman Clemson University.
Mathematics throughout the CS Curriculum Support by NSF #
Jason Hallstrom (Clemson), Joan Krone (Denison), Joseph E. Hollingsworth (IU Southeast), and Murali Sitaraman(Clemson) This workshop is funded in part.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Murali Sitaraman
Computer Science School of Computing Clemson University Specification and Reasoning in SE Projects Using a Web IDE Charles T. Cook (Clemson) Svetlana V.
Computer Science School of Computing Clemson University Mathematical Reasoning across the Curriculum Software Development Foundations and Software Engineering.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Lecture 16 March 22, 2011 Formal Methods CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
Lecture 3.1: Mathematical Induction CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
CSNB143 – Discrete Structure Topic 5 – Induction Part I.
Computer Science School of Computing Clemson University Introduction to Formal Specification Murali Sitaraman Clemson University.
Lecture 17 March 24, 2011 Formal Methods 2 CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Joseph E. Hollingsworth
9.4 Mathematical Induction
111/15/2015CS150 Introduction to Computer Science 1 Summary  Exam: Friday, October 17,  Assignment: Wednesday, October 15, 2003  We have completed.
Reasoning about programs March CSE 403, Winter 2011, Brun.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
This research is funded in part by grant CCR from the U. S. National Science Foundation. Profiles: A Compositional Mechanism for Performance Specification.
Methods of Proof for Boolean Logic Chapter 5 Language, Proof and Logic.
Spring 2016 COMP 2300 Discrete Structures for Computation
Computer Science School of Computing Clemson University Mathematical Reasoning with Objects.
1 CMSC 341 Math Review. 2 Exponents Identities (X A ) B = X AB X A * X B = X A+B X A / X B = X A-B X A + X B  X A+B.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
5-5 Indirect Proof. Indirect Reasoning: all possibilities are considered and then all but one are proved false. The remaining possibility must be true.
Section 2.3 Mathematical Induction. First Example Investigate the sum of the first n positive odd integers. 1= ____ 1 + 3= ____ = ____
Interface specifications At the core of each Larch interface language is a model of the state manipulated by the associated programming language. Each.
Lecture 18 March 29, 2011 Formal Methods 3 CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
Computer Science School of Computing Clemson University Reasoning with Queues and Web Interface Demo.
Mathematical Induction. The Principle of Mathematical Induction Let S n be a statement involving the positive integer n. If 1.S 1 is true, and 2.the truth.
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2012
Component Implementations Using RESOLVE
Formal Specification of Java Interfaces
CSE 311: Foundations of Computing
C Puzzles Taken from old exams
Introduction to Components and Specifications Using RESOLVE
CSE 311: Foundations of Computing
Formal Specification of Interfaces
Introduction to Components and Specifications Using RESOLVE
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Mathematical Reasoning
CISC181 Introduction to Computer Science Dr
CMSC 341 Math Review.
Mathematical Induction
Lecture 3.1: Mathematical Induction
Functions Divide and Conquer
More Mathematical Reasoning (Conditional Statements)
Bottom Up: Soundness and Completeness
Mathematical Reasoning with Data Abstractions
CSE 1020:Software Development
Mathematical Induction
DS.I.1 CSE 373: Data Structures and Algorithms Autumn Quarter 2000
Lecture 3.1: Mathematical Induction
Formal Methods Lecture 16 March 22, 2011 CS 315 Spring 2011
Mathematical Induction
Presentation transcript:

Computer Science School of Computing Clemson University Introduction to Mathematical Reasoning Jason Hallstrom and Murali Sitaraman Clemson University

School of Computing Clemson University  What does this code do to Integer I, where Foo1 and Bar1 are functions that modify their argument? I = Foo1(I); I = Bar1(I);

School of Computing Clemson University  Or this to Integers I and J? I = Foo2(I, J); J = Bar2(I, J); I = Bar2(I, J);

School of Computing Clemson University  What does this code do to Integer I? I = Next(I); I = Prev(I);

School of Computing Clemson University  What does this code do to Integer x? I = Next(I); I = Prev(I);  How sure are we?

School of Computing Clemson University  What does this code do to Integer x? I = Next(I); I = Prev(I);  How sure are we?  Have to account for bounds in our analysis  Summary: … Need formal descriptions beyond names

School of Computing Clemson University  What does this code do to Integers I and J? I = Sum (I, J); J = Difference (I, J); I = Difference (I, J);  Same discussion as before…

School of Computing Clemson University Specification of Integer Operations  Think of ints as integers in math  Constraints, for all Integers I: min _Int <= I <= max_Int  Operation Next (I: Integer): Integer; requires I < max_int; ensures Next = I + 1;  Operation Prev (I: Integer): Integer; requires I > min_Int; ensures Prev = I - 1;

School of Computing Clemson University Specification of Integer Operations  Parameters are allowed to be changed, depending on the language and how parameters are passed  So to make it clear that the parameter isn’t modified, we specify:  Operation Next (preserves I: Integer): Integer; requires I < max_int; ensures Next = I + 1;

School of Computing Clemson University Specification of Integer Operations  Parameters are allowed to be changed, depending on the language and how parameters are passed  We can also specify:  Operation Increment (updates I: Integer); requires I < max_int; ensures I = #I + 1;  In the ensures clause, #I denotes the input I value  Exercise: Specify Decrement

School of Computing Clemson University Meaning of specifications  Requirements and guarantees Requires clauses are preconditions Ensures clauses are postconditions  Callers are responsible for requirements  Caller of Increment is responsible for making sure input I < max_int  Guarantees hold only if callers meet their requirements

School of Computing Clemson University Is the code correct for the given spec? Spec: Operation Do_Nothing (updates I: Integer); requires … ensures I = #I; Code: Increment(I); Decrement(I);

School of Computing Clemson University These specs are the same… Spec: Operation Do_Nothing (preserves I: Integer); requires … Spec: Operation Do_Nothing (updates I: Integer); requires … ensures I = #I;

School of Computing Clemson University Methods for checking correctness  Testing?  Tracing or inspection?  Mathematical reasoning

School of Computing Clemson University Mathematical reasoning  Goal: To prove correctness  Method: The rest of this presentation  Can prove correctness on all valid inputs  Can show absence of bugs

School of Computing Clemson University Example: Prove correctness Spec: Operation Do_Nothing (updates I: Integer); requires I < max_int; ensures I = #I; Code: Increment(I); Decrement(I);

School of Computing Clemson University Establish the goals in state-oriented terms using a table AssumeConfirm 0 Increment(I); 1 Decrement(I) 2I2 = I0

School of Computing Clemson University Assume requires clause at the beginning (Why?) AssumeConfirm 0I0 < max_int and … Increment(I); 1 Decrement(I) 2I2 = I0

School of Computing Clemson University Assume calls work as advertised AssumeConfirm 0I0 < max_Int and … Increment(I); 1I1 = I0 + 1 Decrement(I) 2I2 = I1 - 1I2 = I0

School of Computing Clemson University Prove the goal(s) using assumptions  Prove I2 = I0  Proof of I2 = J0 I2 = I1 – 1 (assumption in state 2) = (I0 + 1) – 1 (assumption in state 1) = I0 (simplification)  More proof needed…

School of Computing Clemson University More assertions to be confirmed (Why?) AssumeConfirm 0I0 < max_int I0 < max_int and … Increment(I); 1I1 = I0 + 1 I1 > min_int Decrement(I) 2I2 = I1 - 1I2 = I0

School of Computing Clemson University Prove all assertions to be confirmed  Proofs - exercises

School of Computing Clemson University Basics of Mathematical Reasoning  Suppose you are verifying code for some operation P Assume its requires clause in state 0 Confirm its ensures clause at the end  Suppose that P calls Q Confirm the requires clause of Q in the state before Q is called  Why? Because caller is responsible Assume the ensures clause of Q in the state after Q  Why? Because Q is assumed to work  Prove assertions to be confirmed