Topic 2: Logic – CSc 245 v1.1 (McCann) – p. 1 Logic.
-
Upload
phoebe-wilkinson -
Category
Documents
-
view
217 -
download
1
Transcript of Topic 2: Logic – CSc 245 v1.1 (McCann) – p. 1 Logic.
Topic 2:
Logic – CSc 245 v1.1 (McCann) – p. 1
Logic
What Is Logic?
Logic – CSc 245 v1.1 (McCann) – p. 2
Definition: Philosophical Logic
Definition: Mathematical Logic
What Is Logic?
Logic – CSc 245 v1.1 (McCann) – p. 2
Definition: Mathematical Logic
Definition: Philosophical Logic
The study of thought and reasoning, including
argu- ments and proof techniques. (This is the
classical no- tion of logic.)
What Is Logic?
Logic – CSc 245 v1.1 (McCann) – p. 2
Definition: Philosophical Logic
The study of thought and reasoning, including
argu- ments and proof techniques. (This is the
classical no- tion of logic.)
Definition: Mathematical Logic
The use of formal languages and grammars to represent
the syntax and semantics of computation.
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
◦ Selection:
if (score <= max) { ... }
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
◦ Selection:
if (score <= max) { ... }
◦ Iteration:
while (i<limit && list[i]!=sentinel) ...
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
◦ Selection:
if (score <= max) { ... }
◦ Iteration:
while (i<limit && list[i]!=sentinel) ...
• All manner of structures in computing have properties that need to
be proven (and proofs that need to be understood).
◦ Examples: Trees, Graphs, Recursive Algorithms, . . .
Why Are We Studying Logic?
Logic – CSc 245 v1.1 (McCann) – p. 5
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
◦ Selection:
if (score <= max) { ... }
◦ Iteration:
while (i<limit && list[i]!=sentinel) ...
• All manner of structures in computing have properties that need to
be proven (and proofs that need to be understood).
◦ Examples: Trees, Graphs, Recursive Algorithms, . . .
• Programs can be proven correct.
Why Are We Studying Logic?
A few of the many reasons:
• Logic is the foundation for computer operation.
• Logical conditions are common in programs:
◦ Selection:
if (score <= max) { ... }
◦ Iteration:
while (i<limit && list[i]!=sentinel) ...
• All manner of structures in computing have properties that need to
be proven (and proofs that need to be understood).
◦ Examples: Trees, Graphs, Recursive Algorithms, . . .
• Programs can be proven correct.
• Computational linguistics must represent and reason about human
language, and language represents thought (and thus also logic).
So we can relate to Mr. Spock
Simple Propositions (1 / 2)
Logic – CSc 245 v1.1 (McCann) – p. 6
Definition: Simple Proposition
Definition: Proposition
A proposition (a.k.a. statement) is a claim that is
either true or false with respect to an associated
context.
Simple Propositions (1 / 2)
Logic – CSc 245 v1.1 (McCann) – p. 6
Definition: Proposition
A proposition (a.k.a. statement) is a claim that is
either true or false with respect to an associated
context.
Definition: Simple Proposition
A proposition containing no logical operators.
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Some non-propositions:
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Isotope 52Fe is radioactive
Logic – CSc 245 v1.1 (McCann) – p. 7
True
Some non-propositions:
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
True
False (Ottawa)
Some non-propositions:
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
5 ∗(1 + 4) = 5 ∗4 + 5
∗1
True
False (Ottawa)
True
(Distributivity)
Some non-propositions:
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
5 ∗(1 + 4) = 5 ∗4 + 5
∗199.44 is irrational.
True
False (Ottawa)
True
(Distributivity)
False (rational)Some non-propositions:
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
5 ∗(1 + 4) = 5 ∗4 + 5
∗199.44 is irrational.
True
False (Ottawa)
True
(Distributivity)
False (rational)Some non-propositions:
log2x = 4 (what is x?)
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Logic – CSc 245 v1.1 (McCann) – p. 7
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
5 ∗(1 + 4) = 5 ∗4 + 5
∗199.44 is irrational.
True
False (Ottawa)
True
(Distributivity)
False (rational)Some non-propositions:
log2x = 4
Is your name Ferb?
(what is x?)
(questions are not claims)
Simple Propositions (2 / 2)
Example(s):
Some propositions:
Isotope 52Fe is radioactive
Toronto is the capital of
Canada.
5 ∗(1 + 4) = 5 ∗4 + 5
∗199.44 is irrational.
True
False (Ottawa)
True
(Distributivity)
False (rational)Some non-propositions:
log2x = 4
Is your name Ferb?
Listen to me!
(what is x?)
(questions are not claims)
(a command, not a claim)
Logic – CSc 245 v1.1 (McCann) – p. 7
Proposition Labels
To save writing, it is traditional to label propositions with
lower-case letters called proposition labels or statement
letters.
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 8
Proposition Labels
To save writing, it is traditional to label propositions with
lower-case letters called proposition labels or statement
letters.
Example(s):
t: Toronto is the capital of Canada.
Logic – CSc 245 v1.1 (McCann) – p. 8
Proposition Labels
To save writing, it is traditional to label propositions with
lower-case letters called proposition labels or statement
letters. (also called propositional or statement variable)
Example(s):
t: Toronto is the capital of Canada.
Either:
• Select meaningful letters (like ‘t’, above), or
• Use letters in sequence starting with ‘p’
Note: Labeled propositions are still True or False.
Logic – CSc 245 v1.1 (McCann) – p. 8
In Other Words
A propositional or statement variable is just a variable that takes on the values of True or False.
A computer scientist might call them a Boolean variable or even a bit.
Compound Propositions
And with what do we combine them?
Logic – CSc 245 v1.1 (McCann) – p. 9
Definition: Compound Proposition
A statement that is a logical combination of multiple sim-
ple propositions.
Conjunctions
Conjunctions are:
• compound propositions formed in English with the word “and”,
• formed in logic with the caret symbol (“ ∧ ”), and
• true only when both participating propositions are true.
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 11
Conjunctions
Conjunctions are:
• compound propositions formed in English with the word “and”,
• formed in logic with the caret symbol (“ ∧ ”), and
• true only when both participating propositions are true.
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 11
I bought gas.p:
q:I got a haircut.
Conjunctions
Conjunctions are:
• compound propositions formed in English with the word “and”,
• formed in logic with the caret symbol (“ ∧ ”), and
• true only when both participating propositions are true.
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 11
I bought gas.
I got a haircut.
p:
q:
p ∧ q:
I bought gas and I got a haircut.
More Examples
My name is Eric and I am 6’10’ tall.
Is this a true or false proposition?What are the simple propositions that make it up?Are they true or false?
Disjunctions (1 / 3)
Logic – CSc 245 v1.1 (McCann) – p. 12
When two propositions p, q are joined by a disjunction, the compound proposition is true if at least one of them is true:
Disjunctions (1 / 3)
Logic – CSc 245 v1.1 (McCann) – p. 12
When two propositions p, q are joined by a disjunction, the compound proposition is true if at least one of them is true:
Example
n: My name is Erict: I’m 6’10” tall
n t: My name is Eric or I’m 6’10” tall.
Proposition is true.
Problems with English
While in mathematics, formal logic, and computer science “or” means disjunction (the prop is true if one or both of the joined props is true), in spoken English the meaning is not so clear.
Problems with English
While in mathematics, formal logic, and computer science “or” means disjunction (the prop is true if one or both of the joined props is true), in spoken English the meaning is not so clear.
For Example: If you drink the potion in the cup, you will live or you will die.
The speaker doesn’t mean you can both live and die. One or the other will happen. In other words, EXACTLY one has to be true. We call this an exclusive or.
Exclusive or
p
True if p is true or q is true but not both are true.
⊕
∨
is always called exclusive or
is sometimes called inclusive or to emphasize the difference
Negation
Negating a proposition simply flips its value.
Symbols representing negation include:
¬x x
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 15
Negation
Negating a proposition simply flips its value.
Symbols representing negation include:
x ′
¬x x∼ x
Example(s):
We will not use these forms.
Logic – CSc 245 v1.1 (McCann) – p. 15
Negation
Negating a proposition simply flips its value.
Symbols representing negation include:
¬x x
Example(s):
Logic – CSc 245 v1.1 (McCann) – p. 15
h: Homework 1 is easy
Negation
Negating a proposition simply flips its value.
Symbols representing negation include:
¬x x
Example(s):
h: Homework 1 is easy
h: Homework 1 is not easy
Logic – CSc 245 v1.1 (McCann) – p. 15
Conditional Propositions (1 / 3)
Logic – CSc 245 v1.1 (McCann) – p. 29
Definition: Conditional Proposition
A proposition expressible in the form “if p, then q” (p →
q, read “p implies q”), where p and q are propo- sitions, is
a conditional proposition.
Example:
Conditional Propositions (1 / 3)
Logic – CSc 245 v1.1 (McCann) – p. 29
Definition: Conditional Proposition
A proposition expressible in the form “if p, then q” (p →
q, read “p implies q”), where p and q are propo- sitions, is
a conditional proposition.
Example:
If Sauron gets the ring, then all Middle-earth will be destroyed.
Conditional Propositions (2 / 3)
In “if p, then q”, p and qare known by various names:
Common forms of “if p, then q” (Rosen 7/e, p. 6):
—p q
Logic – CSc 245 v1.1 (McCann) – p. 30
Conditional Propositions (2 / 3)
In “if p, then q”, p and qare known by various names:
Common forms of “if p, then q” (Rosen 7/e, p. 6):
—p q
antecedent — consequent
Logic – CSc 245 v1.1 (McCann) – p. 30
Conditional Propositions (2 / 3)
In “if p, then q”, p and qare known by various names:
Common forms of “if p, then q” (Rosen 7/e, p. 6):
—p q
antecedent
hypothesis
— consequent— conclusion
Logic – CSc 245 v1.1 (McCann) – p. 30
Conditional Propositions (2 / 3)
In “if p, then q”, p and qare known by various names:
Common forms of “if p, then q” (Rosen 7/e, p. 6):
—p q
antecedent
hypothesis
sufficient
— consequent— conclusion— necessary
Logic – CSc 245 v1.1 (McCann) – p. 30
Conditional Propositions (2 / 3)
In “if p, then q”, p and qare known by various names:
Common forms of “if p, then q” (Rosen 7/e, p. 6):
—p q
antecedent
hypothesis
sufficient
— consequent— conclusion— necessary
Logic – CSc 245 v1.1 (McCann) – p. 30
⊲ if p, then q ⊲ q if p⊲ if p, q ⊲ q when p⊲ p implies q ⊲ q whenever p⊲ p only if q ⊲ q follows from p⊲ p is sufficient for q ⊲ q is necessary for p⊲⊲
a necessary condition for p is q
q unless ¬p
⊲⊲
a sufficient condition for q is pand I’m sure you could find more!
Conditional Propositions (3 / 3)
Example(s):
You will get a citation if you part in the loading zone.
≡ If you park in the loading zone, then you will get a citation.
Logic – CSc 245 v1.1 (McCann) – p. 31
The crops will grow well only if they are adequately fertilized.
≡ If the crops grow well, then they are adequately fertilized.
[Switching p and q gives an incorrect statement; crops need more than
just fertilizer.]
Inverse, Converse, and Contrapositive
Logic – CSc 245 v1.1 (McCann) – p. 34
Definition: Inverse
Definition: Converse
Definition: Contrapositive
r s
T T
T F
F T
F F
(Inverse)
¬r → ¬s
(Converse)
s → r
Thus, Original ≡ Contrapositive Inverse ≡ Converse
(Orig.)(Contrapos.)
¬r ¬s r → s ¬s → ¬r
F F
F T
T F
T T
Logic – CSc 245 v1.1 (McCann) – p. 35
Inverse, Converse, and Contrapositive
(Original) (Contrapos.)
If UA is in session, beer sales increase.If beer sales don't increase, UA isn't in session.
(Converse) (Inverse)
If beer sales increase, UA is in session.If UA isn't in session, beer sales do not increase.
Inverse, Converse, and Contrapositive
Logic – CSc 245 v1.1 (McCann) – p. 35
(Orig.) (Contrapos.) (Inverse) (Converse)
r s ¬r ¬s r → s ¬s →
¬r
¬r → ¬s s → r
T T F F T T T T
T F F T F F T T
F T T F T T F F
F F T T T T T T
Contraposition
Logic – CSc 245 v1.1 (McCann) – p. 35
An implication p→q gives you interesting information in two scenarios:
- If p is TRUE, then q must be TRUE- If q is FALSE, then p must be FALSE
.
Biconditional Propositions and if (1 / 2)
Logic – CSc 245 v1.1 (McCann) – p. 41
What is the meaning of:
A triangle is equilateral if and only if all three angles are equal.
Biconditional Propositions and if (1 / 2)What is the meaning of:
A triangle is equilateral if and only if all three angles are equal.
t: A triangle is equilateral a : All three angles are equal
IF AND ONLY IF
Logic – CSc 245 v1.1 (McCann) – p. 41
Biconditional Propositions and if (1 / 2)What is the meaning of:
A triangle is equilateral if and only if all three angles are equal.
t: A triangle is equilateral a : All three angles are equal
IF AND ONLY IF
Logic – CSc 245 v1.1 (McCann) – p. 41
∧
Biconditional Propositions and if (1 / 2)What is the meaning of:
A triangle is equilateral if and only if all three angles are equal.
t: A triangle is equilateral a : All three angles are equal
IF AND ONLY IF
Logic – CSc 245 v1.1 (McCann) – p. 41
t if a
if a , then t
( a →
t) ∧
Biconditional Propositions and if (1 / 2)What is the meaning of:
A triangle is equilateral if and only if all three angles are equal.
t: A triangle is equilateral a : All three angles are equal
IF AND ONLY IF
Logic – CSc 245 v1.1 (McCann) – p. 41
t if a
if a , then t
t only if a
if t, then a
( a →
t) ∧ ( t →
a )
Biconditional Propositions and if (2 / 2)Definition: Biconditional Proposition
The expression “p if and only if q” (“p iff q”) is called
the biconditional proposition (a.k.a. biimplication)
and is represented by the symbol ↔ (as in: p ↔ q).
Logic – CSc 245 v1.1 (McCann) – p. 42
Biconditional Propositions and if (2 / 2)
r s
T T
T F
F T
F F
Definition: Biconditional Proposition
The expression “p if and only if q” (“p iff q”) is called
the biconditional proposition (a.k.a. biimplication)
and is represented by the symbol ↔ (as in: p ↔ q).
r → s s → r ( r → s) ∧ ( s → r )
r ↔ s
Logic – CSc 245 v1.1 (McCann) – p. 42
Biconditional Propositions and if (2 / 2)Definition: Biconditional Proposition
The expression “p if and only if q” (“p iff q”) is called
the biconditional proposition (a.k.a. biimplication)
and is represented by the symbol ↔ (as in: p ↔ q).
Logic – CSc 245 v1.1 (McCann) – p. 42
r s r → s s → r (r→ s) ∧ (s → r )
r— s
T T T T T T
T F F T F F
F T T F F F
F F T T T T
Precedence of Logical Operators
Logic – CSc 245 v1.1 (McCann) – p. 18
Total agreement is hard to come by:
Precedence of Logical Operators
Total agreement is hard to come by:
Rosen 7/ePrecedence p. 11
Highest
Lowest
¬
∧
∨
→
↔
(Note: We’ll cover → and ↔ soon.)
Logic – CSc 245 v1.1 (McCann) – p. 18
Precedence of Logical Operators
Total agreement is hard to come by:
(Note: We’ll cover → and ↔ soon.)
Logic – CSc 245 v1.1 (McCann) – p. 18
Precedence
Rosen 7/e
p. 11
Gersting 5/e
p. 6
Highest ¬
∧
’
∧,∨
∨ →
Lowest
→
↔
↔
Precedence of Logical Operators
Total agreement is hard to come by:
(Note: We’ll cover → and ↔ soon.)
Logic – CSc 245 v1.1 (McCann) – p. 18
Precedence
Rosen 7/e
p. 11
Gersting 5/e
p. 6
Hein 2/e
p. 351
Highest ¬
∧
’
∧,∨
¬
∧
∨ → ∨
Lowest
→
↔
↔ →
Precedence of Logical Operators
Total agreement is hard to come by:
(Note: We’ll cover → and ↔ soon.)
Logic – CSc 245 v1.1 (McCann) – p. 18
Precedence
Rosen 7/e
p. 11
Gersting 5/e
p. 6
Hein 2/e
p. 351
Epp 1/e
p. 24
Highest ¬
∧
’
∧,∨
¬
∧
∼
∧,∨
Lowest
∨
→
↔
→
↔
∨
→
→ ,↔
Precedence of Logical Operators
Total agreement is hard to come by:
(Note: We’ll cover → and ↔ soon.)
In this class: Use parentheses to avoid confusion.
Logic – CSc 245 v1.1 (McCann) – p. 18
Precedence
Rosen 7/e
p. 11
Gersting 5/e
p. 6
Hein 2/e
p. 351
Epp 1/e
p. 24
Highest ¬
∧
’
∧,∨
¬
∧
∼
∧,∨
Lowest
∨
→
↔
→
↔
∨
→
→ ,↔