Prolog programming Introduction to Prolog - PNU-CS-AI

Prolog programming Introduction to Prolog CS370d - CS 461 ? What is Prolog programming Prolog is a programming language for symbolic , non-numeric commutation.

It solves problems that involve objects and relations between objects. Defining relations by facts The fact that Tom is a parent of Bob can be written in prolog as: parent(tom, bob). tom and bob are objects,

parent(tom, bob) is a relation between these objects. Defining relations by facts The whole family tree can be described by the following facts: to pa

m m bo b an

n liz pat jim

Defining relations by facts The whole family tree can be described by the following facts: to pa m m parent(pam,bob).

parent(tom,bob). bo liz parent(tom,liz). b parent(bob,ann). an parent(bob,pat).

pat n parent(pat,jim). jim Defining relations by facts We can also add information about the sex of the people by the following facts:

female(pam). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim).

Defining relations by facts female(pam) is a Unary relation parent(bob,pat) is a Binary relation. Think about this relation: sex(pam, feminist). SWI-Prolog SWI-Prolog editor is an open source implementation of the programming

language . Prolog is a free software and you can download it from here: http://www.swi-prolog.org/Download.html SWI-Prolog Getting started: Any Prolog program in SWI-Prolog is written in a file with extension .pl. You can write your own one by following these steps:

SWI-Prolog After opening SWI Prolog environment, choose . file -> new to create a new.pl file SWI-Prolog This will open a new window to create the new file, choose any name

for your programs (here we name it tree) then choose to save it. SWIProlog Now the .pl file we have just created will be opened, and we can write our own program. Let's write the following facts about parent , male and female relationships: parent(pam,bob) .

parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). female(pam). female(liz). female(pat).

female(ann). male(tom). male(bob). male(jim). SWI-Prolog SWI-Prolog

Compile your program. Compile - > Make SWI-Prolog Then click OK to save the changes on your file. SWI-Prolog In SWI Prolog environment, load your program by file -> consult. Then choose your program .

.Questions in prolog Prolog can posed questions about any relation. So, we can ask a question about Parent relation, For example : Is bob a parent of Pat? ?- parent(bob,pat).

The answer will be true. : Exercise 1 Write prolog program of your own family tree .

Recently Viewed Presentations

  • AIDS 2008 PowerPoint Template - TheBody.com

    AIDS 2008 PowerPoint Template - TheBody.com

    * Prior studies have shown that serum TxB2 is higher in men than women Sex related differences in prostaglandin synthesis (PGI2, PGE2) made by endothelial cells from umbilical cord veins - cells from male babies made more of these two...
  • CONNECTICUT DEPARTMENT OF EDUCATION DISTRICT ORIENTATION TO CONNECTICUT

    CONNECTICUT DEPARTMENT OF EDUCATION DISTRICT ORIENTATION TO CONNECTICUT

    Connecticut General Statutes state: "If the State Board of Education determines that a local or regional board of education is not in compliance with any provisions of sections 10-144o to 10-149, inclusive, and section 10-220a, the State Board of Education...
  • NA STOPĚ PACHATELE Díl první: Pachatelem je stafylokok

    NA STOPĚ PACHATELE Díl první: Pachatelem je stafylokok

    Pátráme po mikrobech Díl XII. Parazitologie Ondřej Zahradníček K praktickému cvičení pro VLLM0421c a ZLLM0421c [email protected] Roupi (mrle) Roup: vajíčko, červ, životní cyklus Škrkavka versus žížala Škrkavčí životní cyklus a výskyt ve světě Toxoplasma - životní cyklus Odběrové médium C....
  • Stoichiometry: Calculations with Chemical Formulas and Equations

    Stoichiometry: Calculations with Chemical Formulas and Equations

    The molar mass of an element is the mass number for the element that we find on the periodic table. The formula weight (in amu's) will be the same number as the molar mass (in g/mol).
  • Social Factors Influencing Food Selection

    Social Factors Influencing Food Selection

    Social factors influencing food selection include: Food habits and patterns . Knowledge about food. Ability to prepare and cook food. ... family meal times are an opportunity for young children to role model good eating behaviours from adults, to learn...
  • Engaging Practice Team In Quality Improvement

    Engaging Practice Team In Quality Improvement

    Practice Nursing Structure. Lesley Frater. Nurse Manager. Tracey Mooney. Housebound LTC &LD lead. Gillian Anderson. HCA - LD Lead. Katherine Hardy. Marie Cooper
  • How much agency does the individual nurse have in delivering ...

    How much agency does the individual nurse have in delivering ...

    Structural constraints and individual agency in delivering compassionate care. ... Midwifery and Care Staff Vision and Strategy was launched by Jane Cummings, CNO, NHS England/Department of Health. Shared purpose of nurses, midwives and care staff to deliver high quality, compassionate...
  • The Second Red Scare - Northland Preparatory Academy

    The Second Red Scare - Northland Preparatory Academy

    The Second Red Scare. Suspicion and Fear. Semi-Socialist policies of the New Deal left an opening for conservatives to attack FDR's and Truman's policies . Fear of Communist infiltration led to close scrutiny in academic and political sectors.