Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Applications of Propositional Logic: Presenter Yukun Wang Computer Science and Technology

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Applications of Propositional

Logic

P r e s e n t e r : Yu k u n Wa n g

C o m p u t e r s c i e n c e a n d Te c h n o l o g y
Review
logical operators p ∧?q
p q ?q
p→ p q
• (Negation) ┐ 0 0 1 0 0 0
0 1 1 0 1 0
• (Conjunction)
1 0 0 1 0 0
• (Disjunction) 1 1 1 1 1 1

• implication (Conditional) → p q p ?q p q p ∨?q


0 0 1 0 0 0
• bi-implication (Biconditional) 
0 1 0 0 1 1
• exclusive or 1 0 0 1 0 1
1 1 1 1 1 1
Introduction
Introduction
•Translating English Sentences

•System Specifications

•Boolean Searches

•Logic Puzzles

•Logical Circuits
1
Tr a n s l a t i n g
English Sentences
Translating English Sentences
Translating sentences into compound statements removes the ambiguity.

Once we have translated sentences from English into logical expressions,


we can analyze these logical expressions to determine their truth values,
we can manipulate them, and we can use rules of inference ( will be
discussed in Section 1.6)to reason about them.
Translating English Sentences
Exercise 1: How can this English sentence be translated into a logical expression?
“You can access the internet from campus only if you are computer science major or
you are not a freshman.”

Solution:
Open Question Points: 10

How can this English sentence be translated into a logical expression?


“You can access the internet from campus only if you are computer
science major or you are not a freshman.”

Answer
Translating English Sentences
Exercise 1: How can this English sentence be translated into a logical expression?
“You can access the internet from campus only if you are computer science major or
you are not a freshman.”

Solution:
Although it is possible to represent the sentence by a single propositional variable, such
as p, this would not be useful when analyzing its meaning or reasoning with it.
Instead, we will use propositional variables to represent each sentence part and
determine the appropriate logical connectives between them.
In particular, we let a, c, and f represent “You can access the Internet from campus,”
“You are a computer science major,” and “You are a freshman,” respectively. Noting that
“only if” is one way a conditional statement can be expressed, this sentence can be
represented as
a → (c ¬f).
Translating English Sentences
Example 1: How can this English sentence be translated into a logical expression?
“You cannot ride the roller coaster if you are under 4 feet tall unless you are older
than 16 years old.”

Solution:
Let q, r, and s represent “You can ride the roller coaster,” “You are under 4 feet
tall,”and “You are older than 16 years old,” respectively. Then the sentence can be
translated to
(r ¬s) → ¬q
There are other ways to represent the original sentence as a logical expression,
but the one we have used should meet our needs.
2
System Specifications
System Specifications
Translating sentences in natural language (such as English) into logical expressions is
an essential part of specifying both hardware and software systems.

System and software engineers take requirements in natural language and produce
precise and unambiguous specifications that can be used as the basis for system
development.
Translating English Sentences
Example 2: Express the specification “The automated reply cannot be sent when
the file system is full” using logical connectives.

Solution:
One way to translate this is to let p denote “The automated reply can be sent”
and q denote “The file system is full.” Then ¬p represents “It is not the case that the
automated reply can be sent,” which can also be expressed as “The automated reply
cannot be sent.”
Consequently, our specification can be represented by the conditional statement
q → ¬p.
System Specifications
System specifications should be consistent, that is, they should not contain
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.
Translating English Sentences
Example 3: Determine whether these system specifications are consistent:
“The diagnostic message is stored in the buffer or it is retransmitted.”
“The diagnostic message is not stored in the buffer.”
“If the diagnostic message is stored in the buffer, then it is retransmitted.”

Solution:
To determine whether these specifications are consistent, we first express them
using logical expressions. Let p denote “The diagnostic message is stored in the buffer”
and let q denote “The diagnostic message is retransmitted.”
The specifications can then be written as p q, ¬p, and p → q. An assignment of
truth values that makes all three specifications true must have p false to make ¬p true.
Translating English Sentences
Example 3: Determine whether these system specifications are consistent:
“The diagnostic message is stored in the buffer or it is retransmitted.”
“The diagnostic message is not stored in the buffer.”
“If the diagnostic message is stored in the buffer, then it is retransmitted.”

