35
CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Embed Size (px)

Citation preview

Page 1: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

CS1502 Formal Methods in Computer Science

Lecture Notes 1

Course Information

Introduction to Logic

Part 1

Page 2: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Content

70% logic and proofs Pervades computer science, e.g., hardware circuit

design, artificial intelligence, knowledge representation, database systems, programming languages, software engineering (design, verification, specification), …

Will help you understand proofs in math, science, theoretical CS

Page 3: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Content

30% Abstract models of computation Needed for hardware design, compilers,

computational complexity analysis, … Interesting proofs; you will use what you learn in

the first part of the course to understand them

Page 4: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

Prerequisites: CS441 Discrete Structures for Computer Science CS445 Data Structures

Materials on course website, reachable from www.cs.pitt.edu/~wiebe Schedule of readings, homeworks, exams Lecture notes, available before class

Support for lectures; filled in in class

Page 5: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

The TA will go over exercises and answer questions in recitation.

He will also cover logistics of submitting homeworks, and will post solutions to the homework.

Page 6: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

Workload is steady throughout the course 3 exams Weekly homeworks (no projects)

Many are graded electronically You can submit solutions as many times as you like Get feedback without having to wait for instructor

grading Purpose is to help you master the material for the exams

Exams 90% Homework 10%

Page 7: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

Exams Challenging, but not devious

All of the questions will be related to an example worked out in the text, a homework exercise, or a problem we did in class.

Page 8: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

Work is steady throughout the course If you keep up, you will likely do OK The work gets harder! Please ask questions (lectures, recitations,

office hours) My office hours are T,TH 1:30-2:30 and by

appointment – just send mail to set up a time

Page 9: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logistics

Do readings before lecture Do the “you try it” exercises as you read the

logic text

Page 10: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Software with LPL TextFitch

Named for Frederic Fitch Construct formal proofs Prove an argument is valid

Page 11: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Software with LPL TextBoole

Named for George Boole

Construct truth tables Verify a sentence is a tautology Verify two sentences are tautologically equivalent Prove an argument is valid

Page 12: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Software with the TextTarski’s World

Named for Alfred Tarski

Construct sentences in first-order logic Determine if a sentence is true wrt a world Create a world that shows that an argument is

invalid

Page 13: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Software with TextSubmit

Verify your solutions are correct (without instructor seeing)

Submit homework for final grading to TA (by due date)

Page 14: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

More Notes on Homework

Many exercises will be submitted to the grade grinder

Please request that your grade assessments be sent to the TA (not to me!)

You may submit your solutions as many times as you like, but please send your TA only a single report per assignment

Now, let’s look at the webpage and syllabus…

Page 15: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Introduction to Logic

Page 16: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Examples

All x All y ((cube(x) ^ tet(y)) (leftof(x,y) ^ frontof(x,a)))

circle(a)small(a)

feed(max,scruffy)

All x All y ((pet(x,y) ^ hungry(y)) feed(x,y))

Page 17: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Logic

A simple grammar. Each sentence has a single interpretation (unlike English!)

Used to describe a world, which we define. Once we define the world, we can say what

things names refer to, and whether a logical sentence is true or false.

Page 18: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Names

Constants are used to name existing objectsa, b, c, d, e, fmax, claire, carl

No constant can name more than one object An object can have more than one name or

no name at all

Page 19: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Predicates

A property possessed by an objectShape (e.g., Tet, Cube)Size (e.g., Small, Large)

A relationship among objectsShape relationship (e.g., SameShape)Size relationship (e.g., Smaller)Positional relationship (e.g., Between, LeftOf)Equality =

Page 20: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Quick Example

Ackermann’s sentences and world in Tarski Properties:

Cube, Tet (4 faces), Dodec (12 faces), Medium

Relations Backof, Leftof

(Click verify, and you see that one of the sentences is false about the world)

Page 21: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Predicates

Each predicate has a fixed number of arguments or “arity”. This is the number of constants the predicate needs to form a sentence.

In English, OK, but not in logic: Susanna is taller than Dimitri Susanna is taller than Dimitri and Jerome

Page 22: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Predicates

Predicates must be “determinate” Suppose p is an n-ary predicate. For every n-tuple <o1,o2,…,oN> of objects,

p(o1,o2,…,oN) is true or false (not kind of true). What’s an n-tuple? An n-tuple is a collection of n objects where order

matters. Duplicates are allowed. In contrast, sets may not have duplicates, and the members of sets are not ordered.

Page 23: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Atomic Sentences (so far)

A sentence formed by a single predicate followed by one or more names

Max is tall Tall(max)

e is larger than b Larger(e,b)

e is identical to a e = a

A sentence expresses a claim that is either true or false

Page 24: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Atomic Sentences (so far)

Predicate(arg1, arg2,…, argn) Predicates have names beginning with an uppercase letter or are

represented by an operator symbol The number of arguments is called the predicate’s arity The order of the arguments is important

Larger(e,c) – e is larger than cLarger(c,e) – c is larger than eBetween(a,b,e) – a is between b and eBetween(b,a,e) – b is between a and e

=(a,b) a and b are identical Usually, written in infix form a = b

Page 25: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Function Symbols

A function is used to express complex names (a reference to an individual without using a name)

father(b) – b’s father Used in a sentence: Tall(father(b)) password(c) – c’s password Used in a sentence: Long(password(c))

A function may be nested father(father(max)) Used in a sentence: Short(father(father(max)))

Can’t nest predicates Tall(Tall(max)) * not a legal sentence*

Page 26: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Functional Expressions

Function(arg1, arg2,…, argn)Function names begin with a lowercase letter or are

expressed with a symbol father(max) Max’s father

father(mother(max)) Max’s mother’s father

youngestChild(max,ann) Max and Ann’s youngest child

*(5,+(2,4)) 30

Page 27: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Atomic Sentences (so far)

A sentence formed by a single predicate followed by one or more terms

A term is either a constant or a functional expression

Page 28: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Example Atomic Sentences (which are functions and which are

predicates?)

Predicate(term1,term2,…,term-n)Happy(bossof(sally))

Father(bill)Tall(fatherOf(motherOf(sally)))

Happier(motherOf(bill),bossof(fatherOf(max)))Fake(santa(rossParkMall)))

Real(santa(robinsonTownCenter)))

Page 29: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

ConnectivesApply to sentences to

create more complex sentences.

Not And, Or , Material Conditional Biconditional

Page 30: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Examples

Larger(e,c)

Cube(b) Large(b)

SameRow(e,c) BackOf(e,b)

e is not larger than c

b is a cube or b is large

e and c are in the same row and e is in back of b

Page 31: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

First Order Logic

Names Predicates Functions Connectives

Are there more?

Page 32: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Example FOL

English FOLNames Brando brando

Nancy nancySean sean

Predicates x is identical to y x = yx is a better actor than y BetterActor(x,y)

Functions x's favorite actor favoriteActor(x)

Page 33: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Translation

Brando is Nancy’s favorite actor. brando = favoriteActor(nancy)

BetterActor(favoriteActor(nancy), favoriteActor(max))

Nancy’s favorite actor is better than Max’s favorite actor.

sean = favoriteActor(sean) Sean is his own favorite actor.

Brando is someone’s favorite actor. x(brando = favoriteActor(x))

Page 34: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

Quantifiers and Variables

For every x x x (man(x) mortal(x))

There exists y y x(brando = favoriteActor(x))

Page 35: CS1502 Formal Methods in Computer Science Lecture Notes 1 Course Information Introduction to Logic Part 1

First Order Logic

Names Predicates Functions Connectives Quantifiers and variables

Revised List