Chapter_8

67
LOGIC

description

tsetst

Transcript of Chapter_8

Page 1: Chapter_8

LOGIC

Page 2: Chapter_8

LOGIC

• The discipline that deals with the methods of

reasoning.

• Logical reasoning is used in mathematics to prove

theorems, in computer science to verify the

correctness of programs and to prove theorems.

Page 3: Chapter_8

PROPOSITIONS

• A proposition is a declarative sentence that is either

true or false, but not both.

• Examples:

“the earth is round”,

“2+3=5”

Page 4: Chapter_8

Compound PropositionsPropositional variables (statements) can be combined together by logical connectives to obtain compound propositions (compound statements).

For example,

if we have two propositions, e.g.

(1) “the sun is shining”,

(2) “it is cold”,

we can combine them together by the connective “and” to form the compound statement

“the sun is shining and it is cold”.

Page 5: Chapter_8

logical operators

• The truth value of an entire compound proposition

depends only on the truth values of the statements

being combined and on the types of connectives

being used.

• These connectives in logic are called logical

operators.

Page 6: Chapter_8

logical operatorsOperator Symbol Usage

Negation not

Conjunction and

Disjunction or

Exclusive or /v xor

Conditional if,then

Biconditional iff

Page 7: Chapter_8

Example 1Let P be the proposition logic is fun and Q be the proposition today is Friday. Express each of the following compound propositions in symbolic form:

• Logic is not fun and today is Friday

• Today is not Friday, nor is logic fun

• Either logic is fun or it is Friday

SOLUTION

(a) (not P) and Q

(b) (not Q) and (not P)

(c) P or Q

Page 8: Chapter_8

truth table.

To determine the truth value of compound proposition

we need to know the effect of logical operators.

These can be summarized using a truth table.

Page 9: Chapter_8

Truth Table -NOT /NEGATION

(¬)

A truth table that expresses a relationship a propositional variable (p) and a

negation of that variable (¬p):

(p) (¬p)

T F

F T

Page 10: Chapter_8

Truth Table for AND/CONJUCTION (λ), OR/DISJUNCTION

(v), EXCLUSIVE OR (v), IMPLICATION (→), and

EQUIVALENCE (↔)

(p) (q) (p Λ q) (p V q) (p V q) (p →q) (p ↔ q)

T T

T F

F T

F F

Page 11: Chapter_8

Truth Table for AND/CONJUCTION (λ), OR/DISJUNCTION

(v), EXCLUSIVE OR (v), IMPLICATION (→), and

EQUIVALENCE (↔)

(p) (q) (p Λ q) (p V q) (p V q) (p →q) (p ↔ q)

T T T T F T T

T F F T T F F

F T F T T T F

F F F F F T T

Page 12: Chapter_8

logically equivalent

In implication/ conditional propositions

(p →q),

the preposition p is sometimes called the antecedent

(hypothesis) and q is called the consequent (conclusion).

Two compound propositions are logically equivalent (≡) if

they have the same truth value for every possible set of

truth values of the constituent propositions.

Page 13: Chapter_8

Example 1

Show that the proposition

(not (P and (not Q)))

is logically equivalent to the proposition

((not P) or Q)

Page 14: Chapter_8

Solution

P Q not P not Q P and (not Q) R S

T T

T F

F T

F F

We construct a combined truth table for the compound propositions R= (not (P and (not Q))) and S= ((not P) or Q). Intermediary columns are used as required to build up each of the expressions from P and Q.

Page 15: Chapter_8

Solution

P Q not P not Q P and (not Q) R S

T T F F F T T

T F F T T F F

F T T F F T T

F F T T F T T

We construct a combined truth table for the compound propositions R= (not (P and (not Q))) and S= ((not P) or Q). Intermediary columns are used as required to build up each of the expressions from P and Q.

Since the last two columns are identical, R is logically equivalent to S (R≡S).

Page 16: Chapter_8

More about conditionals

Given the conditional proposition (p →q), we define