Solution:
Because we want p q to be true but p must be false, q must be true.
Because p → q is true when p is false and q is true, we conclude that these
specifications are consistent, because they are all true when p is false and q is true.
We could come to the same conclusion by use of a truth table to examine the four
possible assignments of truth values to p and q.
3
Boolean Searches
Boolean Searches
Logical connectives are used extensively in searches of large collections of
information, such as indexes of Web pages. Because these searches employ
techniques from propositional logic, Links they are called Boolean searches.

In Boolean searches, the connective AND is used to match records that contain both
of two search terms, the connective OR is used to match one or both of two search
terms, and the connective NOT (sometimes written as AND NOT ) is used to exclude
a particular search term.
Boolean Searches
Example 4: Web Page Searching
Find Web pages about universities in New Mexico, we can look for pages matching
NEW AND MEXICO AND UNIVERSITIES. The results of this search will include
those pages that contain the three words NEW, MEXICO, and UNIVERSITIES.
To find pages that deal with universities in New Mexico or Arizona, we can search
for pages matching (NEW AND MEXICO OR ARIZONA) AND UNIVERSITIES.

Note: Here the AND operator takes precedence over the OR operator. The results of
this search will include all pages that contain the word UNIVERSITIES and either both
the words NEW and MEXICO or the word ARIZONA.
Boolean Searches
Example 4: Web Page Searching
To find Web pages that deal with universities in Mexico (and not New Mexico)

We should search for pages matching (MEXICO AND UNIVERSITIES) NOT


NEW. The results of this search include pages that contain both the words MEXICO
and UNIVERSITIES but do not contain the word NEW.
4
Logic Puzzles
Logic Puzzles

Puzzles that can be solved using logical reasoning are known as logic puzzles.
Solving logic puzzles is an excellent way to practice working with the rules of logic.
Also, computer programs designed to carry out logical reasoning often use well-
known logic puzzles to illustrate their capabilities.

Next, a simple logic puzzle is shown.


Logic Puzzles
Example 5:
As a reward for saving his daughter from pirates, the King has given you the
opportunity to win a treasure hidden inside one of three trunks. The two trunks that do
not hold the treasure are empty. To win, you must select the correct trunk. Trunks 1 and
2 are each inscribed with the message “This trunk is empty,” and Trunk 3 is inscribed
with the message “The treasure is in Trunk 2.” The Queen, who never lies, tells you that
only one of these inscriptions is true, while the other two are wrong. Which trunk
should you select to win?
Boolean Searches
Solution:
Let pi be the proposition that the treasure is in Trunk i, for i = 1, 2, 3. To translate
into propositional logic the Queen’s statement that exactly one of the inscriptions is true,
we observe that the inscriptions on Trunk 1, Trunk 2, and Trunk 3, are ¬p1, ¬p2, and p2,
respectively. So, her statement can be translated to
(¬p1 ¬(¬p2) ¬p2) (¬(¬p1) ¬p2 ¬p2) (¬(¬p1) ¬(¬p2) p2)).
not p1 or (p1 and not p2)or (p1 and p2)
Logic Puzzles
Exercise 2:
In an island there has two kinds of inhabitants,knight, who always tell the truth, and
their opposites,knaves, who always lie, you encounter two people A and B, what are A
and B if A says “B is knight” and B says “The two of us are opposite types”.
Solution:
Logic Puzzles
Exercise 2:
In an island there has two kinds of inhabitants,knight, who always tell the truth,
and their opposites,knaves, who always lie, you encounter two people A and B, what
are A and B if A says “B is knight” and B says “The two of us are opposite types”.
Solution:
• Let p and q be the statements that A is a knight and B is a knight, so that ¬p and
¬q are the statements that A is a knave and B is a knave respectively.
• First consider A is a knight; that p is true. Ais telling the truth so that q is true, A and
B are the same type. However, if B is a knight, then B’s statement that A and B are of
opposite, the statement (p ¬q) (¬p q), would have to be true, which it is not,
• Second conclude that A is not a knight, p is false. A’s statement that B is
a knight is a lie. This means that q is false and B is also a knave. If B is a knave, then
B’s statement is a lie, which is consistent with both A and B being knaves. We can
conclude that both A and B are knaves.
Logic Puzzles
Exercise 2:
In an island there has two kinds of inhabitants,knight, who always tell the truth, and
their opposites,knaves, who always lie, you encounter two people A and B, what are A
and B if A says “B is knight” and B says “The two of us are opposite types”.
Solution:
• conclude that A is not a knight.If A is a knave, then because everything a knave
says is false, A’s statement that B is a knight, that is, that q is true, is a lie. This
means that q is false and B is also a knave.
• Furthermore, if B is a knave, then B’s statement that A and B are opposite types
is a lie, which is consistent with both A and B being knaves. We can conclude
that both A and B are knaves.
Logic Puzzles
Exercise 3:
A father tells his two children, a boy and a girl, to play in their backyard without
getting dirty.However, while playing, both children get mud on their foreheads.
When the children stop playing, the father says “At least one of you has a muddy
forehead,” and then asks the children to answer “Yes” or “No” to the question:
“Do you know whether you have a muddy forehead?” The father asks this question
twice. What will the children answer each time this question is asked, assuming that a
child can see whether his or her sibling has a muddy forehead, but cannot see his or her
own forehead? Assume that both children are honest and that the children answer
each question simultaneously.
5
Logic Circuits
Logic Circuits

