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

Ex 1

The document discusses bitwise operations on bit strings and provides examples. It defines bitwise OR, AND, and XOR operations on bit strings as applying the respective operation to corresponding bits. An example calculates the bitwise OR, AND, and XOR of two 9-bit strings. Exercises are then provided to test understanding of concepts.

Uploaded by

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

Ex 1

The document discusses bitwise operations on bit strings and provides examples. It defines bitwise OR, AND, and XOR operations on bit strings as applying the respective operation to corresponding bits. An example calculates the bitwise OR, AND, and XOR of two 9-bit strings. Exercises are then provided to test understanding of concepts.

Uploaded by

deepak3568eg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

12 1 / The Foundations: Logic and Proofs

TABLE 9 Table for the Bit Operators OR,


AND, and XOR.
x y x∨y x∧y x ⊕y

0 0 0 0 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 0

Information is often represented using bit strings, which are lists of zeros and ones. When
this is done, operations on the bit strings can be used to manipulate this information.

DEFINITION 7 A bit string is a sequence of zero or more bits. The length of this string is the number of bits
in the string.

EXAMPLE 12 101010011 is a bit string of length nine.


We can extend bit operations to bit strings. We define the bitwise OR, bitwise AND, and
bitwise XOR of two strings of the same length to be the strings that have as their bits the OR,
AND, and XOR of the corresponding bits in the two strings, respectively. We use the symbols
∨, ∧, and ⊕ to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively.
We illustrate bitwise operations on bit strings with Example 13.
EXAMPLE 13 Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 01 1011 0110 and
11 0001 1101. (Here, and throughout this book, bit strings will be split into blocks of four
bits to make them easier to read.)

Solution: The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by taking
the OR, AND, and XOR of the corresponding bits, respectively. This gives us
01 1011 0110
11 0001 1101
11 1011 1111 bitwise OR
01 0001 0100 bitwise AND
10 1010 1011 bitwise XOR


Exercises

1. Which of these sentences are propositions? What are the d) 4 + x = 5.


truth values of those that are propositions? e) The moon is made of green cheese.
a) Boston is the capital of Massachusetts. f ) 2n ≥ 100.
b) Miami is the capital of Florida. 3. What is the negation of each of these propositions?
c) 2 + 3 = 5. a) Mei has an MP3 player.
d) 5 + 7 = 10. b) There is no pollution in New Jersey.
e) x + 2 = 11. c) 2 + 1 = 3.
f ) Answer this question. d) The summer in Maine is hot and sunny.
2. Which of these are propositions? What are the truth values 4. What is the negation of each of these propositions?
of those that are propositions? a) Jennifer and Teja are friends.
a) Do not pass go. b) There are 13 items in a baker’s dozen.
b) What time is it? c) Abby sent more than 100 text messages every day.
c) There are no black flies in Maine. d) 121 is a perfect square.
1.1 Propositional Logic 13

