Logic Programming Prolog 11
اسلاید 1: Summary
اسلاید 2: likes(tom,jerry).likes(mary,john).likes(tom,mouse).likes(tom,jerry).likes(jerry,cheeze).likes(mary,fruit).likes(john,book).likes(mary,book).likes(tom,john).Queries?- likes(jerry,cheeze).yes?-likes(X,john).X=mary;X=tom;noProlog: Facts
اسلاید 3: RulesX is brother of Y if X is a male andX and Y have the same parents.In Prologis_brother_of(X,Y):-male(X), parents(X, Father, Mother), parents(Y, Father, Mother).
اسلاید 4: Backtracking?- concen(X,Y).X = usY = 91.6667 ;X = chinaY = 315.5 ;X = nzY = 16 ;X = indiaY = 304.136 ;Nopopulation(us,275).population(china,1262).population(nz,4).Population(india,1000).land(us,3000).land(china,4000).land(nz,250).land(india,3288).concen(X,Y):-population(X,P),land(X,L),Y is P*1000/L.
اسلاید 5: Cut: !Eliminates choicesAlways succeeds but stops backtrackinga:-b,c,!,d.a:-e,f.max(X,Y,Y) :- Y>X.max(X,Y,X). ?- max(1,2,X).X = 2 ;X = 1 ;No?- max(X,Y,Y) :- Y>X, !. max(X,Y,X). ?- max(1,2,X).X = 2 ;No?-
اسلاید 6: [ ][a,b,c,d,e][5,8,3,9,7][the, boy, run]A list can be split into a head and a tail: [H|T].grades(john, [70,87,90,58]).?- grades(john, [H|T]). H = 70 T = [87,90,58]member(X,[X| _ ]).member(X, [ _ | Y]) :- member(X, Y).?- member(1, [3,4,5,8,1,9]).YesRecursion and ListsLists
اسلاید 7: put(Ch).get(Ch).get0(Ch).tab(X).nl.read(X).write(X).I/Otell(Filename) telling(X) told see(Filename) seeing(X) seen File I/O
اسلاید 8: male(andrew).male(john). male(george). male(greg). male(adam). female(mary). female(jennifer). female(eve). parents(john,george,mary).parents(greg,adam,eve).parents(jennifer, adam,eve).parents(andrew, adam,eve).?- male(X).X= andrew;X= john;X= george;X= greg;X= adam;?- female(X).X= mary;X= jennifer;X= eve;?- parents(X, adam, eve).X= greg;X= jennifer;X= andrew;?- findall(X, male(X), List).List= [andrew, john, george, greg, adam]?- findall(X, female(X), List).List= [mary, jennifer, eve]?- findall(X, parents(X,adam,eve), List).List= [greg, jennifer, andrew]findall(X,Term,List).
اسلاید 9: ?- arg(2,likes(mary,john),X).X = john Yes?- arg(2,likes(mary,X),john).X = john Yes?- arg(3,parents(john,george,X),Val).X = _G346Val = _G346 Yes?- arg(3,parents(john,george,victoria),Val).Val = victoria Yes?- functor(likes(mary,john),Fun,Arity).Fun = likesArity = 2 Yes?- X=likes(mary,john),functor(X,Func,Arity).X = likes(mary, john)Func = likesArity = 2 Yes?- functor(parents(adam,john,mary),F,N).F = parentsN = 3 Yes?- functor(X,likes,2).X = likes(_G303, _G304) Yesfunctor(Term, Functor, Arity)arg(N,Term,Value)
اسلاید 10: GamesRobot control Natural language processingExpert systemsImage processingParsing of context-free languagesCompiler writingVLSI Design Relational database applicationsOther AI applicationsApplications
اسلاید 11: expr ::= term | term addop expr term ::= factor | factor multop termfactor ::= ‘x’ | ‘y’ | lbr expr rbraddop ::= ‘+’ | ‘-’multop ::= ‘*’ | ‘/’lbr ::= ‘(’ rbr ::= ‘)’ A simple grammar for expressionsApplications
اسلاید 12: expr --> term. expr --> term, addop, expr. term --> factor. term --> factor, multop, term. factor -->[x]. factor -->[y]. factor --> lbr, expr, rbr. addop -->[+]. addop -->[-]. multop -->[*]. multop -->[/]. lbr -->[(]. rbr -->[)]. ?- phrase(expr, [y, *, (, x, +, x, )]) Yes ?- phrase(factor, [y]) Yes ?- phrase(rbr, [)]) Yes ?- phrase(factor, [y , *, x]) No ?- phrase(expr, [y , *, x]) .Yes?- phrase(factor, [(,y , *, x,)]). Yes?- Applications
اسلاید 13: A Grammar for a very small fragment of Englishsentence --> noun_phrase, verb_phrase. noun_phrase --> determiner, noun. noun_phrase --> proper_noun. determiner -->[the]. determiner -->[a]. proper_noun -->[pedro]. noun -->[man]. noun -->[apple]. verb_phrase --> verb, noun_phrase. verb_phrase --> verb. verb -->[eats]. verb -->[sings]. Applications
اسلاید 14: InferenceEngineKnowledge BaseWorking MemoryExplanationFacilityUserUser InterfaceDomain Expert(S) Knowledge EngineerKnowledgeFormalizedKnowledegApplications
اسلاید 15: Horn ClausesDefinition: A Horn clause is a clause with at most one positive literal.A Horn clause therefore belongs to one of four categories:A rule: 1 positive literal, at least 1 negative literal. A rule has the form: ~P1 V ~P2 V ... V ~Pk V Q This is logically equivalent to P1^P2^ ... ^Pk => Q thus, an if-then implication with any number of conditions but one conclusion. Examples: ~man(X) V mortal(X) (All men are mortal); ~parent(X,Y) V ~ancestor(Y,Z) V ancestor(X,Z) If X is parent of Y and Y is ancestor of Z then X is ancestor of Z.
اسلاید 16: A fact or unit: 1 positive literal, 0 negative literals. Examples: man(socrates) parent(elizabeth,charles), A negated goal : 0 positive literals, at least 1 negative literal. In virtually all implementations of Horn clause logic, the negated goal is the negation of the statement to be proved The null clause: 0 positive and 0 negative literals. Appears only as the end of a proof.
اسلاید 17: Prolog • is designed to represent Horn clauses, • does backward chaining only, • is a full Turing equivalent programming language, and can compute anything any other programming language can. Modern Prolog implementations have GUI facilities, fast compilers and (if your code is designed appropriately) very high run-time performance.
اسلاید 18: Program ::= Clause... Query | Query Clause ::= Predicate . | Predicate :- PredicateList . PredicateList ::= Predicate | PredicateList , Predicate Predicate ::= Atom | Atom( TermList ) TermList ::= Term | TermList , Term Term ::= Numeral | Atom | Variable | Structure Structure ::= Atom ( TermList ) Query ::= ?- PredicateList . Numeral ::= an integer or real number Atom ::= string of characters beginning with a lowercase letter or enclosed in apostrophes.Variable ::= string of characters beginning with an uppercase letter or underscore Terminals = {Numeral, Atom, Variable, :-, ?-, comma, period, left and right parentheses } Prolog Grammer
اسلاید 19: Comparing Prolog and Haskell SyntaxIn Prolog: functions are not evaluated - they are like data constructors the language is untyped variables begin with upper-case letters or an underscore predicate and function symbols begin with a lower-case letter the list constructor functor is [ | ], not :
اسلاید 20: Haskell Prolog Kinds of objects functions relations Arity (number of parameters) fixed; if fewer arguments, then return a function variable; indicated with /n ending Variables start with lower case start with upper case Values start with upper case start with lower case Clause parameters separated by spaces separated by commas Head-body separator = (after possible alternatives) :- (when body is needed) Alternatives preceded by | (or can use if-then-else) separated by semi-colons Clause ending off-side rule (or semi-colon) full stop List constructor : (inside parens when potentially ambiguous) | (always inside brackets)
اسلاید 21: reverse [] = []reverse (h:t) = (reverse t) ++ [h]reverse([], []).reverse([H|T], R) :-reverse(T, RT), append(RT, [H], R).
نقد و بررسی ها
هیچ نظری برای این پاورپوینت نوشته نشده است.