08-logicalargs
DESCRIPTION
sssTRANSCRIPT
Discussion #8 2
Topics Introduction to logic and logical arguments
Propositions Connectives Propositional expressions
Logic is used for: Databases Software specification Program validation Computer hardware design Semantic web … And yes … Projects for CS236
Discussion #8 3
Logical Arguments
Consider the following statements.1. if you study then you succeed2. you study3. you succeed
These three statements create a logical argument. Lines 1 and 2 are premises and line 3 is the conclusion. This logical argument is sound.
Premises can be true or false. If the premises are true, the conclusion must be true. If one (or more than one) of the premises is false, the
argument is still sound, but we don’t know whether the conclusion is true or false.
Discussion #8 4
Modus Ponens
if you study then you succeed
you study
you succeed
Aristotle called this modus ponens:
if P then QP
Q
Premises
Conclusion
(a rule of inference – one of the most important rules)
Discussion #8 5
Important!
We are dealing with the validity of an argument, NOT with the validity of the result!
In logic, it doesn’t matter if a logical statement makes sense or not.
What does matter is that if the premises are correct, then so is the result.
Discussion #8 6
Modus Ponens Examples
P: I study hardQ: I get an A
P: cows give milkQ: doors open
P: I follow the gospel planQ: I will be exalted
P: you sail past the end of the worldQ: you will fall off
Makes sense
Doesn’t make sense
Makes sense
Doesn’t make sense
if P then QP
Q
Discussion #8 7
if thinks(‘Jill’) then exists(‘Jill’)thinks(‘Jill’)exists(‘Jill’)
if P(‘Jill’) then Q(‘Jill’)P(‘Jill’)Q(‘Jill’)
Predicates and Arguments
if ‘Jill’ thinks then ‘Jill’ exists‘Jill’ thinks
‘Jill’ exists
if thinks(X) then exists(X)thinks(X)exists(X)
Discussion #8 8
Predicates in arguments (continued…)
thinks(X) exists(X)thinks(X)exists(X)
thinks(X) -: exists(X)thinks(X)exists(X)
exists(X) :- thinks(X)thinks(X)exists(X)
if thinks(X) then exists(X)thinks(X)exists(X)
Discussion #8 9
Datalog – Class ProjectSchemes:
thinks(A) exists(B)
Facts: thinks(‘Pat’). thinks(‘Tracy’). exists(‘Lynn’).
Rules: exists(A) :- thinks(A).
Queries: exists(‘Tracy’)? exists(‘Lynn’)? thinks(‘Pat’)? thinks(‘Lynn’)?exists(‘Kelly’)?
What does all of this mean?
Prove True if possible,(otherwise, False)
Yes
Yes
Yes
No
No
Discussion #8 10
What do we need to know to understand and implement this?
Grammars (to parse Datalog)Propositions & Introduction to LogicPredicate Calculus (to add variables)Recursion (to handle recursive rules)Derivations & Normal Forms (to ease to programming)Sets and Relations (to build relational data bases)Relational Databases (to optimize)Graphs and Trees (to further optimize)
Discussion #8 11
Propositions
Any statement that is either True or False is a proposition.
Propositional variables: a variable that can assume a value of T or F.
Propositional constants: T or F. Atomic proposition: A proposition consisting of
only a single propositional variable or constant. Logical connectives: logical operators.
Discussion #8 12
Truth Tables
Give the values of a proposition under all possible assignments of T and F
Are used to define connectives
P P
T F
F T
Discussion #8 13
Connectives (= Operators)
FF
TF
FT
TT
QP
T
F
F
T
P Q
Biconditional
“equivalent”
T
T
F
T
P Q
Conditional
“implies”
F
T
T
T
P Q
Disjunction
“or”
F
F
F
T
P Q
Conjunction
“and”
Discussion #8 14
Vocabulary for Conditionals P is the antecedent and
Q the consequent. Many ways to express
conditionals: if P then Q whenever P then Q P is sufficient for Q P only if Q Q if P (for Datalog: Q :- P) Q is necessary for P P implies Q
P Q P Q
T T T
T F F
F T T
F F T
Discussion #8 15
Vocabulary for Biconditional
P and Q are equivalent.
Many ways to express biconditionals: P if and only if Q P is necessary and
sufficient for Q P iff Q
P Q P Q
T T T
T F F
F T F
F F T
Discussion #8 16
Compound Propositions
Also called logical expressions, formulas, and well-formed formulas (wffs).
Well-formed formulas are defined inductively: Basis:
T and F are wffs (these are the constants)
P, Q, … are wffs (these are the variables)
Induction: if A and B are wffs, then so are:(A)
(A B), (A B), (A B), (A B)
Discussion #8 17
Parentheses Well-formed formulas are fully parenthesized:
((((P Q)) ((P) Q)) R) We can remove some parentheses:
Outside parentheses can be removed Use precedence:
Use associativity always left associative
Discussion #8 18
Parentheses (continued …)
((((P Q)) ((P) Q)) R) (((P Q)) ((P) Q)) R ((P Q) (P Q)) R (P Q) (P Q) R (P Q) P Q R
((((P Q)) ((P) Q)) R)
Discussion #8 19
Evaluating Logical Expressions
By truth tables (columns)
F
T
T
T
T
T
F
F
FF
TF
FT
TT
((P) Q)QP
P Q
Q
P
By expression trees (rows)
Discussion #8 20
Logical Expressions with 3 Variables
T
T
T
T
T
T
F
T
6
F
F
T
T
F
F
F
F
4
T
T
T
T
F
F
F
F
2
T
T
T
T
T
T
F
F
5
F
F
F
F
F
F
T
T
1
T
T
T
T
T
T
F
F
3
FFF
TFF
FTF
TTF
FFT
TFT
FTT
TTT
R QP) PQ(RQP
(P Q) P Q R
By truth table
R
Q
P Q P
By expression trees
Discussion #8 21FFF
TFF
FTF
TTF
FFT
TFT
FTT
TTT
RQP
(P Q) P Q R
F
F
F
F
F
F
T
T
A
PQ
(A) P Q R
T
T
T
T
T
T
F
F
B
A
B P Q R
T
T
T
T
F
F
F
F
C
P
B C Q R
F
F
T
T
F
F
F
F
D
CQ
B D R
T
T
T
T
T
T
F
F
E
BD
E R
T
T
T
T
T
T
F
T
G
ER
G
Discussion #8 22
Number of Binary Operators
T
T
T
T
F
F
F
F
T
F
F
F
F
T
F
F
T
T
F
F
F
F
T
F
T
F
T
F
F
T
T
F
T
T
T
F
F
F
F
T
T
F
F
T
F
T
F
T
T
T
F
T
F
F
T
T
T
F
T
T
F
T
T
T
FPQ+QPT
FF
TF
FT
TT
QP
(PQ)QP PQ = P Q
Discussion #8 23
Number of Operators
FF
TF
FT
TT
QP
P Q R
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
#expresions = #columns = 2#rows = 24 = 16#rows = 2#variables = 22 = 4
223
#expressions = = 256
22k
In general, #expressions = when there are k variables.
Discussion #8 24
Truth Table Solutions In general…
To evaluate expressions using truth tables with k variables and n operations, it takes time proportional to 2kn = O(2kn).
If we have one operator (n = 1) and if we can substitute in T or F and evaluate in 1 sec, then
k time 30 20 minutes 40 14 days 50 40 years 60 40,000 years!
Thus, it is not practical to use truth tables for “large” k.
P1 P2 … Pk
T T … T
T T … F
T … … T
T … … F
… … … …