A logic circuit (or digital circuit) receives input signals p1, p2, … , each
a bit [either 0 (off) or 1 (on)], and produces output signals s1, s2, …,
each a bit. In this section we will restrict our attention to logic circuits
with a single output signal; in general, digital circuits may have multiple
outputs.
Gates

Use electronic components to physically implement logical operations


Logical operationscan be constructed from three basic circuits, called
gates,shown in Figure.
•The inverter, or NOT gate, takes an input bit p, and produces as output ¬p.
•The OR gate takes two input signals p and q, each a bit, and produces as output the
signal p q.
• The AND gate takes two input signals p and q, each a bit, and produces as output
the signal p q.
Logic Circuits
Using gates to construct complicated digital circuits.
Example 6: Determine the output for the combinatorial circuit in Figure.

Solution:
In Figure we display the output of each logic gate in the circuit. We see that the
AND gate takes input of p and ¬q, the output of the inverter with input q, and produces
p ¬q. Next, we note that the OR gate takes input p ¬q and ¬r, the output of the
inverter with input r, and produces the final output (p ¬q) ¬r.
Logic Circuits
Exercise 4: uild a digital circuit that produces the output (p ¬r) (¬p (q ¬r))
when given input bits p, q, and r.

Solution:
3
Exercises
Homework 二:
Pages 25
40 (a) (b)
4
Applications of
Satisfiability
Propositional variable and combination formula

Propositional constants: p, 2 + 3 = 5
Proposition:
Propositional variable: p, ?
Both constant and variable terms are used p, q, r, …, pi, qi, ri, …,

A=(p ¬r) (¬p (q ¬r))


Definition Propositon formulas (Recursive definition) :
(1) A single propositional variable is a well-formed formula, called an atomic propositional formula
(2) If A is A well-formed formula, then (A) is also
(3) If A and B are well-formed formulas, then so are (AB), (AB), (AB), (AB)
(4) Only the string of symbols formed by the finite application of (1) - (3) is a proper formula
Thinking question

Given n propositional variables, how many propositional formulas can be written?


(According to the formation rules of the formula) ( )
Given n propositional arguments, how many truth tables are there? ( )

双击在此
p 添加你的
q 文本信息
┐p内 容 双 击 在 此┐p∨q
添加你的 pq
文本信息内容双击在此添加你的文本信息内容双击
0 0 1
在此添加你的文本信息内容双击在此添加你的文本 1 1

0 1 1
双击在此添加你的文本信息内容双击在此添加你的 1 1
文本信息内容双击在此添加你的文本信息内容双击
1 0 0 0 0

1 1 0 1 1
Open Question Points: 10

(1)Given n propositional variables, how many propositional formulas


can be written? (According to the formation rules of the formula)
(2)Given n propositional arguments, how many truth tables are there?

Answer
Thinking question

Given n propositional variables, how many propositional formulas can be written?


(According to the formation rules of the formula) ( infinite )
Given n propositional arguments, how many truth tables are there? ( )

双击在此
p 添加你的
q 文本信息
┐p内 容 双 击 在 此┐p∨q
添加你的 pq
文本信息内容双击在此添加你的文本信息内容双击
0 0 1
在此添加你的文本信息内容双击在此添加你的文本 1 1

