• Save
PROLOG: Introduction To Prolog
Upcoming SlideShare
Loading in...5
×
 

PROLOG: Introduction To Prolog

on

  • 2,861 views

PROLOG: Introduction To Prolog

PROLOG: Introduction To Prolog

Statistics

Views

Total Views
2,861
Views on SlideShare
2,817
Embed Views
44

Actions

Likes
2
Downloads
0
Comments
0

4 Embeds 44

http://oliva.uhk.cz 28
http://www.slideshare.net 8
http://web1.fairfield-h.schools.nsw.edu.au 4
http://dataminingtools.net 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

PROLOG: Introduction To Prolog PROLOG: Introduction To Prolog Presentation Transcript

  • Introduction to Prolog
    Introduction to prolog
  • AGENDA
    Introduction
    Syntax
    Data types
    Rules and facts
    Evaluation
    Examples
  • Introduction
    Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.
    Prolog is declarative,
    The program logic is expressed in terms of relations, represented as facts and rules and a computation is initiated by running a query over these relations.
    The language was first conceived by a group around Alain Colmeraurer in Marseille, France.
  • Data types
    Prolog’s single data type is the term.
    Terms are either atoms, numbers, variables and compound terms.
    An atom is a general purpose name with no inherit meaning. Ex: x,blue etc.
    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 characters and underscore.
    A compound term is composed of an atom called “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 the parentheses.
    A List is an ordered collection of terms. It is denoted by square brackets with the terms separated by brackets with the terms separated by commas or in the case of an empty list, [] ex: [1,2,3] or [red, green, blue] etc.
    Strings are a sequence of characters surrounded by quotes.Ex: “ to be, or not to be”
  • Rules and Facts
    Prolog programs describe relations, defined by means of clauses.
    There are two types of clauses:
    • Facts
    • Roles
    A role is of the form Head :- Body and is read as head is true if body is true.
    A rule’s body consists of calls to predicates, which are called the rule’s goals.
    Classes with empty bodies are called facts.
    Ex: cat(tom).
  • Evaluation
    Execution of a Prolog program is initiated by the user's posting of a single goal, called the query.
    Logically, the Prolog engine tries to find a resolution refutation of the negated query.
    The resolution method used by Prolog is called SLD resolution.
  • Ex: mother_child(trude, sally).
    father_child(tom, sally).
    father_child(tom, erica).
    father_child(mike, tom).
    sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
    parent_child(X, Y) :- father_child(X, Y).
    parent_child(X, Y) :- mother_child(X, Y).
    Results in the following query being evaluated as true:
    ?- sibling(sally, erica).
     Yes
  • Loops and Recursion
    Iterative algorithms can be implemented by means of recursive predicates
    Negation:
    The built-in Prolog predicate +/1 provides negation as failure, which allows for non-monotonic reasoning.
    legal(X) :- + illegal(X).
    •  Prolog attempts to prove the illegal(X).
    • If a proof for that goal can be found, the original goal (i.e., + illegal(X)) fails.
    • If no proof can be found, the original goal succeeds.
  • Examples:
    An example of a query:
    ?- write('Hello world!'), nl.
    Hello world! true. ?-
    An example  Quick Sort sorting algorithm, relating a list to its sorted version:
    partition([], _, [], []).
    partition([X|Xs], Pivot, Smalls, Bigs) :-
    ( X @< Pivot ->
    Smalls = [X|Rest],
    partition(Xs, Pivot, Rest, Bigs)
    ; Bigs = [X|Rest],
    partition(Xs, Pivot, Smalls, Rest)
    ).
    quicksort([]) --> [].
    quicksort([X|Xs]) -->
    { partition(Xs, X, Smaller, Bigger) },
    quicksort(Smaller), [X], quicksort(Bigger).
  • Visit more self help tutorials
    Pick a tutorial of your choice and browse through it at your own pace.
    The tutorials section is free, self-guiding and will not involve any additional support.
    Visit us at www.dataminingtools.net