Predicate Logic Second Term Fourth Year (10 CS) 1.

25
Predicate Logic Second Term Fourth Year (10 CS) 1

Transcript of Predicate Logic Second Term Fourth Year (10 CS) 1.

Page 1: Predicate Logic Second Term Fourth Year (10 CS) 1.

1

Predicate Logic

Second Term Fourth Year (10 CS)

Page 2: Predicate Logic Second Term Fourth Year (10 CS) 1.

2

In this course, we shall only study First order Logic (FOL)

Predicate Calculus

First-Order Logic

Higher-Order Logic

Page 3: Predicate Logic Second Term Fourth Year (10 CS) 1.

3

Introduction to FOL• In propositional calculus, each atomic sentence (P, Q etc.)

denotes a proposition of some complexity. There is no way to access the components of an individual assertion. Predicate calculus provides this ability.

• Example:In Propositional logic, we may write the entire sentence:P = “It rained on Tuesday”

In Predicate Calculus, we may create a predicate weather that describes a relationship between a date/day and weather:weather (Tuesday, rained)

Through inference rules, we can manipulate predicate calculus expressions, accessing their individual components and inferring new sentences.

Page 4: Predicate Logic Second Term Fourth Year (10 CS) 1.

4

Introduction to FOL• Predicate calculus allows expressions to contain

variables.• Variables let us create general assertions about

classes of entities:Example: we could state that for all values of X, where X

is a day of the week, the statement weather(X, rain) is true; i.e. It rains everyday.

Page 5: Predicate Logic Second Term Fourth Year (10 CS) 1.

5

Basic terminology• Object: Objects are things with individual identities

and properties that distinguish from other objects.Examples: people, houses, numbers, colours, football matches, 07 CS batch etc.

• Relations: Among objects, various relations hold.Example: brother, greater than, has colour, inside, part of etc.

• Functions: Relations in which there is only value for a given input.Example: father of, best friend, one more than etc.

Page 6: Predicate Logic Second Term Fourth Year (10 CS) 1.

6

BasicsExample 1: One plus two equals threeObjects: one, two, three, one plus two.Relation: equalsFunction: plus

Example 2: President Musharaf ruled Pakistan in 2004.Objects: Musharaf, Pakistan, 2004.Relation: ruledProperties: President

Page 7: Predicate Logic Second Term Fourth Year (10 CS) 1.

7

Basics• In Propositional Logic, every expression is a sentence

which represents a fact.• FOL has sentences and terms (which represent

objects)• Constant symbols, variables, and function symbols

are used to build terms• Quantifiers and predicate symbols are used to build

sentences.

Page 8: Predicate Logic Second Term Fourth Year (10 CS) 1.

8

Syntax of FOL• Connectives: , , , • Quantifiers: , • Constants: A, X1, C, Akber, ...• Variables: a, x, s, ...• Predicate: before, HasColor, ...• Function: father, rightArmof, ...

Page 9: Predicate Logic Second Term Fourth Year (10 CS) 1.

9

BasicsExamples:• Ahmad likes Chocolates.

likes(Ahmad , Chocolates)• Asma loves dolls and jewellery.

likes(Asma, dolls)likes(Asma, jewellery)• Asim and Adil are brothers of Abid

brother(Abid, Asim)brother(Abid, Adil)• Akhtar is older than 20 or Akhtar is younger than 20.

older(Akhtar, 20)younger(Akhtar,20)• If Akhtar is older than 20, then he is not younger than 20.

older(Akhtar, 20) younger(Akhtar, 20)• Father of Jawad is Munir

father(Jawad) = Munir

Page 10: Predicate Logic Second Term Fourth Year (10 CS) 1.

10

BasicsExamples:• Father of Sarah and Uncle of Shahid are friends.

friends(father_of(Sarah), uncle_of(Shahid))• All Shaikhs are not Sindhi.

x: Shaikh(x) Sindhi(x)• All men are mortal

x: man(x) mortal(x)• All basket ball players are tall

x: (basketball_player(x) tall(x))• Everyone likes ice cream

x: likes(x, ice_cream)

Page 11: Predicate Logic Second Term Fourth Year (10 CS) 1.

11

BasicsExamples:• If wishes were horses, beggars would ride equal(wishes, horses) ride(beggars)• There exists some bird that does not fly

x: bird(x) flies(x)• Sanya eats everything that she likes

x: (likes(Sanya, x) eats(Sanya,x))• There exists a white allegator

x: allegator(x)white(x)• No body likes taxes

x: likes(x, taxes)

Page 12: Predicate Logic Second Term Fourth Year (10 CS) 1.

12

More Examples• Every gardener likes the sun

x: gardener(x) likes(x, sun)• All purple mushrooms are poisonous

x: (mushroom(x)purple(x)) poisonous(x)• No purple mushroom is poisonous

x: (mushroom(x)purple(x)) poisonous(x)• Everybody loves somebody

x y loves(x,y)• There is someone who is loved by everyone

y x loves(x,y)

Page 13: Predicate Logic Second Term Fourth Year (10 CS) 1.

13

Using FOLAssertions and queries in FOL

Sentences are added to a knowledge base (KB) using TELL. Such sentences are called assertions.Examples:TELL(KB, prime_minister(Geelani))TELL(KB, King(Baber))TELL(KB, x King(x) Person(x))

Page 14: Predicate Logic Second Term Fourth Year (10 CS) 1.

14

Using FOLQueries

We ask questions of the knowledge base using ASK. Questions asked using ASK are called queries:ASK(KB, prime_minister(Geelani))ASK(KB, King(Baber))ASK(KB, x King(x) Person(x))

