View
221
Download
3
Category
Preview:
Citation preview
1
Weixiong ZhangWashington University in St. Louis
http://www.cse.wustl.edu/~zhang/teaching/cse240/Spring10/index.html
CSE 240Logic and Discrete Math
Lecture notes Introduction and Propositional
Logic
2
Why This Course?
Relation to real life:
Algorithm correctness ~ programming, reverse-engineering, debugging
Propositional logic ~ hardware (including VLSI) design
Sets/relations ~ databases (Oracle, MS Access, etc.)
Predicate logic ~ Artificial Intelligence, compilers
Proofs ~ Artificial Intelligence, VLSI, compilers, theoretical physics/chemistry
This is the “calculus” course for the computer science
4
ImportanceUSS Yorktown, a guided-missile cruiser --- the first to be outfitted with Smart Ship technology09/97: suffered a widespread system failure off the coast of Virginia. After a crew member mistakenly entered a zero into the data field of an application, the computer system proceeded to divide another quantity by that zero. The operation caused a buffer overflow, in which data leak from a temporary storage space in memory, and the error eventually brought down the ship's propulsion system. The result: the Yorktown was dead in the water for more than two hours.
5
More Software Bugs…On June 4, 1996, the maiden flight of the European Ariane 5 launcher crashed about 40 seconds after takeoff. Media reports indicated that the amount lost was half a billion dollars -- uninsured.
The exception was due to a floating-point error: a conversion from a 64-bit integer to a 16-bit signed integer, which should only have been applied to a number less than 2^15, was erroneously applied to a greater number, representing the "horizontal bias" of the flight.
There was no explicit exception handler to catch the exception, so it followed the usual fate of uncaught exceptions and crashed the entire software, hence the on-board computers, hence the mission.
6
Where is CSE 240?How do we find such bugs in software?
TracingDebug statementsTest casesMany software testers working in parallel…
All of that had been employed in the previous casesYet the disasters occurred…
7
CSE240 : Program Correctness
Logic : means to prove correctness of software
Sometimes can be semi-automated
Can also verify a provided correctness proof
9
Argument #2
Nothing is better than GodA sandwich is better than nothing
Therefore, a sandwich is better than God
10
Argument #3
An island
A barber cannot cut his/her own hair
The barber cuts everyone’s hair on the island
Jon is a barber
So, Jon will cut his own hair
11
Validity
An argument is valid if and only if given that its premises hold its conclusion also holds
So…Socrates argument: Valid or Invalid?Sandwich argument: Valid or Invalid?Barber argument: Valid or Invalid?
13
CSE 240
Logic : a formal way to assess a validity of an argument
Can prove theorems in a semi-automatic fashion – construct a proof
Can verify given proofs that an argument is valid
14
Material CoverageChapter 1: propositional calculusChapter 2: 1st order predicate calculusChapter 3: number theory and proof techniquesChapter 4: mathematical inductionChapter 5: set theoryChapter 6: counting / probabilitiesChapter 7: functionsChapter 10: relationsChapter 11: graphs and trees
18
A possible argument (solution)The original statement can be written as:S = X or YX = “A is a Knave”Y = “B is a Knight”Suppose A is a KnaveThen S must be false since A said itThen both X and Y are falseIf X is false then A is not a Knave(Contradiction : A can be a Knave and cannot a Knave !)So A must be a KnightSo S is true (why?) and X is not trueThus, to keep S true Y must be trueSo B is a Knight too
20
Features Of An Argumentarguments involve things or objectsthings have propertiesarguments consist of statementsstatements may be composedan argument starts with assumptions which create a context.each step yields another statement which is true, within its context.arguments may contain sub-argumentsit is absurd for a statement to be both true and false
21
Formalization
Why formalize?
to remove ambiguity
to represent facts on a computer and use it for proving, proof-checking, etc.
to detect unsound reasoning in arguments
23
Logic
Mathematical logic is a tool for dealing with formal reasoningIn a nutshell:
Logic does:Assess if an argument is valid/invalid
Logic does not directly:Assess the truth of atomic statements
24
DifferencesLogic can deduce that:
St Louis is in the USAgiven these facts:
St Louis is in MissouriMissouri is a part of the USA
and the definitions of:‘to be a part of’‘to be in’
Logic knows nothing of whether these facts actually hold in real life!
Lecture 04 © Vadim Bulitko : CMPUT 272, Winter 2004, UofA 26
Announcement
It is Ok for an assignment problem to refer to the material that is:
Not covered in class by the due dateNot covered in class at all
Why?
Because the lectures only highlight the material in the textbookThey are not a substitute for reading the text
27
Propositional Calculus (Ch 1.)
Simplest kind of math logic
Dealing with:
Propositions: X,P,Q,…each can be true or falseExamples: P=“I’m a knave”
Q=“He is a knight”
Connectives: & (˄), v, , , ~ (¬), …connect propositions: X v Y
28
Connectives
Different notation is in useWe will use the common math notation:
~ notV or (non-exclusive!)& and implies (if … then …) if and only if∀ for all∃ exists
See the reverse of the text’s front cover
29
Formulae
A statement/proposition: true or false
Atomic: P, Q, X, Y, …
Unit Formula: P, ~P, (formula), …
Conjunctive: P & Q, P & ~Q, …
Disjunctive: P v Q, P v (P & X),…
Conditional: P Q
Biconditional: P Q
30
Determining Truth of A Formula
Atomic formulae: givenCompound formulae: via meaning of
the connectivesSuppose: P is true
Q is falseHow about: (P v Q)
Truth tables
33
Parenthesizing
Parenthesize & build truth tablesSimilar to arithmetics:
3*5+7 = (3*5)+7 but NOT 3*(5+7)A&B v C = (A&B) v C but NOT A&(B v C)
So start with sub-formulae with highest-precedence connectives and work your way out
Let’s do the knave & knight problem in TT
34
TT for K&KS = X or YX = “A is a Knave”Y = “B is a Knight”
A B S X Y X v Y Absurd------------------------------------------------------------------------------Knave Knave false true false true yesKnave Knight false true true true yesKnight Knave true false false false yesKnight Knight true false true true no
36
Conditionals
“If I go to Save-on-Foods tomorrow I will buy oranges there”
S = (go to SOF) (buy oranges)
When is S true?When I went to SOF and bought orangesWhen I didn’t go there at all!
When is S false?When I went there but didn’t buy oranges
37
Truth Table
N independent atomic formulae (variables) 2N rowsN=20: 220 ~ 1 millionConsider A B:
A B A BF F TF T TT F FT T T
39
Bi-Conditionals“Marion will take 240 if and only if Norma does so”
S = (Marion takes 240) (Norma takes 240)
When is S true?When Marion takes is and Norma takes itWhen Marion doesn’t take it and neither does Norma
When is S false?When one of them takes it but not the other
41
, and Daily LifeSuppose:
“Buy Ferrari” = B“Ferrari is on sale” = S
I will buy a Ferrari if it is on sale:S B
I will buy a Ferrari if and only if it is on sale:
S BI will buy a Ferrari only if it is on sale:
~S ~BB S
42
Sufficient & Necessary Conditions
Suppose the Ferrari salesperson wants to figure out when you are ready to buy one of their cars…
B = “ready to buy”X = some condition of you
If they find X such that: X BThen they have a sufficient conditionExample: X = “got a WashU scholarship”
If they find X such that: B XThen they have a necessary conditionExample: X = “it is winterized”
43
CriteriaIf they find X such that: B X
Then they have a criterion
What would be an example?How about a conjunction of the sufficient and necessary conditions?
X = “got WashU scholarship and it is winterized”
Doesn’t work: you may get a Ferrari Christmas gift certificate from your grandma and you will just go and pick one up (regardless of whether you got the scholarship)
44
SummarySuppose X is a statement
A is a sufficient condition for X iff we can prove that:“A implies X”
A is necessary condition for X iff we can prove that:“X implies A”
A is a criterion for X iff we can prove that:“X holds if and only if A holds”
45
Contradictions & Tautologies
Contradiction:A statement that is always false regardless of the values of its variables
Examples: A & ~A
Tautology:A statement that is always true regardless of the values of its variables
Examples: A v ~A
46
Contingencies
What is I have a formula that is sometimes true and sometimes false?
It is called a contingency
Example:A & B
If A and B are independent variables
47
Interpretation
In propositional logic interpretation (instantiation) is a mapping from symbols in your formulae to {true, false}
Example:Formula: A v BInterpretation: A = true, B = false
48
Formula Classification
Tautology : all interpretations satisfy the formula
Contradiction : all interpretations falsify the formula
Contingency : some interpretations satisfy and some falsify the formula
49
Models / Counter-models
An interpretation is called a model for formula F iff:
It satisfies F (i.e., makes F=true)
An interpretation is called a counter-model for formula F iff:
It falsifies F (i.e., makes F=false)
50
Logic EquivalencePropositions/statements/formulae A and B are logically equivalent when:
A holds if and only if B holdsNotation: A ≡ BExamples:
A v A is equivalent to:A
A v ~A is equivalent to:true
51
Equivalence & Tautology
Suppose A and B are logically equivalentConsider proposition (A B)What can we say about it?It is a tautology!Why?A B A BF F TT T T
52
More Equivalences
Alex is not unemployedAlex is employed
P ≡ ~(~P) : Double-negationIt is not true that she is single and she is cute
She is not single or she is not cute
~(A & B) ≡ ~A v ~B : De Morgan’s lawIt is not true that she is single or she is cute
She is not single and she is not cute
~(A v B) ≡ ~A & ~B : De Morgan’s law
53
Boolean AlgebraPage 14 presents Theorem 1.1.1 with 21 equivalencesHowever, only the first 10 are neededThe rest can be derived from them
Example: let’s prove that P v P ≡ PP v C ≡ P (4)P v (P & ~P) ≡ P (5)(P v P) & (P v ~P) ≡ P (3)(P v P) & T ≡ P (5)P v P ≡ P (4)
55
Proving Equivalences
Suppose P and Q can take on T and Fonly Then all equivalences can be proven by definition using truth tablesP Q ~(P v Q) ~P & ~QF F T F T T TF T F T T F FT F F T F F TT T F T F F F
58
Uses of Equivalences
SimplificationSuppose someone gives you
~P v (AB) v ~(C v D H) v P v XY
and asks you to compute it for all possible input valuesYou can either immediately draw a truth table with 28 = 256 rows
Or you can simplify it first
59
Simplification
~P v (AB) v ~(C v D H) v P v XY~P v P v (AB) v ~(C v D H) v XYT v (AB) v ~(C v D H) v XYT YY
60
Test Drive
Let’s take our equivalence tool box for a spin…What can we tell about
A B
and its contraposition:~B ~A
?They are equivalent !
62
Test Drive
Let’s try another one!What can we tell about
A B
and its inverse:~A ~B
?Oh-oh…They are not equivalent!Counter-model: A is false and B is true…
63
Summary
ImplicationA B
is equivalent to:~B ~A : its contraposition
But is not equivalent to:~A ~B : its inverse
Or to:B A : its converse
64
Another Lesson Learned
Proving equivalencesvia truth-tablesvia other equivalences
Proving non-equivalence:Finding an instantiation that makes one formula hold and the other doesn’t
65
Bi-conditionals
How can we express:A B
With &, v, ~ ?It is simply:
(A & B) v (~A & ~B)
How can we express it with , & ?Why, but of course it is just:
(A B) & (B A)
66
Another Spin…
Ok, let’s try this fun ride:(P Q) & P
In English it would sound:(If P is true then Q is true) and (P is true)
What does it tell us?Naturally Q is true!
Let’s prove it…
67
Proving…
(P Q) & P(~P v Q) & P~P & P v Q & PF v Q & PQ & PBut we want just Q not Q & P!Is Q & P ≡ Q ?No -- counter-model: Q=T and P=F …
68
What is the matter?
Not all arguments have the form of a chain of equivalencesExample:
PQ = “If Socrates is human then Socrates is mortal”P=“Socrates is human”A conjunction of these two is NOT equivalent to Q= “Socrates is mortal”Why? Name a dog Socrates. It is mortal (Q holds). But it is NOT human (P does not hold)…
69
Entailment
A collection of statements P1,…,Pn (premises) entails statement Q (conclusion) if and only if:Whenever all premises hold the conclusion holds
Example:Premises:
P1 = “If Socrates is human then Socrates is mortal”P2 = “Socrates is human”
Conclusion:Q = “Socrates is mortal”
70
Valid/Invalid Arguments
Suppose someone makes an argument:P1,..,PN therefore Q
The argument is called valid iff:P1,…,PN logically entail Q
That is:Q must hold when all Pi hold
Otherwise the argument is called invalid
71
Relation to Tautologies
We already know that formulae A and B are equivalent iff (A B) is a tautology (i.e., holds for any interpretation)
How about entailment?
Formula A entails formula B iff (A B) is a tautologyIn general: premises P1,…,PN entail Q iff (P1 & … & PN Q) is a tautology
73
Today
Refresher: Chapter 1.2
Chapter 1.3 : Arguments
All i
mag
es a
re c
opyr
ight
ed t
o th
eir
resp
ectiv
e co
pyrig
ht h
olde
rs a
nd r
epro
duce
d he
re fo
r ac
adem
ic p
urpo
ses
unde
r th
e co
nditi
on o
f “fa
ir us
ing”
.
74
Interpretation
In propositional logic interpretation is a mapping from variables in your formulae to {true, false}
Example:Formula: A v BInterpretation 1: A = true, B = falseInterpretation 2: A = false, B = false
75
Interpretations
How many interpretations do the following formulae allow?A B
4
(AB & A) B4
Why not 8 or 16?
The number of interpretations is 2N where Nis the number of independent variables
77
ConditionsSuppose we care about statement X
X = “this assignment is copied”We want to evaluate X (true/false?)
Suppose we know A such that AXA is a sufficient conditionA=“the cheater is caught in the act”
Suppose we know B such that XBB is a necessary conditionB=“there was an original assignment to copy from”
78
Criteria
Suppose we know C such that CXC is a criterionC=“someone has copied this assignment”
Graphically:
X
A
B
C
79
Wanted : Criteria
Medical testsSoftware/hardware correctnessFraud/cheatingFinancial marketPsychology (e.g., in sales)Science : mathematics, physics, chemistry, etc.Logic :
If C is a criterion for X then C ≡ X !
80
PracticeIt is frequently non-trivial to derive a criterion for a real-life property X
Then we have to settle for:Sufficient conditions:
“If this quality test passes then the product is fine”Necessary conditions:
“If the patient breaks a leg they will be in pain”
Statistical validity : the condition works most of the timeIn logic : the condition works all the time!
81
Derivation of Criteria
Logic/Mathematics/Theoretical sciences:Equivalent transformationsProofs by contradiction
Empirical sciences:Statistical testsFunction approximation
Artificial Intelligence:Machine learning
These methods are
notguaranteed to produce true
criteria…
83
Logic EquivalencePropositions/statements/formulae A and B are logically equivalent when:
A holds if and only if B holdsNotation: A ≡ BExamples:
A v A is equivalent to:A
A v ~A is equivalent to:true
84
Challenge
Theorem 1.1.1 : Boolean AlgebraDerive the rest (e.g., #8) from the first 5 equivalences…
85
Use of Equivalences
Deriving equivalent formulae!Of course, but why do we care?
Simplification of formula
Simplification of code
Simplification of hardware (e.g., circuits)
Derivation of criteria!
86
Limitations
Not all statements are equivalent!Of course not, but what else is there?
Some formulae are stronger than others
They imply or entail other formula but not the other way around…
Equivalences cannot directly help us proving such entailments…
87
EntailmentA collection of statements P1,…,Pn (premises) entails statement Q (conclusion) if and only if:
Whenever all premises hold the conclusion holds
For every interpretation I that makes all Pj hold, I also makes Q hold
Example:Premises:
P1 = “If Socrates is human then Socrates is mortal”P2 = “Socrates is human”
Conclusion:Q = “Socrates is mortal”
88
Valid/Invalid Arguments
Suppose someone makes an argument:P1,..,PN therefore Q
The argument is called valid iff:P1,…,PN logically entail Q
That is:Q must hold if all Pi hold
Otherwise the argument is called invalid
89
Example
Sample argument:P1 = “If Socrates is human then Socrates is mortal”P2 = “Socrates is human”Therefore:Q = “Socrates is mortal”
Valid / invalid?
90
Entailment
Then is the following argument valid?P1
P2
entailsQ
Yes?Very well, but what if my interpretation I sets P1 and P2 to true but Q to false?
Then by definition Q is not entailed by P1 and P2
So do P1,P2 entail Q or do they not?
91
What Happened…We considered P1, P2, and Q under a particular(common sense) interpretation:
P1 = “If Socrates is human then Socrates is mortal” trueP2 = “Socrates is human” trueQ = “Socrates is mortal” true
Thus, they were merely logical constants to us:P1=trueP2=trueQ=true
92
Generality…Thus our argument was:
TrueTrueentailsTrue
Well, this is not very useful because it doesn’t tell us anything about validity of other arguments. For example:
P1=“If J.B. broke his leg then J.B. is in pain”P2=“J.B. broke his leg”entailsQ=“J.B. is in pain”
Is this argument valid?
93
Extracting the Essence
How do we know it is valid?Because regardless of who J.B. is and what happened to him/her, we somehow know that:
If P1 and P2 holdThen Q will hold
But how do we know that?How can we extract the essence of the “dead Socrates” and “J.B. in pain” arguments?
94
General Structure!Recall both arguments:
P1 “If Socrates is human then Socrates is mortal” “If J.B. broke his leg then J.B. is in pain”P2 “Socrates is human” “J.B. broke his leg”entailsQ “Socrates is mortal” “J.B. is in pain”
Note that P1, P2, and Q are related!Both arguments share the same structure:
P1 If X then YP2 XentailsQ Y
Then for any interpretation I as long as I satisfies P1and P2, interpretation I must satisfy Q
95
Modus PonensThe “generalized” argument
P1 = X YP2 = XentailsQ = Y
…is much more useful!Why?
Because it captures the essence of both arguments and can be used for infinitely many more
“method of affirming” (Lat.)
96
Valid Arguments (Revisited)Suppose someone makes an argument:
P1,..,PN therefore QThe argument is called valid iff:
P1,…,PN logically entail QThat is:
For any interpretation I that satisfies all Pj, interpretation I must necessarily satisfy Q
Usually: Pj and Q are somehow related formulae and P1 & … & PN can be true or false depending on the interpretation I
98
How Do We:Tell between a valid argument and an invalid argument:
People are mortal. Socrates is a man. Socrates is mortal.Ducks fly. F-16 flies. F-16 is a duck.
Prove that something logically follows from something else:
1: Everybody likes Buddha2: Everybody likes someone
Prove that something is logically equivalent to something else:
1: Everybody likes cream and sugar2: Everybody likes cream and everybody likes sugar
Prove that there is a contradiction?
99
Propositional Logic
Method #1:Go through all possible interpretations and check the definition of valid argument
Method #2:Use derivation rules to get from the premises to the conclusion in a logically sound way
“derive the conclusions from premises”
100
Method #1
Section 1.3 in the text proves many arguments/inference rules using truth tables
Suppose the argument is:P1,…,PN therefore Q
Create a truth table for formulaF=(P1 & … & PN Q)
Check if F is a tautology
101
But Why? Recall:
Formula A entails formula Biff (A B) is a tautology
In general:premises P1,…,PN entail Qiffformula F=(P1 & … & PN Q)is a tautology
106
Example #5
P v Q~P & ~Qentails P & Q
valid/invalid?
Any argument with a contradiction in its premises is valid by default…
109
Pros & Cons
Method #1:Pro: straight-forward, not much creativity machines can do
Con: the number of interpretations grows exponentially with the number of variables cannot do for many variables
Con: in predicate and some other logics even a small formula may have an infinitenumber of interpretations
111
Method #2 : Derivations
To prove that an argument is valid:
Begin with the premisesThen which high level strategy?
Equivalence, entailment, (contradiction)
Use valid/sound inference rules
Arrive at the conclusion
112
Inference Rules
But what are these “inference rules”?They are simply…
…valid arguments! Table 1.1.1
Example:X & Y X & Y Z & WthereforeZ & W by modus ponens
113
Example #1
(X&Y Z&W) & KX&YthereforeZ&WHow?(X&Y Z&W) & KX&Y Z&W by conjunctive simplificationX&YZ&W by modus ponens
114
Derivations
The chain of inference rules that starts with the premises and ends with the conclusion…is called a derivation:
The conclusion is derived from the premises
Such a derivation makes a proof of argument’s validity
115
Example #1
(X&Y Z&W) & KX&YthereforeZ&WHow?(X&Y Z&W) & KX&Y Z&W by conjunctive simplificationX&YZ&W by modus ponens
derivation
116
Pros & Cons
Method #2:Pro: often can get a dramatic speed-up over truth tables.
Con: requires creativity and intuition harder to do by machines some times
Con: semi-decidable : there is no algorithm that can prove any first-order predicate logic argument to be valid or invalid
118
Fallacies
An error in derivation leading to an invalid argumentVague formulations of premises/conclusionMissing stepsUsing non-sound inference rules, e.g.:
Converse errorInverse error
119
Converse Error
If John is smart then John makes a lot of moneyJohn makes a lot of moneyTherefore:John is smart
Tries to use this non-sound “inference rule”:AB, BThus: A
120
Inverse Error
If John is smart then John makes a lot of moneyJohn is not smartTherefore:John doesn’t make a lot of money
Tries to use this non-sound “inference rule”:AB, ~AThus: ~B
122
Truth of facts vs. Validity of Arguments
The premises are assumed to be true ONLY in the context of the argument
The following argument is valid:If John Lennon was a rock star then he was a womanJohn Lennon was a rock starThus:John Lennon was a woman
But the 1st premise doesn’t hold under the common sense interpretation
123
Inference Rules
Table 1.3.1 on page 40 – study them!!
If practice with the rules then will be more fluent using them
If are more fluent using them then will be more likely to get a better mark on exams
124
Summary
Equivalence:A ≡ BA holds iff B holdsA is a criterion for BB is a criterion for AA entails BB entails AA and B are “equivalently strong”Formula F=(AB) is a tautology
125
Summary
Entailment:A entails BB follows from AA∴B is a valid argumentA is a sufficient condition for BB is a necessary condition for AIf A holds then B holdsA may be “stronger than” BFormula F=(AB) is a tautology
126
The Big Picture
Logic is being used to verify validity of arguments
An argument is valid iff its conclusion logically follows from the premises
Derivations are used to prove validity
Inference rules are used as part of derivations
Recommended