0% found this document useful (0 votes)
42 views38 pages

Assignment 02: Adversarial Search (Game Playing)

1. The document discusses knowledge representation and logic, including propositional logic syntax, sound inference rules, theorem proving, and normal forms of propositional logic sentences such as disjunctive normal form and conjunctive normal form. 2. It also introduces Horn sentences, a type of propositional logic sentence with at most one positive literal, and notes some of their properties. 3. Knowledge representation languages allow agents to represent knowledge about the world and perform logical reasoning using this knowledge to derive new facts.

Uploaded by

Kezia Sasmita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views38 pages

Assignment 02: Adversarial Search (Game Playing)

1. The document discusses knowledge representation and logic, including propositional logic syntax, sound inference rules, theorem proving, and normal forms of propositional logic sentences such as disjunctive normal form and conjunctive normal form. 2. It also introduces Horn sentences, a type of propositional logic sentence with at most one positive literal, and notes some of their properties. 3. Knowledge representation languages allow agents to represent knowledge about the world and perform logical reasoning using this knowledge to derive new facts.

Uploaded by

Kezia Sasmita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

ASSIGNMENT 02 :

ADVERSARIAL SEARCH (GAME


PLAYING)
Problem 1
α=-,β= a = -25
max

α/-25/-25 -25/-65/-65
α/43/43
min
43/43/β
-25/-25/43 -25/-65/β
-70/-70/β -75/-75/43
-25/-68/β
max
α/-70/-70 -70/43/43 -25/-68/-68
α/-75/43
min

-70 76 49 43 -75 -18 3 -25 -68 99 48 -65 90 -22 82 -26

Question : Perform left2right a-b pruning to determine a.


Problem 2
α=-,β= a=1
max

α/1/1 1/-12/-12
min

24/24/ β 1/-12/-12
β
1/1/
max
1/-46/-46 1/-12/-12 1/-62/-62
α/24/1
α/1/1 min

79 1 -46 -3 55 24 69 74 -12 92 -62 -82 -77 95 51 -74

Question : Perform left2right a-b pruning to determine a.


FIRST ORDER PREDICATE LOGIC (FOPL)

• A knowledge-based agent consists of a knowledge


base (KB) and an inference engine (IE).
• A knowledge-base is a set of representations of what
one knows about the world (objects and classes of
objects, the fact about objects, relationships among
objects, etc.)
• Each individual representation is called a sentence.
• The sentences are expressed in a knowledge
representation language.
• Examples of sentences
– The moon is made of green cheese
– All humans are mortal
– Confucius is a human

4
• The Inference engine derives new sentences from the input
and KB
• The inference mechanism depends on representation in KB
• The agent operates as follows:
1. It receives percepts from environment
2. It computes what action it should perform (by IE and KB)
3. It performs the chosen action (some actions are simply
inserting inferred new facts into KB).

Input from Inference Output


environment Engine (actions)
Learning
(KB update)
Knowledge
Base

5
6
7
8
Representation, Reasoning, and Logic
• The objective of knowledge representation is to express
knowledge in a computer-tractable form, so that agents
can perform well.
• A knowledge representation language is defined by:
– Its syntax which defines all possible sequences of
symbols that constitute sentences of the language
(grammar to form sentences)
– Its semantics determines the facts in the world to
which the sentences refer (meaning of sentences)
• Each sentence makes a claim about the world.
– Its proof theory (inference rules and proof
procedures)

9
10
Propositional Logic: Syntax
• Symbols:
Logical constants: true (T), false (F)
Propositional symbols: P, Q, S, ...
logical connectives:
 ...conjunction (and)  ...disjunction (or)
~ ...negation (not) => ...implication (if)
<=> ...logical equivalence (if and only if)
Wrapping parentheses: ( … )
• A proposition (denoted by a proposition symbol) is a declarative
statement which can be either true or false but not both or neither.
– The moon is made of green cheese (F)
– UMBC is closer to Baltimore than to Washington, DC (T)
– P = NP (truth unknown)

