CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

35
CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany

Transcript of CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Page 1: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

CS-554Part-3: First-Order Logic

By

Dr. Syed Noman Hasany

Page 2: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Propositional Logic and limitation

• Propositional logic allows us to represent statements about the world using logical symbols.

• However, propositional logic is limited in its expressiveness.

• Consider the following examples:

Page 3: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Examples

• In propositional logic the statement ‘Ali loves Makkah’ would simply be represented by a propositional variable, e.g. p.

• Similarly the statement ‘EveryMuslim loves Makkah’ would also be represented by a propositional variable, e.g. p.

• And the same is true for the following statement: ‘Some people are scared of heights’.

• However, all the above statements have obvious differences in the objects to which they are referring.

Page 4: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Problem with Propositional Logic

• So, the problem with propositional logic is that it treats simple propositions as unanalysed wholes and thus it does not allow us to refer to the objects that are treated by propositions.

• Consider this further example:

Page 5: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Further Example

• In propositional logic we can only distinguish between propositions such as ‘Saad is a man’ and ‘Waqas is a man’ by using crude propositions such as p1 and p2

• When we make a statement about some object, e.g. ‘the sky is blue’, we want to be able to symbolise both the claim and the object about which the claim is made.

• We have no way of expressing this in propositional logic.

• So, we turn to first-order predicate logic which does give us some further expressivity…

Page 6: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

First-Order Logic• In first-order logic we call the claim a predicate and

we say that we are predicating some property of the object.

• So, in the previous example of ‘the sky is blue’, the predicate is the ‘is blue’ part and the object is ‘the sky’.

• As well as stating properties of objects we also wish to talk about relations between objects.

For example, in the statement ‘2 is half of 4’, the relation part is ‘is half of’.

Page 7: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Quantifiers

• In addition to objects, predicates and relations we also have the quantifiers of first-order logic.

• To enable us to express statements like ‘All humans are mortal’ and ‘Some people are scared of heights’ predicate logic provides us with quantifiers.

• There are two such quantifiers:– The universal quantifier, which denotes

‘every’ and its symbol is – The existential quantifier, which denotes

‘some’ and its symbol is

Page 8: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Combining Statements

• To combine atomic statements to form compound ones we use the same connectives that we have in propositional logic, i.e.:

Conjunction (and): Λ

Disjunction (or): v Negation (not): ¬ Implication (if..then): → Equivalence (if and only if): ↔

Page 9: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Constant and Variable Symbols

• The symbols we use to represent objects in first-order logic can be either constants or variables.

• Constants are objects that never change, for example, natural numbers, e.g.

greaterThan(5,2)

• Variables are objects that are not fixed, for example,

loves(x,y)

Page 10: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage

• Given the previous definitions, we will now consider how they are used in first-order predicate logic.

• Consider the statement ‘Waqas is a man’. This may be represented as man(waqas). Similarly, ‘Saad is a man’ can be represented as man(saad).

• In these examples both ‘w’ (Waqas) and ‘s’ (Saad) are the objects and ‘man’ is the predicate that stands for ‘is a man’.

• This is known as prefix notation because the object is prefixed by the predicate.

Page 11: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage

• For example, the statement ‘Humans are mortal’ can be represented as:

human(x) → mortal(x)

This reads as: ‘if someone (x) is a human then he/she (x) is mortal’.

Page 12: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage

• In predicate logic the statement ‘Humans are mortal’ is understood to mean ‘Every human is mortal’

• So, we make use of the universal quantifier and we can symbolise this more precisely as:

x (human(x) → mortal(x))

This now reads: ‘for all x, if x is a human, then x is mortal’.

Page 13: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage

• Symbolise the statement ‘Some cars are red’ as:

x (car(x) Λ isRed(x))

This now reads as:

‘there exists some x, such that x is a car, and x is red’.

Page 14: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage (Binary predicate)

• The two previous examples involve only one object (i.e. they are unary predicates).

• We can extend the statements to allow for further objects to be referred to, for example:

x (evenNumber(x) → divisible(x,2))

This reads: ‘for all x, such that x is an even number, then x is divisible by 2’.

Note: divisible is a binary predicate.

Page 15: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

FOL (First-order predicate calculus)

• Predicate logic includes a richer ontology:

• -objects (terms)

• -properties (unary predicates on terms)

• -relations (n-ary predicates on terms)

• -functions (mappings from terms to other terms)

Page 16: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Usage

• Statement: ‘Everyone loves someone’ we have:

