Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 FOL CS 331/531 Dr M M Awais Composition Find Overall Substitutions Given two or more sets of substitutions.

Similar presentations


Presentation on theme: "1 FOL CS 331/531 Dr M M Awais Composition Find Overall Substitutions Given two or more sets of substitutions."— Presentation transcript:

1 1 FOL CS 331/531 Dr M M Awais Composition Find Overall Substitutions Given two or more sets of substitutions

2 2 FOL CS 331/531 Dr M M Awais Composition Domain: Variables in the substitution together form the domain (denominators) S1={a/X1, b/X2, …z/Xn} Then Dom(S1)={X1, X2, …Xn} St={a/B} B is the domain or Dom(St) Replacements: Terms are the replacements (numerators) Rep(S1)={a,b,…z} St={a/B}a is the replacement or Rep(St)

3 3 FOL CS 331/531 Dr M M Awais Composition Rule Two substitutions S1 and S2 can compose in two ways: S1 composed with S2S12 or S1.S2 S2 composed with S1S21 or S2.S1 S12 is obtained by applying S2 to S1 Adding S2 to the set obtained in step 1 Removing substitutions from the above (newly added substitutions i.e., S2 that have Dom(S2)=Dom(S1)

4 4 FOL CS 331/531 Dr M M Awais Step 1: Applying S2 to S1 Finding Dom(S2) Finding Rep(S1) If elements of Dom(S2) = elements of Rep(S1) S2 applies to S1 otherwise does not. Example: S1={W/A,e/D}, S2={s/W,g/K} Step 1: Dom(S2)={W, K}, Rep(S1)={W,e}, W matches hence apply (S2 to S1) s/W to W/A generate s/A Hence the new set obtained after applying S2 to S1 is: S12={s/A,e/D}

5 5 FOL CS 331/531 Dr M M Awais Step 2&3: Add+Drop Step 2: Add S2 to S12={s/A,e/D} S12={s/A,e/D, s/W,g/K} Step 3: Drop any where Dom(S2)=Dom(S12 in step 1) from substitutions of S2 added in step 2. Nothing gets dropped Final Answer: S12={s/A,e/D, s/W,g/K}

6 6 FOL CS 331/531 Dr M M Awais Composition S1={A/D} S2={D/X} What is possible S12 or S21 or both? D is in the domain in S1, and replacement in S2 A is the replacement in S1 X is the domain in S2 S1 can be applied to S2, as the domain of S1(D) is the replacement in S2. Hence S2 modifies as {A/X} S2 cannot be applied to S1, as the domain of S2 is not a replacement in S1, S1 remains{A/D}

7 7 FOL CS 331/531 Dr M M Awais Composition S1={A/K} replacements=A, domain=K S2={a/A} replacements=a, domain=A S21 Apply S1 to S2 Cannot be applied as K is not a replacement in S2.{a/A} Non Composable S12 Apply S2 t S1 Can be applied, as A is a replacement in S1, {a/K} Composable

8 8 FOL CS 331/531 Dr M M Awais Composition S1={A/K,f/M} replacements=A,f domain=K,M S2={a/A,j/R} replacements=a,j domain=A,R Apply S1 to S2 A/K Cannot be applied as K is not a replacement in S2. F/M Cannot be applied as M is not a replacement in S2 {a/A,j/R} Non Composable Apply S2 t S1 a/A can be applied, as A is a replacement in S1, {a/K} J/R cannot be applied as R is not a replacement in S1 {a/K, f/M} Composable

9 9 FOL CS 331/531 Dr M M Awais Example S1={A/K} S2={a/A, H/J} S12={a/K, a/A,H/J} Algorithm 1. Apply S2 to S1 (find overall substitution) and generate a modified S1 2. Add to the answer in Step 1 all the substitutions of S2 (combined +uncombined) 3. Drop all substitutions in S2 which have common denominators with S12

10 10 FOL CS 331/531 Dr M M Awais Example: S12 S1={A/K} S2={a/A, H/J} Algorithm for S12: Apply S2 to S1 See if A and J are present among the replacements of S1 if Yes replace A with a and J with H This would generate {a/K} Add S2 to S1 (Modified S1 in step 1+ all of S2) Modified S1={a/K} + {a/A,H/J} Drop all substitutions in S2 which have common denominators with S1 nothing gets dropped, hence the answer is S12={a/K,a/A,H/J}

11 11 FOL CS 331/531 Dr M M Awais Example: S21 S1={A/K} S2={a/A, H/J} Algorithm for S21: Apply S1 to S2 See if K is present among the replacements of S2 if Yes replace K with A (no change in S2) This would generate {a/A, H/J} Add S1 to S2 (Modified S2 in step 1+ all of S1) Modified S1={a/A,H/J}+{A/K} Drop all substitutions in S1 which have common denominators with S2 nothing gets dropped, hence the answer is S12={a/A,H/J,A/K}

12 12 FOL CS 331/531 Dr M M Awais Example S1={D/A} S2={a/D} S12 Step 1: Combining (S2 to S1)S12={a/A} Step 2:Addition (Add S2)S12={a/A}+{a/D} Step 3: DropS12={a/A,a/D} S1={D/A,S/G,n/N} S2={x/X, f/D, q/S,w/A} S12 Step 1:CombiningS12={f/A,q/G,n/N} Step 2:Addition S12={f/A,q/G,n/N}+{x/X, f/D, q/S,w/A} Step 3: DropS12={f/A,q/G,n/N,x/X,f/D,q/S}

13 13 FOL CS 331/531 Dr M M Awais Is S12 same as S21 S1={D/A} S2={a/D} S21 Step 1: Combine (S1 to S2)S2={a/D} Combination cannot possible because no A is present in S2, so cannot replace with D, output is same as S2 Step 2: AddS21={a/D}+{D/A} Step 3: DropS21={a/D,D/A} S1={D/A,S/G,n/N} S2={x/X, f/D, q/S,w/A} S21 Step 1: CombineS2={ x/X, f/D, q/S,w/A } Step 2: AddS2={ x/X, f/D, q/S,w/A }+{D/A,S/G,n/N} Step 3: DropS21={ x/X, f/D, q/S,w/A, S/G,n/N}

14 14 FOL CS 331/531 Dr M M Awais Is S12 same as S21 S1={D/A} S2={X/A} S12={D/A} Combine:S12={D/A} Add:S12={D/A}+{X/A} Drop:S12={D/A} X/A gets dropped S21={X/A} Combine:S21={X/A} Add:S21={X/A}+{D/A} Drop:S21={X/A} D/A gets dropped

15 15 FOL CS 331/531 Dr M M Awais Example S1={D/A, d/F,S/E} S2={g/D} S12={g/A, d/F, S/E, g/D} S12={g/A, d/F, S/E, g/D} (nothing gets dropped) S21={g/D, D/A, d/F, S/E} S21={g/D, D/A,d/F,S/E} (nothing gets dropped)

16 16 FOL CS 331/531 Dr M M Awais Example S1={a/A,b/B,c/C} S2={A/X,B/Y,S/Q} S12={a/A,b/B,c/C} + {A/X,B/Y,S/Q} S12={a/A, b/B, c/C, A/X, B/Y, S/Q} S21= {a/X, b/Y, S/Q} + {a/A,b/B,c/C} S21={a/X, b/Y, S/Q, a/A, b/B, c/C}

17 17 FOL CS 331/531 Dr M M Awais Substitution: Discussion Domain: Variables in the substitution together form the domain (denominators) Replacements: Terms are the replacements (numerators) Pure Vs Impure Substitutions: A pure substitution is if all replacements are free of the variables in the domain of the substitution. Otherwise impure {s/X, t/I, j/G} (pure) The composition of pure substitutions may be impure and vice versa Composability:

18 18 FOL CS 331/531 Dr M M Awais Application Example Knowledge base: knows(ali,sana) knows(X,shahid)knows(X,Y) We also know knows(ali,X)  hates(ali,X) Unify the conditions to find ali hates whom unify(knows(ali,X), knows(ali,sana)) = {sana/X} Using the binding and the rule: ali hates sana unify(knows(ali,X), knows(X,shahid)) = {ali/X,shahid/X} This would fail as X cannot have two values at the same time As the composition of {ali/X} with {shahid/X} or vice versa will result in only one valid substitution unify(knows(ali,X), knows(X,Y)) = {ali/X,X/Y} This would mean that ali knows everyone including himself, therefore hates everyone.

19 19 FOL CS 331/531 Dr M M Awais Unification “It is an algorithm for determining the substitutions needed to make two predicate calculus expressions match” Reference: Luger’s Book chapter 3, 2 nd edition

20 20 FOL CS 331/531 Dr M M Awais Implementation of Unification Using“List format” (PNF have already been discussed) PC SyntaxList Syntax p(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))

