View
220
Download
2
Tags:
Embed Size (px)
Citation preview
CS 331/531 Dr M M Awais 1
FOL
Unification
“It is an algorithm for determining the substitutions needed to make two predicate calculus
expressions match”
Reference: Luger’s Book chapter 3, 2nd edition
CS 331/531 Dr M M Awais 2
FOL
Implementation of Unification
Using“List format” (PNF have already been discussed)
PC Syntax List Syntaxp(a,b) (p a b) p(f(a), g(X,Y)) (p(f a)(g X Y)) p(x) ^ q(y) ((p x) ^ (q y))
CS 331/531 Dr M M Awais 3
FOL
Unification: Examples
Unify(
(parents X(father X) (mother bill)), (parents bill (father bill)Y)
).
Complete Substitution
{bill/X, mother (bill)/Y}
CS 331/531 Dr M M Awais 7
FOL
Logic – Based Financial Advisor
To help a user decide whether to invest in a saving A/C or the stock market or both
CS 331/531 Dr M M Awais 8
FOL
Policy:Saving inadequate - should invest in saving A/c regardless of income
Saving adequateand adequate income - More profitable option of stock investment
Low Income& adequate savings - Split surplus between saving and stock investment
CS 331/531 Dr M M Awais 9
FOL
Defining ConstraintsDefining Constraints
Adequate Savings/Income:Income: Rs 15,000/month
extra Rs 4000/ dependent/month
Saving: Rs 25,000/yearextra Rs
5000/dependent/year
CS 331/531 Dr M M Awais 10
FOL
Calculating AdequacyDefine Functions to calculate the minimum
income and savings
Minimum Savings: min_saving(X)min_saving(X)=25000+5000*X
Minimum Income: min_income(X)
min_income(X)=15000+4000*X
where X are the number of dependents
CS 331/531 Dr M M Awais 11
FOL
Outputs
Investment (savings)Investment (stocks)Investment (combination)
How can we represent outputs?
CS 331/531 Dr M M Awais 12
FOL
Rules saving_acc (inadequate) investment (savings)
saving_acc(adequate) ^ income(adequate) investment(stocks)
saving_acc (adequate) ^ income (inadequate) investment (combination)
CS 331/531 Dr M M Awais 13
FOL
What next? Define saving adequate Define saving inadequate Define income adequate Define income inadequate
CS 331/531 Dr M M Awais 14
FOL
Savings
Check if saved amount is greater than the minimum saving required
)(_
))(min_,(^)((^)(_
adequateaccsaving
YsavingXgreaterYdependantsYXsavedamtX
)(_
))(min_,(^)((^)(_
inadequateaccsaving
YsavingXgreaterYdependantsYXsavedamtX
CS 331/531 Dr M M Awais 15
FOL
Income
Check if the income is greater than the minimum income
)(
))(_,(^)((^),(
adequateincome
YincomemixgreaterYdependantsYsteadyXearningsX
)(
))(_,(^)((^),(
inadequateincome
YincomemixgreaterYdependantsYsteadyXearningsX
)(),( inadequateincomeunsteadyXearningsX
CS 331/531 Dr M M Awais 17
FOL
Example knowledge baseThe law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.
Prove that Col. West is a criminalProve that Col. West is a criminal
Solution presented using alternate syntaxReference: Norviq and Russell
CS 331/531 Dr M M Awais 18
FOLExample knowledge base contd.
... it is a crime for an American to sell weapons to hostile nations:American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)Nono … has some missiles, i.e., X Owns(Nono,x) Missile(x):
Owns(Nono,M1) and Missile(M1) (skolemization)… all of its missiles were sold to it by Colonel West
Missile(x) Owns(Nono,x) Sells(West,x,Nono)Missiles are weapons:
Missile(x) Weapon(x)An enemy of America counts as "hostile“:
Enemy(x,America) Hostile(x)West, who is American …
American(West)The country Nono, an enemy of America …
Enemy(Nono,America)
CS 331/531 Dr M M Awais 19
FOLExample knowledge base contd.
Rule Base:Rule Base:... it is a crime for an American to sell weapons to hostile nations:
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
Nono … has some missiles, i.e., R2R2: x Owns(Nono,x) Missile(x)
… all of its missiles were sold to it by Colonel WestR3R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono)
Missiles are weapons:R4:R4: Missile(x) Weapon(x)
An enemy of America counts as "hostile“:R5R5: Enemy(x,America) Hostile(x)
Database of Facts:Database of Facts:Owns(Nono,M1) ^ Missile(M1)
West, who is American …American(West)
The country Nono, an enemy of America …Enemy(Nono,America)
CS 331/531 Dr M M Awais 20
FOL
•START FROM THE FACTS•THINK WHICH RULES APPLY
Be careful about the convention constants start with capital letters and variables with small (applicable to next few slides)
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
R2: x Owns(Nono,x) Mssile(x)R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono)R4: Missile(x) Weapon(x)R5: Enemy(x, America) Hostile(x)
1. FORWARD CHAINING
CS 331/531 Dr M M Awais 21
FOL
R4{M1/x}
R3{M1/x}
R5{Nono/x}
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
R2: x Owns(Nono,x) Mssile(x)R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono)R4: Missile(x) Weapon(x)R5: Enemy(x, America) Hostile(x)
CS 331/531 Dr M M Awais 22
FOL
R1{West/x , M1/y , Nono/z}
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
R2: x Owns(Nono,x) Mssile(x)R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono)R4: Missile(x) Weapon(x)R5: Enemy(x, America) Hostile(x)
CS 331/531 Dr M M Awais 23
FOL
2. BACKWARD CHAINING
•START FROM THE CONCLUSION•THINK IS THE RULE SUPPORT AVAILABLE
R1: American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
R2: x Owns(Nono,x) Mssile(x)R3: Missile(x) Owns(Nono,x) Sells(West,x,Nono)R4: Missile(x) Weapon(x)R5: Enemy(x, America) Hostile(x)