30
Lecture 8 Introduction to Logic CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

Lecture 8 Introduction to Logic CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

Embed Size (px)

Citation preview

Lecture 8Introduction to Logic

CSCI – 1900 Mathematics for Computer Science

Fall 2014

Bill Pine

CSCI 1900 Lecture 8 - 2

Lecture Introduction

• Reading– Rosen - Section 1.1

• Logical Statements• Logical Connectives / Compound Statements

– Negation– Conjunction– Disjunction

• Truth Tables• Quantifiers

– Universal– Existential

CSCI 1900 Lecture 8 - 3

Statement of Proposition

• Proposition (statement of proposition) – a declarative sentence that is either true or false, but not both

• Examples:– Star Trek was a TV series: True– 2+3 = 5: True– Do you speak Klingon? This is a question, not a

statement

CSCI 1900 Lecture 8 - 4

Statement of Proposition (cont)

– x - 3 = 5: a declarative sentence, but not a statement since it is true or false depending on the value of x

– Take two aspirins: a command, not a statement– The current temperature on the surface of the

planet Venus is 800oF: a proposition of whose truth is unknown to us

– The sun will come out tomorrow: a proposition that is either true or false, but not both, although we will have to wait until tomorrow to determine the answer

CSCI 1900 Lecture 8 - 5

Notation

• x, y, z, … denote variables that can represent real numbers

• p, q, r,… denote propositional variables that can be replaced by statements– p: The sun is shining today– q: It is cold

CSCI 1900 Lecture 8 - 6

Negation (Not)

• If p is a statement, the negation of p is the statement not p

• Denoted ~p ( alternately: !p or p or p )• If p is True,

– ~p is False

• If p is False, – ~p is True

• not is a unary operator for the collection of statements and ~p is a statement if p is a statement

CSCI 1900 Lecture 8 - 7

Negation Truth Table

p ~ p

T F

F T

CSCI 1900 Lecture 8 - 8

Examples of Negation

• If p: 2+3 > 1 Then ~p: 2+3 < 1• If q: It is night Then

– ~q: It is not the case that it is night,• It is not night• It is day

CSCI 1900 Lecture 8 - 9

Conjunction

• If p and q are statements– The conjunction of p and q is the compound

statement “p and q”– Denoted p q

• p q is true only if both p and q are true• Example:

– p: ETSU parking permits are readily available– q: ETSU has plenty of parking – p q = ?

CSCI 1900 Lecture 8 - 10

Conjunction Truth Table

p q p q

T T T

T F F

F T F

F F F

English Conjunctives

• The following are common conjunctives in English:

And, Now, But, Still, So, Only, Therefore, Moreover, Besides, Consequently, Nevertheless, For, However, Hence, Both... And, Not only... but also, While, Then, So then

CSCI 1900 Lecture 8 - 11

CSCI 1900 Lecture 8 - 12

Disjunction (Inclusive)

• If p and q are statements, – The (inclusive) disjunction of p and q is the compound

statement “p or q”– Denoted p q

• p q is true if either p is true or q is true or both are true

• Example:– p: I am a male q: I am under 90 years old– p q = ?– p: I am a male q: I am under 20 years old– p q = ?

CSCI 1900 Lecture 8 - 13

Disjunction (Inclusive) Truth Table

p q p q

T T T

T F T

F T T

F F F

CSCI 1900 Lecture 8 - 14

Exclusive Disjunction

• If p and q are statements– The exclusive disjunction true if either p is true or q

is true, but not both are true– Denoted p q

• Example:– p: It is daytime– q: It is night time– p q (in the exclusive sense) = ?

CSCI 1900 Lecture 8 - 15

Disjunction(Exclusive) Truth Table

p q p q

T T F

T F T

F T T

F F F

CSCI 1900 Lecture 8 - 16

Exclusive versus Inclusive

• Depending on the circumstances, some English disjunctions are inclusive and some of exclusive.

• Examples of Inclusive– “I have a dog” or “I have a cat”– “It is warm outside” or “It is raining”

• Examples of Exclusive– Today is either Tuesday or it is Thursday– The light is either on or off

CSCI 1900 Lecture 8 - 17

Compound Statements

• A compound statement is a statement made by joining simple propositions with logical connectors

