Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

AIM: STUDY OF PROLOG AND LISP Introduction: Prolog is a general purpose logic programming language associated with artificial

intelligence and computational linguistics. Prolog is a declarative programming language. This means that in prolog, you do not write out what the computer should do line by line, as in procedural languages such as C and Java . The general idea behind declarative languages is that you describe a situation. Based on this code, the interpreter or compiler will tell you a solution. In the case of prolog, it will tell you whether a prolog sentence is true or not and, if it contains variables, what the values of the variables need to be. Data Types: Prolog's single data type is the term.

An atom is a general-purpose name with no inherent meaning. Examples of atoms include x, blue, 'Burrito', and 'some atom'. Numbers can be floats or integers. Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper-case letter or underscore. Variables closely resemble variables in logic in that they are placeholders for arbitrary terms. A compound term is composed of an atom called a "functor" and a number of "arguments", which are again terms. Compound terms are ordinarily written as a functor followed by a comma-separated list of argument terms, which is contained in parentheses. The number of arguments is called the term's arity. An atom can be regarded as a compound term with arity zero. Examples of compound terms are truck_year('Mazda', 1986) and 'Person_Friends'(zelda,[tom,jim]).

Special cases of compound terms:

A List is an ordered collection of terms. It is denoted by square brackets with the terms separated by commas or in the case of the empty list, []. For example [1,2,3] or [red,green,blue]. Strings: A sequence of characters surrounded by quotes is equivalent to a list of (numeric) character codes, generally in the local character encoding, or Unicode if the system supports Unicode. For example, "to be, or not to be".

Predicates: Term unification 1) =/2 2) (\=)/2

Prolog unification: unify_with_occurs_check/2 Not Prolog unifiable

Type testing var/1: atom/1: integer/1: float/1: atomic/1:

True if term currently is a variable True if term is bound to an atom True if term is bound to an integer True if term is bound to a floating point number True if term is bound to an atom, integer or floating point number

compound/1: True if term is bound to a compound term nonvar/1: number/1 : Term comparison (@=<)/2: (==)/2: (\==)/2: (@<)/2: (@>)/2: (@>=)/2: True if term is not a variable True if term is bound to an integer or floating point number

Term less than or equal to Term identical Term not identical Term less than Term greater than Term greater than or equal to

Term creation and decomposition functor/3 arg/3 (=../2) copy_term/2

Arithmetic evaluation is/2 Arithmetic comparison '=:='/2: Arithmetic equal '=\='/2: '<'/2: '=<'/2: '>'/2: '>='/2: Arithmetic not equal Arithmetic less than Arithmetic less than or equal to Arithmetic greater than Arithmetic greater than or equal to

Clauses: Clause retrieval and information clause/2 current_predicate/1

Clause creation and destruction asserta/1 assertz/1 retract/1 abolish/1

All solutions findall/3 bagof/3 Applications: Some applications of Prolog are:


intelligent data base retrieval natural language understanding expert systems specification language machine learning robot planning automated reasoning problem solving

LISP: A lisp, also known as sigmatism, is a speech impediment whose sufferers are unable to articulate sibilants . These mis-articulations often result in unclear speech. Lisp (historically, LISP) is a family of computerprogramming languages with a long history and a distinctive, fully parenthesized Polish prefix notation.[1] Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older (by one year). Like Fortran, Lisp has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme. Lisp was originally created as a practical mathematical notation for computer programs, influenced by the notation of Alonzo Church's lambda calculus. It quickly became the favored programming language for artificial intelligence (AI) research. As one of the earliest programming languages, Lisp pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, conditionals, higher-order functions, recursion, and the self-hostingcompiler.[2] The name LISP derives from "LISt Processing". Linked lists are one of Lisp language's major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or even new domain-specific languages embedded in Lisp. Sample program: domains name=symbol predicates parent(name,name). offspring(name,name). clauses parent(tom,bob). parent(bob,ann). parent(bob,pat). parent(pat,jim). offspring(X,Y):-parent(Y,X).

Q.1)Who is the parent of jim? Goal: parent(X,jim) X=pat 1 Solution Goal: parent(Y,jim),pare nt(A,Y) Y=pat, A=bob 1 Solution

Q.2)Who is the child of bob? Goal: parent(bob,X) X=ann X=pat 2 Solutions Q.3)Who are Toms grandchildren? Goal: parent(tom,A),pare nt(X,D) A=bob, X=tom, D=bob A=bob, X=bob, D=ann A=bob, X=bob, D=pat A=bob, X=pat, D=jim 4 Solutions Q.4)Find the greatgrand children of tom? Goal: parent(tom,A),pare nt(X,Y),parent(Y,Z) A=bob, X=tom, Y=bob, Z=a nn A=bob, X=tom, Y=bob, Z=p at A=bob, X=bob, Y=pat, Z=jim 3 Solutions Q.5)Find father of ann and pat? Goal: parent(X,ann),pare nt(X,pat) X=bob 1 Solution Q.6)Who is the grandparent of jim? Goal: parent(A,jim),pare nt(S,A) A=pat, S=bob 1 Solution Goal: offspring(ann,bob) Yes Goal: parent(X,Y),parent (Y,jim) X=bob, Y=pat 1 Solution

You might also like