the following:

• The converse of p →q : q → p

• The inverse of p →q : 𝑝 → 𝑝

• The contrapositive of p →q : 𝑞 → 𝑝

Page 17: Chapter_8

The converse of p →q : q → p

The inverse of p →q : 𝑝 → 𝑝

inverse: p →

Example 3:

• Original: If you finish dinner, you can have dessert.

• Converse: If you are eating dessert, you must have

finished dinner.

• Inverse: If you do not finish dinner, you cannot

have dessert.

Page 18: Chapter_8

The contrapositive of p →q : 𝑞 → 𝑝Examples 4:

1. If you want to get there faster, you need to take a plane.

contrapositive:

If you don’t take a plane, you cannot get there faster.

2. If you eat too much turkey, you will feel sleepy.

contrapositive:

If you do not want to feel sleepy, you better not eat that much turkey.

3. If you want to see sunrise, you have to get up early.

contrapositive:

If you do not get up early, you cannot see sunrise.

Page 19: Chapter_8

Truth Table for Converse, Inverse,

and Contrapositive

(p) (q) (p →q) (q → p) ( 𝒑 → 𝒒 ) ( 𝒒 → 𝒑)

T T

T F

F T

F F

Page 20: Chapter_8

Truth Table for Converse, Inverse,

and Contrapositive

(p) (q) (p →q) (q → p) ( 𝒑 → 𝒒 ) ( 𝒒 → 𝒑)

T T T T T T

T F F T T F

F T T F F T

F F T T T T

Page 21: Chapter_8

Tautology, Contradiction and

Contingency

• Tautology: A compound proposition that is always true, no matter what the truth values of proposition that occur

• Contradiction: A compound proposition that is always false, no matter what the truth values of proposition that occur

• Contingency: A compound proposition that is neither a tautology nor contradictory.

Page 22: Chapter_8

Example 5

• Show that 𝑝 V 𝑝 is a tautology

SOLUTION

Constructing the truth table for p V 𝑝 , we have :

Note that p V 𝑝 is always true (no matter what proposition is substituted for

p) and is therefore a tautology.

(p) ( 𝒑) (p V 𝒑)

T F T

F T T

Page 23: Chapter_8

PREDICATES AND

QUANTIFIES

A predicates describes a property of one or several objects or individuals that we called variables which is either true or false depending on the values assigned to the variables.

Example 4

x is an integer satisfying x=x2

is a predicate since it is true for x=0 or 1

and false for all other values.

Page 24: Chapter_8

quantifiers

Logical operations can now be applied to predicates. In general, the truth of a compound predicate ultimately depends on the values assigned to the variables involved. However, there are further logical operators, known as quantifiers, which when applied to a predicate produce either a true proposition. The following are the two predicate quantifiers,

Universal quantifier: The symbol is ∀

• ∀ x is read as ‘for all x’ or ‘for every x’

Existential quantifier: The symbol is ∃

• ∃ x is read as ‘there exist at least one x’ or ‘for some x’

Page 25: Chapter_8

Example 6

Which of the following statements are true, and which are

false?

1. All triangles have the sum of their angles equal to 180⁰.

2. All cats have tails.

3. There is an integer x satisfying x2 = 2.

4. There is a prime number which is not odd

Page 26: Chapter_8

SOLUTION

1. True

2. False. Many cats have no tails

3. False

4. True. The number 2 is both a prime number and it

is even.

Page 27: Chapter_8

SET

Page 28: Chapter_8

Set Theoretic Operations

Set theoretic operations allow us to build new sets out of old,

just as the logical connectives allowed us to create compound

propositions from simpler propositions.

Given sets A and B, the set theoretic operators are:

• Union ()

• Intersection ()

• Difference (-)

• Complement (“—”)

• Symmetric Difference ()

give us new sets AB, AB, A-B, AB, andA .

Page 29: Chapter_8

Sets

• Set-builder method

• A = { x | x S, P(x) } or A = { x S | P(x) }

