Applications of Propositional Logic: Presenter Yukun Wang Computer Science and Technology
Applications of Propositional Logic: Presenter Yukun Wang Computer Science and Technology
Applications of Propositional Logic: Presenter Yukun Wang Computer Science and Technology
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
•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.
Solution:
Open Question Points: 10
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)
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.
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
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, …,
双击在此
p 添加你的
q 文本信息
┐p内 容 双 击 在 此┐p∨q
添加你的 pq
文本信息内容双击在此添加你的文本信息内容双击
0 0 1
在此添加你的文本信息内容双击在此添加你的文本 1 1
0 1 1
双击在此添加你的文本信息内容双击在此添加你的 1 1
文本信息内容双击在此添加你的文本信息内容双击
1 0 0 0 0
1 1 0 1 1
Open Question Points: 10
Answer
Thinking question
双击在此
p 添加你的
q 文本信息
┐p内 容 双 击 在 此┐p∨q
添加你的 pq
文本信息内容双击在此添加你的文本信息内容双击
0 0 1
在此添加你的文本信息内容双击在此添加你的文本 1 1
0 1 1
双击在此添加你的文本信息内容双击在此添加你的 1 1
文本信息内容双击在此添加你的文本信息内容双击
1 0 0 0 0
1 1 0 1 1
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.
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.
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:
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