14
Dr. Muhammed Al-Mulhe Dr. Muhammed Al-Mulhe m ICS535-101 ICS535-101 1 An Introduction to An Introduction to Logical Programming Logical Programming

An Introduction to Logical Programming

Embed Size (px)

DESCRIPTION

An Introduction to Logical Programming. Predicate Calculus. Logic programming is based on formal logic. Formal logic was developed to provide a method for describing propositions. Propositions are logical statements that may or may not be true. - PowerPoint PPT Presentation

Citation preview

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 11

An Introduction toAn Introduction toLogical ProgrammingLogical Programming

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 22

Predicate CalculusPredicate Calculus

Logic programming is based on formal logic.Logic programming is based on formal logic.

Formal logic was developed to provide a method for Formal logic was developed to provide a method for describing propositions.describing propositions.

Propositions are logical statements that may or may not Propositions are logical statements that may or may not be true. be true.

Symbolic logic can be used for the three basic needs of Symbolic logic can be used for the three basic needs of formal logic:formal logic:

To express propositionsTo express propositions

To express the relationship between propositionsTo express the relationship between propositions

To describe how new propositions can be inferred from other To describe how new propositions can be inferred from other propositions that are assumed to be true.propositions that are assumed to be true.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 33

Predicate CalculusPredicate CalculusOne form of symbolic logic that is used for logic One form of symbolic logic that is used for logic programming is called first-order predicate calculus programming is called first-order predicate calculus (predicate calculus for short).(predicate calculus for short).

A brief look at predicate calculus follows:A brief look at predicate calculus follows:

Propositions Are logical statements that may or may Propositions Are logical statements that may or may not be true. There are two types of propositions;not be true. There are two types of propositions;

1.1. Atomic Propositions: consists of two parts: a functor Atomic Propositions: consists of two parts: a functor or relation and an ordered list of parameters. or relation and an ordered list of parameters.

Examples:Examples:

man (ahmed)man (ahmed) 1-tuple predicate 1-tuple predicate likes (ahmed, steak)likes (ahmed, steak)2-tuple predicate2-tuple predicate

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 44

Predicate CalculusPredicate Calculus

2. Compound Proposition: have two or more atomic propositions, which are connected by Logical Connectors.

Logical Connectors are operators that connects simple predicates to produce complex ones. A list of these connectors is:

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 55

ExamplesExamples

The following are examples of CompoundThe following are examples of Compound Propositions:Propositions:

The precedence of the operators is:The precedence of the operators is:

The second example is equivalent to:The second example is equivalent to:

dba

cba