x y loves(x,y)

This reads as: ‘for all x, there exists a y such that x loves y’.

• Statement: ‘Every natural number is either even or odd’ we have:

x (naturalNumber(x) → (even(x) V odd(x)))

This reads as: ‘for all x, such that x is a natural number, then x is even or x is odd’.

Page 17: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

17

Caution

• The quantifiers are required to be put in the correct place.

• Consider the previous example: ‘Everyone loves someone’ we have:

x y loves(x,y)

• Now consider the statement: ‘There is someone who is loved by everyone’. In this case we have:

y x loves(x,y)x y loves(x,y): someone loves all

Page 18: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Nested Quantifiers• Combinations of universal and existential

quantification are possible:

( , ) ( , )

( , ) ( , )

( , ) ( , )

( , ) ( , )

, { }

x yFather x y y x Father x y

x yFather x y y x Father x y

x y Father x y y x Father x y

x yFather x y y x Father x y

x y All people

Order is important: Everyone is the father of someone. There is a person who has everyone as a father. There is a person who is the father of everyone. Everyone has a father.

Page 19: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

19

Quantifiers• Have you noticed a specific feature with the use of the

quantifiers?

• Statements involving the universal quantifier ( are used with the implication connective (→).

• Statements involving the existential quantifier ( are used with the conjunction connective (Λ).

• Because statements involving the universal quantifier are read as ‘For all…then…’

• And statements involving the existential quantifier are read as ‘Some …are both …and…’

Page 20: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Quantifiers and Connectives• Convert to English::

• ∀x At(x, Qassim) isSmart(x)⇒• Everyone at Qassim is smart.• ∀x At(x, Qassim) isSmart(x)∧• Everyone is at Qassim. Everyone is smart. This is probably not what you wanted to write. It’s

also a very common mistake. Remember – use with , not .⇒ ∀ ∧• ∃x At(x, Qassim) isSmart(x)⇒• Contrary to what many people think, this statement does not say that there is a person at

Qassim who is smart. It says that if there is at least one person who, if he is at Qassim, is also smart. And if he isn’t, who knows. While it’s possible the author meant this, in most cases this is an error. Remember – use with , not . Applying implication elimination, you could also ∧ ∃ ⇒write:

• ∃x ¬At(x, Qassim) isSmart(x)∨• which means there exists at least one person who either doesn’t go to Qassim or who is smart

(whether he’s at Qassim or not).• If you build a truth table for this statement you’ll find that it is false when someone attends

Qassim and none of them are smart and is true all other times - if there is someone at Qassim who is smart and if nobody attends Qassim. Implicative rules are always true if the antecedent – the if part – is false, with the reasoning that you can’t test the rule and as a result can’t violate it.

• ∃x At(x, Qassim) isSmart(x)∧

Page 21: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

FOL Grammar

• Sentence AtomicSentence | Sentence Connective Sentence | Quantifier Variable Sentence

| Sentence | (Sentence)• AtomicSentence Predicate(Term, Term, ...) |

Term=Term• Term Function(Term,Term,...) | Constant | Variable• Connective | | | • Quanitfier | • Constant A | John | Car1• Variable x | y | z |...• Predicate Brother | Owns | ...• Function father-of | plus | ...

Page 22: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

22

Connections Between and • The universal and existential quantifiers are connected with

each other through negation.

e.g., asserting ‘everyone dislikes sprouts’ is the same as asserting ‘there does not exist someone who likes sprouts’, and vice versa.

We can express these two equivalent statements as follows.

Firstly, for ‘everyone dislikes sprouts’ we have:

x ¬likes(x, sprouts)and for ‘there does not exist someone who likes sprouts’, we have:

¬x likes(x, sprouts)

Page 23: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

23

Connections Between and

• Furthermore, making the assertion ‘everyone likes chocolate’ is the same as asserting ‘there is no-one who does not like chocolate’:

Firstly, for ‘everyone likes chocolate’ we have:

x likes(x, chocolate)

which is equivalent to stating ‘there is no-one who does not like chocolate’, as follows:

¬x ¬likes(x, chocolate)

Page 24: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

24

Connections Between and

• Laws that define the relationship between the universal and existential quantifiers are as follows:

x ¬p ≡ ¬x p ¬x p ≡ x ¬p x p ≡ ¬x ¬p x p ≡ ¬x ¬p

• This rules are known as DeMorgan’s laws for quantified statements

• The reasons these connections exist is because the universal quantifier is really a conjunction over the universe of objects, and the existential quantifier is really a disjunction over the universe of objects…

Page 25: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

25

Connections Between and • Recall , DeMorgan’s laws for propositional logic are as follows:

¬(p V q) ≡ ¬p Λ ¬q ¬(p Λ q) ≡ ¬p V ¬q

there are two more of DeMorgan’s laws, for propositional logic :

p V q ≡ ¬(¬p Λ ¬q) p Λ q ≡ ¬(¬p V ¬q)

• Given that the universal quantifier is a conjunction over the universe of objects, and the existential quantifier a disjunction over the universe of objects, we can see the relation between DeMorgan’s laws for quantified and unquantified statements as follows:

x ¬p ≡ ¬x p ¬p Λ ¬q ≡ ¬(p V q) ¬x p ≡ x ¬p ¬(p Λ q) ≡ ¬p V ¬q x p ≡ ¬x ¬p p Λ q ≡ ¬(¬p V ¬q) x p ≡ ¬x ¬p p V q ≡ ¬(¬p Λ ¬q)

Page 26: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

26

Functions• The use of functions in first-order logic enables us to refer more

specifically to unique objects.

• For example, consider the statement ‘Mary’s mother likes chocolate’. We could represent this in the following way:

x (motherOf(x,y) Λ likes(x,z))

• However, this could be read as ‘Mary has at least one mother and she likes chocolate’ and it would be better if we could specify that Mary has one unique mother.

• For this we can make use of functions. Example:

likes(motherOf(y),z)or likes(motherOf(Mary), chocolate)

Here, the ‘motherOf’ part is the function.

Page 27: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

27

Further Examples

• Here are a few more examples of the use of functions:

loves(motherOf(y),fatherOf(y))

If y represents ‘Mary’ then this statement can be read as ‘Mary’s mother loves Mary’s father’

x (odd(x) → odd(square(x)))

If x represents ‘a natural number’ then this statement can be read as ‘The square of an odd number is odd’

Page 28: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

28

Inference Rules

Quantifiers are changed to propositional formulae and inference is done according to PL.

Page 29: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Examples (from sentences to FOL)

1. All cats are cute.• ∀x Cat(x) Cute(x)⇒1a. Cat of Noman is cute.

Cute (CatOf(Noman))

2. All students taking AI are genius. • ∀x Student(x) TakingAI(x) Genius(x)∧ ⇒3. Some students taking AI are genius and

hardworking.• ∃x Student(x) TakingAI(x) Genius(x) ∧ ⇒ ∧

Hardworking(x)

Page 30: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

• Mary’s mother likes chocolate and dislikes milk.

– likes(motherOf(Mary), chocolate) ∧ ¬ likes (motherOf(Mary), milk)

Page 31: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Examples (from FOL to sentences)

• ∃s h Student(s) Taking(s,AI) ∀ ∧ ∧HomeworkFor(h,AI) ¬Hates(s,h)∧

• There are some student of AI course who doesn’t hate all of the AI homework.

• ∀x Mushroom(x) ¬( Poisonous(x) Purple(x) )⇒ ∧• There are no mushrooms that are poisonous and

purple. (All mushrooms are not purple and poisonous at the same time.)

• ∃x IsABunny(x) IsCute(x)∧• There is a bunny who is a cute. (some bunnies are

cute)

Page 32: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Assign_1:Q.4

• Convert the following to FOL predicate calculus:

1.Every Muslim loves Makkah.

2.All purple mushrooms are poisonous.

3.Sun is not cold.

4.Not every cat likes fish.

5.Every cat that lives in street is not a pet.

Page 33: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Assign_1:Q.5

• Convert the following into English language sentences.

1.( x) gardener(x) => likes(x,Sun)∀2.xy(Parent(x,y) Male(y) Son(y,x))

3.x (mushroom(x) ^ purple(x)) => ~poisonous

4.~ x purple(x) ^ mushroom(x) ^ poisonous(x)

Page 34: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

Software

• Prolog

• CLIPS

• JESS

Page 35: CS-554 Part-3: First-Order Logic By Dr. Syed Noman Hasany.

• Midterm-1 (20) (without help paper)• Q.1: Fill in the blanks (5)

• Q.2 Propositional logic (8)– Formulae yes/no– Proof; having knowledge base using inference

rules– Entailment using truth table– Tautaulogy, contradiction and contingency

• Q.3 FOL (7)– Formula conversion with negation– FOL to sentences and vice versa