11
• Sentence
1. T or F itself is a sentence
2. Individual proposition symbols P, Q, ... are
sentences
3. If S is a sentence, so is (S)
4. If S1 and S2 are sentences, so are
S1  S2, S1 S2, S1 => S2, S1 <=> S2, ~ S1
• Order of precedence of logical connectors
~ , , , => , <=>
• Minimum set of logical connectors
(~ , ), or (~ , )
• Atomic sentences: T, F, P, Q, ...
• Literals: atomic sentences and their negations

12
Sound Inference Rules (deductive rules)

• Here are some examples of sound rules of inference.


• Each can be shown to be sound using a truth table -- a rule
is sound if it’s conclusion is true whenever the premise is
true.
RULE PREMISE CONCLUSION
Modus Ponens A, A => B B
Modus Tollens ~B, A => B ~A
And Introduction A, B A^B
And Elimination A^B A
Or Introduction A AvB
Double Negation ~~A A
Chaining A => B, B => C A => C

13
• Resolution rule
Unit Resolution A v B, ~A B
Resolution A v B, ~B v C AvC
Let 1... i ,  ,  1... k be literals. Then
1  ...   i   , ~  ,  1  ... k 1  ...   i   1  ... k
– Operates on two disjunctions of literals
– The pair of two opposite literals (  and ~  ) cancel
each other, all other literals from the two disjuncts are
combined to form a new disjunct as the inferred sentence
– Resolution rule can replace all other inference rules
Modus Ponens A, ~A v B B
Modus Tollens ~B, ~A v B ~A
Chaining ~A v B, ~B v C ~A v C

14
KB AGENTS : EXAMPLES
• Bila dalam sebuah knowledge base (KB) diketahui terdapat
premise-premise sebagai berikut :
1. Premise Q=>P means “if it is humid, it is hot”
2. Premise (P^Q)=>R means “If it’s hot & humid, it’s
raining”

Pertanyaan :
a.Buktikan bahwa hujan akan turun bila knowledge-based agent
Saudara menerima input bahwa cuaca sangat humid !!.
Gunakan aturan inferensi yang telah Saudara pelajari.
b.Pertanyaan sama dengan (a) tetapi pembuktian menggunakan
teknik resolusi.

15
Proving things
• A proof is a sequence of sentences, where each sentence is either a
premise (also called an axiom) or a sentence derived from earlier
sentences in the proof by one of the rules of inference.
• The last sentence is the theorem (also called goal or query) that we
want to prove.
• Complete proof procedure for PL has time complexity exponential to the
number of premises
• Example for the "weather problem" given before.
1 Q Premise “It is humid”
2 Q=>P Premise “if it is humid, it is hot”
3 P Modus Ponens(1,2) “It is hot”
4 (P^Q)=>R Premise “If it’s hot & humid, it’s raining”
5 P^Q And Introduction(1) “It is hot and humid”
6 R Modus Ponens(4,5) “It is raining”

16
• Proof by resolution

Q ~Q v P ~P v ~Q v R premises

~Q v R

theorem
R
• Theorem proving as search
– Start node: the set of given premises/axioms (KB + Input)
– Operator: inference rule (add a new sentence into parent node)
– Goal: a state that contains the theorem asked to prove
– Solution: a path from start node to a goal

17
Normal forms of PL sentences
• Disjunctive normal form (DNF)
– Any sentence can be written as a disjunction of conjunctions of
literals.
– Examples: P ^ Q ^ ~R; A^B v C^D v P^Q^R; P
– Widely used in logical circuit design (simplification)
• Conjunctive normal form (CNF)
– Any sentence can be written as a conjunction of disjunctions of
literals.
– Examples: P v Q v ~R; (A v B) ^ (C v D) ^ (P v Q v R); P
• Normal forms can be obtained by applying equivalence laws
 [(A v B) => (C v D)] => P
 ~[~(A v B) v (C v D)] v P
 [~~(A v B) ^ ~(C v D)] v P
 [(A v B)^(~C ^ ~D)] v P
 (A v B v P)^(~C^~D v P)
