Sunteți pe pagina 1din 33

CSI30

Lecture 2

Chapter 1. The Foundations: Logic and Proofs


1.1 Propositional Logic (continues):
Translating English Sentences
System Specifications
Boolean Searches
Logic and Bit Operations
Logic Puzzles

Lecture 2

Translating English Sentences

CSI30

There are many reasons to translate English sentences into expressions


involving propositional variables and logical connectives.
One of them: ambiguity of English (as well as any other language's).
Translation into compound propositions removes the ambiguity.
Another: once we did the translation we can analyze these logical
expressions to determine their truth values, manipulate the, use rules of
inference (will be discussed later) to reason about them.

Lecture 2

Translating English Sentences

CSI30

Example 1: translate a given sentence into a logical expression


You can go swimming if you know how to swim and the water is not too
cold

Lecture 2

Translating English Sentences

CSI30

Example 1: translate a given sentence into a logical expression


You can go swimming if you know how to swim and the water is not too
cold
implication

conjunction

Lecture 2

Translating English Sentences

CSI30

Example 1: translate a given sentence into a logical expression


You can go swimming if you know how to swim and the water is not too
cold
implication

therefore, let
p: you can go swimming
q: you know how to swim
r: the water is (too) cold another option:

conjunction

r: the water is not too cold

Lecture 2

Translating English Sentences

CSI30

Example 1: translate a given sentence into a logical expression


You can go swimming if you know how to swim and the water is not too
cold
implication

therefore, let
p: you can go swimming
q: you know how to swim
r: the water is (too) cold another option:

conjunction

r: the water is not too cold

Then we get: (q r) p

Lecture 2

Translating English Sentences

CSI30

Example 2: translate a given sentence into a logical expression;


determine whether an inclusive() or exclusive() or is intended.
a) To take discrete math, you must have taken calculus or a course in
computer science

b) When you buy a new car from company A, you can get $2000 cash
back or a 2% car loan

Lecture 2

Translating English Sentences

CSI30

Example 2: translate a given sentence into a logical expression;


determine whether an inclusive() or exclusive() or is intended.
a) To take discrete math, you must have taken calculus or a course in
computer science
p: you can take discrete math
q: you took calculus
r: you took a course in computer science
(q r) p
b) When you buy a new car from company A, you can get $2000 cash
back or a 2% car loan

Lecture 2

Translating English Sentences

CSI30

Example 2: translate a given sentence into a logical expression;


determine whether an inclusive() or exclusive() or is intended.
a) To take discrete math, you must have taken calculus or a course in
computer science
p: you can take discrete math
q: you took calculus
r: you took a course in computer science
(q r) p
b) When you buy a new car from company A, you can get $2000 cash
back or a 2% car loan
p: you buy a new car from a company A
q: you can get $2000 cash back
r: you can get a 2% car loan
p (q r)
most likely
Note that during translation we may make a set of reasonable
9
assumptions based on the intended meaning of the sentence.

Lecture 2

System Specifications

CSI30

Having hardware or software specification in natural language we would


like to be able to translate them into logical expressions. This will make
the specification precise and unambiguous, and can be used as basis for
system development.
System specification is consistent if and only if it doesn't have any
conflicting requirements that could be used to derive a contradiction.
When specifications are not consistent, there would be no way to develop
a system that satisfies all specifications.
Example 3 (page 20/50): Determine whether the system specification is
consistent (i.e. not contradictory)
Whenever the system software is being upgraded, users cannot access
the file system. If users can access the file system, then they can save
new files. If users cannot save new files, then the system software is not
being upgraded
10

Lecture 2

System Specifications

CSI30

System specification is consistent if and only if it doesn't have any


conflicting requirements that could be used to derive a contradiction.
When specifications are not consistent, there would be no way to develop
a system that satisfies all specifications.
Example 3 (page 20/50): Determine whether the system specification is
consistent (i.e. not contradictory)
Whenever the system software is being upgraded, users cannot access
the file system. If users can access the file system, then they can save
new files. If users cannot save new files, then the system software is not
being upgraded
p: the system software is being upgraded
q: users can access the file system
r: users can save new files

11

Lecture 2

System Specifications

CSI30

System specification is consistent if and only if it doesn't have any


conflicting requirements that could be used to derive a contradiction.
When specifications are not consistent, there would be no way to develop
a system that satisfies all specifications.
Example 3 (page 20/50): Determine whether the system specification is
consistent (i.e. not contradictory)
Whenever the system software is being upgraded, users cannot access
the file system. If users can access the file system, then they can save
new files. If users cannot save new files, then the system software is not
being upgraded
p: the system software is being upgraded
q: users can access the file system
r: users can save new files
p q
qr
r p

12

Lecture 2

System Specifications

CSI30

System specification is consistent if and only if it doesn't have any


