Sei sulla pagina 1di 86

Knowledge Representation

- Propositional Logic
Dr. Jenila Livingston
Knowledge Storing

Natural language for people


Symbols for computer: a number or
character string that represents an
object or idea (Internal representation
of the knowledge).

2
Knowledge Representation
● Knowledge representation (KR) is an
important issue in both cognitive science and
artificial intelligence.
− In cognitive science, it is concerned with
the way people store and process
information and
− In artificial intelligence (AI), main focus is to
store knowledge so that programs can
process it and achieve human intelligence.
3
Knowledge Representation
● There are different ways of representing knowledge
e.g.
− Logical Representation
− Propositional logic / Sentential Logic
− Predicate logic
− Production rule
− Network Representation
− Semantic networks
− Extended semantic net,
− Structured Representation- Frames
− Conceptual dependency etc.
4
What is a Logic?
• A language with concrete rules
– No ambiguity in representation (may be other errors!)
– Allows unambiguous communication and processing
– Very unlike natural languages e.g. English

Formal logic is a language with its own syntax, which defines how to
make sentences, and corresponding semantics, which describe the
meaning of the sentences.

5
Syntax and Semantics
• Syntax
– Rules for constructing legal sentences in the logic
– Which symbols we can use (English: letters, punctuation)
– How we are allowed to combine symbols
• Semantics
– How we interpret (read) sentences in the logic
– Assigns a meaning to each sentence
• Example: “All lecturers are seven foot tall”
– A valid sentence (syntax)
– And we can understand the meaning (semantics)
– This sentence happens to be false (there is a counterexample)
6
Propositional logic (PL)
• Logical constants: T (True), F (False)
• Propositional symbols: P, Q, S, ...(atomic sentences)
• Wrapping parentheses: ( … )
• Sentences are combined by connectives:
 ... and [conjunction]
 ... or [disjunction]
...implies [implication / conditional]
…iff equivalent [biconditional or Double Implication]
 …not [negation]
• Literal: atomic sentence or negated atomic sentence
7
A BNF grammar of sentences in
propositional logic

S := <Sentence> ;
<Sentence> := <AtomicSentence> | <ComplexSentence> ;
<AtomicSentence> := "TRUE" | "FALSE" |
"P" | "Q" | "S" ;
<ComplexSentence> := "(" <Sentence> ")" |
<Sentence> <Connective> <Sentence> |
"NOT" <Sentence> ;
<Connective> := "AND" | "OR" | "IMPLIES" |
"EQUIVALENT" ;

BNF: Backus Normal Form

8
Examples of PL sentences
• Use Letters to represent the statements
• P: “It is Hot” Q : “It is humid.” R: “It is raining”

Write the prepositional logic for the below sentence

“If it is hot and humid, then it is raining”


“If it is humid, then it is hot”

9
Examples of PL sentences
• P: “It is Hot” Q : “It is humid.” R: “It is raining”
• (P  Q)  R
“If it is hot and humid, then it is raining”
• QP
“If it is humid, then it is hot”
• A better way:
Ho = “It is hot”
Hu = “It is humid”
R = “It is raining”

10
Propositional Logic
• Semantics (Classical / Boolean)
– Define how connectives affect truth
• “P and Q” is true if and only if P is true and Q is true
– Use truth tables to work out the truth of
statements

11
Truth tables

/ (P Q)

12
Truth tables II
The five logical connectives:

A complex sentence:

13
Models of complex sentences

14
15
16
More terms
1. A valid sentence or tautology is a sentence
that is True under all interpretations.
2. An inconsistent sentence or contradiction is a
sentence that is False under all interpretations.
3. Entailment: P entails Q, written P |= Q, means
that whenever P is True, so is Q.
4. Consistent
5. Logical Equivalence / Identical
6. Validity – tautology is valid

17
1. Tautology
• Show that
i)
ii)
is a tautology.

18
Tautology

19
Tautology

20
2. Contradiction

21
Contradiction
• Prove
is a contradiction

22
Contradiction

23
Contingency
• A proposition that is neither a tautology nor a
contradiction is called a contingency.

24
Exercise
• Let p be a proposition. Indicate whether the
propositions are:
(A) tautologies
(B) contradictions or
(C) contingencies.
• p∧¬p
• p∨¬p
• p∨p
25
Exercise - Answer
• p ∧ ¬ p …..Contradiction

• p ∨ ¬ p …..Tautology

• p∨p …..Contingency

26
3. Logical Entailment
• the sentence p logically entails the sentence (p
∨ q). Since a disjunction is true whenever one
of its disjuncts is true, then (p ∨ q) must be
true whenever p is true.
• On the other hand, the sentence p does not
logically entail (p ∧ q). A conjunction is true if
and only if both of its conjuncts are true, and
q may be false.
• P |= P ∨ Q
27
28
{p, q} logically entails (p ∧ q).
• {p, q} |= (p ∧ q).

29
{(m ⇒ p ∨ q), (p ⇒ q)} |= (m ⇒ q)

