• No results found

'It is sunny'

N/A
N/A
Protected

Academic year: 2022

Share "'It is sunny'"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

Introductory Lecture

(2)

Logical variables

Pattern matching facility

Backtracking strategy to search for proofs

(3)

Facts Rules Query

Variables: must begin with an upper case letter

Constants: must begin with lowercase letter, or enclosed in single quotes

(4)

Fact is just what it appears to be Often a proposition like It is sunny

represented as It is sunny .

(5)

Action of asking the program about information contained within its data base

After a program is loaded, you will receive the query prompt,

?-

you can ask the program a question such as

?- 'It is sunny'.

and it will respond with the answer Yes

?-

(6)

give Prolog the ability to pursue its decision- making process

'It is sunny'.

'It is summer'.

It is hot' :- 'It is summer', 'It is sunny'.

'It is cold' :- 'It is winter', 'It is snowing'.

The query,

?- 'It is hot'.

Yes

(7)

female(amy).

female(johnette).

male(anthony).

male(bruce).

male(ogden).

parentof(amy,johnette).

parentof(amy,anthony).

parentof(amy,bruce).

parentof(ogden,johnette).

parentof(ogden,anthony).

parentof(ogden,bruce).

siblingof(X,Y) :- parentof(Z,X) , parentof(Z,Y) , X Y.

(8)

List is designated by square brackets. Ex:

[dog,cat,mouse]

Records or tuples are represented as patterns.

The elements of a tuple are accessed by pattern matching.

book(Title,Author,Publisher,Date).

author(LastName,FirstName,MI).

publisher(Company,City).

book(T,A,publisher(C,rome),Date)

(9)

+ addition

- subtraction

* multiplication / real division // integer division

mod modulus

** power

?- X is 3*4.

X = 12 yes

(10)

a :- b. % a if b

a :- b,c. % a if b and c.

a :- b;c. % a if b or c.

a :- \++ b. % a if b is not provable a :- not b. % a if b fails

a :- b -> c;d. % a if (if b then c else d)

(11)

% deriv(Polynomial, variable, derivative)

% dc/dx = 0

deriv(C,X,0) :- number(C).

% dx/dx = 1 deriv(X,X,1).

% d(cv)/dx = c(dv/dx)

deriv(C*U,X,C*DU) :- number(C), deriv(U,X,DU).

% d(u v)/dx = u(dv/dx) + v(du/dx)

deriv(U*V,X,U*DV + V*DU) :- deriv(U,X,DU), deriv(V,X,DV).

(12)

Prolog does not provide for a function type so, functions must be defined as relations.

fac(0,1).

fac(N,F) :- N > 0, M is N - 1, fac(M,Fm), F is N * Fm.

minimum(M,N,M) :- M =< N.

minimum(M,N,N) :- N =< M.

(13)

List --> [ ]

List --> [Element|List]

Example:

length([ ],0).

length([H|T],N) :- length(T,M), N is M+1.

sum([ ],0).

sum([X|L],Sum) :- sum(L,SL), Sum is X + SL.

(14)

Write the program in simple text editor &

save it as .pl

On the terminal, type gprolog.

To load a file, [filename].

(15)

Allows to watch Prolog's reasoning as it happens

Helpful for debugging

Type trace. on the ? prompt & then type any query.

To turn off tracing type notrace.

(16)

It allows you to tell Prolog, which previous choices it

need not consider again when it backtracks through the chain of satisfied goals.

Example:

facility(Pers,Fac) :- book_overdue(Pers,Book), !, basic_facility(Fac).

Facility(Pers,Fac) :- general_facility(Fac)

?- client(X) , facility(X,Y).

If a client is found to have an overdue book, then only allow the client the basic facilities of the library. Don t bother going through all the client s overdue books, and don t consider any other rule about facilities.

(17)

Has no arguments

When a fail is encountered after a cut, the normal backtracking behavior is altered by the effect of cut.

average_taxpayer :- foreigner(X) , ! , fail.

average_taxpayer :- spouse(X,Y) ,

(18)

Can read up various online tutorials for detailed study of Prolog.

One good reference is Programming in Prolog , by Clocksin & Mellish, Narosa Publishing House.

(19)
(20)

This document was created with Win2PDF available at http://www.daneprairie.com.

The unregistered version of Win2PDF is for evaluation or non-commercial use only.

References

Related documents

Fig 3-01.02: Number of public sector undertakings under respective independent departments and Ministry of Science and Technology of the Central Government Ministry undertaking

arrangements such as placing 50 x 50 mm opening chain link mesh or waste tyres and sand bags, monitoring ground vibrations at specified locations, costof all materials,

from Col-0 (flower diameter, trichome density, rosette leaf width, cauline leaf length and width) and other from Don-0 (rosette leaf diameter with their leaf length,

says the State Government “feels that the activities connected with development of hydro power potential at the proposed Lower Subansiri site might aggravate prevailing

“This provision (S.21) is clearly a rule of interpretation which has been made applicable to the Constitution in the same manner as it applies to any Central Act

and DON concentrations were low, especially for the Hooghly site at Kolkata. Human influence, however, was revealed by the more labile nature and elevated

The glass transition temperature (T g ), dilatometric soften- ing point (T d ) and softening point (T s )—all of them show the same trend of variation, a gradual increase followed by

If the adsorption isotherms of tartrazine and safranine-T on Ag2 S and CdS-doped AgzS are compared, it is seen that both tartrazine (anionic) and safranine-T