jargaq.blogg.se

12 vile vortices history channel
12 vile vortices history channel










To represent the rule that express the facts that two persons are friends if they both like the same game: friends( P1,P2):- likes (P1,G),likes (P2,G),P1P2.A rule consists of two parts: head and body separated by the symbol (:-).Rules are used to infer new facts from existing ones.If we put a goal like: drinks (samy,water).To add the fact that all persons drink water: drinks (Everyone, water).Assume we add the drinks facts to the likes database as follows: PREDICATES drinks(symbol, symbol) CLAUSES drinks(ali, pepsi).To find games liked by more than one person: likes (P1,Game),likes(P2,Game),P1P2.To find persons who like more than one game: likes(Person, G1),likes (Person,G2),G1G2.Person=ali Game=tennisĤ-Compound queries with multiple variables To list games liked by ali and ahmad likes (ali,Game),likes (ahmad,Game). For example to express the likes relation: likes(person, game) We should first declare person in the domains section as follows: domains person,game= symbol predicates likes (person, game) Person and game are unknown domains(error) This declaration will allow prolog to detect type errors.It is used to define domains other than the built-in ones, also to give suitable meanings to predicate arguments.PROLOG will do the following matches and backtracking to the friends rule: For PROLOG to answer the query : friends (ali, P2).Rule’s symbol The head of the rule The body of the rule

12 vile vortices history channel

Example: the query likes(X,Y), likes(Y,Z) will result in a type error, because Y will be matched to a game constant and can not replace a person variable in the second sub goal.ġ1. How to do arithmetic operations DOMAINS number=integer PREDICATES addnum(number,number,number) multnum(number,number,number) CLAUSES addnum(X,Y,S):- S=X+Y. The isletter(X) predicate gives yes if X is a letter: PREDICATES isletter(char) CLAUSES isletter(Ch):- ‘a’=N.Note:The compound goal: multnum(7,5,X),addnum(X,X,Answer).

12 vile vortices history channel

canbuy ( Person,Car, “takseet”):- salary (Person, M), takseet(Car,T),M/3>=T/30. OR howcanbuy (Person,Car,Way):- canbuy (Person,Car,Way),Way="cash" canbuy (Person, Car, Way), Way="takseet", NOT(canbuy (Person,Car,"cash")). Should be placed around expressions which include only constants and /or bounded variables.

12 vile vortices history channel

These variables will be bounded before reaching the “not” expression containing themġ6. Controlling Backtracking DOMAINS name=symbol PREDICATES nondeterm father(name,name) everybody CLAUSES father (ali, salem). Everybody:- father (X,Y), write (X,” is ” ,Y,”’s father\n” ), fail.












12 vile vortices history channel