dba ))((

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 66

Predicate CalculusPredicate Calculus

Quantifiers

• We can introduce variables into propositions using Quantifiers.

• There are two quantifiers:

1. Universal quantifier (reads for all), and

2. Existential quantifier (reads there exists).

• For example:

X.(man(X) human (X))

X.(mother (mary, X) ∩ male(X))

Quantifiers

• We can introduce variables into propositions using Quantifiers.

• There are two quantifiers:

1. Universal quantifier (reads for all), and

2. Existential quantifier (reads there exists).

• For example:

X.(man(X) human (X))

X.(mother (mary, X) ∩ male(X))

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 77

Clausal Form

In predicate calculus we can represent the same proposition with more than one way.

This will represent a problem if we want to use this technique with computers.

Therefore, we must use a standard form to represent proposition called the clausal form.

All propositions can be expressed in clausal form.

Clausal Form

In predicate calculus we can represent the same proposition with more than one way.

This will represent a problem if we want to use this technique with computers.

Therefore, we must use a standard form to represent proposition called the clausal form.

All propositions can be expressed in clausal form.

Clausal FormClausal Form

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 88

• A proposition in “Clausal Form” has the following general syntax: B1 B2 …. Bn A1 A2 …. Am

• The meaning of this proposition is as follows:• If all the As are true, then at least one B is true.

• The characteristics of the clausal form proposition are:1. Existential quantifiers are not required.2. Universal quantifiers are implicit3. No operators other than conjunction and disjunction are

required4. Disjunctions appear on the left side and conjunctions on the

right side.5. All predicate calculus propositions can be converted to clausal

form.

• A proposition in “Clausal Form” has the following general syntax: B1 B2 …. Bn A1 A2 …. Am

• The meaning of this proposition is as follows:• If all the As are true, then at least one B is true.

• The characteristics of the clausal form proposition are:1. Existential quantifiers are not required.2. Universal quantifiers are implicit3. No operators other than conjunction and disjunction are

required4. Disjunctions appear on the left side and conjunctions on the

right side.5. All predicate calculus propositions can be converted to clausal

form.

Clausal FormClausal Form

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 99

Clausal FormClausal Form

The right side of clausal form is called the “The right side of clausal form is called the “antecedentantecedent” ” or the “or the “headhead” and the left side is the “” and the left side is the “consequenceconsequence” or ” or the “the “tailtail”.”.

Examples of Clausal forms are:Examples of Clausal forms are:

likes(ahmed, hamour) likes(ahmed, hamour) likes(ahmed, fish) likes(ahmed, fish) fish(hamour)fish(hamour)

father( louis, al ) father( louis, al ) father( louis, violet ) father( louis, violet )

father( al, bob ) father( al, bob ) mother( violet, bob ) mother( violet, bob ) grandfather( louis, bob )grandfather( louis, bob )

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 1010

Resolution is an inference rule that is used to infer propositions from given propositions. The concept of resolution is the following: From (P Q) and (R P) infer (R Q)

Example From older(ahmed, ali) father(ahmed, ali)

and

wiser(ahmed, ali) older(ahmed, ali)

Then infer

wiser(ahmed, ali) father(ahmed, ali)

Resolution is an inference rule that is used to infer propositions from given propositions. The concept of resolution is the following: From (P Q) and (R P) infer (R Q)

Example From older(ahmed, ali) father(ahmed, ali)

and

wiser(ahmed, ali) older(ahmed, ali)

Then infer

wiser(ahmed, ali) father(ahmed, ali)

PC and Theorem ProvingPC and Theorem Proving

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 1111

ResolutionResolution The mechanics of this resolution construction are The mechanics of this resolution construction are

as follows: as follows:

The left sides of the two propositions are The left sides of the two propositions are ANDed together to make the left side of the ANDed together to make the left side of the new proposition.new proposition.

Same thing is done to get the right side.Same thing is done to get the right side.

Any term that appears on both sides of the Any term that appears on both sides of the new propositions is removed from both sides.new propositions is removed from both sides.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 1212

UnificationUnificationThe presence of variables in propositions requires The presence of variables in propositions requires resolution to find values for those variables that allow resolution to find values for those variables that allow the matching process to succeed.the matching process to succeed.

This process of determining useful values for variables This process of determining useful values for variables is called is called unificationunification..

The temporary assigning of values to variables to allow The temporary assigning of values to variables to allow unification is called unification is called instantiationinstantiation

ExampleExample– What if we haveWhat if we have wiser(X,Y) wiser(X,Y) older(X,Y) older(X,Y) – Then we need to do unification (instantiation)Then we need to do unification (instantiation)

{X/ahmed and Y/ali }{X/ahmed and Y/ali }

This will be discussed in the context of Prolog.This will be discussed in the context of Prolog.

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 1313

• When prepositions are used for resolution, only a restricted kind of clausal form called Horn clauses can be used.

A Horn clause is a clause that has one of two forms:

A single atomic proposition on the left side, or

An empty left side.

This mean that a Horn clause will contain one predicate head, in this case we call it headed Horn clause, or it has an empty head and we call it headless Horn clause.

• When prepositions are used for resolution, only a restricted kind of clausal form called Horn clauses can be used.

A Horn clause is a clause that has one of two forms:

A single atomic proposition on the left side, or

An empty left side.

This mean that a Horn clause will contain one predicate head, in this case we call it headed Horn clause, or it has an empty head and we call it headless Horn clause.

Horn Clauses Horn Clauses

Dr. Muhammed Al-MulhemDr. Muhammed Al-Mulhem ICS535-101ICS535-101 1414

Horn ClausesHorn Clauses

Headed Horn clauses are used to state relationships, Headed Horn clauses are used to state relationships, such as:such as:

likes(ahmed, hamour) likes(ahmed, hamour) likes(ahmed, fish) likes(ahmed, fish)

fish(hamour)fish(hamour)

Headedless Horn clauses are used to state facts, such asHeadedless Horn clauses are used to state facts, such as

father(muhammed, khaled)father(muhammed, khaled)

Most but not all, propositions can be stated in Horn Most but not all, propositions can be stated in Horn clauses.clauses.