Propositional (Boolean) Logic - Oswego

Preview:

Citation preview

Propositional (Boolean) Logic

Prof. Elaine Wenderholm

Computer Science Department

SUNY Oswego

c©2009 Elaine Wenderholm All Rights Reserved – p.1/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

... false

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

... false

“calc I is a hard course” is ...

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

... false

“calc I is a hard course” is ...

... NOT a proposition!

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

... false

“calc I is a hard course” is ...

... NOT a proposition!

“x is a prime number” is ...

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Propositions

A (logical) proposition is a statement that is unequivically

either true or false.

“13 is an odd number” is ...

... true

“√

25 = 5” is ...

... false

“calc I is a hard course” is ...

... NOT a proposition!

“x is a prime number” is ...

... not a proposition.

c©2009 Elaine Wenderholm All Rights Reserved – p.2/18

Logical Operators

Logical operators are used to combine existing propositions

to form new propositions.

c©2009 Elaine Wenderholm All Rights Reserved – p.3/18

Logical Operators

Logical operators are used to combine existing propositions

to form new propositions.

Logical operators are defined with truth tables.

c©2009 Elaine Wenderholm All Rights Reserved – p.3/18

AND, OR, NOT Operators

and or not

p q p ∧ q

T T T

T F F

F T F

F F F

p q p ∨ q

T T T

T F T

F T T

F F F

p ¬p

T F

F T

c©2009 Elaine Wenderholm All Rights Reserved – p.4/18

Venn Diagrams

A Venn Diagram provides a visual depiction of logical operations

in terms of sets .

This is an excellent web reference to learn aboutVenn Diagrams.

http://www.purplemath.com/modules/venndiag.htm

c©2009 Elaine Wenderholm All Rights Reserved – p.5/18

Implication (conditional) and Bicondi-tional Operators

p implies q p iff q

p q p → q

T T T

T F F

F T T

F F T

p q p ↔ q

T T T

T F F

F T F

F F T

c©2009 Elaine Wenderholm All Rights Reserved – p.6/18

Implication (conditional) and Bicondi-tional Operators

p implies q p iff q

p q p → q

T T T

T F F

F T T

F F T

p q p ↔ q

T T T

T F F

F T F

F F T

p → q “p implies q” is false only when p (the antecedent) is

true and q (the consequence) is false. Let me explain...

The operators p ↔ q and p ≡ q are logically equivalent.

c©2009 Elaine Wenderholm All Rights Reserved – p.6/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

Use truth tables to determine...

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

Use truth tables to determine...

You answer these

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

Use truth tables to determine...

You answer these

What is equivalent to ¬(p ∧ q) ? (Hint: the other

DeMorgan’s law)

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

Use truth tables to determine...

You answer these

What is equivalent to ¬(p ∧ q) ? (Hint: the other

DeMorgan’s law)

¬¬p ≡ ?

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Logical Equivalence

Two propositions are logically equivalent (or equivalent, or

equal) if their truth tables are identical.

Common equivalences:

p → q ≡ ¬p ∨ q

(one of) DeMorgan’s laws: ¬(p ∨ q) ≡ ¬p ∧ ¬q

Use truth tables to determine...

You answer these

What is equivalent to ¬(p ∧ q) ? (Hint: the other

DeMorgan’s law)

¬¬p ≡ ?

p ∧ T ≡ ? p ∨ F ≡ ?

c©2009 Elaine Wenderholm All Rights Reserved – p.7/18

Tautologies, Contradictions

A tautology is a proposition that is TRUE under any

assignment of values to propositional variables.

Example: p ∨ ¬p

c©2009 Elaine Wenderholm All Rights Reserved – p.8/18

Tautologies, Contradictions

A tautology is a proposition that is TRUE under any

assignment of values to propositional variables.

Example: p ∨ ¬p

A contradition is a propostion that is FALSE under any

assignment of values to propositional variables.

Example: p ∧ ¬p

c©2009 Elaine Wenderholm All Rights Reserved – p.8/18

Tautologies, Contradictions

A tautology is a proposition that is TRUE under any

assignment of values to propositional variables.

Example: p ∨ ¬p

A contradition is a propostion that is FALSE under any

assignment of values to propositional variables.

Example: p ∧ ¬p

Other examples? The previous slides lists equivalences –

these are tautologies.

c©2009 Elaine Wenderholm All Rights Reserved – p.8/18

Predicate Logic

Propositions may contain a variable from some domain.

Example: x2 < 4 where x ∈ RIn this case the domain is the set of real numbers.

c©2009 Elaine Wenderholm All Rights Reserved – p.9/18

Predicate Logic

Propositions may contain a variable from some domain.

Example: x2 < 4 where x ∈ RIn this case the domain is the set of real numbers.

Predicate Logic is propositional logic, and it also

c©2009 Elaine Wenderholm All Rights Reserved – p.9/18

Predicate Logic

Propositions may contain a variable from some domain.

Example: x2 < 4 where x ∈ RIn this case the domain is the set of real numbers.

Predicate Logic is propositional logic, and it also

Has a domain of discourse (or a Universe)