Page 15: Predicate Logic Second Term Fourth Year (10 CS) 1.

15

Using FOLThe Kinship Domain

• The objects in the Kinship domain are people• The properties they have include gender and they related by

relations such as parenthood, brotherhood, marriage and so on.Examples: one’s mother is one’s female parent

m,c Mother(c) = m female(m) Parent(m,c) One’s husband is one’s male spouse

w, h Husband(h,w) Male(h) Spouse(h,w) Male and female are disjoint categories

x Male(x) Female(x)

Page 16: Predicate Logic Second Term Fourth Year (10 CS) 1.

16

Using FOL

The Kinship Domain Parent and child are inverse relations:

p,c Parent(p,c) Child(c,p) A grand parent is a parent of one’s

parentg,c Grandparent(g,c) Parent(g,p) parent(p,c)

Page 17: Predicate Logic Second Term Fourth Year (10 CS) 1.

17

Building a Knowledge Base• An important objective of Knowledge engineering is

to build knowledge base.• Following five steps may be used to develop a

knowledge base. Step1: Decide what to talk about. Step2: Decide on a vocabulary of predicates, functions and

constants. Step3: Encode general knowledge about the domain Step4: Encode a description of the specific problem

instance. Step5: Pose queries to the inference procedure and get

answers.

Page 18: Predicate Logic Second Term Fourth Year (10 CS) 1.

18

Example: Electronic Circuit Domain

Step1: Decide what to talk about:Before developing knowledge base, you should know:• that there are four types of gates: AND, OR, XOR and NOT.• How each gate works• How the gates are connected in the given circuit• How current flows through the circuit

Page 19: Predicate Logic Second Term Fourth Year (10 CS) 1.

19

Example: Electronic Circuit Domain

Step2: Decide on a vocabulary• Introduce the predicate Type to define type of a gate. • Introduce the predicate Connected to define connections.• Introduce the predicate Signal to define current flow.• Use the predicate In and Out to define input and output

respectively.• Use the connectives , , , , etc. and quantifiers , etc.

wherever necessary.

Page 20: Predicate Logic Second Term Fourth Year (10 CS) 1.

20

Example: Electronic Circuit Domain

Step3: Encode general rulesRule 1: If two terminals are connected, then they have the same signal.

t1, t2 Connected(t1, t2) Signal(t1) = Signal(t2)

Rule 2: The signal at every terminal is either ON or OFF (but not both).t Signal(t) = On Signal(t) = OffOn Off

Rule 3: Connected is a commutative predicatet1, t2 Connected(t1, t2) Connected(t2, t1)

Page 21: Predicate Logic Second Term Fourth Year (10 CS) 1.

21

Example: Electronic Circuit Domain

Rule 4: An OR gate’s output is on if and only if any of inputs are on.g Type(g) = OR Signal(Out(1,g)) = On n Signal(In(n,g)) = On

Rule 5: An AND gate’s output is Off if and only if any of its inputs are off.g Type(g) = AND Signal(Out(1,g)) = Off n Signal(In(n,g)) = Off

Page 22: Predicate Logic Second Term Fourth Year (10 CS) 1.

22

Example: Electronic Circuit Domain

Rule 6: An Exclusive OR gate’s output is on if and only if its inputs are differentg Type(g) = XOR Signal(Out(1,g)) = On

Signal(In(1,g)) Signal(In(2,g))Rule 7: A NOT gate’s output is different from its input

g Type(g) = NOT Signal(Out(1,g)) Signal(In(1,g))

Page 23: Predicate Logic Second Term Fourth Year (10 CS) 1.

23

Step 4: Encode the specific instance

(a) Categorize the gatesType(X1) = XOR Type(X2) = XOR Type(A1) = AND

Type(A2) = AND Type(O1) = OR

(b) Define the ConnectionsConnected(Out(1, X1), In(1,X2)) Connected(In(1,C1), In(1,X1))

Connected(Out(1, X1), In(2,A2)) Connected(In(1,C1), In(1,A1))

Connected(Out(1, A2), In(1,O1)) Connected(In(2,C1), In(2,X1))

Connected(Out(1, A1), In(2,O1)) Connected(In(2,C1), In(2,A1))

Connected(Out(1, X2), Out(1,C1)) Connected(In(3,C1), In(2,X2))

Connected(Out(1, O1), In(2,C1)) Connected(In(3,C1), In(1,A2))

Page 24: Predicate Logic Second Term Fourth Year (10 CS) 1.

24

Example: Electronic Circuit Domain

Step 5: Pose queries to the inference procedure(i) What combinations of inputs would cause the first output of C1 (the

sum bit) to be OFF and the second output of C1 to be ON?

i1, i2, i3 Signal(In(1,C1)=i1 Signal(In(2,C1) = i2 Signal(In(3,C1) = i3Signal(Out(1,C1) = Off Signal(Out(2,C1) =On

The answer is:(i1 = On i2 = On i3 = Off) (i1 = On i2 = Off i3 = On)

(i1 = Off i2 = On i3 = On)

Page 25: Predicate Logic Second Term Fourth Year (10 CS) 1.

25

Example: Electronic Circuit Domain

Step 5: Pose queries to the inference procedure(ii) What are the possible set of values of all the terminals for

the circuiti1, i2, i3, o1, o2 Signal(In(1,C1)=i1 Signal(In(2,C1) = i2

Signal(In(3,C1) = i3Signal(Out(1,C1) = o1 Signal(Out(2,C1) =o2

This query will return a complete input/output table for the circuit, which can be used to check that it does in fact add its inputs correctly.