1 Logic
1 Logic
Structures
CSCE 121
Chapter 1: Logic
Abdullah Marian
Department of Information and Computer Science
1
Logic
The rules of logic are used to distinguish between
valid and invalid mathematical arguments(proof).
2
Logic
Topics
1. Propositional logic.
2. Propositional Equivalence.
3. Predicates and Quantifiers.
4. Nested Quantifiers.
3
Logic
Propositions Logic
• Definition: A proposition is a declarative statement that
can be either true or false
• Example: examples for proposition are
– “Riyad is a capital of KSA.”
– “Ali is a professor.”
– “3 = 2 + 1”
– “3 = 2 + 2”
• Not propositions:
– Sit down!
– “x +1= 2” (either true or false).
– What time is it? (not declarative sentence)
4
Logic
Propositions Logic
We use propositional variables to refer to propositions.
Usually are lower case letters starting with p (i.e. p, q,r etc.)
A propositional variable can have one of two values: true
(T) or false (F)
Example:
p = “7 is a prime number”
– q = “Today is my exam”
5
Logic
Propositions Logic
Many mathematical statements are constructed by
combining one or more propositions. New propositions,
called compound propositions.
Compound propositions are formed from existing
propositions using logical operators.
A truth table is a listing of all possible combinations of the
individual proposition statement as true or false, along with
the resulting truth value of the compound statements.
6
compound propositions
⚫Negation ¬ (Uniary)
Logical Operators:
7
Logic
Propositions Logic
Truth Table
P p q p q r
T T T T T T
F T F T T F
F T T F T
F F T F F
F T T
F T F
F F T
F F F
8
Logic
Propositions Logic
(1) Logical operators: Not
Definition: For the proposition p, the negation is the opposite
of the truth value of p and denote by ¬ p.
p p
The negation of p read “not p”. T F
F T
Examples: “Today is Sunday”
p = “Today is Sunday”
p = “Today is not Sunday”
q=Rakan’s PC runs Linux
q = Rakan’s PC does not run Linux
9
Logic
Propositions Logic
(2) Logical operators: And (conjunction)
Definition: For propositions p and q ,the conjunction of p and
q is true if both operands are true and is false otherwise.
The conjunction of p and q denoted by p ^ q p q pq
T T T
and read “p and q”.
Example: Today is Sunday and today is my T F F
exam. F T F
p=Today is Sunday, F F F
It is true only when
q = today is my exam it is Sunday and it
. is my exam
p^q
In some times, we used “ But “instead of AND.
Example: The sun is shining but it is raining .
10
Logic
Propositions Logic
(3) Logical operators: Or (disjunction)
Definition: For propositions p and q, the disjunction of p and
q is false when both operands are false and is true otherwise.
The disjunction of p and q denoted by p q pq
p q and read “p or q”. T T T
Examples: Today is the lecture of ICS T F T
251 or ICS 252. F T T
p=Today is the lecture of ICS 251, F F F
q = the lecture of ICS 252
pq
11
Logic
Propositions Logic
(4) Logical operators: Exclusive Or
Definition: For propositions p and q, the exclusive or of p
and q is true if exactly one of p and q is true and is false
otherwise. p q pq
The exclusive or of p and q denoted by p T T F
T F T
q or p XOR q and read “p exclusive or q”.
F T T
Prov F F F
pq (p q) ¬(p q)
e
One of p and q
To exclude both
is true (may be
(p and q) are true
both)
12
Logic
Propositions Logic
(4) Logical operators: Exclusive Or
Examples: Today is Sunday or today is my exam, but not
both.
Today is Sunday, today is my exam, not both
p =Today is Sunday, q = today is my exam,
p q = Today is Sunday or today is my exam
¬(p q) = but not both
pq (p q) ¬(p q)
14
Logic
Propositions Logic
(5) Conditional operator: if then (implication) (→)
Definition: For propositions p and q, the conditional
statement of p → q is false when p is true and q is false,
and true otherwise. p q pq
The implication of p and q denoted by p → q T T T
and read “if p then q”. T F F
• p implies q
F T T
• If p, q
• p only if q F F T
• p is sufficient for q
• q if p
• q whenever p
• q is necessary for p 15
Logic
Propositions Logic
(5) Conditional operator: if then (implication) (→)
Example : “If today is Sunday, then today is my
exam”
p → q
If you get 90% on the final, then you will get an
A.
p → q
p→q =¬p q
The hypothesis The conclusion
(antecedent) (consequence)
16
Logic
Propositions Logic
(5) Conditional operator: if then (implication) (→)
Example : Let p = “Tariq do hard at study” and q =
“Tariq will get high mark”. Convert these statements
using if then.
17
Logic
Propositions Logic
(5) Conditional operator: if then (implication) (→)
Propositions Logic
(5) Conditional operator: if then (implication) (→)
Example : Let “if it is raining, then the home
team wins””. Find the converse , contrapositive , and
inverse of p → q.
Sol: p= it is raining & q= the home team wins
The converse of p → q is q → p
“if the home team wins, then it is
raining”
The contrapositive of p → q is ¬q → ¬p
“if the home team not win, then it is not raining”
or
“if it is raining, then the home team wins”(original
statement) 19
Converse ,contrapositive and inverse ex:
⚫ From p →q we can form new conditional statements .
⚫ q →p is the converse of p →q
⚫ ¬q → ¬ p is the contrapositive of p →q
⚫¬p→¬q is the inverse of p →q
Example: Find the converse, inverse, and
contrapositive of “It is raining a sufficient condition for
me not going to town.”
Solution: p=it is raining , q=I am not going to town.
converse: If I do not go to town, then it is raining.
inverse: If it is not raining, then I will go to town.
contrapositive: If I go to town, then it is not
raining.
20
Logic
Propositions Logic
(6) Conditional operator: Bi-conditional ()
Definition: For propositions p and q, a bi-conditional
statement p ↔ q, is true when p and q have the same truth
value and is false Otherwise. p q p↔q
21
Logic
Propositions Logic
(6) Conditional operator: Bi-conditional ()
Example : Let p = “You take this class” and q = “You
get a grade”
Then pq is
“You take this class if and only if you get a grade” or
“If you take this class, then you get a grade and if you
get a grade then you take (took) this class”
let the p is ” you can take A+” and q is “your marks
grater than or equal to 95”
Then pq is
“ You can take A+ if and only if your marks
grater than
or equal to 95” 22
Logic
Propositions Logic
Boolean operators summary
23
Logic
Propositions Logic
Questions
Q1) Determine whether the following statements is
propositional or not (give reason). If the statement
is propositional then determine the value of this
propositional statement.
1) 5 + 2 = 8. (Yes. F)
Propositions Logic
Questions
Q2) What is the negation of each of these
proposition?
1) Today is Thursday.
2) There is no pollution in New Jersey.
3) 2+1=3.
4) The summer in Main is hot and sunny.
Q3) Let p and q be the propositions
p: I bought a lottery ticket this week.
q: I won the million dollar jackpot on Friday.
Express each of these propositions as English
sentence. 25
Logic
Propositions Logic
Questions
Q4) Given :
p = “It is below freezing”
q = “It is snowing”
Write the following propositions using p and q and
logical connections.
1) It is below freezing and it is snowing pq
2) It is below freezing but not snowing p¬q
3) It is not below freezing and it is not snowing
¬p¬q
4) It is either snowing or below freezing (or pq
both)
5) If it is below freezing, it is also snowing p→q
6) It is either below freezing or it is snowing,(pq)(p→¬q)
but it is not snowing if it is below freezing
7) That it is below freezing is necessary and
p↔q
8) sufficient for it to be snowing
26
Logic
Propositions Logic
Questions
Q5) Let “I go to the beach whenever it is a sunny
summer day”. Find the converse , contrapositive
, and inverse of p → q.
Propositions Logic
Questions
Q7) Determine whether these conditionals are
true or false.
a) If 1+1=2, then 2+2=5 (false)
b) If 1+1=3, then 2+2=4 (true)
c) If 1+1=3, then 2+2=5 (true)
28
Logic
Propositions Logic
Questions
Q8) Translate the following statements to
propositions using p and q and logical connections.
a) I have neither given nor received help on this
exam.
b) You can access the Internet from campus only if
you are a computer science major or you are not
a freshman.
c) p You
Let cannot
= “I have rideonthe
given help this rolleracoaster
(c f)
if you are
exam”under 4 feet tall unless you are older than 16
Let q = “I have received help on
years old.
this exam” (f s) r
¬p¬q r ( f s)
29
Precedence of operators
Just as in algebra, operators have precedence
4+3*2 = 4+(3*2), not (4+3)*2
Precedence order (from highest to lowest):
¬→↔
The first three are the most important
This means that p q ¬r → s ↔ t
yields: (p (q (¬r)) → s) ↔ (t)
Not is always performed before any other
operation
30
Bit Operations
Computer representation of True and False
:We need to encode two values True and False
Computers represents data and programs using 0s and 1s •
Logical truth values – True and False •
:A bit is sufficient to represent two possible values •
or 1(True) )False( 0 –
A variable that takes on values 0 or 1 is called a Boolean •
.variable
.Definition: A bit string is a sequence of zero or more bits •
.The length of this string is the number of bits in the string
31
Bit Operations
T and F replaced with 1 and 0
p q p^q p˅q
1 1 1 1
1 0 0 1
0 1 0 1
0 0 0 0
:Examples
10110011 10110011 10110011
01101010 01101010 ^ 01101010 ˅
11011001 00100010 11111011
32