c©2009 Elaine Wenderholm All Rights Reserved – p.9/18

Predicate Logic

Propositions may contain a variable from some domain.

Example: x2 < 4 where x ∈ RIn this case the domain is the set of real numbers.

Predicate Logic is propositional logic, and it also

Has a domain of discourse (or a Universe)

Has variables : free and bound

c©2009 Elaine Wenderholm All Rights Reserved – p.9/18

Predicate Logic

Propositions may contain a variable from some domain.

Example: x2 < 4 where x ∈ RIn this case the domain is the set of real numbers.

Predicate Logic is propositional logic, and it also

Has a domain of discourse (or a Universe)

Has variables : free and bound

Has quantifiers :

universal quantifier - “for all” - ∀existential quantifier - “there exists” (for some) - ∃

c©2009 Elaine Wenderholm All Rights Reserved – p.9/18

Free Variables

Example: A proposition involving a free variable over some

domain U .

c©2009 Elaine Wenderholm All Rights Reserved – p.10/18

Free Variables

Example: A proposition involving a free variable over some

domain U .

p(x) is some property of x (and evaluates to TRUE or FALSE).

c©2009 Elaine Wenderholm All Rights Reserved – p.10/18

Free Variables

Example: A proposition involving a free variable over some

domain U .

p(x) is some property of x (and evaluates to TRUE or FALSE).

Example : x < 4 – x has the property that its value is less than

4.

c©2009 Elaine Wenderholm All Rights Reserved – p.10/18

Free Variables

Example: A proposition involving a free variable over some

domain U .

p(x) is some property of x (and evaluates to TRUE or FALSE).

Example : x < 4 – x has the property that its value is less than

4.

x is a free variable because we are free to substitute any

value form x ∈ U , and evaluate the truth or falsity of the

proposition.

c©2009 Elaine Wenderholm All Rights Reserved – p.10/18

Free Variables

Example: A proposition involving a free variable over some

domain U .

p(x) is some property of x (and evaluates to TRUE or FALSE).

Example : x < 4 – x has the property that its value is less than

4.

x is a free variable because we are free to substitute any

value form x ∈ U , and evaluate the truth or falsity of the

proposition.

p(x) is called a propositional function, an open sentence, or

a condition defined on the domain U .

c©2009 Elaine Wenderholm All Rights Reserved – p.10/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

{x|p(x)} = {6, 7, 8, . . .}

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

{x|p(x)} = {6, 7, 8, . . .}p(x) is x + 3 < 1 ...

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

{x|p(x)} = {6, 7, 8, . . .}p(x) is x + 3 < 1 ...

{x|p(x)} = ∅

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

{x|p(x)} = {6, 7, 8, . . .}p(x) is x + 3 < 1 ...

{x|p(x)} = ∅x < 5 ∧ x%2 = 0

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

How do we evaluate a propositionalfunction?

Look at some p(x) defined on domain U .

We can take every element a in U , substitute it into p(x), and

evaluate each one for truth or falsity.

We look at all the elements that make p(x) true and call it the

truth set of p(x).

Examples on the domain N - the Natural numbers. Let’s

define the truth set for each propositinal function.

p(x) is x + 2 > 7. What elements of N make this true?

{x|p(x)} = {6, 7, 8, . . .}p(x) is x + 3 < 1 ...

{x|p(x)} = ∅x < 5 ∧ x%2 = 0

{x|p(x)} = {2, 4}

c©2009 Elaine Wenderholm All Rights Reserved – p.11/18

Bound Variables - Quantified Statements

∀x(p(x)) means

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀Example: domain is N ∀x(x >= 0)

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀Example: domain is N ∀x(x >= 0)

This is true for every x ∈ N . In fact it is a tautology.

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀Example: domain is N ∀x(x >= 0)

This is true for every x ∈ N . In fact it is a tautology.

Example: domain is Z - the Integers

∃x(x2 − 4 = 0)

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀Example: domain is N ∀x(x >= 0)

This is true for every x ∈ N . In fact it is a tautology.

Example: domain is Z - the Integers

∃x(x2 − 4 = 0)

The only values of x to make this true are x = {2,−2}.

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Bound Variables - Quantified Statements

∀x(p(x)) means

for all variables x in the domain, the property p is true for x.

x is a bound variable

It is bound to the quantifier ∀Example: domain is N ∀x(x >= 0)

This is true for every x ∈ N . In fact it is a tautology.

Example: domain is Z - the Integers

∃x(x2 − 4 = 0)

The only values of x to make this true are x = {2,−2}.

Only some of the values in Z make the statement true,

but that’sall we need.

c©2009 Elaine Wenderholm All Rights Reserved – p.12/18

Another way to define quantifiers in termsof sets

Given: domain U , and p(x) is a property of x on elements in U .

Universal Quantifier

c©2009 Elaine Wenderholm All Rights Reserved – p.13/18

Another way to define quantifiers in termsof sets

Given: domain U , and p(x) is a property of x on elements in U .

Universal Quantifier

∀xp(x) is true whenever {x|p(x)} = U , otherwise ∀xp(x) is

false.

