my prolog presentation

Upload: omid-shirkhorshidi

Post on 05-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 My Prolog Presentation

    1/20

    Programming LanguageInstructor:

    Dr. Einollah Khanjari

    By:Omid ShirkhorshidiThe slides included information was taken from the Site Wikipedia And Books:1) Learn Prolog Now!, Patrick Blackburn, Johan Bos, Kristina Striegnitz, 2006

    2) PROLOG Programming for Artificial Intelligence, William F. Clocksin, Christopher S., 20003) Programming in Prolog: Using the ISO Standard. Springer, 5th ed., 2003

    Spring 2011

  • 8/2/2019 My Prolog Presentation

    2/20

    1. HistoryOf Prolog Language

    2. A BriefIdentification3. Basic Elements and How to Program?4. Syntax and semantics & Some Examples5. Usages6. WhyProlog?

    7. Criticisms About this language8. References

  • 8/2/2019 My Prolog Presentation

    3/20

    History OfProlog Language

    Alain Colmerauer Philippe Roussel

    Creator :Alain Colmerauer with Philippe Roussel

    Date Of Creation :Around 1972

    Based On Past Works Of :Robert Kowalski

    Prolog Is An Abbreviation Of:programmation en logique

    (French for programming in logic)

    Robert Kowalski

  • 8/2/2019 My Prolog Presentation

    4/20

    Brief IdentificationProlog is a general purpose logic programming language associated with artificial intelligence

    and computational linguistics.

    There is some Useful Information :

    1. Paradigms : Logic Programming ( It should be mentioned here that thereare many extensions ofProlog with other Paradigmsfeatures)

    2. Some FeaturesOf Prolog : Declarative, Reflective , Rule-based &High-level interactive language.

  • 8/2/2019 My Prolog Presentation

    5/20

    Brief Identification3. Major implementations (Extensions) :

    HiLogand Prologextend Prolog with higher-order programming features.

    Logtalkand Oblogare some prolog extension with Object Orientation features.

    SWI-prolog,Visual-prolog and B-Prologare some Prolog systems thatprovide a graphics library.

    Some Prolog implementations, notablySWI-Prolog, support server-side webprogramming with support for web protocols, HTML andXML.

    4. Usual File Extensions : .PL & .PRO

    5. Web-site : ????????????????????????????????

    http://en.wikipedia.org/wiki/HTMLhttp://en.wikipedia.org/wiki/XMLhttp://en.wikipedia.org/wiki/XMLhttp://en.wikipedia.org/wiki/HTML
  • 8/2/2019 My Prolog Presentation

    6/20

    What is a Declarative Lang.?Programming languages are of two kinds:

    Procedural: (BASIC, ForTran, C++, Pascal, Java);Declarative: (LISP, Prolog, ML).

    In procedural programming, we tell the computer how to solve a problem.

    In declarative programming, we tell the computer whatproblem we want solved.

    (However, in Prolog, we are often forced to give clues as to the solution method).

  • 8/2/2019 My Prolog Presentation

    7/20

    Our program is a database offacts and rules.

    Some are always true (facts):father( john, jim).

    Some are dependent on others being true (rules):parent( Person1, Person2 ) :-

    father( Person1, Person2 ).

    To run a program, we ask questions about thedatabase. (Queries)

    Basic Elements of Prolog:

  • 8/2/2019 My Prolog Presentation

    8/20

    Example Database In English:John is the father of Jim.Jane is the mother of Jim.Jack is the father of John.

    Person 1 is a parent of Person 2 if

    Person 1 is the father of Person 2 orPerson 1 is the mother of Person 2.

    Person 1 is a grandparent of Person 2 ifsome Person 3 is a parent of Person 2 andPerson 1 is a parent of Person 3.

    Example questions In English:Who is Jim's father?Is Jane the mother of Fred?Is Jane the mother of Jim?Does Jack have a grandchild?

    Example Database In Prolog:father( john, jim ).mother( jane, jim ).father( jack, john ).

    parent( Person1, Person2 ) :-father( Person1, Person2 ).

    parent( Person1, Person2 ) :-mother( Person1, Person2 ).

    grandparent( Person1, Person2 ) :-parent( Person3, Person2 ),parent( Person1, Person3 ).

    Example questions In Prolog:

    ?- father( Who, jim ).?- mother( jane, fred ).?- mother( jane, jim ).?- grandparent( jack, _ ).

    Basic Elements of Prolog:

  • 8/2/2019 My Prolog Presentation

    9/20

    .pl files contain lists of clauses.

    Clauses can be either facts or rules.

    The Prolog comment characters:

    Single line comments: (%)

    % This is a commentThis is not a comment, but an error

    Multiple line comments: ( /* */ )/* This is a multi-line commentwhich must be closed with a */

  • 8/2/2019 My Prolog Presentation

    10/20

    Prolog's single data type is the term. Terms are either atoms, numbers, variablesor compound terms.

    1)An atom is a general-purpose name with no inherent meaning. Examples ofatoms include x, blue, 'Taco', and 'some atom'.

    2)Numbers can be floats or integers.

    http://en.wikipedia.org/wiki/Floating_pointhttp://en.wikipedia.org/wiki/Integerhttp://en.wikipedia.org/wiki/Integerhttp://en.wikipedia.org/wiki/Floating_point
  • 8/2/2019 My Prolog Presentation

    11/20

    3)Variables are denoted by a string consisting of letters, numbers and underscorecharacters, and beginning with an upper-case letter or underscore. Variables

    closely resemble variables in logic in that they are placeholders for arbitrary terms.

    4)Acompound term is composed of an atom called a "functor" and a number of"arguments", which are again terms.

    Examples of compound terms aretruck_year('Mazda', 1986)

    and'Person_Friends'(zelda,[tom,jim]).

  • 8/2/2019 My Prolog Presentation

    12/20

    Arule is of the form:Head :- Body.

    and is read as "Head is true if Body is true".

    An example of a fact is:cat(tom).

    which is equivalent to the rule:cat(tom) :- true.

    An example of a rule is:animal(X):- cat(X).

    Given the beside fact, one can ask:is tom a cat?

    ?- cat(tom).Yes

    what things are cats??- cat(X).X = tom

    If we add that rule and ask

    what things are animals?

    ?- animal(X).

    X = tom

  • 8/2/2019 My Prolog Presentation

    13/20

    greetings:-

    write(What is your name?),

    nl,

    read(X),

    write(Hello ),

    write(X).

    | ?- greetings.

    What is your name?

    |: tim.

    Hello tim

    X = tim ?

    yesProlog Code Terminal

    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).

    This results in the following query being evaluated as true:?- sibling(sally, erica).Yes

    Prolog Code

    Terminal

  • 8/2/2019 My Prolog Presentation

    14/20

    Recursive Definitions

    For all X and YX is in Ys food chain if

    Y eats X

    orY eats some Z and X is in Zs food chain:

    food_chain(X,Y) :- eats(Y,X).

    food_chain(X,Y) :- eats(Y,Z),food_chain(X,Z).Afterwards we can ask:?-food_chain(X,rat).X=salmon;X=wormOr:?-food_chain(worm,X).X=rat;

    X=bear

  • 8/2/2019 My Prolog Presentation

    15/20

    Hello world !

    As an example of a query:?- write('Hello world!'), nl.

    Hello world!

    true.

    ?-

  • 8/2/2019 My Prolog Presentation

    16/20

    Artificial intelligence or any Intelligent systems

    Complicated knowledge databases Natural language processing Logic data analysis

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

  • 8/2/2019 My Prolog Presentation

    17/20

    Prolog is interactive. It comes with a top-level interpreter: a command interfacethat you can type code at and get itexecuted immediately.

    Prolog is fast.

    Some extensions like SWI-Prolog are free,open-source, and very well maintained.

    Unlike many other programminglanguages, Prolog is declarative

  • 8/2/2019 My Prolog Presentation

    18/20

    Complicated syntax

    Difficult to understand programs at first sight

    Programming in the large is considered to be complicated because notall Prolog compilers support modules, and there are compatibilityproblems between the module systems of the major Prolog compilers.

    Portability of Prolog code across implementations has also been aproblem

  • 8/2/2019 My Prolog Presentation

    19/20

    The slides included information was takenfrom the Site Wikipedia And Books:

    1) Learn Prolog Now!, Patrick Blackburn,Johan Bos, Kristina Striegnitz, 2006

    2) PROLOG Programming for ArtificialIntelligence, William F. Clocksin, Christopher

    S., 2000

    3) Programming in Prolog: Using the ISOStandard. Springer, 5th ed., 2003

  • 8/2/2019 My Prolog Presentation

    20/20