30
{(m ⇒ p ∨ q), (p ⇒ q)} |= (m ⇒ q)

Both premises are satisfied by the truth


assignments on rows 1, 3, 5, 7, and 8 31
Prove: Entailment

32
Logical Entailment
Use the Truth Table Method to answer the
following questions about logical entailment.
• {p ⇒ q ∨ r} |= (p ⇒ r)
• {p ⇒ r} |= (p ⇒ q ∨ r)
• {p ⇒ q ∨ r, p ⇒ r} |= (q ⇒ r)
• {p ⇒ q ∨ r, q ⇒ r} |= (p ⇒ r)

33
4. Consistent
• A set of sentences are said to be consistent if
it’s logically possible for all of them to be TRUE
at the same time
• set of statements is logically consistent when
it involves no logical contradiction
• Else it is said to be inconsistent
• Eg: Ken will be a little late for the party. He
died yesterday.

34
Consistent
• All humans are mortal (T)
• Simon is immortal (T)
• Simon is a human (F)

• All humans are mortal (T)


• Simon is immortal (T)
• Simon is not a human (T)

35
Consistent
• All humans are mortal (T)
• Some humans are not mortal (F)

• All humans are mortal (T)


• Simon is immortal (T)

• All humans are mortal (T)


• Simon is immortal (T)
• Simon is a human (F)
36
Exercise
• (a) Mr. Pheeper is my friend
(b) All my friends are good people.
(c) Mr. Pheeper is an atheist.
(d) All atheists are bad people

37
Consistency : Truth table
• To test for consistency, do a joint truth table
for the two statements. If there is a row (one
or more) on which both statements are T,
then they are consistent.

38
39
40
5. Logical Equivalence
• Two statements are equivalent if they have
the same truth value in every possible
situation

41
Show that
logically equivalent

42
show that ¬(p ∨ q) is logically
equivalent to (¬p ∧ ¬q).

43
show that ¬(p ∨ q) is logically
equivalent to (¬p ∧ ¬q).

44
45
Name Logical Equivalences
p∧T≡p
Identity p∨F≡p
p∨T≡T
Domination p∧F≡F
p∧p≡p
Idempotent p∨p≡p
Double Negation ¬(¬p)≡p
p∨q≡q∨p
Commutative p∧q≡q∧p
(p∨q)∨r≡p∨(q∨r)
Associative (p∧q)∧r≡p∧(q∧r)
p∨(q∧r)≡(p∨q)∧(p∨r)
Distributive p∧(q∨r)≡(p∧q)∨(p∧r)
¬(p∧q)≡¬p∨¬q
De Morgan's Law ¬(p∨q)≡¬p∧¬q
p∨(p∧q)≡p
Absorption p∧(p∨q)≡p
p∨¬p≡T
Negation p∧¬p≡F
46
• Conditional / Implication Equivalence
pq ≡ p  q
pq ≡ q   p

• Bi-conditional Equivalence
pq ≡(pq)  (qp)
pq ≡ ¬ p  q

47
Prove that q∧¬(p→q) is a
contradiction without truth tables

48
Prove that q∧¬(p→q) is a
contradiction:

49
• Prove:
(p∧¬q) ∨ q ≡ p∨q
p → p ∨ q is a tautology
p ↔ q ≡ ¬ p ↔ ¬q
(p∧q) → p is a tautology
¬(p∨(¬p∧q)) and (¬p ∧ ¬q) equivalent?

50
Prove: (p∧¬q) ∨ q ≡ p∨q

51
Prove: p → p ∨ q is a tautology

52
Prove:¬p ↔ q ≡ p ↔ ¬q

53
(p∧q) → p is a tautology

54
Are ¬(p∨(¬p∧q)) and (¬p ∧ ¬q)
equivalent?

55
6. Validity
To test the validity of an argument, we use the
following three-step process
1. Symbolize each premise and the conclusion.
2. Make a truth table that has a column for each
premise and a column for the conclusion.
3. If the truth table has a row where the
conclusion column is FALSE while every
premise column is TRUE, then the argument is
INVALID. Otherwise, the argument is VALID.

56
Arguments, Validity and Tautology
• In other words, an argument form with
premises p1; p2; : : : ; pn and
conclusion q
is valid if and only if
(p1 ^ p2 ^ ^ pn)  q
is a tautology.

57
Validity
• Argument validity An argument is deductively
valid iff the premises jointly imply the
conclusion.
This pizza is either pepperoni or cheese.
It is not cheese.
Conclusion: Therefore, it is pepperoni.

58
Truth table

Pre = (PVC) ˄~C Pre -> P

F T

F T

T T

F T

59
Validity
• If ducks sink, then ducks are made of small
rocks.
• Ducks do sink.

60
Validity
• If ducks sink, then ducks are made of small
rocks.
• Ducks do sink.
• Conclusion: Therefore, ducks are made of
small rocks.

D: ducks sink
R: ducks are made of small rocks

61
Truth Table

Pre = (D->R) ˄ D Pre -> R