conflicting requirements that could be used to derive a contradiction.
When specifications are not consistent, there would be no way to develop
a system that satisfies all specifications.
Example 3 (page 20/50): Determine whether the system specification is
consistent (i.e. not contradictory)
Whenever the system software is being upgraded, users cannot access
the file system. If users can access the file system, then they can save
new files. If users cannot save new files, then the system software is not
being upgraded
p: the system software is being upgraded
q: users can access the file system
r: users can save new files
let's check if there exists an assignment of
p q
truth values (to p, q, and r) that makes all of
qr
these compound propositions true.
r p

13

Lecture 2

System Specifications

CSI30

Example 3 (page 20/50): Determine whether the system specification is


consistent (i.e. not contradictory)
p q
qr
r p

let's check if there exists an assignment of


truth values (to p, q, and r) that makes all of
these compound propositions true.

If p is True, then q should be also True (otherwise the implication p


q will be False). Therefore q is False. From the second implication since
q is False, r may have any truth value, since it anyway leads to q r
being True. So let's see the last implication: r p.: we assumed that p
is True, therefore p is False, and r has to have truth value False, in
which case r is True. So, if p is True, q is False and r is True, each of our
compound propositions are True.
Therefore, the system specification is consistent.
P.S. we could also do it with a truth table do it for practice.

14

Lecture 2

System Specifications

CSI30

Example 4 (page 20/49): Determine whether the system specification is


consistent.
The system is in multiuser state if and only if it is operating normally. If
the system is operating normally the kernel is functioning.
The kernel is not functioning or the system is in interrupt mode. If the
system is not in multiuser state, then it is in interrupt mode. The system is
not in interrupt mode.

15

Lecture 2

System Specifications

CSI30

Example 4 (page 20/49): Determine whether the system specification is


consistent.
The system is in multiuser state if and only if it is operating normally. If
the system is operating normally the kernel is functioning.
The kernel is not functioning or the system is in interrupt mode. If the
system is not in multiuser state, then it is in interrupt mode. The system is
not in interrupt mode.
p: the system is in multiuser state
q: it is operating normally
r: the kernel is functioning
s: the system is in interrupt mode
pq
qr
r s
p s
s

same technique:
let's check if there exists an assignment of
truth values (to p, q, r, and s) that makes all of
these compound propositions true.
16

Lecture 2

System Specifications

CSI30

Example 4 (page 20/49): Determine whether the system specification is


consistent.
pq
qr
r s
p s
s

same technique:
let's check if there exists an assignment of
truth values (to p, q, r, and s) that makes all of
these compound propositions true.

1) s must be True, therefore s is False


2) if s is False, then in order for implication p s to be True, p must
be also False. Therefore, p is True.
3) if p is True, then in order for p q to be True, q must be True.
4) if q is True then in order for q r to be True, r also must be True.
5) if r is True, and s is False, then r s is False False, which gives us
False.
So, there is no assignment of truth values that makes all of the above
17
propositions true. Hence, the system specification is inconsistent.

Lecture 2

Boolean Search

CSI30

Logical connectives are used extensively in searches of large collections


of information online.
AND
NOT (-)
OR
Examples:
1) to find all universities in New York, the search request can be written:
New and York and Universities
2) to find community public schools in NY:
New and York and school - private
3) to find our book :
Discrete Mathematics and Its Application and sixth edition and Rosen

18

Lecture 2

Logic and Bit Operations

CSI30

In computer all the information is represented with bits (binary digit). Bit is
a symbol with two possible values: 0 (zero), and 1(one)
bit can be used to represent truth values:1 for True, 0 for False
Boolean variable is a variable with two possible values (0,1)
Note: Computer operations correspond to the logical operations.
AND
OR
XOR

0
0
1
1

0
1
0
1

xy

x y

xy

19

Lecture 2

Logic and Bit Operations

CSI30

In computer all the information is represented with bits (binary digit). Bit is
a symbol with two possible values: 0 (zero), and 1(one)
bit can be used to represent truth values:1 for True, 0 for False
Boolean variable is a variable with two possible values (0,1)
Note: Computer operations correspond to the logical operations.
AND
OR
XOR

0
0
1
1

0
1
0
1

xy
0
0
0
1

x y

xy

20

Lecture 2

Logic and Bit Operations

CSI30

In computer all the information is represented with bits (binary digit). Bit is
a symbol with two possible values: 0 (zero), and 1(one)
bit can be used to represent truth values:1 for True, 0 for False
Boolean variable is a variable with two possible values (0,1)
Note: Computer operations correspond to the logical operations.
AND
OR
XOR

0
0
1
1

0
1
0
1

xy
0
0
0
1

x y
0
1
1
1

xy

21

Lecture 2

Logic and Bit Operations

CSI30

In computer all the information is represented with bits (binary digit). Bit is
a symbol with two possible values: 0 (zero), and 1(one)
bit can be used to represent truth values:1 for True, 0 for False
Boolean variable is a variable with two possible values (0,1)
Note: Computer operations correspond to the logical operations.
AND
OR
XOR

0
0
1
1

0
1
0
1

xy
0
0
0
1

