Presentation1

Post on 27-May-2015

405 views 0 download

Tags:

Transcript of Presentation1

Topic: Languages Of AI (lisp/prolog)Group Members:Shagufta Arif (027)Sania Alyas (020)Maryam Afza (006)

What is LISP??

LISP stands for (LIST PROCESSING). It was invented by John McCarthy in 1958. As its name implies, LISP is a programming language that manipulates LISTS.

LISP Discription:A list is either empty or non-empty.

[a, b, c, d]Empty: [] Non-empty: head=[a] tail=[b, c, d]

Example:

We can implement a function to compute factorials using recursion:

(defun factorial (N) "Compute the factorial of N." (if (= N 1) 1 (* N (factorial (- N 1)))))

Example:

Here are some simple example using the if operator:

CL-USER(): (if (> 3 4)"yes“ "no") ANS: "no“

Applications of LISP:

Mathematics Artificial intelligence and natural

language processing. Expert Systems (diagnosis,

identification, design )

Advantages of LISP:

Common Lisp is : a general-purpose programming language and

an AI language

Common Lisp programs are:

easy to test easy to maintain (depending on

programming style) intractive

Cont… Provides clear syntax LISP expressions are case-insensitive.

runtime typing: the programmer need not bother about type declarations

several data types: numbers, strings, arrays, lists, char, symbols etc.

Disadvantages of LISP

The major disadvantage is due to the lack of popularity and lack of widespread support and knowledge.

It is relatively hard to find Lisp programmers.

What is PROLOG?

PROLOG is a declarative language where programs are expressed in terms of relations.

A program in PROLOG can use logical reasoning to answer questions that can be inferred from the knowledge base.

Cont …

A Prolog language designed in Europe to support natural language processing.

It was created by Alain and Robert 1972 as an alternative to the Lisp programming languages.

Conti…

There are three basic stratgies in Prolog: facts, rules, and queries.

A collection of facts and rules which describe some collection of relationships is called a knowledge base.

That is, Prolog programs simply are knowledge bases.

Conti…

Prolog includes an inference engine, which is a process for reasoning logically about information. The inference engine includes a pattern matcher, which retrieves stored (known) information by matching answers to questions.One important feature of Prolog is find all possible solutions rather than only one.

mortal(X) :- man(X) % Xismortal if X is a man. man(socrates). % Socrates is a man and then ask Prolog ?- mortal(socrates). % Is Socrates mortal?and it will immediately tell me yes

PROLOG Example

Applications of PROLOG Expert systems Relational queries Parsing of context free language Natural language processing Natural support of pattern-matching

Advantages of PROLOG

The language works well for tasks like proving mathematical theorems

It has built-in list handling, very useful for representing sequences, trees, and so on.

It is easy to read and write programs which build structures.

Similarities:

One of the similarities that makes these languages unique is their ability to rewrite themselves as the program is running.

In Lisp, the program itself can be treated as data that the program can manipulate.

The both languages are object oriented programming languages.

Differences: The main difference between the two

languages is the way problems are described. In Lisp, the programmer must describe how the

computer will solve the problem (chess game). In Prolog, the developer does not need to

describe how, but rules points the program toward the desired results. (medical symptoms).

Prolog is not a general-purpose theorem prover. LISP is a general purpose theorem

PROLOG has many functional languages other than LISP.

LISP & PROLOG PROGRAMMING LANGUAGE

Arithmetic Operations

Point of comparison

LISP PROLOG

ADD (+2 3) 2+3

SUBTRACT (-5 2) (5-2)

MULTIPLICATION (* 3 2) (2*3)

DIVISION (/ 6 2) (6/2)

BRACES (+3 (* 3 2 ) 4) (3+ (3 *2)

Logical operations

Point of comparison

LISP PROLOG

SMALLER (< 3 4 )True

3 < 4yes

GREATER (> 3 4 )NIL

3 > 4No

Smaller than or equal

(< = 3 2)Nil

3 = < 2No

Greater than or equal

( > = 3 2)true

3 > = 2Yes

Equal ( = 3 4)Nil

3 =:= 4no

Not Equal (\ = 3 4 )True

( 3 == 4)Yes

PROLOG Example

age(john,32). age(agnes,41). age(george,72). age(hiba,2). age(thomas,25). QUERIES age(hiba,2). agnes(41).

Thanks