5. What is the negation of each of these propositions? 10. Let p and q be the propositions “The election is decided”
a) Steve has more than 100 GB free disk space on his and “The votes have been counted,” respectively. Express
laptop. each of these compound propositions as an English sen-
b) Zach blocks e-mails and texts from Jennifer. tence.
c) 7 · 11 · 13 = 999. a) ¬p b) p ∨ q
d) Diane rode her bicycle 100 miles on Sunday. c) ¬p ∧ q d) q → p
6. Suppose that Smartphone A has 256 MB RAM and 32 GB e) ¬q → ¬p f ) ¬p → ¬q
ROM, and the resolution of its camera is 8 MP; Smart- g) p ↔ q h) ¬q ∨ (¬p ∧ q)
phone B has 288 MB RAM and 64 GB ROM, and the 11. Let p and q be the propositions
resolution of its camera is 4 MP; and Smartphone C has p : It is below freezing.
128 MB RAM and 32 GB ROM, and the resolution of q : It is snowing.
its camera is 5 MP. Determine the truth value of each of
Write these propositions using p and q and logical con-
these propositions.
nectives (including negations).
a) Smartphone B has the most RAM of these three smart-
a) It is below freezing and snowing.
phones.
b) It is below freezing but not snowing.
b) Smartphone C has more ROM or a higher resolution
c) It is not below freezing and it is not snowing.
camera than Smartphone B.
d) It is either snowing or below freezing (or both).
c) Smartphone B has more RAM, more ROM, and a
e) If it is below freezing, it is also snowing.
higher resolution camera than Smartphone A.
f ) Either it is below freezing or it is snowing, but it is
d) If Smartphone B has more RAM and more ROM than
not snowing if it is below freezing.
Smartphone C, then it also has a higher resolution
g) That it is below freezing is necessary and sufficient
camera.
e) Smartphone A has more RAM than Smartphone B if for it to be snowing.
and only if Smartphone B has more RAM than Smart- 12. Let p, q, and r be the propositions
phone A. p : You have the flu.
7. Suppose that during the most recent fiscal year, the an- q : You miss the final examination.
nual revenue of Acme Computer was 138 billion dollars r : You pass the course.
and its net profit was 8 billion dollars, the annual revenue Express each of these propositions as an English sen-
of Nadir Software was 87 billion dollars and its net profit tence.
was 5 billion dollars, and the annual revenue of Quixote a) p → q b) ¬q ↔ r
Media was 111 billion dollars and its net profit was c) q → ¬r d) p ∨ q ∨ r
13 billion dollars. Determine the truth value of each of e) (p → ¬r) ∨ (q → ¬r)
these propositions for the most recent fiscal year. f ) (p ∧ q) ∨ (¬q ∧ r)
a) Quixote Media had the largest annual revenue. 13. Let p and q be the propositions
b) Nadir Software had the lowest net profit and Acme p : You drive over 65 miles per hour.
Computer had the largest annual revenue. q : You get a speeding ticket.
c) Acme Computer had the largest net profit or Quixote
Write these propositions using p and q and logical con-
Media had the largest net profit.
d) If Quixote Media had the smallest net profit, then nectives (including negations).
Acme Computer had the largest annual revenue. a) You do not drive over 65 miles per hour.
e) Nadir Software had the smallest net profit if and only b) You drive over 65 miles per hour, but you do not get
if Acme Computer had the largest annual revenue. a speeding ticket.
8. Let p and q be the propositions c) You will get a speeding ticket if you drive over
65 miles per hour.
p : I bought a lottery ticket this week. d) If you do not drive over 65 miles per hour, then you
q : I won the million dollar jackpot. will not get a speeding ticket.
Express each of these propositions as an English sen- e) Driving over 65 miles per hour is sufficient for getting
tence. a speeding ticket.
a) ¬p b) p ∨ q c) p → q f ) You get a speeding ticket, but you do not drive over
d) p ∧ q e) p ↔ q f ) ¬p → ¬q 65 miles per hour.
g) ¬p ∧ ¬q h) ¬p ∨ (p ∧ q) g) Whenever you get a speeding ticket, you are driving
9. Let p and q be the propositions “Swimming at the New over 65 miles per hour.
Jersey shore is allowed” and “Sharks have been spotted 14. Let p, q, and r be the propositions
near the shore,” respectively. Express each of these com- p : You get an A on the final exam.
pound propositions as an English sentence. q : You do every exercise in this book.
a) ¬q b) p ∧ q c) ¬p ∨ q r : You get an A in this class.
d) p → ¬q e) ¬q → p f ) ¬p → ¬q Write these propositions using p, q, and r and logical
g) p ↔ ¬q h) ¬p ∧ (p ∨ ¬q) connectives (including negations).
14 1 / The Foundations: Logic and Proofs