x y
0
1
1
1

xy
0
1
1
0

22

Lecture 2

Logic and Bit Operations

CSI30

In computer all the information is represented with bits (binary digit). Bit is
a symbol with two possible values: 0 (zero), and 1(one)
bit can be used to represent truth values:1 for True, 0 for False
Boolean variable is a variable with two possible values (0,1)
Note: Computer operations correspond to the logical operations.
AND
OR
XOR

0
0
1
1

0
1
0
1

xy
0
0
0
1

x y
0
1
1
1

xy
0
1
1
0

a bit string is a sequence of 0's and 1's.


length of a bit string is the number of bits in the string
Example: 00110101110 length=11
bit string

23

Logic and Bit Operations

Lecture 2

CSI30

Exercise: find the bitwise OR, AND, and XOR of the bit strings
001110101 and 110101100 (from now on we'll be splitting the bit strings
into blocks of four to make them easier to read).
0 0111 0101
1 1010 1100
----------AND

0 0111 0101
1 1010 1100
----------OR

0 0111 0101
1 1010 1100
-----------

xy

x y

xy

XOR

24

Lecture 2

Logic and Bit Operations

CSI30

Exercise: find the bitwise OR, AND, and XOR of the bit strings
001110101 and 110101100 (from now on we'll be splitting the bit strings
into blocks of four to make them easier to read).
0 0111 0101
1 1010 1100
----------0 0010 0100 AND

0 0111 0101
1 1010 1100
----------OR

0 0111 0101
1 1010 1100
-----------

xy

x y

xy

XOR

25

Lecture 2

Logic and Bit Operations

CSI30

Exercise: find the bitwise OR, AND, and XOR of the bit strings
001110101 and 110101100 (from now on we'll be splitting the bit strings
into blocks of four to make them easier to read).
0 0111 0101
1 1010 1100
----------0 0010 0100 AND

0 0111 0101
1 1010 1100
----------1 1111 1101 OR

0 0111 0101
1 1010 1100
----------XOR

xy

x y

xy

0
26

Lecture 2

Logic and Bit Operations

CSI30

Exercise: find the bitwise OR, AND, and XOR of the bit strings
001110101 and 110101100 (from now on we'll be splitting the bit strings
into blocks of four to make them easier to read).
0 0111 0101
1 1010 1100
----------0 0010 0100 AND

0 0111 0101
1 1010 1100
----------1 1111 1101 OR

0 0111 0101
1 1010 1100
----------1 1101 1001 XOR

xy

x y

xy

0
27

Logic and Bit Operations

Lecture 2

CSI30

Exercise: Evaluate expression (0 1101 1001) (01101 00111)


0 1101
1001
------

0 1101
0 0111
-----OR

-----AND

xy

x y

xy

0
28

Lecture 2

Logic and Bit Operations

CSI30

Exercise: Evaluate expression (0 1101 1001) (01101 00111)


0 1101
1001
-----0 1101 OR

0 1101
0 0111
-----0 0101 AND

------

xy

x y

xy

0
29

Lecture 2

Logic and Bit Operations

CSI30

Exercise: Evaluate expression (0 1101 1001) (01101 00111)=0 100


0 1101
1001
-----0 1101 OR

0 1101
0 0111
-----0 0101 AND

0 1101
0 0101
-----0 1000

xy

x y

xy

0
30

Lecture 2

Logic Puzzles

CSI30

Puzzles that can be solved using logical reasoning are called logic
puzzles.
Raymond Smullyan posed lots of logic puzzles (read page 14).
Puzzle 1:
An island has two kinds of inhabitants:
knights who always tell true, and
knaves their opposites, who always lie
We encounter two people (A and B). Determine, if possible, what A
and B are, if
a) A says: at least one of us is a knave
B says nothing.
b) A says: we are both knaves
B says nothing

31

Lecture 2

Logic Puzzles

CSI30

Puzzle 1:
An island has two kinds of inhabitants:
knights who always tell true, and
knaves their opposites, who always lie
We encounter two people (A and B). Determine, if possible, what A
and B are, if
a) A says: at least one of us is a knave
B says nothing.
p: A is a knight
q: B is a knight
A says: p q. Let's assume that A is a knight, then we have
p (p q)
T (F q) - q must be T for the entire compound proposition to be
True. Therefore, when p is True and q is False, the p (p q) is
True.
A is a knight, and B is a knave.
32

Lecture 2

Logic Puzzles

CSI30

Puzzle 1:
An island has two kinds of inhabitants:
knights who always tell true, and
knaves their opposites, who always lie
We encounter two people (A and B). Determine, if possible, what A
and B are, if
b) A says: we are both knaves
B says nothing
p: A is a knight
q: B is a knight
A says: p q. Let's assume that A is a knave (this time), then we
have p (p q)
T (T q) - q must be F for the entire compound
proposition to be True. Therefore, when p is False and q is True, the
p (p q) is True.
A is a knave, and B is a knight.
33

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