(A v B v P)^(~C v P)^(~D v P) a CNF
18
Horn Sentences
• A Horn sentences is a disjunction of literals with at most one of
these literals being non-negated (positive).
~P1 v ~P2 v ~P3 ... v ~Pn v Q; or alternatively
P1 ^ P2 ^ P3 ... ^ Pn => Q; (an implication or if-then
rule)
• Some properties of Horn sentences
– P => Q ^ R  (P => Q) ^ (P => R)
– P v Q => R  (P => R) ^ (Q => R)
– P => Q v R cannot be represented as Horn sentences
• We will expand Horn sentences to Horn clauses in first order
predicate logic later and give it more discussion then

19
Weaknesses of PL
• Hard to identify "individuals." E.g., Mary
• Difficult to directly and clearly talk about properties of
individuals or relations between individuals (hard to
connect individuals to class properties).
– E.g., property of being a human implies property of
being mortal
• Generalizations, patterns, regularities can't easily be
represented.
– All members of a class have this property
– Some member of a class have this property
• A better representation is needed to capture the
relationship (and distinction) between objects and classes,
including properties belonging to classes and individuals

20
Weaknesses of PL
• First-Order Logic (abbreviated FOPL or FOPC) is expressive
enough to concisely represent this kind of situation by
separating classes and individuals
– Explicit representation of individuals and classes, x,
Mary, 3, persons.
– Adds relations, variables, and quantifiers, e.g.,
• “Every person is mortal”
Forall X: person(X) => mortal(X)
• “There is a white alligator”
There exists some X: Alligator(X) ^ white(X)

21
First Order Predicate Logic (FOPL)
• First-order logic is used to model the world in terms of
– objects which are things with individual identities
e.g., individual students, lecturers, companies, cars ...
– properties of objects that distinguish them from other
objects
e.g., mortal, blue, oval, even, large, ...
– classes of objects (often defined by properties)
e.g., human, mammal, machine, ...
– relations that hold among objects
e.g., brother of, bigger than, outside, part of, has color,
occurs after, owns, a member of, ...
– functions which are a subset of the relations in which
there is only one ``value'' for any given ``input''.
e.g., father of, best friend, second half, one more
than ...
22
Syntax of FOPL
• Predicates: P(x[1], ..., x[n])
– P: predicate name; (x[1], ..., x[n]): argument list
– A special function with range = {T, F};
– Examples: human(x), /* x is a human */
father(x, y) /* x is the father of y */
– When all arguments of a predicate is assigned values (said to
be instantiated), the predicate becomes either true or false,
i.e., it becomes a proposition. Ex. Father(Fred, Joe)
– A predicate, like a membership function, defines a set (or a
class) of objects
• Terms (arguments of predicates must be terms)
– Constants are terms (e.g., Fred, a, Z, “red”, etc.)
– Variables are terms (e.g., x, y, z, etc.), a variable is
instantiated when it is assigned a constant as its value
– Functions of terms are terms (e.g., f(x, y, z), f(x, g(a)), etc.)
23
• Quantifiers
Universal quantification  (or forall)
– (x)P(x) means that P holds for all values of x in the
domain associated with that variable.
– E.g., (x) dolphin(x) => mammal(x)
(x) human(x) => mortal(x)
– Universal quantifiers often used with "implication
(=>)" to form "rules" about properties of a class
(x) student(x) => smart(x) (All students are smart)
– Often associated with English words “all”, “everyone”,
“always”, etc.

24
Existential quantification 
– (x)P(x) means that P holds for some value(s) of x in the
domain associated with that variable.
– E.g., (x) mammal(x) ^ lays-eggs(x)
(x) taller(x, Fred)
(x) UMBC-Student (x) ^ taller(x, Fred)
– Existential quantifiers usually used with “^ (and)" to specify
a list of properties about an individual.
(x) student(x) ^ smart(x) (there is a student who is
smart.)
– A common mistake is to represent this English sentence as
the FOL sentence:
(x) student(x) => smart(x)
– Often associated with English words “someone”,
“sometimes”, etc.

