To transform an English sentence to Predicate Logic, we remove unnecessary terms.
This leaves only the relationship and the entities involved, known as arguments.
Predicate Logic
Ex: A pie is good = good(pie)
The relation is ‘good’, the relation’s argument is ‘pie’.
Prolog Rules To infer facts from other facts, Prolog uses Rules. Ex: Bill likes cars if they are red = likes(bill, cars):- red(cars).
By the way, in prolog, ‘:-’ is pronounced ‘if’.
Prolog Queries • We may want to ask, “What does ali like?”
•In Prolog syntax, we ask: likes(ali,What). Note: capital W on what
Examples: a_kind_of(aa,ship).
a_kind_of(bb,ship).
part_of(aa,jordanian_navy).
part_of(bb,jordanian_navy).
part_of(jordanian_navy,jordanian_government). a_kind_of(jordanian_government,government).
color(ship,red).
a_kind_of(aa,ship). a_kind_of(bb,ship).
part_of(aa,jordanian_navy).
part_of(bb,jordanian_navy).
part_of(jordanian_navy,jordanian_government). a_kind_of(jordanian_government,government).
color(ship,red).
Parts of a Prolog Program All programs written in Prolog contain at least 4 parts:
Domains: The section of code where we define the legal values for any type that is not defined as a standard type. Predicates: The predicate section is where we define predicates to be used in the CLAUSES section and define the domains for their arguments. Symbolic name of a relation
We found it best to think of predicate declarations as function prototypes.
Ex: age(string, integer)
Clauses: Clauses are the heart of the program.
A clause is an instance of a predicate, followed by a period.
Clauses are of two types:
Goals: Part of program where queries are made.
Can be singular or compound.
Each part of a compound goal is known as a subgoal.
To satisfy a compound goal (or query) each subgoal must itself be satisfied by the system •Ex: What are the things do Bill and Cindy both like (in common)?
•In Prolog:
likes(bill, What), likes(cindy, What). Attached a ppt with more information on the AI page.
|