A is the set of all elements x of S, such that x satisfies the property P

Example 1:

If X = {2,4,6,8,10}, then in set-builder notation, X can be described

as

X = {n Z | n is even and 2 n 10}

Page 30: Chapter_8

Sets• Standard Symbols which denote sets of numbers

• N : The set of all natural numbers (i.e.,all positive integers)

• Z : The set of all integers

• Z* : The set of all nonzero integers

• E : The set of all even integers

• Q : The set of all rational numbers

• Q* : The set of all nonzero rational numbers

• Q+ : The set of all positive rational numbers

• R : The set of all real numbers

• R* : The set of all nonzero real numbers

• R+ : The set of all positive real numbers

• C : The set of all complex numbers

• C* : The set of all nonzero complex numbers

Page 31: Chapter_8

Sets

• Subsets

• “X is a subset of Y” is written as X Y

• “X is not a subset of Y” is written as X Y

Example 2:

• X = {a,e,i,o,u}, Y = {a, i, u} and z = {b,c,d,f,g}

• Y X, since every element of Y is an element of X

• Y Z, since a Y, but a Z

31

Page 32: Chapter_8

Sets

• Superset

X and Y are sets. If X Y, then “X is contained in Y” or “Y contains X” or Y is a superset of X, written Y X

• Proper Subset

X and Y are sets. X is a proper subset of Y

if X Y and there exists at least one element in Y that is not in X. This is written X Y.

Example 3:

X = {a,e,i,o,u}, Y = {a,e,i,o,u,y}

X Y , since y Y, but y X

Page 33: Chapter_8

Sets • Set Equality

X and Y are sets. They are said to be equal if every element of X is an element of Y and every element of Y is an element of X, i.e. X Y and Y X

Example 4:

• {1,2,3} = {2,3,1}

• X = {red, blue, yellow} and Y = {c | c is a primary color} Therefore, X=Y

• Empty (Null) Set

• A Set is Empty (Null) if it contains no elements.

• The Empty Set is written as

• The Empty Set is a subset of every set

Page 34: Chapter_8

Sets

• Finite and Infinite Sets

• X is a set. If there exists a nonnegative integer n such that X

has n elements, then X is called a finite set with n elements.

• If a set is not finite, then it is an infinite set.

Example 5:

• Y = {1,2,3} is a finite set

• P = {red, blue, yellow} is a finite set

• E , the set of all even integers, is an infinite set

• , the Empty Set, is a finite set with 0 elements

Page 35: Chapter_8

Sets• Cardinality of Sets

• Let S be a finite set with n distinct elements, where n ≥ 0. Then |S| = n , where the cardinality (number of elements) of S is n

Example 6:

• If P = {red, blue, yellow}, then |P| = 3

• Singleton

• A set with only one element is a singleton

• Example:

• H = { 4 }, |H| = 1, H is a singleton

Page 36: Chapter_8

Sets

• Power Set

For any set X ,the power set of X ,written P(X),is the set of all

subsets of X

Example 7:

• If X = {red, blue, yellow}, then P(X) = { , {red}, {blue},

{yellow}, {red,blue}, {red, yellow}, {blue, yellow}, {red, blue,

yellow} }

• Universal Set

An arbitrarily chosen, but fixed set

Page 37: Chapter_8

Venn Diagrams

• Venn diagrams are useful in representing sets and set operations.

• Various sets are represented by circles inside a big rectangle representing the universe of reference.

• Common universal sets

• R =real numbers

• N =natural numbers ={0,1,2,3,…}

• Z =all integers

• Z+ = is the set of positive integers

Page 38: Chapter_8

38

UNION

AB = { x | x A x B }Elements in at least one of the two sets:

A B

U

AB

Example 8:

If A = {1,2,3,4,5} and B = {5,6,7,8,9}, then A∪B = {1,2,3,4,5,6,7,8,9}

Page 39: Chapter_8

Intersection

AB = { x | x A x B }

Elements in exactly one of the two sets:

A B

U

AB

Example 9:

If A = {1,2,3,4,5} and B = {5,6,7,8,9}, then A ∩ B = {5}

Page 40: Chapter_8

Disjoint SetsDEF: If A and B have no common elements, they

are said to be disjoint, i.e. A B = ={ } .

A B

U

Example 10:

If A = {1,2,3,4,} and B = {6,7,8,9}, then A ∩ B=

Page 41: Chapter_8

Disjoint UnionWhen A and B are disjoint, the disjoint union operationis well defined. The circle above the union symbol indicates disjointedness.

A B

U

BA

Page 42: Chapter_8

Disjoint Union

FACT: In a disjoint union of finite sets, cardinality of

the union is the sum of the cardinalities. I.e.

BABA

Example 11 :

A={a,b,c} |A|= 3

B={0.2, 1, 3, 4.5, 3, 9} |B|= ?

Page 43: Chapter_8

Set Difference

A-B = { x | x A x B }

Elements in first set but not second:

A

B

U

A-B

Example 12:

If A = {a,b,c,d} and B = {c,d,e,f}, then A – B = {a,b}

and B – A = {e,f}

Page 44: Chapter_8

Symmetric Difference

A B

UAB

AB = { x | x A x B }

Elements in exactly one of the two sets:

Page 45: Chapter_8

Complement

A = { x | x A }

Elements not in the set (unary operator):

A

U

A

Example 13:

If U = {a,b,c,d,e,f} and A= {c,d,e,f}, then B’ = {a,b}

Page 46: Chapter_8

Set Identities

Table 1, Rosen p. 49

• Identity laws

• Domination laws

• Idempotent laws

• Double complementation

• Commutativity

• Associativity

• Distribuitivity

• DeMorgan

This table is gotten from the previous table of logical identities by rewriting as follows:

• disjunction “” becomes union “”

• conjunction “” becomes intersection “”

• negation “” becomes complementation “–”

• false “F” becomes the empty set

• true “T” becomes the universe of reference U

L5 46

Page 47: Chapter_8

Sets• Ordered Pair

• X and Y are sets. If x X and y Y, then an ordered pair is written (x,y)

• Order of elements is important. (x,y) is not necessarily equal to (y,x)

• Cartesian Product

• The Cartesian product of two sets X and Y ,written X × Y ,is the set

• X × Y ={(x,y)|x ∈ X , y ∈ Y}

• For any set X, X × = = × X

Example 14:

• X = {a,b}, Y = {c,d}

• X × Y = {(a,c), (a,d), (b,c), (b,d)}

• Y × X = {(c,a), (d,a), (c,b), (d,b)}

Page 48: Chapter_8

Sets

• Diagonal of a Set

• For a set X ,the set δx , is the diagonal of X, defined by

δx = {(x,x) | x ∈ X}

Example 15:

• X = {a,b,c}, δx = {(a,a), (b,b), (c,c)}

Page 49: Chapter_8

FUNCTION

Page 50: Chapter_8

Definition of Functions

• Given any sets A, B, a function f from (or “mapping”)

A to B (f:AB) is an assignment of exactly one

element f(x)B

to each element xA.

50

Page 51: Chapter_8

Graphical Representations• Functions can be represented graphically in several ways:

51

B

• •

A

a b

f

f

•••

•x

y

PlotGraph

Like Venn diagrams

A B

Page 52: Chapter_8

Some Function Terminology

• If f:AB, and f(a)=b (where aA & bB), then:

• A is the domain of f.

• B is the codomain of f.

• b is the image of a under f.

• a is a pre-image of b under f.

• In general, b may have more than one pre-image.

• The range RB of f is {b | a f(a)=b }.

52

• •

A

a b

f

f

B

Page 53: Chapter_8

Range vs. Codomain - Example• Suppose that: “f is a function mapping students in this class to the set

of grades {A,B,C,D,E}.”

• At this point, you know f’s codomain is: __________, and its

range is ________.