c©2009 Elaine Wenderholm All Rights Reserved – p.13/18

Another way to define quantifiers in termsof sets

Given: domain U , and p(x) is a property of x on elements in U .

Universal Quantifier

∀xp(x) is true whenever {x|p(x)} = U , otherwise ∀xp(x) is

false.

Existential Quantifier

c©2009 Elaine Wenderholm All Rights Reserved – p.13/18

Another way to define quantifiers in termsof sets

Given: domain U , and p(x) is a property of x on elements in U .

Universal Quantifier

∀xp(x) is true whenever {x|p(x)} = U , otherwise ∀xp(x) is

false.

Existential Quantifier

∃xp(x) is true whenever {x|p(x)} 6= ∅, otherwise ∃xp(x) is

false.

c©2009 Elaine Wenderholm All Rights Reserved – p.13/18

Negating Quantifiers

¬(∀x(p(x)) ≡ ∃x(¬p(x))

c©2009 Elaine Wenderholm All Rights Reserved – p.14/18

Negating Quantifiers

¬(∀x(p(x)) ≡ ∃x(¬p(x))

¬(∃x(p(x)) ≡ ∀x(¬p(x))

c©2009 Elaine Wenderholm All Rights Reserved – p.14/18

Nested Quantifiers - 1

Domain = Z (the Integers).

How do we evalute ∃x∀y(x + y = 0)? (btw it’s true)

From the inside to the outside:

c©2009 Elaine Wenderholm All Rights Reserved – p.15/18

Nested Quantifiers - 1

Domain = Z (the Integers).

How do we evalute ∃x∀y(x + y = 0)? (btw it’s true)

From the inside to the outside:

∃x∀y(x + y = 0)︸ ︷︷ ︸

pick any y

c©2009 Elaine Wenderholm All Rights Reserved – p.15/18

Nested Quantifiers - 1

Domain = Z (the Integers).

How do we evalute ∃x∀y(x + y = 0)? (btw it’s true)

From the inside to the outside:

∃x∀y(x + y = 0)︸ ︷︷ ︸

pick any y

∃x∀y(x + y = 0)︸ ︷︷ ︸

pick any y︸ ︷︷ ︸

there is some x that makes this true

c©2009 Elaine Wenderholm All Rights Reserved – p.15/18

Nested Quantifiers - 2

This is not the same as ∀x∃y(x + y = 0) (btw it’s false)

c©2009 Elaine Wenderholm All Rights Reserved – p.16/18

Nested Quantifiers - 2

This is not the same as ∀x∃y(x + y = 0) (btw it’s false)

∀x∃y(x + y = 0)︸ ︷︷ ︸

pick some y

c©2009 Elaine Wenderholm All Rights Reserved – p.16/18

Nested Quantifiers - 2

This is not the same as ∀x∃y(x + y = 0) (btw it’s false)

∀x∃y(x + y = 0)︸ ︷︷ ︸

pick some y

∀x∃y(x + y = 0)︸ ︷︷ ︸

pick some y︸ ︷︷ ︸

any x makes this true

c©2009 Elaine Wenderholm All Rights Reserved – p.16/18

DeMorgan’s laws in logic and program-ming languages

Logic Software Hardware

¬(p ∨ q) = ¬p ∧ ¬q !(x||y) = !x && !y p · q = p + q

¬(p ∧ q) = ¬p ∨ ¬q !(x&&y) = !x || !y p + q = p · q

c©2009 Elaine Wenderholm All Rights Reserved – p.17/18

DeMorgan’s laws in logic and program-ming languages

Logic Software Hardware

¬(p ∨ q) = ¬p ∧ ¬q !(x||y) = !x && !y p · q = p + q

¬(p ∧ q) = ¬p ∨ ¬q !(x&&y) = !x || !y p + q = p · q

In (digital) hardware, the gates are AND gates and OR gates.

(Actually, AND and OR can be made from one gate - NAND

gate.)

c©2009 Elaine Wenderholm All Rights Reserved – p.17/18

DeMorgan’s laws in logic and program-ming languages

Logic Software Hardware

¬(p ∨ q) = ¬p ∧ ¬q !(x||y) = !x && !y p · q = p + q

¬(p ∧ q) = ¬p ∨ ¬q !(x&&y) = !x || !y p + q = p · q

In (digital) hardware, the gates are AND gates and OR gates.

(Actually, AND and OR can be made from one gate - NAND

gate.)

We can draw the circuit diagram (a combinatorial circuit) for

any propositional statement in hardware. table.

c©2009 Elaine Wenderholm All Rights Reserved – p.17/18

Algorithm

The proposition is viewed as a function: it has input values (the

logical variables) and an output value (what the proposition

evaluates to)

Write the truth table for the function (How many rows in the

truth table?)

Draw the input variables as vertical lines

For each row in the truth table that evaluates to T do:

Connect the input variables to an AND gate - if the

variable is T , connect it directly; if it is F , put an inverter

between it and the gate

Connect the output of all the AND gates into an OR gate.

The output from the OR gate is the output of the function

c©2009 Elaine Wenderholm All Rights Reserved – p.18/18

Recommended