0% found this document useful (0 votes)
17 views

17 Logic Operators Puzzles

AI

Uploaded by

Moiz Masood
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

17 Logic Operators Puzzles

AI

Uploaded by

Moiz Masood
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

CS-370 Artificial Intelligence

Logic Operators & Puzzles

Dr. Sohail Iqbal

Text Book: Logic in Computer Science


Ref: Discrete Mathematics by Rosen
1
Outline
• Using propositional logic in real life
– Conversion from English to Symbols

– Solving a logic puzzles using PL

• Precedence of Logical Operators


• Usefulness of Logic
– Bitwise operations
– Logic in Theoretical Computer Science (SAT)
2
Using Propositional Logic in Real
Life
For practicing the propositional logic:
1. Convert text into small propositions
2. Assign symbols for basic propositions
3. Make compound symbolic proposition using
logic operators
4. Use logic rules to get results
5. Interpret in real world

3
Puzzle (an example for conversion from
English to Symbolic logic)

Five friends have access to a chat room. Is it


possible to determine who is chatting if the
following information is known:
1. Either Kevin or Heather or both are chatting.
2. Either Randy or Paul but not both are chatting.
3. If Abby is chatting, so is Randy
4. Paul and Kevin are either both chatting, or
neither is.
5. If Heather is chatting than so are Abby and Kevin.
4
Let
• A = Abby is chatting,
• H = heather is chatting,
• K = Kevin is chatting,
• P = Paul is chatting,
• R = Randy is chatting

5
Conversion
1. Either Kevin or Heather or both are chatting.
2. Either Randy or Paul but not both are chatting.
3. If Abby is chatting, so is Randy.
4. Paul and Kevin are either both chatting, or neither is.
5. If Heather is chatting than so are Abby and Kevin.
In symbols:
(1) K V H
(2) R  P
(3) A  R
(4) P  K
(5) H  (A  K)
6
How to proceed:
• Observe that assuming hypothesis of (5) leads
to a strong (informative) conclusion
• We start with (5):

In symbols:
(1) K V H
(2) R  P
(3) A  R
(4) P  K
(5) H  (A  K)
7
• Assume H is true
• (6) H

• From (6) and (5) we conclude


• (7) A
• (8) K

• From (8) and (4) we conclude (1) K V H


• (9) P (2) R  P
(3) A  R
• From (7) and (3) we conclude
(4) P  K
• (10) R
(5) H  (A  K)
• From (10) and (2) we conclude
• (11) ~P
This contradicts (9), (system is inconsistent) therefore our
assumption is false.
Therefore we can conclude ~H: Heather is not chatting 8
(12) ~H

From (12) and (1) by we conclude


(13) K

From (13) and (4) we conclude


(14) P
(1) K V H
(2) R  P
From (14) and (2) we conclude
(15) ~R (3) A  R
(4) P  K
From (15) and (3) we conclude (5) H  (A  K)
(16) ~A

Thus we have determined that Kevin and Paul are chatting, but Heather,
Abbey and Randy are not chatting.
9
Note
• Only a contradiction tell that initial hypothesis
was wrong.
• In case of absence of a contradiction, we can
not conclude any useful information.

Practice: Try the similar logic puzzles, also given at the


end of slides, and be ready for a quiz coming week!

10
Precedence of Logical Operators (1)

• As in arithmetic, an ordering is imposed on the


use of logical operators in compound
propositions
• However, it is preferable to use parentheses to
disambiguate operators and facilitate
readability
 p  q   r  (p)  (q  (r))

11
Precedence of Logical Operators (2)

• To avoid unnecessary parenthesis, the


following precedences hold:
1. Negation ()
2. Conjunction ()
3. Disjunction ()
4. Implication ()
5. Biconditional ()

12
Usefulness of Logic (1)

• Logic is more precise than natural language

– In desserts, you can have cake or ice cream.


• Can I have both?

– If you buy your air ticket in advance, it is cheaper.


• Don’t we have cheap last-minute tickets?

13
Usefulness of Logic (2)

• For this reason (ambiguity), logic is used for


hardware and software specification
– Given a set of logic statements,
– One can decide whether or not they are satisfiable
(i.e., consistent), although this is a costly process…

14
Bitwise Operations
• Computers represent information as bits (binary digits)
• A bit string is a sequence of bits
• The length of the string is the number of bits in the string
• Logical connectives can be applied to bit strings of equal
length
• Example 0110 1010 1101
0101 0010 1111
_____________
Bitwise OR 0111 1010 1111
Bitwise AND ...
Bitwise XOR …

15
Logic in AI
• What is SAT? SAT is the problem of determining
whether or not a sentence in propositional logic
(PL) is satisfiable.
– Given: a PL sentence
– Question: Determine whether or not it is satisfiable
• Characterizing SAT as an NP-complete problem
(complexity class) is at the foundation of
Theoretical Computer Science.

• MiniSat @ http://minisat.se/
16
17
Questions & Ideas?

Thank You!

18
Practice Puzzle 1
A detective has interviewed four witnesses to a crime.
From the stories of the witnesses the detective has con-
cluded that if the butler is telling the truth then so is the
cook; the cook and the gardener cannot both be telling the
truth; the gardener and the handyman are not both lying;
and if the handyman is telling the truth then the cook is
lying. For each of the four witnesses, can the detective de-
termine whether that person is telling the truth or lying?
Explain your reasoning.

19
Practice Puzzle 2
Four friends have been identified as suspects for an unau-
thorized access into a computer system. They have made
statements to the investigating authorities. Alice said
“Carlos did it.” John said “I did not do it.” Carlos said
“Diana did it.” Diana said “Carlos lied when he said that
I did it.”
a) If the authorities also know that exactly one of the
four suspects is telling the truth, who did it? Explain
your reasoning.
b) If the authorities also know that exactly one is lying,
who did it? Explain your reasoning.
20

You might also like