43
CS322 Formal Methods

Formal Methods. D AVID B OWIE 1947 - 2016 Dr. Barry Wittman Not Dr. Barry Whitman Education: PhD and MS in Computer Science, Purdue University

Embed Size (px)

DESCRIPTION

 Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University  BS in Computer Science, Morehouse College  Hobbies:  Reading, writing  Enjoying ethnic cuisine  DJing  Lockpicking

Citation preview

Page 1: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

CS322Formal Methods

Page 2: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

DAVID BOWIE • 1947 - 2016

Page 3: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Who am I? (for those of you who don’t know me already) Dr. Barry Wittman Not Dr. Barry Whitman Education:

PhD and MS in Computer Science, Purdue University

BS in Computer Science, Morehouse College Hobbies:

Reading, writing Enjoying ethnic cuisine DJing Lockpicking

Page 4: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

How can you reach me?

E-mail: [email protected]: Esbenshade 284BPhone: (717) 361-4761Office hours: MWF 11:00am – 12:00pm

MF 3:30 – 5:00pmT 1:00 – 3:00pmAnd by appointment

Website:http://users.etown.edu/w/wittmanb/

Page 5: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Course Overview

Page 6: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Textbook

Susanna S. EppDiscrete Mathematics with

Applications 4th Edition, 2010, Brooks Cole ISBN-10: 0495391328 ISBN-13: 978-0495391326

Page 7: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

You have to read the book You are expected to read the

material before class If you're not prepared, you will be

asked to leave You will forfeit the opportunity to take

quizzes Much more importantly, you will forfeit

the education you have paid around $100 per class meeting to get

Page 8: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

This is a math class

It’s mostly discrete math Meaning math that is not continuous

It is not discreet math Meaning math that won’t tell people

what you did There are certain kinds of math that

are really beneficial to CS We have collected a big chunk of

these and put them in this course It’s a grab bag

Page 9: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Topics to be covered Logic Proofs Basic number theory Mathematical induction Set theory Functions and relations Counting and probability Graphs and trees Regular expressions and finite automata Running time Formal languages and grammars

Page 10: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

More information For more information, visit the webpage:

http://users.etown.edu/w/wittmanb/cs322

The webpage will contain: The most current schedule Notes available for download Reminders about exams and homework Syllabus (you can request a printed copy if you like) Detailed policies and guidelines

Piazza will allow for discussion and questions about assignments: https://piazza.com/etown/spring2016/cs322/

Page 11: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Homework

Page 12: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Ten homework assignments 30% of your grade will be ten equally

weighted homework assignments Each will focus on a different set of

topics from the course All homework is to be done

individually I am available for assistance during

office hours, through Piazza, and through e-mail

Page 13: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Turning in homework Homework assignments must be turned in by

saving them in your class folder (J:\SP2015-2016\CS322A) before the deadline

Do not put assignments in your public directories

Late homework will not be accepted Paper copies of homework will not be accepted Each homework done in LaTeX will earn 0.5%

extra credit toward the final semester grade Doing every homework in LaTeX will raise your

final grade by 5% (half a letter grade)

Page 14: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Impromptu student lectures

Page 15: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Impromptu lectures 5% of your grade will be lectures that you give You will give roughly two of these lectures at any

time during the semester, without any warning You will have 3 to 5 minutes in which you must

present the material to be read for that day Students are encouraged to ask questions

There is no better way to learn material than by teaching it

Polishing public speaking skills is never a bad thing

Page 16: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Quizzes

Page 17: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Pop Quizzes

5% of your grade will be pop quizzes These quizzes will be based on material

covered in the previous one or two lectures

They will be graded leniently They are useful for these reasons:

1. Informing me of your understanding2. Feedback to you about your understanding3. Easy points for you4. Attendance

Page 18: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Exams

Page 19: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Exams

There will be three equally weighted in-class exams totaling 45% of your final grade Exam 1: 2/08/2016 Exam 2: 3/11/2016 Exam 3: 4/11/2016

The final exam will be worth 15% of your grade Final: 2:30 – 5:30pm5/05/2016

Page 20: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Course Schedule

Page 21: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Tentative scheduleWeek Starting Topics Chapters

1 01/11/16 Propositional logic 22 01/18/16 Predicate logic 33 01/25/16 Proofs 44 02/01/16 Number theory 45 02/08/16 Mathematical induction 56 02/15/16 Set theory 67 02/22/16 Functions 7

02/29/16 Spring Break8 03/07/16 Relations 89 03/14/16 Counting and probability 9

10 03/21/16 Counting and probability continued 911 03/28/16 Graphs and trees 1012 04/04/16 Running time 1113 04/11/16 Regular languages 1214 04/18/16 Higher level languages Handouts15 04/25/16 Review 2 - 12 + Handouts

Page 22: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Policies

Page 23: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Grading breakdown30% •Ten homeworks

5% •Impromptu student lectures