a) You get an A in this class, but you do not do every a) Coffee or tea comes with dinner.
exercise in this book. b) A password must have at least three digits or be at
b) You get an A on the final, you do every exercise in this least eight characters long.
book, and you get an A in this class. c) The prerequisite for the course is a course in number
c) To get an A in this class, it is necessary for you to get theory or a course in cryptography.
an A on the final. d) You can pay using U.S. dollars or euros.
d) You get an A on the final, but you don’t do every ex-
20. For each of these sentences, determine whether an in-
ercise in this book; nevertheless, you get an A in this
clusive or, or an exclusive or, is intended. Explain your
class.
answer.
e) Getting an A on the final and doing every exercise in
this book is sufficient for getting an A in this class. a) Experience with C++ or Java is required.
f ) You will get an A in this class if and only if you either b) Lunch includes soup or salad.
do every exercise in this book or you get an A on the c) To enter the country you need a passport or a voter
final. registration card.
15. Let p, q, and r be the propositions d) Publish or perish.
p : Grizzly bears have been seen in the area. 21. For each of these sentences, state what the sentence means
q : Hiking is safe on the trail. if the logical connective or is an inclusive or (that is, a dis-
r : Berries are ripe along the trail. junction) versus an exclusive or. Which of these meanings
Write these propositions using p, q, and r and logical of or do you think is intended?
connectives (including negations). a) To take discrete mathematics, you must have taken
a) Berries are ripe along the trail, but grizzly bears have calculus or a course in computer science.
not been seen in the area. b) When you buy a new car from Acme Motor Company,
b) Grizzly bears have not been seen in the area and hik- you get $2000 back in cash or a 2% car loan.
ing on the trail is safe, but berries are ripe along the c) Dinner for two includes two items from column A or
trail. three items from column B.
c) If berries are ripe along the trail, hiking is safe if and d) School is closed if more than 2 feet of snow falls or if
only if grizzly bears have not been seen in the area. the wind chill is below −100.
d) It is not safe to hike on the trail, but grizzly bears have 22. Write each of these statements in the form “if p, then q”
not been seen in the area and the berries along the trail in English. [Hint: Refer to the list of common ways to ex-
are ripe. press conditional statements provided in this section.]
e) For hiking on the trail to be safe, it is necessary but not a) It is necessary to wash the boss’s car to get promoted.
sufficient that berries not be ripe along the trail and b) Winds from the south imply a spring thaw.
for grizzly bears not to have been seen in the area.
c) A sufficient condition for the warranty to be good is
f ) Hiking is not safe on the trail whenever grizzly bears
that you bought the computer less than a year ago.
have been seen in the area and berries are ripe along
d) Willy gets caught whenever he cheats.
the trail.
e) You can access the website only if you pay a subscrip-
16. Determine whether these biconditionals are true or
tion fee.
false.
f ) Getting elected follows from knowing the right peo-
a) 2 + 2 = 4 if and only if 1 + 1 = 2. ple.
b) 1 + 1 = 2 if and only if 2 + 3 = 4.
g) Carol gets seasick whenever she is on a boat.
c) 1 + 1 = 3 if and only if monkeys can fly.
d) 0 > 1 if and only if 2 > 1. 23. Write each of these statements in the form “if p, then q”
in English. [Hint: Refer to the list of common ways to
17. Determine whether each of these conditional statements
express conditional statements.]
is true or false.
a) It snows whenever the wind blows from the northeast.
a) If 1 + 1 = 2, then 2 + 2 = 5.
b) If 1 + 1 = 3, then 2 + 2 = 4. b) The apple trees will bloom if it stays warm for a week.
c) If 1 + 1 = 3, then 2 + 2 = 5. c) That the Pistons win the championship implies that
d) If monkeys can fly, then 1 + 1 = 3. they beat the Lakers.
18. Determine whether each of these conditional statements d) It is necessary to walk 8 miles to get to the top of
is true or false. Long’s Peak.
e) To get tenure as a professor, it is sufficient to be world-
a) If 1 + 1 = 3, then unicorns exist.
famous.
b) If 1 + 1 = 3, then dogs can fly.
c) If 1 + 1 = 2, then dogs can fly. f ) If you drive more than 400 miles, you will need to buy
d) If 2 + 2 = 4, then 1 + 2 = 3. gasoline.
g) Your guarantee is good only if you bought your CD
19. For each of these sentences, determine whether an in-
player less than 90 days ago.
clusive or, or an exclusive or, is intended. Explain your
answer. h) Jan will go swimming unless the water is too cold.
1.1 Propositional Logic 15

24. Write each of these statements in the form “if p, then q” c) q ∨ p ∨ ¬s ∨ ¬r ∨ ¬t ∨ u


