Sunteți pe pagina 1din 17

4CC503 Computational Mathematics

Week 9: Boolean types, logic and quantifiers

Dr Ovidiu Bagdasar

Department of Computing & Mathematics


Email: o.bagdasar@derby.ac.uk
Autumn Semester, Week 9

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

1 / 13

Lecture Outline

Boolean datatype: set and operations


Logically equivalent expressions
Sentences and predicates
Quantifiers and their negation

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

2 / 13

Boolean types
Boolean datatype: set B = {T , F } = {0, 1}, and the operations on B.
Boolean Operations:

:BB
: BB B
: BB B
: B B B
: B B B

NOT (some older books may use )


OR
AND
IMPLIES
EQUIVALENT (when pq AND qp)

Truth tables: Binary representation of boolean operations with tables.


p

1
1
0
0

1
0
1
0

Dr Ovidiu Bagdasar (Comp&Maths)

p
0
0
1
1

pq

pq

pq

pq

1
1
1
0

1
0
0
0

1
0
1
1

1
0
0
1

4CC503 Computational Mathematics

Autumn Semester, Week 9

3 / 13

Logical equivalence - two variables


Exercise 1: Two boolean variables. Find the table of H= (pq).

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

4 / 13

Logical equivalence - two variables


Exercise 1: Two boolean variables. Find the table of H= (pq).
Solution: After the standard two columns, add all the necessary steps.
p
1
1
0
0

p
0
0
1
1

q
1
0
1
0

pq
0
0
1
0

H
1
1
0
1

Remark: Logical variables can be connected by , , , ...

Definition (Logical equivalence)


Two expressions are said to be equivalent if they have the same truth table.
Example: Prove that H= (pq) and G=(pq) are logically equivalent.
Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

4 / 13

Logical equivalence - three variables


Exercise 1: Three boolean variables.
Prove that G=(pq)r and H=(pr)(qr) are logically equivalent.

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

5 / 13

Logical equivalence - three variables


Exercise 1: Three boolean variables.
Prove that G=(pq)r and H=(pr)(qr) are logically equivalent.
Solution: The truth table for G and H is
p
1
1
1
1
0
0
0
0

q
1
1
0
0
1
1
0
0

r
1
0
1
0
1
0
1
0

pq
1
1
0
0
0
0
0
0

pr
1
1
1
1
1
0
1
0

qr
1
1
1
0
1
1
1
0

G
1
1
1
0
1
0
1
0

H
1
1
1
0
1
0
1
0

hence the two statements are logically equivalent.


Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

5 / 13

Equivalence between boolean and set operations


Let A, B be two subsets of universe U and p and q be defined as
p (x ) is true if and only if x A
q (x ) is true if and only if x B
Boolean vs set operations:

p (x ) is true if and only if x Ac = U \ A.


p q (x ) is true if and only if x A B.
p q (x ) is true if and only if x A B.
NOT

Dr Ovidiu Bagdasar (Comp&Maths)

OR

4CC503 Computational Mathematics

AND

Autumn Semester, Week 9

6 / 13

Sentences, Propositions and Predicates


Definition (Sentence)
A sentence is a statement that takes a value true or false.
Definitions:
A proposition is a sentence with no variables.
A predicate is a sentence which contains variables.
Examples:
3 > 5 (proposition with value false)
x > 5 (predicate). If x N then for
I x = 0, 1, ..., 5 the predicate is false
I x = 6, 7, ... the predicate is true
Special predicates:
Tautology - always true
Contradiction - always false
Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

7 / 13

Logic Questions
1. Let p = she is kind Let q = she is strict
Write each of the following sentences symbolically.
a) She is kind but strict.
b) She is not both kind and strict.
c) She is neither kind nor strict.
2. Suppose x is a particular real number. Let p, q and r symbolise
0 < x , x < 3 and x = 3 respectively.
Write the following inequalities symbolically.
a) x = 3
b) 0 < x < 3
c) 0 < x 3
3. Show that (p q ) and p q are not logically equivalent.

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

8 / 13

Useful formulas (they also work with sets!)


De Morgans Laws

(p q ) = p q
(p q ) = p q
Distributive Law
p (q r ) = (p q ) (p r )
p (q r ) = (p q ) (p r )
Associative Law
p (q r ) = (p q ) (p r )
p (q r ) = (p q ) (p r )
Observation: Applying to an expression has the following effect:
p becomes p (and of course, p becomes p)
becomes
becomes
Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

9 / 13

Quantifiers
for all
existential quantifier there exists
universal quantifier
Examples:

x
x
x
x
x

N
N
N
N
N

[x 0]
[even(x )]
[even(2x )]
[x > 4]
[x < 4]

Exercise: Rewrite each of the following using quantifiers.


All triangles have three sides.
No dogs have wings.
Some programs work..
Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

10 / 13

Negation of quantifiers - what people could say...

An engineer, a physicist and a mathematician were traveling through


Scotland. Glancing from a train window, they observed a black sheep in
the middle of a field.
Aha, says the engineer, I see that Scottish sheep are black.
The physicist responded, No, no! Some Scottish sheep are black!
No, says the mathematician, All we know is that:

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

11 / 13

Negation of quantifiers - what people could say...

An engineer, a physicist and a mathematician were traveling through


Scotland. Glancing from a train window, they observed a black sheep in
the middle of a field.
Aha, says the engineer, I see that Scottish sheep are black.
The physicist responded, No, no! Some Scottish sheep are black!
No, says the mathematician, All we know is that:
I

there is at least one sheep in Scotland,

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

11 / 13

Negation of quantifiers - what people could say...

An engineer, a physicist and a mathematician were traveling through


Scotland. Glancing from a train window, they observed a black sheep in
the middle of a field.
Aha, says the engineer, I see that Scottish sheep are black.
The physicist responded, No, no! Some Scottish sheep are black!
No, says the mathematician, All we know is that:
I
I

there is at least one sheep in Scotland,


and that at least one side of that one sheep is black!.

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

11 / 13

The negation of quantifiers


The negation of the Universal Quantifier :
By negation becomes : (x [p (x )]) x [p (x )]
The negation of the Existential Quantifier :
By negation becomes : (x [p (x )]) x [p (x )]
Example 1: (x N[x + 3 2]) x N[x + 3 < 2]
Example 2: (x N[x 2 > 4]) x N[x 2 4]
Exercise: What are the negations of the following ?
1. all dogs can swim.
2. all mathematicians can count.
3. some birds can fly.

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

12 / 13

To do
Assessed work:
CM Test 2 released today!
Get the best mark you can!
Weekly Homework: All problems in the tutorial sheet for Lecture 4.
Next week:
Disjunctive normal forms (d.n.f)
Conjunctive normal forms (c.n.f)
Useful reading:
Logical Equivalence
Dnf with Karnaugh maps

Dr Ovidiu Bagdasar (Comp&Maths)

4CC503 Computational Mathematics

Autumn Semester, Week 9

13 / 13

S-ar putea să vă placă și