25
Sentences are built from terms and atoms
• A term (denoting a individual in the world) is a constant symbol, a
variable symbol, or a function of terms.
• An atom (atomic sentence) is a predicate P(x[1], ..., x[n])
– Ground atom: all terms in its arguments are ground terms (does not
involve variables)
– A ground atom has value true or false (like a proposition in PL)
• A literal is either an atom or a negation of an atom
• A sentence is an atom, or,
– ~P, P v Q, P ^ Q, P => Q, P <=> Q, (P) where P and Q are
sentences
– If P is a sentence and x is a variable, then (x)P and (x)P are
sentences
• A well-formed formula (wff) is a sentence containing no "free"
variables. i.e., all variables are "bound" by universal or existential
quantifiers.
(x)P(x,y) has x bound as a universally quantified variable, but y is
free.
26
A BNF for FOL Sentences
S := <Sentence> ;
<Sentence> := <AtomicSentence> |
<Sentence> <Connective> <Sentence> |
<Quantifier> <Variable>,... <Sentence> |
~ <Sentence> |
"(" <Sentence> ")";
<AtomicSentence> := <Predicate> "(" <Term>, ... ")" |
<Term> "=" <Term>;
<Term> := <Function> "(" <Term>, ... ")" |
<Constant> |
<Variable>;
<Connective> := ^ | v | => | <=>;
<Quantifier> :=  | ;
<Constant> := "A" | "X1" | "John" | ... ;
<Variable> := "a" | "x" | "s" | ... ;
<Predicate> := "Before" | "HasColor" | "Raining" | ... ;
<Function> := "Mother" | "LeftLegOf" | ... ;
<Literal> := <AutomicSetence> | ~ <AutomicSetence>

27
EXAMPLES
Perhatikan kalimat cerita “happy student” berikut ini :

Setiap orang yang lulus ujian matakuliah Intelijensia Semu(IS)


dan memenangkan undian akan berbahagia. Setiap orang yang
belajar atau beruntung akan dapat lulus dari seluruh ujian-
ujiannya. Ali tidak belajar tetapi dia beruntung. Setiap orang
yang beruntung akan memenangkan undian.

Pertanyaan :
a. Ubah kalimat di atas ke dalam bentuk logika predikatif.
b. Buktikan dengan teknik resolusi bahwa Ali berbahagia.

28
A. Ubah ke logika predikatif
- x : lulus (x, IS)  menang (x, undian)  bahagia (x)
- x y : belajar (x)  beruntung (x)  lulus (x, y)
- ¬belajar (ali)  beruntung (ali)
- x : beruntung (x)  menang (x, undian)

B. Bentuk klausa dari kalimat di atas


- ¬lulus (x, IS)  ¬menang (x, undian)  bahagia (x) (a)
- ¬belajar (y)  lulus (y, z) (b)
- ¬beruntung (w)  lulus (w, z) (c)
- ¬belajar (ali) (d)
- beruntung (ali) (e)
- ¬beruntung (u)  menang (u, undian) (f)
- ¬bahagia (ali) (g)

29
B. Bentuk klausa dari kalimat di atas
- ¬lulus (x, IS)  ¬menang (x, undian)  bahagia (x) (a)
- ¬belajar (y)  lulus (y, z) (b)
- ¬beruntung (w)  lulus (w, z) (c)
- ¬belajar (ali) (d)
- beruntung (ali) (e)
- ¬beruntung (u)  menang (u, undian) (f)
- ¬bahagia (ali) (g)

Pembuktian : apakah ali berbahagia ?


(a) dan (f) : ¬lulus (u, IS)  ¬beruntung (u)  bahagia (u) (aa)
(aa) dan (g) : ¬lulus (ali, IS)  ¬beruntung (ali) (bb)
(bb) dan (e) : ¬lulus (ali, IS) (cc)
(cc) dan (c) : ¬beruntung (ali) (dd)
(dd) dan (e) : nil (terbukti)

30
¬lulus (x, IS)  ¬menang (x, undian)  bahagia (x) ¬bahagia (ali)

ali/x

¬lulus (x, IS)  ¬menang (x, undian)

¬beruntung (u)  menang (u, undian)


u/x

¬lulus (u, IS)  ¬beruntung (u)

beruntung (ali)

¬lulus (ali, IS)


beruntung (ali)
¬beruntung (w)  lulus (w, z)

¬beruntung (ali)

NIL

31
¬lulus (x, IS)  ¬menang (x, undian)  bahagia (x)

¬beruntung (u)  menang (u, undian)


u/x

¬lulus (u, IS)  ¬beruntung (u)  bahagia (u)

