0% found this document useful (0 votes)
17 views5 pages

Lecture 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Lecture 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Logical programing

Lecture 8
 Horn Clause:-
is a clause with at most one positive literal.
 Any horn clause belong to one of four categories:
1. Fact : ( 1 positive , 0 negative )
EX: {Father(ali, ahmed)}
2. Negated goal: ( 0 positive , 1 or more negative )
EX: {¬ male(X), ¬ Father(ali ,X)}
3. Null clause : ( 0 positive , 0 negative )
EX: the clause appears at the end of resolution proof
4. Rule : ( 1 positive , 1 or more negative )
EX: {¬ father(X,Y), parent(X,Y)}
 Resolution of Horn clause
The resolvent of two Horn clauses is a Horn clause
EX: {P(c,b)} {P(c,b)}
{¬P(c, b),q(c)} {¬P(c, b)}
------------------------ ----------------------
{q(c)} Horn clause {}
 Prolog: adopt the horn clause resolution
 Two types of programming languages:
 Imperative languages (C, C++, VB, C#, Java, …)
 Declarative languages (Prolog, lisp, …)
NOTE:
- Logic programming(Prolog) is a type of programming called
declarative programming.
- Logic programming used in AI: NLP, expert systems, games
 Imperative Languages:
 They are also called procedural languages
 It is about how the problem be solved?
 Programmer gives all steps to solve a problem.
Page 1
 He must know an algorithm to solve a problem.
 Declarative Languages:
 It is about what is the problem?
 Programmer describe the problem without the control
flow, then the system will solve the problem.
 Programmer must know the relations between objects to
solve the problem
 Programmer does not need to know an algorithm to
solve the problem.

 Prolog sections:
1) Clauses section: The body of the prolog program.
Consists of:
- Facts: May be relation or properties.
EX: Ayman likes Saly  relation
Sky is blue  properties
- Rules: enable you to infer facts from other
facts and has two parts Head and Body.
Comments in prolog has two types:
- Multiple line comments begin with the
characters /* and end with */
- single line comments starting with %
2) Domains section: Enable you to give distinctive
names to different kinds of data
The section begins with the keyword Domains.
Domains section serves two very useful purposes:
- Giving meaningful names to domains .
- Declare data structures that don’t defined by
the standard prolog domains .
EX: Domains
Name=symbol

Page 2
3) Constants section: Where you can declare symbolic
constants in your Prolog programs.
- A constant declaration section is indicated by
the keyword constants, followed by the
declarations themselves.
EX: constants
pi=3.14159
4) Predicates section: The section begins with the
keyword Predicates
- List each predicate showing the type( domain)
of it’s argument
- A predicate name is not followed by period ).(
- The argument type could be standard domains
or user defined domains declared in the
domains section.
- Predicate Names: must begin with letter
followed by a sequence of letters ,
digits and underscores.
- Predicate Arguments: must belongs to known
prolog standard domains, or one you declare in
the domains section.
EX: Predicates
parent(symbol, symbol)
Or Domains
Person =symbol
Predicates
parent(person, person)
5) Goal section: There are two types of goal depend on
its place :
 External goal : Written outside the program and Can
be changed each time the program is executed
‫ف الرن بيطلعلي كل الحاالت الممكنة عندي‬

Page 3
 Internal goal Written in the Goal Section inside the
program
Run automatically when the program is
executed and Can’t be changed during
execution.
‫بيطلعلي حالة ممكنة واحدة بس ف الرن‬

 Variables
name must begin with a capital letter or an underscore, followed by
any number of letters , digits or underscores.
 Variables in prolog get their values by being matched to
constant in facts or rule ( Unification process).
matching ‫بمعني انها بتاخد القيم بتاعتها اثناء عملية ال‬
 You can not store information by giving a value to a variable.
‫واخزن فيه قيم لكن بياخد القيم دي اثناء ال‬Variable ‫مقدرش اني اعرف‬
matcgin
 Variables are used to express general rules and to ask
question
 A anonymous variables: is represented by single underscore(_)
 It can be used to ignore the values you do not need
 It never get a value
 It match anything
 Compound objects
Compound data :objects allow you to treat several pieces of
information as a single item such a way that you can easily pick
them apart again.
Item ‫واحد بطريقة يسهل اني افصل ال‬Item ‫بتعامل مع اكثر من معلومة كما لو كانت‬
‫دا وادمجه ثاني‬
EX: Domains (functor)
(name ) date_cmp = date (string, integer, integer)
Page 4
Predicates
Person(string, date_cmp)
Clauses
Person(ali, date(“Oct.”,4,1993)).

A functor : is just a name that identifies a kind of compound data


object and hold it’s argument together .
NOTES:
Section keyword Purpose
Database To declare data base contain set of facts
Domains To declare domains of the variables
Constants To declare constant values
Predicates To declare the predicates
Clauses The beady of the prolog program

, It mean Conjunction of sub-goals, all rules must be satisfied


; It means Disjunction of sub-goals, any sub-goal provide rule
satisfied
:- It means( if ) placed between rule head and rule body
. it means the termination of Fact,Rule or Goal

Page 5

You might also like