• Save
Artificial intelligence Prolog Language
Upcoming SlideShare
Loading in...5
×
 

Artificial intelligence Prolog Language

on

  • 1,027 views

Artificial intelligence -> Prolog Language

Artificial intelligence -> Prolog Language

Statistics

Views

Total Views
1,027
Views on SlideShare
1,027
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

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

Artificial intelligence Prolog Language Artificial intelligence Prolog Language Presentation Transcript

  •  
    • The first, official version of prolog was developed at the university of Marseilles, France by Alain Colmerauer in the early 1970s as a tool for programming in logic.
    • Today, prolog is an important tool in programming artificial intelligence applications and in the development of customized knowledge bases, expert systems, natural language interfaces, and smart information management systems.
    • Visual prolog addresses the same target market as SQL database systems, C++ development systems and other language tools like visual basic, Borland's Delphi, or IBM's visual age.
    • Facts are like relations in Database systems, representing the known data.
      • Bill likes Cindy.
      • Cindy likes Bill.
      • Bill likes dogs.
    • In Prolog
      • likes(bill, cindy).
      • likes(cindy, bill).
      • likes(bill, dogs).
    • Natural Language
      • Cindy likes everything that Bill likes.
      • Caitlin likes everything that is green.
    • Prolog
      • likes(cindy, Something):- likes(bill, Something).
      • likes(caitlin, Something):- green(Something).
    • We call “likes” for a predicate
    • The predicate has two clauses .
    • A clause has a head and a body .
    • A predicate has a name and an arity
    • Like has two arguments ( arity=2 )
    Read as IF
    • Variables start with an uppercase letter or underscore.
    • VALID Variables
      • My_first_correct_variable_name
      • _My first quarter
      • Sales_10_11_86
    • INVALID Variables
      • 1stattempt
      • second_attempt
      • "disaster"
  • Variables in Prolog get their values by being unified with values. Until it gets a value, a variable is said to be free ; when it gets a value, it becomes bound . When backtracking; variables becomes free again. Variables are used as part of the pattern-matching, process, not as a kind of information storage.
    • PREDICATES
      • nondeterm likes(symbol,symbol)
    • CLAUSES
      • likes(ellen,reading).
      • likes(john,computers).
      • likes(john,badminton).
      • likes(leonard,badminton).
      • likes(eric,swimming).
      • likes(eric,reading).
    • Consider this query: Is there a person who likes both reading and swimming?
      • likes(Person, reading), likes(Person, swimming).
    • The solutions are found through Searching, Matching/Unification and Backtracking
    • Basic types: Integer, Real, char, Strings, Symbols
    • List’s [1,2,3,4]
    • Compound structures: person(“leo”,39) font(“arial”,b,21)
    • Special types like binary (an array of byte values)
      • In natural language, we ask you:
        • Does Bill like Cindy?
      • In Prolog syntax, we ask Prolog:
        • likes(bill, cindy).
      • Given this query, Prolog would answer
        • yes
    • Predicates and their arguments MUST be declared. They are declared in the PREDICATES sections.
    • Compound domains and sub domains can be declared in the DOMAINS sections.
    • Clauses for the predicates are given in the CLAUSES section.
    • Dynamic facts can be given in the FACTS sections (Former name was DATABASE).
    • Execution starts in the GOAL Section.
    • We could ask you in natural language:
      • What does Bill like?
    • In Prolog syntax, we ask Prolog:
      • likes(bill, What).
    • Prolog will return
      • What=cindy
      • What=dogs
    • 2 Solutions
      • /* This is an example of a comment */
      • % This is also a comment
      • /***************************************/
      • /* and so are these three lines */
      • /***************************************/
      • /*You can also nest a comment /*within a comment*/ like this */
      • CONSTANTS
        • restricted = 1
      • ifdef restricted
      • savebase(_):-
        • write("nBase cannot be saved in demo version"),
        • readchar(_).
      • elsedef
      • savebase(Name):-
        • write("nSaving ",Name),
        • save(Name).
      • enddef
  • domains mydom = i(integer); s(string) predicates procedure wr(mydom) - (i) clauses wr(i(Int)):- write("Was integer: ",Int). wr(s(Str)) :- write("Was String: ",Str). GOAL wr(i(88)). Passing input to the predicate The variable will be bound to 88 Procedure means no fail! Only input flow accepted! Case/switch statement!
  • Factorial of 1 is 1 Factorial of N is N multiplied with factorial of N-1
    • PREDICATES
      • factorial(integer,integer)
    • CLAUSES
      • factorial(1,1):-!.
      • factorial(X,FactX):-
        • Y=X-1,
        • factorial(Y,FactY),
        • FactX = X*FactY.
  • Erroneous - Always exit failure - Always fail procedure - Always success determ - succeed or fails multi - 1 or more solutions (never fail) nondeterm - 0 or more solutions predicates append(list,list,list)- procedure (i,i,o), determ (i,i,i) nondeterm (o,i,i)
  • write(Param1, Param2, Param3, ..., ParamN) readln(Line) readchar(CharParam) file_str(Filename, Text) - file_str("t.dat", My_text) openread(SymbolicFileName, OSFileName) openwrite(SymbolicFileName, OSFileName) closefile(SymbolicFileName)
      • Result = cast(returndomain,Expr)
    • LongVal = cast(LONG,”This was a text”)
    save(fileName) /* (i) */ save(fileName, databaseName) /* (i, i) */
  • Stack: the stack is used for transferring arguments and return addresses for predicate calls. The stack also holds the information for backtrackpoints. Heap: the heap holds all objects that are more or less permanent, such as database facts, window buffers, file buffers etc. Gstack: the global stack, normally called gstack, is the place where lists, compound structures and strings are placed. The Gstack is only released during backtracking. Trail: the trail is only used when the program uses reference variables. It holds information about which reference variables must be unbound during backtracking. The trail is allocated in the heap.
    • http://rigaux.org/language-study/syntax-across-languages-per-language/Prolog.html
    • http://en.wikipedia.org/wiki/Prolog
    • http://en.wikipedia.org/wiki/Prolog#Data_types
    • www.g prolog .org/manual/g prolog .html
    • www.csci.csusb.edu/dick/samples/ prolog . predicates .html
    • boklm.eu/ prolog /page_9.html