in English. [Hint: Refer to the list of common ways to ex- d) (p ∧ r ∧ t) ↔ (q ∧ t)
press conditional statements provided in this section.] 30. How many rows appear in a truth table for each of these
a) I will remember to send you the address only if you compound propositions?
send me an e-mail message. a) (q → ¬p) ∨ (¬p → ¬q)
b) To be a citizen of this country, it is sufficient that you
b) (p ∨ ¬t) ∧ (p ∨ ¬s)
were born in the United States.
c) If you keep your textbook, it will be a useful reference c) (p → r) ∨ (¬s → ¬t) ∨ (¬u → v)
in your future courses. d) (p ∧ r ∧ s) ∨ (q ∧ t) ∨ (r ∧ ¬t)
d) The Red Wings will win the Stanley Cup if their goalie 31. Construct a truth table for each of these compound propo-
plays well. sitions.
e) That you get the job implies that you had the best a) p ∧ ¬p b) p ∨ ¬p
credentials. c) (p ∨ ¬q) → q d) (p ∨ q) → (p ∧ q)
f ) The beach erodes whenever there is a storm. e) (p → q) ↔ (¬q → ¬p)
g) It is necessary to have a valid password to log on to
f ) (p → q) → (q → p)
the server.
h) You will reach the summit unless you begin your climb 32. Construct a truth table for each of these compound propo-
too late. sitions.
25. Write each of these propositions in the form “p if and a) p → ¬p b) p ↔ ¬p
only if q” in English. c) p ⊕ (p ∨ q) d) (p ∧ q) → (p ∨ q)
a) If it is hot outside you buy an ice cream cone, and if e) (q → ¬p) ↔ (p ↔ q)
you buy an ice cream cone it is hot outside. f ) (p ↔ q) ⊕ (p ↔ ¬q)
b) For you to win the contest it is necessary and sufficient 33. Construct a truth table for each of these compound propo-
that you have the only winning ticket. sitions.
c) You get promoted only if you have connections, and a) (p ∨ q) → (p ⊕ q) b) (p ⊕ q) → (p ∧ q)
you have connections only if you get promoted.
c) (p ∨ q) ⊕ (p ∧ q) d) (p ↔ q) ⊕ (¬p ↔ q)
d) If you watch television your mind will decay, and con-
versely. e) (p ↔ q) ⊕ (¬p ↔ ¬r)
e) The trains run late on exactly those days when I take f ) (p ⊕ q) → (p ⊕ ¬q)
it. 34. Construct a truth table for each of these compound propo-
26. Write each of these propositions in the form “p if and sitions.
only if q” in English. a) p ⊕ p b) p ⊕ ¬p
a) For you to get an A in this course, it is necessary and c) p ⊕ ¬q d) ¬p ⊕ ¬q
sufficient that you learn how to solve discrete mathe- e) (p ⊕ q) ∨ (p ⊕ ¬q) f ) (p ⊕ q) ∧ (p ⊕ ¬q)
matics problems. 35. Construct a truth table for each of these compound propo-
b) If you read the newspaper every day, you will be in- sitions.
formed, and conversely.
a) p → ¬q b) ¬p ↔ q
c) It rains if it is a weekend day, and it is a weekend day
if it rains. c) (p → q) ∨ (¬p → q) d) (p → q) ∧ (¬p → q)
d) You can see the wizard only if the wizard is not in, e) (p ↔ q) ∨ (¬p ↔ q)
and the wizard is not in only if you can see him. f ) (¬p ↔ ¬q) ↔ (p ↔ q)
27. State the converse, contrapositive, and inverse of each of 36. Construct a truth table for each of these compound propo-
these conditional statements. sitions.
a) If it snows today, I will ski tomorrow. a) (p ∨ q) ∨ r b) (p ∨ q) ∧ r
b) I come to class whenever there is going to be a quiz. c) (p ∧ q) ∨ r d) (p ∧ q) ∧ r
c) A positive integer is a prime only if it has no divisors e) (p ∨ q) ∧ ¬r f ) (p ∧ q) ∨ ¬r
other than 1 and itself. 37. Construct a truth table for each of these compound propo-
28. State the converse, contrapositive, and inverse of each of sitions.
these conditional statements. a) p → (¬q ∨ r)
a) If it snows tonight, then I will stay at home. b) ¬p → (q → r)
b) I go to the beach whenever it is a sunny summer day. c) (p → q) ∨ (¬p → r)
c) When I stay up late, it is necessary that I sleep until
noon. d) (p → q) ∧ (¬p → r)
e) (p ↔ q) ∨ (¬q ↔ r)
29. How many rows appear in a truth table for each of these
compound propositions? f ) (¬p ↔ ¬q) ↔ (q ↔ r)
a) p → ¬p 38. Construct a truth table for ((p → q) → r) → s.
b) (p ∨ ¬r) ∧ (q ∨ ¬s) 39. Construct a truth table for (p ↔ q) ↔ (r ↔ s).
16 1 / The Foundations: Logic and Proofs