• Suppose the grades turn out all As and Bs.

• Then the range of f is _________, but its codomain is

__________________.

53

{A,B,C,D,E}

unknown!

{A,B}

still {A,B,C,D,E}!

Page 54: Chapter_8

Function Addition/Multiplication

• We can add and multiply functions

f,g:RR:

• (f g):RR, where (f g)(x) = f(x) g(x)

• (f × g):RR, where (f × g)(x) = f(x)× g(x)

54

Page 55: Chapter_8

Function Composition• For functions g:AB and f:BC, there is a special operator called compose

(“°”).

• It composes (i.e., creates) a new function out of f,g by applying f to

the result of g.

(f °g):AC, where (f ° g)(a) = f(g(a)).

• Note g(a)B, so f(g(a)) is defined and C.

• The range of g must be a subset of f’s domain!!

• Note that ° (like Cartesian , but unlike +,,) is non-commuting.

(In general, f ° g g ° f.)

55

Page 56: Chapter_8

Function Composition

56

Page 57: Chapter_8

Images of Sets under Functions

• Given f:AB, and SA,

• The image of S under f is simply the set of all images

(under f) of the elements of S.

f(S) : {f(s) | sS}

: {b | sS: f(s)=b}.

• Note the range of f can be defined as simply the

image (under f) of f’s domain!

57

Page 58: Chapter_8

One-to-One Functions• A function is one-to-one (1-1), or injective, or an injection, iff every

element of its range has only one pre-image.

• Only one element of the domain is mapped to any given one

element of the range.

• Domain & range have same cardinality. What about codomain?

58

Page 59: Chapter_8

One-to-One Illustration• Graph representations of functions that are (or not) one-to-

one:

59

•••

One-to-one

••••

••

Not one-to-one

••••

••

•Not even a

function!

Page 60: Chapter_8

Sufficient Conditions for 1-1ness• Definitions (for functions f over numbers):

• f is strictly (or monotonically) increasing iff x>y f(x)>f(y) for all x,y in

domain;

• f is strictly (or monotonically) decreasing iff x>y f(x)<f(y) for all x,y in

domain;

• If f is either strictly increasing or strictly decreasing, then f is

one-to-one.

• Example . f(x)=x3

60

Page 61: Chapter_8

Onto (Surjective) Functions

• A function f:AB is onto or surjective or a surjection iff its

range is equal to its codomain (bB, aA: f(a)=b).

• An onto function maps the set A onto (over, covering) the

entirety of the set B, not just over a piece of it.

• Example: for domain & codomain R, x3 is onto, whereas x2 isn’t.

(Why not?)

61

Page 62: Chapter_8

Illustration of Onto• Some functions that are or are not onto their codomains:

62

Onto

(but not 1-1)

•••

Not Onto

(or 1-1)

•••

Both 1-1

and onto

•••

1-1 but

not onto

•••

Page 63: Chapter_8

Bijections

• A function f is a one-to-one correspondence, or a bijection,

or reversible, or invertible, iff it is both one-to-one and

onto.

63

Page 64: Chapter_8

Inverse of a Function

• For bijections f:AB, there exists an inverse of f,

written f -1:BA, which is the unique function such

that:

64

Iff - 1

Page 65: Chapter_8

Inverse of a function (cont’d)

65

Page 66: Chapter_8

The Identity Function

• For any domain A, the identity function I:AA

(variously written, IA, 1, 1A) is the unique function

such that aA: I(a)=a.

• Some identity functions you’ve seen:

• ing with T, ing with F, ing with , ing with U.

• Note that the identity function is both one-to-one

and onto (bijective).

66

Page 67: Chapter_8

Graphs of Functions

• We can represent a function f:AB as a set of ordered pairs

{(a,f(a)) | aA}.

• Note that a, there is only one pair (a, f(a)).

• For functions over numbers, we can represent an ordered pair

(x,y) as a point on a plane. A function is then drawn as a

curve (set of points) with only one y for each x.

67