0 1 1
双击在此添加你的文本信息内容双击在此添加你的 1 1
文本信息内容双击在此添加你的文本信息内容双击
1 0 0 0 0

1 1 0 1 1
Truth function

 Propositional formula A: {0,1}n{0,1} is a n-ary truth-value fuction.

domain:{00…0, 00…1, …, 11…1}, range:{0,1}

such as A=¬p q: A(00)=A(01)=A(11)=0, A(01)=1,

A: {0,1}2{0,1}, is a 2-ary truth-value function.


Truth function

The following table gives the truth table corresponding to all 2-ary truth functions,
and the truth table of every formula with two propositional variables can be found in
the table.

such as:A= pq, A=pq, A=(pq)((pq)q) are all corressponding to F14 .

p q F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15


F16
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Applications of Satisfiability
A compound proposition is satisfiable if there is an assignment of truth values to
its variables that makes it true (that is, when it is a tautology or a contingency).

When we find a particular assignment of truth values that makes a compound


proposition true, we have shown that it is satisfiable; such an assignment is called
a solution of this particular satisfiability problem.
The n-Queens Problem
The n-queens problem asks for a placement of n queens on an n × n chessboard
so that no queen can attack another queen. This means that no two queens can be
placed in the same row, in the same column, or on the same diagonal. We display
a solution to the eight-queens problem in Figure 1.

(The eight-queens problem dates back to 1848 when


it was proposed by Max Bezzel and was completely solved by Franz Nauck in 1850.
The n-Queens Problem
we introduce n2 variables, p(i, j)for i = 1, 2, … , n and j = 1, 2, … , n. For a given
placement of a queens on the chessboard,p(i, j) is true when there is a queen on
the square in the i-th row and j-th column, and is false,otherwise.

And that squares (i, j) and (i′, j′) are on the same diagonal if either i + i′ = j + j′ ori
− i′ = j − j′
. In the chessboard, p(6, 2) and p(2, 1) are true, while p(3, 4) and p(5, 4) are false.
The n-Queens Problem
 row-column constraint: For no two of the n queens to be in the same row, there
must be one queen in each row. We can show that there is one queen in each row
by verifying that every row contains at least one queen and that every row
contains at most one queen.

First case:We first note that asserts that row i contains at least one
queen.

asserts that every row contains at least one queen.


The n-Queens Problem
 row-column constraint: For no two of the n queens to be in the same row, there
must be one queen in each row. We can show that there is one queen in each row
by verifying that every row contains at least one queen and that every row
contains at most one queen.

Second case:For every row to include at most one queen


Row: the case that p(i, j) and p(k,j) are not both true for integers i and k with 1 ≤ i < k ≤ n.

Column: the case that p(i, j) and p(i,k) are not both true for integers j and k with 1 ≤j< k ≤ n.

p(i,k))

Row-column constraint:
The n-Queens Problem
 Diagnoal constraint:

To assert that no diagonal contains two queens, we assert

The innermost conjunction in Q4 and in Q5 for a pair (i, j) runs through the positions on a
diagonal that begin at (i, j) and runs rightward along this diagonal. The upper limits on
these innermost conjunctions identify the last cell in the board on each diagonal.
The n-Queens Problem
Putting all this together, we find that the solutions of the n-queens problem are
given by the assignments of truth values to the variables p(i, j), i = 1, 2, … , n and
j = 1, 2, … , n.
makes

Q = Q1 Q2 Q3 Q4 Q5

be true.

Using this and other approaches, the number of ways n queens can be placed on a
chessboard so that no queen can attack another has been computed for n ≤ 27. When n = 8
there are 92 such placements, while for n = 16 this number grows to 14,772,512.
Sudoku puzzles
Sudoku puzzles are constructed using a 9 × 9 grid made up of nine 3 × 3
subgrids, known as blocks.
• For each puzzle, some of the 81 cells, called givens, are assigned one of the
numbers 1, 2, … , 9, and the other cells are blank.
• The puzzle is solved by assigning a number to each blank cell so that every
row, every column, and every one of the nine 3 × 3 blocks contains each of
the nine possible numbers.
• Note that instead of using a 9 × 9 grid, Sudoku puzzles can be based on n2 ×
n2 grids, for any positive integer n, with the n2 × n2 grid made up of n2 n × n
subgrids

You might also like