¬bahagia (ali)
ali/u

¬lulus (ali, IS)  ¬beruntung (ali)

beruntung (ali)

¬lulus (ali, IS)


beruntung (ali)
¬beruntung (w)  lulus (w, z)

¬beruntung (ali)

NIL

32
A. FOPL
- x : successful (x)  famous (x)
- x : famous (x)  loved (x)  elected (x)
- loved(jokowi)  successfull (jokowi)
- x : elected (x)  president (x)

B. CNF (Normal Form)


- ¬successful (x)  famous (x)
- ¬famous (x)  ¬loved (x)  elected (x)
- loved (jokowi)
- successful(jokowi)
- ¬elected (x)  president (x)
- ¬president (jokowi)

33
¬elected (x)  president (x)

¬president (jokowi)
jokowi/x

¬elected(jokowi)

¬famous (x)  ¬loved (x)  elected (x)


jokowi/x

¬famous (jokowi)  ¬loved (jokowi)

¬successful (x)  famous (x)

¬successful (x)  ¬loved (jokowi)


successful (jokowi) loved (jokowi)
jokowi/x

¬successful (jokowi)

NIL

34
Build a small genealogy KB that
– contains facts of immediate family relations (spouses,
parents, etc.)
– contains definitions of more complex relations (ancestors,
relatives)
– is able to answer queries about relationships between
people

James I

Charles I Elizabeth

Chaterine Charles II James II Sophia

George I

35
Example: A simple genealogy KB by FOL
• Build a small genealogy knowledge base by FOL that
– contains facts of immediate family relations (spouses, parents, etc.)
– contains definitions of more complex relations (ancestors, relatives)
– is able to answer queries about relationships between people
• Predicates:
– parent(x, y), child (x, y), father(x, y), daughter(x, y), etc.
– spouse(x, y), husband(x, y), wife(x,y)
– ancestor(x, y), descendent(x, y)
– relative(x, y)
• Facts:
– husband(Joe, Mary), son(Fred, Joe)
– spouse(John, Nancy), male(John), son(Mark, Nancy)
– father(Jack, Nancy), daughter(Linda, Jack)
– daughter(Liz, Linda)
– etc.

36
• Rules for genealogical relations
– (x,y) parent(x, y) <=> child (y, x)
(x,y) father(x, y) <=> parent(x, y) ^ male(x) (similarly for mother(x, y))
(x,y) daughter(x, y) <=> child(x, y) ^ female(x) (similarly for son(x, y))
– (x,y) husband(x, y) <=> spouse(x, y) ^ male(x) (similarly for wife(x, y))
(x,y) spouse(x, y) <=> spouse(y, x) (spouse relation is symmetric)
– (x,y) parent(x, y) => ancestor(x, y)
(x,y)(z) parent(x, z) ^ ancestor(z, y) => ancestor(x, y)
– (x,y) descendent(x, y) <=> ancestor(y, x)
– (x,y)(z) ancestor(z, x) ^ ancestor(z, y) => relative(x, y)
(related by common ancestry)
(x,y) spouse(x, y) => relative(x, y) (related by marriage)
(x,y)(z) relative(z, x) ^ relative(z, y) => relative(x, y) (transitive)
(x,y) relative(x, y) => relative(y, x) (symmetric)
• Queries
– ancestor(Jack, Fred) /* the answer is yes */
– relative(Liz, Joe) /* the answer is yes */
– relative(Nancy, Mathews)
/* no answer in general, no if under closed world assumption */

37
ASK (Queries) :
enrolled(mary, 322).
course_mate(jane,harold) !?
enrolled(mary, 312).
Knowledgebase
enrolled(john, 322).
course(312).
enrolled(john, 315).
course(322). enrolled(harold, 322).
course(315). enrolled(mary, 315).
course(371). enrolled(jane, 312).
department(312, comp_science). enrolled(jane, 322).
department(322, comp_science). Rules :
department(315, math). course_mate(S1,S2) :-
in_dept(S1,D) & in_dept(S2,D)
department(371, physics).
in_dept(S, D) :- enrolled(S, C) &
student(mary). department(C, D).
student(jane).
student(john).
student(harold).
female(mary).
female(jane).

38

You might also like