T T

F T

F T

F T 62
Arguments

• We have the two premises:


• “All men are mortal.”
• “Socrates is a man.”

And the conclusion:


• “Socrates is mortal.”

63
Express the Argument
• We can express the premises (above the line)
and the conclusion (below the line) in
predicate logic as an argument:

Premises:
• “If it is snowing, then I will study AI.” p  q
• “It is snowing.” p

Conclusion: q
• Therefore , “I will study AI.” 64
Valid Arguments
• We will show how to construct valid
arguments in two stages
1. Propositional Logic
– Inference Rules
2. Predicate Logic
– Inference rules for propositional logic plus
additional inference rules to handle variables and
quantifiers.

65
Invalid Arguments
• Trees are green
• Banu is a girl

The premises will not jointly imply the conclusion. So


they are invalid

66
Inference rules

• Rules of inference are templates for building


valid arguments.

• Inference rules are all argument simple


argument forms that will be used to construct
more complex argument forms.

67
Rules of Inference

68
69
Modus Ponens: Example

Example:
• “If it is snowing, then I will study AI.” p  q
• “It is snowing.” p

• Conclusion: q
• Therefore , “I will study AI.”

70
Modus Tollens: Example

Example:
• “If it is snowing, then I will study AI.” p  q
• “I will not study AI.” ¬q

• Conclusion: ¬p
• Therefore , “It is not snowing.”

71
Hypothetical Syllogism / Transitivity

Example:
• “If it snows, then I will study AI.” p  q
• “If I study AI, I will get S grade.” q  r

• Conclusion: p  r
• Therefore , “If it snows, I will get S grade.”

72
Disjunctive Syllogism / Elimination

Example:
• “I will study OOP or I will study AI.” p V q
• “I will not study OOP.” ¬p

• Conclusion: p  r
• Therefore , “I will study AI.”

73
Addition

Example:
• “I will study AI.” p

• Conclusion: p V q
• Therefore , “I will study AI or I will visit Phoenix
mall”

74
Simplification

Example:
• “I will study AI and I will study OOP.” p  q

• Conclusion: q
• Therefore , “I will study OOP”

75
Conjunction

Example:
• “I will study AI”. p
• “I will study OOP.” q

• Conclusion: p  q
• Therefore , “I will study AI and I will study OOP”

76
Resolution

Example:
• “I will study not AI or I will study DBMS”. ¬p V r
• “I will study AI or I will study OOP”. p V q

• Conclusion: q V r
• Therefore , “I will study OOP and I will study DBMS”

77
Contradiction
• Sita falsely stated
“It was not a mountain” ¬p

Conclusion :
“ It was a mountain” p

78
Valid Arguments – Exercise1

79
Valid Arguments – Exercise2
With these hypotheses:
• “It is not sunny this afternoon and it is colder than yesterday.”
• “If we go swimming then it is sunny”
• “If we do not go swimming, then we will take a canoe trip.”
• “If we take a canoe trip, then we will be home by sunset.”
Using the inference rules, construct a valid
argument for the conclusion:
“We will be home by sunset.”

80
Proof
• p : “It is sunny this afternoon.”
• q : “It is colder than yesterday.”
• r : “We will go swimming.”
• s : “We will take a canoe trip.”
• t : “We will be home by sunset.”
Translation into propositional logic:
Hypotheses:
¬ p  q, r  p, ¬ r  s, s  t
Conclusion: t 81
1. It is not sunny this afternoon and it is colder than yesterday.
2. If we go swimming then it is sunny.
3. If we do not go swimming then we will take a canoe trip.
4. If we take a canoe trip then we will be home by sunset.
5. We will be home by sunset

p It is sunny this afternoon 1. p  q


q It is colder than yesterday 2. r  p
r We go swimming
3. r  s
s We will take a canoe trip
t We will be home by sunset (the conclusion) 4. s  t
5. t

propositions hypotheses
82
Using the rules of inference to build arguments
1. p  q
p It is sunny this afternoon
q It is colder than yesterday
2. r  p
r We go swimming 3. r  s
s We will take a canoe trip 4. s  t
t We will be home by sunset (the conclusion)
5. t
Step
Step Reason
Reason
Reason
1. 
pp 
 qq Hypothesis
Hypothesis
Hypothesis
2. p Simplifica
Simplification
tionusing
using(1)
(1)
3. rp Hypothesis
Hypothesis
4. r Modus
Modustollens
tollensusing
using(2)
(2)and
and(3)
(3)
5. r  s Hypothesis
6. s Modus ponens using (4) and (5)
7. st Hypothesis
8. t Modus ponens using (6) and (7)
83
Show that the hypotheses
“If you send me an email message, then I will finish
writing the program,”

“If you do not send me an email message, then I will


go to sleep early,”

“If I go to sleep early, then I will wake up feeling


refreshed”

lead to the conclusion “If I do not finish writing the


program, then I will wake up feeling refreshed.”

84
85
86

Potrebbero piacerti anche