You are on page 1of 9

(CSI-607) Artificial Intelligence

Lab Manual # 2

SWI-Prolog
v7.2.3 (Multi-threaded)

Task 7: Condition (if….else) in Prolog

Let’s compare two numbers to decide which number is bigger.


Take two numbers from user input.
Task 8:

Write a program that take a number from user input and tells its zero or not.

Task 9:

Write a program that take a number from user input and tells its less than 100 or greater.

Task 10:

Write a program that take 2 numbers from user input and divides them and display either
result on screen or display division not possible because denominator is zero.

Task 11: Practice The Following Questions on Prolog and also add in lab
manual
1. write('Hello World'),nl,write('Welcome to Prolog'),nl.
2. ?-halt. ?-
statistics.
3. Try following DB

4. Try following:

5. We can also consult DB by writing following command.

6. Try this.
7. Try this.

8. Try this.
9. Try Arithmetic Operators.

10. Try following:

11. Try Relational Operators


12. Try Equality Operator

13. Try this:

14. Checking Identicals

15. Try NOT operator.


16. Try Input/ Output

____________________________________________________________

17. Deduction:
GIVEN THAT
any X is an animal if it is a dog
AND
fido is a dog
DEDUCE
fido must be an animal

Eaxmple:

Enter Rule in database.

dog (fido).
dog (tommy).
dog (henry).

animal (X):- dog(X).

Consult on Prolog.
Start asking questions.

?- dog (fido).
Yes
?- dog(rover).
No

?- animal(fido).
Yes

?- dog(X).
X=fido;
X=tommy;
X=henry.
?- listing(dog).
dog( fido ).
dog( rover ).
dog( tom ).
dog( henry).
yes
______________________________________________________________________

Watch following links for more Prolog Tutorials:

https://www.youtube.com/watch?v=EdbWdZlEDm4
https://www.youtube.com/watch?v=SykxWpFwMGs

Check Out Following Links (If you are interested in advance Prolog):

Amzi! Prolog
http://www.amzi.com/products/prolog_products.htm

 B-Prolog
http://www.probp.com/

Ciao Prolog
http://clip.dia.fi.upm.es/Software/Ciao/

 GNU Prolog
http://gnu-prolog.inria.fr/

Logic Programming Associates Prolog (versions for Windows, DOS and


Macintosh) http://www.lpa.co.uk

 Open Prolog (for Apple Macintosh)
http://www.cs.tcd.ie/open-prolog/

 PD Prolog (a public domain version for MS-DOS only)


http://www-2.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/prolog/impl/prolog/pdprolog/0.html

SICStus Prolog
http://www.sics.se/isl/sicstuswww/site/index.html
SWI Prolog
http://www.swi-prolog.org/

Turbo Prolog (an old version that only runs in MS-DOS)


http://www.fraber.de/university/prolog/tprolog.html

  Visual Prolog
http://www.visual-prolog.com/

W-Prolog (a Prolog-like language that runs in a web
browser) http://goanna.cs.rmit.edu.au/~winikoff/wp/

 YAP Prolog
http://www.ncc.up.pt/~vsc/Yap/











Sehar
 Rehman
Lecturer

Govt. Islamia Postgraduate College, Faisalabad (GIC)

You might also like