27
2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of Proofs

2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

Embed Size (px)

Citation preview

Page 1: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 1

Logic and Proofs

§1.1 Introduction§1.2 Propositional Equivalences§1.3 Predicates and Quantifiers§1.4 Nested Quantifiers§1.5~7 Methods of Proofs

Page 2: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 2

Introduction to Logic (§1.1)

In this section we will introduce the Propositional Logic.

Propositional Logic is the logic of compound statements built from

simpler statements using

so-called Boolean connectives.

George Boole(1815-1864)

Page 3: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 3

Definition of a Proposition

A proposition (p, q, r, …) is simply a statement (i.e., a declarative sentence) with a definite meaning, having a truth value that’s either true (T) or false (F) (never both, neither, or somewhere in between).

However, you might not know the actual truth value, and it might be situation-dependent.

命題

Page 4: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 4

Examples of Propositions

“It is raining.” (In a given situation.) “Taipei is the capital of Taiwan.” “1 + 2 = 3”But, the following are NOT propositions: “Who’s there?” (interrogative, question) “Just do it!” (imperative, command) “1 + 2” (expression with a non-true/false

value)

疑問句

祈使句

無真假可言的句子

Page 5: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 5

An operator or connective combines one or more propositions into a larger proposition. Unary operators take 1 operand (e.g., −3) Binary operators take 2 operands (eg 3 4).

Propositional or Boolean operators operate on propositions or truth values instead of on numbers.

Operators / Connectives運算符號 連接詞

Page 6: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 6

Some Popular Boolean Operators

Formal Name Nickname Arity Symbol

Negation operator NOT Unary ¬

Conjunction operator AND Binary Disjunction operator OR Binary Exclusive-OR operator XOR Binary Implication operator IMPLIES Binary Biconditional operator IFF Binary ↔

否定句

連言選言互斥條件句

雙條件句

Page 7: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 7

The Negation Operator

The unary negation operator “¬” (NOT) transforms a prop. into its logical negation. E.g. If p = “I have brown hair.”

then ¬p = “I do not have brown hair.”

Truth table for NOT: p pT FF TT :≡ True; F :≡ False

“:≡” means “is defined as”

Page 8: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 8

The Conjunction Operator

The binary conjunction operator “” (AND) combines two propositions to form their logical conjunction. E.g. If p=“I will have salad for lunch.” and

q=“I will have steak for dinner.”, then pq =“I will have salad for lunch and I will have steak for dinner.”

Page 9: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 9

Note that aconjunctionp1 p2 … pn

of n propositionswill have 2n rowsin its truth table.

Conjunction Truth Table

p q p qF F FF T FT F FT T T

Page 10: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 10

Note that pq meansthat p is true, or q istrue, or both are true!

So, this operation isalso called inclusive or,because it includes thepossibility that both p and q are true.

Disjunction Truth Table

p q p qF F FF T TT F TT T T

Notedifferencefrom AND

Page 11: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 11

Nested Propositional Expressions

Use parentheses to group sub-expressions:“I just saw my old friend, and either he’s grown or I’ve shrunk.” = f (g s)(f g) s would mean something different f g s would be ambiguous

By convention, “¬” takes precedence over both “” and “”. ¬s f means (¬s) f , not ¬ (s f )

括號在命題中的作用

Page 12: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 12

A Simple Exercise

Let p =“It rained last night”, q =“The sprinklers came on last night,” r =“The lawn was wet this morning.”

Translate each of the following into English:

¬p =

r ¬p =

¬ r p q =

“It didn’t rain last night.”“The lawn was wet this morning, andit didn’t rain last night.”“Either the lawn wasn’t wet this morning, or it rained last night, or the sprinklers came on last night.”

Page 13: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 13

Note that pq meansthat p is true, or q istrue, but not both!

This operation iscalled exclusive or,because it excludes thepossibility that both p and q are true.

Exclusive-Or Truth Table

p q pqF F FF T TT F TT T F Note

differencefrom OR.

