Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROLOG Basics A Prolog program consists of a database of facts and rules, and queries (questions). Fact:.... Rule:... :-.... Query: ?-.... Variables: must.

Similar presentations


Presentation on theme: "PROLOG Basics A Prolog program consists of a database of facts and rules, and queries (questions). Fact:.... Rule:... :-.... Query: ?-.... Variables: must."— Presentation transcript:

1 PROLOG Basics A Prolog program consists of a database of facts and rules, and queries (questions). Fact:.... Rule:... :-.... Query: ?-.... Variables: must begin with an upper case letter. Constants: numbers, begin with lowercase letter, or enclosed in single quotes.

2 Simple Facts john_is_cold. raining. john_Forgot_His_Raincoat. fred_lost_his_car_keys. peter_footballer. ‘peter footballer’.

3 Some more facts 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).

4 Computing a factorial factorial(0,1). factorial(N,F) :- N>0, N1 is N-1, factorial(N1,F1), F is N * F1.

5 Fibonacci f(0,1). f(1, 1). f(N, R) :- N > 1, N1 is N-1, N2 is N-2, f(N1, R1), f(N2, R2), R is R1 + R2.


Download ppt "PROLOG Basics A Prolog program consists of a database of facts and rules, and queries (questions). Fact:.... Rule:... :-.... Query: ?-.... Variables: must."

Similar presentations


Ads by Google