21 21 FOL CS 331/531 Dr M M Awais Unification: Examples Unify ( (parents X(father X) (mother bill)), (parents bill (father bill)Y) ). Complete Substitution {bill/X, mother (bill)/Y}

22 22 FOL CS 331/531 Dr M M Awais

23 23 FOL CS 331/531 Dr M M Awais

24 24 FOL CS 331/531 Dr M M Awais

25 25 FOL CS 331/531 Dr M M Awais Logic – Based Financial Advisor To help a user decide whether to invest in a saving A/C or the stock market or both

26 26 FOL CS 331/531 Dr M M Awais Policy: Saving inadequate - should invest in saving A/c regardless of income Saving adequate and adequate income - More profitable option of stock investment Low Income & adequate savings - Split surplus between saving and stock investment

27 27 FOL CS 331/531 Dr M M Awais Defining Constraints Adequate Savings/Income: Income:Rs 15,000/month extra Rs 4000/ dependent/month Saving:Rs 25,000/year extra Rs 5000/dependent/year

28 28 FOL CS 331/531 Dr M M Awais Calculating Adequacy Define 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

29 29 FOL CS 331/531 Dr M M Awais Outputs Investment (savings) Investment (stocks) Investment (combination) How can we represent outputs?

30 30 FOL CS 331/531 Dr M M Awais Rules  saving_acc (inadequate)  investment (savings)  saving_acc(adequate) ^ income(adequate)  investment(stocks)  saving_acc (adequate) ^ income (inadequate)  investment (combination)