Page 14: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 14

The Implication Operator

The implication p q states that p implies q. I.e., If p is true, then q is true; but if p is not true, then q could be either true or false. E.g., let p = “You study hard.”

q = “You will get a good grade.”

p q = “If you study hard, then you will get a

good grade.” (else, it could go either

way)

hypothesis 前件;假設 conclusion 後件;結論

Page 15: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 15

Implication Truth Table

p q is false only whenp is true but q is not true.

p q does not saythat p causes q!

p q does not requirethat p or q are ever true!

E.g. “(1=0) pigs can fly” is TRUE!

p q p q F F T F T T T F F T T T

The onlyFalsecase!

Page 16: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 16

Examples of Implications

“If this lecture ends, then the sun will rise tomorrow.” True or False?

“If Tuesday is a day of the week, then I am a penguin.” True or False?

“If 1 + 1 = 6, then I am a president.” True or False?

“If the moon is made of green cheese, then I am richer than Bill Gates.” True or False?

Page 17: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 17

English Phrases Meaning pq

“p implies q” “if p, then q” “if p, q” “when p, q” “whenever p, q” “q if p” “q when p” “q whenever p”

“p only if q” “p is sufficient for q” “q is necessary for p” “q follows from p” “q is implied by p”We will see some equivalent

logic expressions later.

Page 18: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 18

Converse, Inverse, Contrapositive

Some terminology, for an implication p q: Its converse is: q p. Its inverse is: ¬p ¬q. Its contrapositive: ¬q ¬ p. One of these three has the same meaning

(same truth table) as p q. Can you figure out which?

逆命題

反命題

質位互換命題

Page 19: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 19

How do we know for sure?

Proving the equivalence of p q and its contrapositive using truth tables:

p q q p p q q pF F T T T TF T F T T TT F T F F FT T F F T T

Page 20: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 20

The biconditional operator

The biconditional p q states that p is true if and only if (IFF) q is true.

p = “You can take the flight.”

q = “You buy a ticket.”

p q =

“You can take the flight if and only if you buy a ticket.”

Page 21: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 21

Biconditional Truth Table

p q means that p and qhave the same truth value.

Note this truth table is theexact opposite of ’s! p q means ¬(p q)

p q does not implyp and q are true, or cause each other.

p q p qF F TF T FT F FT T T

Page 22: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 22

Boolean Operations Summary

We have seen 1 unary operator (out of the 4 possible) and 5 binary operators (out of the 16 possible). Their truth tables are below.

p q p p q p q pq p q pqF F T F F F T TF T T F T T T FT F F F T T F FT T F T T F T T

Page 23: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 23

Some Alternative Notations

Name: notandorxorimplies iffPropositional logic: Boolean algebra: ppq+C/C++/Java (wordwise):!&&||!= ==C/C++/Java (bitwise): ~&|^Logic gates:

Page 24: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 24

Bits and Bit Operations

A bit is a binary (base 2) digit: 0 or 1. Bits may be used to represent truth values. By convention:

0 represents “false”; 1 represents “true”. Boolean algebra is like ordinary algebra

except that variables stand for bits, + means “or”, and multiplication means “and”. See chapter 10 for more details.

Page 25: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 25

Bit Strings

A Bit string of length n is an ordered series or sequence of n0 bits. More on sequences in §3.2.

By convention, bit strings are written left to right: e.g. the first bit of “1001101010” is 1.

When a bit string represents a base-2 number, by convention the first bit is the most significant bit. Ex. 11012=8+4+1=13.

Page 26: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 26

Counting in Binary

Did you know that you can count to 1,023 just using two hands?

Count in binary!Each finger (up/down) represents 1

bit.

Page 27: 2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of

2009/9 27

Bitwise Operations

Boolean operations can be extended to operate on bit strings as well as single bits.

E.g.:01 1011 0110

11 0001 1101

11 1011 1111 Bit-wise OR

01 0001 0100 Bit-wise AND

10 1010 1011 Bit-wise XOR