5% •Quizzes

45% •Three equally weighted midterm exams

15% •Final exam

Page 24: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Grading scale

A 93-100 B- 80-82 D+ 67-69

A- 90-92 C+ 77-79 D 63-66

B+ 87-89 C 73-76 D- 60-62

B 83-86 C- 70-72 F 0-59

Page 25: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Academic dishonesty Don’t cheat First offense:

I will give you a zero for the assignment, then lower your final letter grade for the course by one full grade

Second offense: I will fail you for the course and try to kick you

out of Elizabethtown College Refer to the Student Handbook for the

official policy Ask me if you have questions or concerns

Page 26: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

DisabilityElizabethtown College welcomes otherwise qualified students with disabilities to participate in all of its courses, programs, services, and activities. If you have a documented disability and would like to request accommodations in order to access course material, activities, or requirements, please contact the Director of Disability Services, Lynne Davies, by phone (361-1227) or e-mail [email protected]. If your documentation meets the college’s documentation guidelines, you will be given a letter from Disability Services for each of your professors. Students experiencing certain documented temporary conditions, such as post-concussive symptoms, may also qualify for temporary academic accommodations and adjustments. As early as possible in the semester, set up an appointment to meet with me, the instructor, to discuss the academic adjustments specified in your accommodations letter as they pertain to my class.

Page 27: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Logic

Page 28: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Logical warmup Consider three boxes A, B, and C One contains gold, but the other two are empty Each box has a message printed on it Two of the messages are lies, and one is telling the

truth Which box has the gold?

The gold is not here.

The gold is not here.

The gold is in Box B.

A B C

Page 29: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Metalogic

On a given island, everyone is either a Knight or a Knave

Knights always tell the truth, and Knaves always lie

Imagine that I meet two inhabitants of this island and ask, "Is either of you a Knight?"

Given his response, I know the answer to my question

Are the inhabitants in question Knights or Knaves?

Page 30: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Propositional Logic

Page 31: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Combining truth and falsehood Politicians lie.

True statement! Cast iron sinks.

True statement! Politicians lie in cast iron sinks.

Absurd statement!

Page 32: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Propositional logic

Propositional logic is the logic that governs statements

A statement is either true or false (but nothing else!)

We want to combine them, infer things about them, prove them true or false

First, we have to learn their rules

Page 33: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

p and q "The moon is made of green cheese" is a

statement, that is, something that is either true or false

It takes a long time to write "The moon is made of green cheese"

Mathematicians are lazy, and so they let a variable represent this statement

p and q are common choices for propositional logic So, we can use p in place of "The moon is made of

green cheese" Similarly, we can use q in place of "The earth is

made of rye bread"

Page 34: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

AND, OR, NOT Like programming,

combining two values with AND will be true only if both values are true

Using OR makes the result true if either is true

NOT changes a true to false and a false to true

Mathematicians use their own symbols for AND, OR, and NOT

Operation Symbol Example

AND p q

OR p q

NOT ~ ~p

Page 35: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Truth tables

To better understand an operation, we can make a truth table, giving all possible input values and the corresponding output values

This truth table is for p qp q p qT T TT F TF T TF F F

Page 36: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Think about it…

What’s the truth table for q p? Consider: (p q) ~(p q)

What’s its truth table? What’s its meaning?

What’s the truth table for p q r? How many lines are in a truth table

with n symbols? How many different truth tables are

possible for two input symbols?

Page 37: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Logical equivalence

Two different statements can be written differently and yet be logically equivalent p ~(~p)

Make a truth table If all outputs match up, the statements

are logically equivalent If even one output doesn’t match, the

statements are not equivalent

Page 38: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

De Morgan’s Laws

What’s an expression that logically equivalent to ~(p q) ?

What about logically equivalent to ~(p q) ?

De Morgan’s Laws state: ~(p q) ~p ~q ~(p q) ~p ~q Essentially, the negation flips an AND to

an OR and vice versa

Page 39: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

What are you implying? You can construct all possible outputs using

combinations of AND, OR, and NOT But, sometimes it’s useful to introduce

notation for common operations This truth table is for p q

p q p qT T TT F FF T TF F T

Page 40: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

If… We use to represent an if-then statement Let p be "The moon is made of green cheese" Let q be "The earth is made of rye bread" Thus, p q is how a logician would write:

If the moon is made of green cheese, then the earth is made of rye bread

Here, p is called the hypothesis and q is called the conclusion

What other combination of p and q is logically equivalent to p q ?

Page 41: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Upcoming

Page 42: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Next time…

More on implications Validity of arguments

Tautologies and contradictions Rules of inference Examples with digital circuits

Page 43: Formal Methods. D AVID B OWIE 1947 - 2016  Dr. Barry Wittman  Not Dr. Barry Whitman  Education:  PhD and MS in Computer Science, Purdue University

Reminders

Read Chapter 2