31 31 FOL CS 331/531 Dr M M Awais What next? Define saving adequate Define saving inadequate Define income adequate Define income inadequate

32 32 FOL CS 331/531 Dr M M Awais Savings Check if saved amount is greater than the minimum saving required

33 33 FOL CS 331/531 Dr M M Awais Income Check if the income is greater than the minimum income

34 34 FOL CS 331/531 Dr M M Awais Try firing rules with 9, 10, 11

35 35 FOL CS 331/531 Dr M M Awais Example knowledge base The 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 criminal Solution presented using alternate syntax Reference: Norviq and Russell

36 36 FOL CS 331/531 Dr M M Awais Example 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,M 1 ) and Missile(M 1 )(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)

37 37 FOL CS 331/531 Dr M M Awais Example knowledge base contd. 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., R2 R2:  x Owns(Nono,x)  Missile(x) … all of its missiles were sold to it by Colonel West R3 R3: 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“: R5 R5: Enemy(x,America)  Hostile(x) Database of Facts: Owns(Nono,M 1 ) ^ Missile(M 1 ) West, who is American … American(West) The country Nono, an enemy of America … Enemy(Nono,America)

38 38 FOL CS 331/531 Dr M M Awais 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

39 39 FOL CS 331/531 Dr M M Awais 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)

40 40 FOL CS 331/531 Dr M M Awais 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)

41 41 FOL CS 331/531 Dr M M Awais 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)

42 42 FOL CS 331/531 Dr M M Awais Backward chaining example West/x

43 43 FOL CS 331/531 Dr M M Awais Backward chaining example West/x

44 44 FOL CS 331/531 Dr M M Awais Backward chaining example West/x

45 45 FOL CS 331/531 Dr M M Awais Backward chaining example West/x, M1/y M1/y

46 46 FOL CS 331/531 Dr M M Awais Backward chaining example West/x, M1/y, Nono/z M1/y Nono/z

47 47 FOL CS 331/531 Dr M M Awais Backward chaining example West/x, M1/y, Nono/z M1/y Nono/z

48 48 FOL CS 331/531 Dr M M Awais Backward chaining example West/x, M1/y, Nono/z M1/y Nono/z


Download ppt "1 FOL CS 331/531 Dr M M Awais Composition Find Overall Substitutions Given two or more sets of substitutions."

Similar presentations


Ads by Google