Introduction to Logic and Logical Arguments

advertisement
Discussion #8
Introduction to Logic
and Logical Arguments
Discussion #8
1
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
2
Logical Arguments

Consider the following statements.
1.
2.
3.



if you study then you succeed
you study
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
3
Modus Ponens
(a rule of inference – one of the most important rules)
if you study then you succeed
you study
you succeed
Premises
Conclusion
Aristotle called this modus ponens:
if P then Q
P
Q
Discussion #8
4
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
5
Modus Ponens Examples
if P then Q
P
Q




P: I study hard
Q: I get an A
P: cows give milk
Q: doors open
P: I follow the gospel plan
Q: I will be exalted
P: you sail past the end of the
world
Q: you will fall off
Discussion #8
Makes sense
Doesn’t make
sense
Makes sense
Doesn’t make
sense
6
Predicates and Arguments
if ‘Jill’ thinks then ‘Jill’ exists
‘Jill’ thinks
if P(‘Jill’) then Q(‘Jill’)
‘Jill’ exists
P(‘Jill’)
Q(‘Jill’)
if thinks(‘Jill’) then exists(‘Jill’)
thinks(‘Jill’)
exists(‘Jill’)
if thinks(X) then exists(X)
thinks(X)
exists(X)
Discussion #8
7
Predicates in arguments
(continued…)
if thinks(X) then exists(X)
thinks(X)
exists(X)
Discussion #8
thinks(X)  exists(X)
thinks(X)
exists(X)
thinks(X) -: exists(X)
thinks(X)
exists(X)
exists(X) :- thinks(X)
thinks(X)
exists(X)
8
Datalog – Class Project
Schemes:
thinks(A)
exists(B)
What does all of this mean?
Facts:
thinks(‘Pat’).
thinks(‘Tracy’).
exists(‘Lynn’).
Rules:
exists(A) :- thinks(A).
Queries:
exists(‘Tracy’)?
Yes
Yes
exists(‘Lynn’)?
Prove True if possible,
Yes
thinks(‘Pat’)?
(otherwise, False)
No
thinks(‘Lynn’)?
No
exists(‘Kelly’)?
Discussion #8
9
What do we need to know to
understand and implement this?
Grammars (to parse Datalog)
Propositions & Introduction to Logic
Predicate 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
10
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
11
Truth Tables


Give the values of a proposition under all
possible assignments of T and F
Are used to define connectives
Discussion #8
P
P
T
F
F
T
12
Connectives (= Operators)
Conjunction
“and”
Disjunction
“or”
Conditional
“implies”
Biconditional
“equivalent”
P
Q
PQ
PQ
PQ
PQ
T
T
T
T
T
T
T
F
F
T
F
F
F
T
F
T
T
F
F
F
F
F
T
T
Discussion #8
13
Vocabulary for Conditionals


P is the antecedent and
Q the consequent.
Many ways to express
conditionals:







Discussion #8
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
14
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
Discussion #8
P
Q
PQ
T
T
T
T
F
F
F
T
F
F
F
T
15
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
16
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
17
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
18
Evaluating Logical Expressions
P  Q
By truth tables (columns)
((P)  Q)
P
Q
T
T
F
T
T
F
F
T
F
T
T
T
F
F
T
F
Discussion #8
By expression trees (rows)


Q
P
19
Logical Expressions with 3 Variables
(P  Q)  P  Q  R
By expression trees
By truth table
3
1
5
2
4
P
Q R ( PQ )  P  Q  R
T
T
T
F
T
F
F
F
T
T
T
F
F
T
F
F
F
F
T
F
T
T
F
T
F
F
T
T
F
F
T
F
T
F
F
T
F
T
T
T
F
T
T
T
T
F
T
F
T
F
T
T
T
T
F
F
T
T
F
T
T
F
T
F
F
F
T
F
T
T
F
T
Discussion #8

6

R



P

Q
Q
P
20
(P  Q)  P  Q  R
(A)  P  Q  R
B  P  Q  R
BCQR
BDR
ER
G
A
B
C
D
E
G
PQ
A
P
CQ
BD
ER
P
Q R
T
T
T
T
F
F
F
F
T
T
T
F
T
F
F
F
F
F
T
F
T
F
T
F
F
T
T
T
F
F
F
T
F
F
T
T
F
T
T
F
T
T
T
T
T
F
T
F
F
T
T
T
T
T
F
F
T
F
T
T
F
T
T
F
F
F
F
T
T
F
T
T
Discussion #8
21
Number of Binary Operators
P
Q
T


P

Q



+
Q

P
T
T
T
T
T
T
T
T
T
T
F
F
F
F
T
F
T
T
T
T
F
F
F
F
T
T
T
F
T
T
T
F
F
T
T
F
F
T
T
F
F
T
F
T
F
T
F
T
F
T
F
QP
Discussion #8
PQ
 
F
F
F
F
F
T
F
F
F
F
F
F
T
T
F
F
T
F
T
F
T
F
(PQ) = P  Q
22
Number of Operators
P
Q
T
T
T
F
F
T
F
F
P
Q
R
T
T
T
T
T
F
T
F
T
T
F
F
F
T
T
#expresions = #columns = 2#rows = 24 = 16
#rows = 2#variables = 22 = 4
F
T
F
F
F
T
F
F
F
Discussion #8
#expressions =
22
3
= 256
2
In general, #expressions = 2
when there are k variables.
k
23
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
30
40
50
60
time
20 minutes
14 days
40 years
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
…
…
…
…
Discussion #8
24
Download
Related flashcards

Logic

29 cards

Conjectures

15 cards

Mathematical logic

34 cards

Set theory

16 cards

Metrology

19 cards

Create Flashcards