• For n individual propositions, there are 2n possible combinations of truth values

• The truth table contains 2n rows identifying the truth values for the statement represented by the table

• Use parenthesis to denote order of precedence• has precedence over • Use parenthesis to ensure meaning is clear

CSCI 1900 Lecture 8 - 18

Truth Tables as Tools

• Compound statements can be easily and systematically investigated with truth tables

• Assign a portion of the compound statement to a column

• Final column represents the complete compound statement

CSCI 1900 Lecture 8 - 19

Compound Statement Example

p q p q ~p (p q) (~p)

T T T F T

T F F F F

F T F T T

F F F T T

(p q) (~p)

CSCI 1900 Lecture 8 - 20

Quantifiers

• Recall from Section 1.1, a set may be defined by its properties {x | P(x)}

• For a specific element e to be a member of the set, P(e) must evaluate to “true”

• P(x) is called a predicate or a propositional function

CSCI 1900 Lecture 8 - 21

Computer Science Functions

• if P(x) then execute certain steps

• while Q(x)

do specified actions

CSCI 1900 Lecture 8 - 22

Universal Quantification

• Universal quantification of the predicate P(x) means “For all values of x, P(x) is true”

• Denoted x P(x)• The symbol is called the universal

quantifier• The order in which multiple universal

quantifications are applied does not matter (e.g., x y P(x,y) ≡ y x P(x,y) )

CSCI 1900 Lecture 8 - 23

Universal Examples:

• P(x): -(-x) = x– This predicate makes sense for all real numbers

x R– The universal quantification of P(x), x P(x), is

a true statement, because for all real numbers, -(-x) = x

• Q(x): x+1<4– x Q(x) is a false statement, because, for

example, Q(5) is not true

CSCI 1900 Lecture 8 - 24

Existential Quantification

• Existential quantification of a predicate P(x) is the statement:

“There exists a value of x for which P(x) is true.”

• Denoted x P(x)• Existential quantification may be applied to several

variables in a predicate• The order in which multiple existential

quantifications are considered does not matter

CSCI 1900 Lecture 8 - 25

Existential Examples:

• P(x): -(-x) = x– The existential quantification of P(x), x P(x), is a true

statement, because there is at least one real number where -(-x) = x

• Q(x): x+1<4– x Q(x) is a true statement, because, for example, Q(2) is

true• Nota Bene: is not the complement of

– An Example• N(x): x ≠ x• x N(x) is false and x N(x) is also false

CSCI 1900 Lecture 8 - 26

Applying Both and Quantifications

• Order of application matters• Example: Let A and B be n x n matrices• The statement A ( B | A + B = In )

• Reads: for every A there is a B such that A + B = In• Prove by coming up for equations for bii and bij (ji)• Now reverse the order: B (A | A + B = In)

• Reads: there exists a B, for all A, such that , A + B = In• The second proposition is F A L S E !

CSCI 1900 Lecture 8 - 27

Assigning Quantification - 1

• Let p: x R(x) [R(x): a person is good]– If p is true then x ~R(x) is false

• If every person is good, then there does not exist person who is not good

– If p is true then x R(x) is true• If every person is good, then there exists a person

who is good– If p is false then x ~R(x) is true

• If not every person is good, then there exists a person who is not good

CSCI 1900 Lecture 8 - 28

Assigning Quantification - 2

• Let p: x R(x) [R(x): a person is good]– If p is true then x ~R(x) is false

• If there exists a person who is good, then it is not true that all people are not good

– If p is false then x ~R(x) is true• If there does not exist a good person then every

person is not good

CSCI 1900 Lecture 8 - 29

Implications of the Previous Slide• Assume a statement is made that “for all x, P(x) is

true”– If we can find one case that is not true

• The statement is false– If there isn’t one case that is not true

• The statement is true

• Example: positive integers, n, n P(n) = n2 - n + 41 is a prime number

– This is false because an integer resulting in a non-prime value, i.e., n such that P(n) is false

CSCI 1900 Lecture 8 - 30

Key Concepts Summary

• Statement of Proposition• Logical Connectives / Compound Statements

– Negation– Conjunction– Disjunction

• Truth Tables• Quantifiers

– Universal– Existential