40. Explain, without using a truth table, why (p ∨ ¬q) ∧ because Fred is happy most of the time, and the truth value
(q ∨ ¬r) ∧ (r ∨ ¬p) is true when p, q, and r have the 0.4 can be assigned to the statement “John is happy,” because
same truth value and it is false otherwise. John is happy slightly less than half the time. Use these truth
41. Explain, without using a truth table, why (p ∨ q ∨ r) ∧ values to solve Exercises 45–47.
(¬p ∨ ¬q ∨ ¬r) is true when at least one of p, q, and r 45. The truth value of the negation of a proposition in fuzzy
is true and at least one is false, but is false when all three logic is 1 minus the truth value of the proposition. What
variables have the same truth value. are the truth values of the statements “Fred is not happy”
42. What is the value of x after each of these statements is and “John is not happy?”
encountered in a computer program, if x = 1 before the 46. The truth value of the conjunction of two propositions in
statement is reached? fuzzy logic is the minimum of the truth values of the two
a) if x + 2 = 3 then x := x + 1 propositions. What are the truth values of the statements
b) if (x + 1 = 3) OR (2x + 2 = 3) then x := x + 1 “Fred and John are happy” and “Neither Fred nor John is
c) if (2x + 3 = 5) AND (3x + 4 = 7) then x := x + 1 happy?”
d) if (x + 1 = 2) XOR (x + 2 = 3) then x := x + 1 47. The truth value of the disjunction of two propositions in
e) if x < 2 then x := x + 1 fuzzy logic is the maximum of the truth values of the two
43. Find the bitwise OR, bitwise AND, and bitwise XOR of propositions. What are the truth values of the statements
each of these pairs of bit strings. “Fred is happy, or John is happy” and “Fred is not happy,
a) 101 1110, 010 0001 or John is not happy?”
b) 1111 0000, 1010 1010 ∗ 48. Is the assertion “This statement is false” a proposition?
c) 00 0111 0001, 10 0100 1000 ∗ 49. The nth statement in a list of 100 statements is “Exactly
d) 11 1111 1111, 00 0000 0000 n of the statements in this list are false.”
44. Evaluate each of these expressions. a) What conclusions can you draw from these state-
a) 1 1000 ∧ (0 1011 ∨ 1 1011) ments?
b) (0 1111 ∧ 1 0101) ∨ 0 1000 b) Answer part (a) if the nth statement is “At least n of
c) (0 1010 ⊕ 1 1011) ⊕ 0 1000 the statements in this list are false.”
d) (1 1011 ∨ 0 1010) ∧ (1 0001 ∨ 1 1011) c) Answer part (b) assuming that the list contains 99
Fuzzy logic is used in artificial intelligence. In fuzzy logic, a statements.
proposition has a truth value that is a number between 0 and 1, 50. An ancient Sicilian legend says that the barber in a remote
inclusive. A proposition with a truth value of 0 is false and one town who can be reached only by traveling a dangerous
with a truth value of 1 is true. Truth values that are between 0 mountain road shaves those people, and only those peo-
and 1 indicate varying degrees of truth. For instance, the truth ple, who do not shave themselves. Can there be such a
value 0.8 can be assigned to the statement “Fred is happy,” barber?

1.2 Applications of Propositional Logic


Introduction
Logic has many important applications to mathematics, computer science, and numerous other
disciplines. Statements in mathematics and the sciences and in natural language often are im-
precise or ambiguous. To make such statements precise, they can be translated into the language
of logic. For example, logic is used in the specification of software and hardware, because these
specifications need to be precise before development begins. Furthermore, propositional logic
and its rules can be used to design computer circuits, to construct computer programs, to verify
the correctness of programs, and to build expert systems. Logic can be used to analyze and
solve many familiar puzzles. Software systems based on the rules of logic have been developed
for constructing some, but not all, types of proofs automatically. We will discuss some of these
applications of propositional logic in this section and in later chapters.

Translating English Sentences


There are many reasons to translate English sentences into expressions involving propositional
variables and logical connectives. In particular, English (and every other human language) is

You might also like