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

## Presentation on theme: "Predicate Logic Second Term Fourth Year (10 CS) 1."— Presentation transcript:

Predicate Logic Second Term Fourth Year (10 CS) 1

In this course, we shall only study First order Logic (FOL) Predicate Calculus Predicate Calculus First-Order Logic Higher-Order Logic 2

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. 3

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. 4

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. 5

Basics Example 1: One plus two equals three Objects: one, two, three, one plus two. Relation: equals Function: plus Example 2: President Musharaf ruled Pakistan in 2004. Objects: Musharaf, Pakistan, 2004. Relation: ruled Properties: President 6

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. 7

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

Basics Examples: 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 9

Basics Examples: 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) 10

Basics Examples: 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) 11

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) 12

Using FOL Assertions 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)) 13

Using FOL The 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: ones mother is ones female parent m,c Mother(c) = m female(m) Parent(m,c) Ones husband is ones male spouse w, h Husband(h,w) Male(h) Spouse(h,w) Male and female are disjoint categories x Male(x) Female(x) 15

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 ones parent g,c Grandparent(g,c) Parent(g,p) parent(p,c) 16

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. 17

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 18

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. 19

Example: Electronic Circuit Domain Step3: Encode general rules Rule 1: If two terminals are connected, then they have the same signal. t 1, t 2 Connected(t 1, t 2 ) Signal(t 1 ) = Signal(t 2 ) Rule 2: The signal at every terminal is either ON or OFF (but not both). t Signal(t) = On Signal(t) = Off On Off Rule 3: Connected is a commutative predicate t 1, t 2 Connected(t 1, t 2 ) Connected(t 2, t 1 ) 20

Example: Electronic Circuit Domain Rule 4: An OR gates 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 gates 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 21

Example: Electronic Circuit Domain Rule 6: An Exclusive OR gates output is on if and only if its inputs are different g Type(g) = XOR Signal(Out(1,g)) = On Signal(In(1,g)) Signal(In(2,g)) Rule 7: A NOT gates output is different from its input g Type(g) = NOT Signal(Out(1,g)) Signal(In(1,g)) 22

Step 4: Encode the specific instance (a) Categorize the gates Type(X 1 ) = XOR Type(X 2 ) = XORType(A 1 ) = AND Type(A 2 ) = ANDType(O 1 ) = OR (b) Define the Connections Connected(Out(1, X 1 ), In(1,X 2 )) Connected(In(1,C 1 ), In(1,X 1 )) Connected(Out(1, X 1 ), In(2,A 2 )) Connected(In(1,C 1 ), In(1,A 1 )) Connected(Out(1, A 2 ), In(1,O 1 )) Connected(In(2,C 1 ), In(2,X 1 )) Connected(Out(1, A 1 ), In(2,O 1 )) Connected(In(2,C 1 ), In(2,A 1 )) Connected(Out(1, X 2 ), Out(1,C 1 ))Connected(In(3,C 1 ), In(2,X 2 )) Connected(Out(1, O 1 ), In(2,C 1 )) Connected(In(3,C 1 ), In(1,A 2 )) 23

Example: Electronic Circuit Domain Step 5: Pose queries to the inference procedure (i) What combinations of inputs would cause the first output of C 1 (the sum bit) to be OFF and the second output of C 1 to be ON? i 1, i 2, i 3 Signal(In(1,C 1 )=i 1 Signal(In(2,C 1 ) = i 2 Signal(In(3,C 1 ) = i 3 Signal(Out(1,C 1 ) = Off Signal(Out(2,C 1 ) =On The answer is: (i 1 = On i 2 = On i 3 = Off) (i 1 = On i 2 = Off i 3 = On) (i 1 = Off i 2 = On i 3 = On) 24

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 circuit i 1, i 2, i 3, o 1, o 2 Signal(In(1,C 1 )=i 1 Signal(In(2,C 1 ) = i 2 Signal(In(3,C 1 ) = i 3 Signal(Out(1,C 1 ) = o 1 Signal(Out(2,C 1 ) =o 2 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. 25