Sei sulla pagina 1di 24

Discussion #8

Introduction to Logic
and Logical Arguments

Discussion #8

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

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 dont know whether the
conclusion is true or false.

Discussion #8

Modus Ponens

(a rule of inference one of the most important rules)

if you study then you succeed


you study
Premises
you succeed
Conclusion
Aristotle called this modus ponens:
if P then Q
P
Q
Discussion #8

Important!

We are dealing with the validity of an


argument, NOT with the validity of the result!
In logic, it doesnt 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

Modus Ponens Examples

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

if P then Q
P
Q
Makes sense
Doesnt make
sense
Makes sense
Doesnt 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

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)

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
exists(Lynn)?
Yes
thinks(Pat)?
Prove True if possible,
Yes
thinks(Lynn)?
(otherwise, False)
No
exists(Kelly)?
No

Discussion #8

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

T
12

Connectives (= Operators)
Conjunction
and

Disjunction
or

Conditional
implies

Biconditional
equivalent

PQ

PQ

PQ

PQ

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

PQ

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

PQ

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

Discussion #8

always left associative


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)

Discussion #8

By expression trees (rows)

P
19

Logical Expressions with 3 Variables


(P Q) P Q R

By expression trees

By truth table
3

Q R ( PQ ) P Q R

Discussion #8

Q
P
20

(P Q) P Q R
(A) P Q R
B P Q R
BCQR
BDR
ER
G
A

PQ

CQ

BD

ER

Q R

Discussion #8

21

Number of Binary Operators


P

QP

Discussion #8

PQ

(PQ) = P Q

22

Number of Operators
P

Discussion #8

#expresions = #columns = 2#rows = 24 = 16


#rows = 2#variables = 22 = 4

#expressions = 2

= 256

In general, #expressions = 2
when there are k variables.

23

Truth Table Solutions

In general

To evaluate expressions using truth tables with k variables and n


operations, it takes time proportional to 2 kn = 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

Discussion #8

24

Potrebbero piacerti anche