Вы находитесь на странице: 1из 117

C:\Users\jnsch\Desktop\O14ThemesHandoffs\WorkingFiles\FinalHanoff\Sketchbook\Cov er.jpg stickie-shadow.png stickie-shadow.png TitleCard.png coverBand.

png PROLOG FUNDAMENTALS PROLOG FUNDAMENTALS PREPARED BY, HARSHIT PATADIYA (168) ARUN PARMAR (172) ME. ACR 2 ELECT. DPT. M.S. UNIVERSITY

Interior-Overlay.png INTRODUCTION 0 PROgramming in LOGic 0Developed by Alain Colmerauer and P. Roussel in 1972 at the university of Marseilles in France. 0PROLOG is the one of the most widely used programming languages in artificial intelligence research. 0As opposed to imperative languages such as C or JAVA, it is an object-oriented language.

Interior-Overlay.png 0That means, when implementing the solution to problem, instead of specifying how to achieve certain goal in a certain situation, we specify what the situation (rules and facts) and the goal (query) are and let the PROLOG interpreter derive the solution for us. 0PROLOG is very useful in some problem areas, like artificial intelligence, natural language processing, data-bases, robotics, expert system . but pretty useless in others, like graphics and numerical algorithms INTRODUCTION 3

Interior-Overlay.png 1. Can compile stand alone programs. 2.A full complement of standard predicates is available. 3.A functional interface to other languages is provided. 4.Declared variables are used to provide more secure development control. 5.Both integer and floating point arithmetic supported. 6.Program development, compilation and debugging is very easy because of integrated editor.

4 FEATURES OF PROLOG

Interior-Overlay.png PROCEDURAL LANG. OBJECT-ORIENTED LANG. 5 0Use previously defined procedures to solve problems 0Most efficient at numerical processing 0Systems created and maintained by programmers 0Use structured programming 0Use heuristics to solve problems

0Most efficient at formal reasoning

0Systems developed and maintained by knowledge engineers

0Interactive and cyclic development COMPARISON

Interior-Overlay.png 6 STARTING WITH TURBO PROLOG C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE 7 Contd Editor: to create or edit program

Interior-Overlay.png 8 Contd Dialog: Output

C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png 9 Contd C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE Message: Processing activity

Interior-Overlay.png 10 Contd C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE Trace: finding problems in the program

Interior-Overlay.png 11 C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE Contd Menu Bar

Interior-Overlay.png 0Select the edit mode and enter the program. 0Enter the text or make corrections as necessary. 0Save the program to disk using the file save option. 0Compile the program. 0Execute the program.

12 CREATING A SAMPLE PROGRAM

Interior-Overlay.png GETTING STARTED:AN EXAMPLE 0As the PROLOG is declarative language, it means Programming in PROLOG means describing the world. 0Using such programs means, asking PROLOG questions about previously describe world. 0The simplest way of describing the world is by stating facts. 0This states that elephant is bigger than horse .

facts

bigger (elephant, horse). bigger (horse, donkey). bigger (donkey, dog). bigger (donkey, monkey).

13

Interior-Overlay.png 14 C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE Contd

Interior-Overlay.png Contd 0This is syntactically correct program, and after compile it we can ask question to PROLOG about it. Goal: bigger ( donkey, dog ) Yes 0It means Is a donkey bigger than dog? . It says YES because it is already communicated in PROLOG system (fact..). 0Now, Goal: bigger ( monkey, elephant ) No 0Here we get exactly what we expected. 15

Interior-Overlay.png C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE 16 Contd

Interior-Overlay.png 17 Contd C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE 18 Contd

Interior-Overlay.png C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE 19 Contd

Interior-Overlay.png 20 C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE Contd

Interior-Overlay.png 0But what happens when we ask other way round? Goal: bigger ( elephant, monkey ) No 0According to this, elephant is not bigger than monkey. This is clearly wrong as far as our real world concerned. 0In our program, it say nothing about the relationship between elephant and monkey. 0But, we know that elephant > horse > donkey > monkey.. 0In mathematical term : the bigger-relation is transitive. But in our program , this has not been defined.

21 Contd

Interior-Overlay.png 0If we would like to get a positive reply for a query like bigger (elephant, monkey), we have to provide a more accurate description of world. 0One way of doing this would be to add the remaining facts, like e.g. bigger (elephant, monkey). In our little program this would mean adding another 5 facts. 0So it means clearly, it would be too much work and probably not too intelligible anyway. 0The far better solution would be to define a new relation, which we will call is_bigger, as the transitive closure of bigger. 22 Contd

Interior-Overlay.png 0Animal X is bigger than Y either if this has been stated as a fact or if there is an animal Z and it can be shown that animal Z is bigger than animal Y. 0In PROLOG such statements are called rules and are implemented like this : is_bigger ( X, Y) :- bigger (X, Y) is_bigger ( X, Y) :- bigger (X, Z), is_bigger (Z, Y) 0In these rule :- means something like if and the coma (,) between the two terms bigger(X, Z) and is_bigger(Z, Y) stands for and . 0Here, X,Y,Z are variables.

23 Contd

Interior-Overlay.png Goal: is_bigger( elephant, monkey) Yes 0Here, PROLOG still cannot find the fact that bigger (elephant, monkey) in its database, so it tries to 2nd rule instead. 0This is done by matching the query with the head of the rule [is_bigger (X, Y)]. 0Here, X= elephant, Y= Monkey 0The rule says that in order to prove the goal is_bigger (X, Y) PROLOG has to prove the two subgoals bigger (X, Z) and is_bigger(Z, Y) again with the same variables. 24 Contd

Interior-Overlay.png 0This process is repeated recursively until the facts that make up the chain between elephant and monkey are found and the query finally succeeds. 0Now, suppose , we want to know what animals are bigger than a donkey? is_bigger( X , donkey). 0The PROLOG interpreter replies as follows: X= horse 0In case, we want to find out if there are more animals that are bigger than donkey, we can press the semicolon key(;), which will cause PROLOG to search more solutions to our query 25 Contd

Interior-Overlay.png Goal: is_bigger (X, donkey). X= horse ; X= elephant ; No 0As a final example, we ask whether there is an animal X that is both smaller than a donkey and bigger than a monkey. Goal: is_bigger (donkey, X), is_bigger (X, monkey). No

26 Contd

Interior-Overlay.png 0The main part of a PROLOG program consists of a collection of knowledge about a specific subject. 0This collection is called a database, and this database is expressed in facts and rules. EXPRESSING FACTS 0Prolog permits to describe facts in terms of symbolic relationships. 0E.g.. Right speaker is not emitting sound: 0English : The right speaker is dead. 0PROLOG : is(right_speaker,dead). 27 LET S SEE IN MORE DETAIL

Interior-Overlay.png is ( right_speaker, dead ) .

28 Contd Relation : Defines the way in which a collection of Objects belong together.

Interior-Overlay.png 29 Contd is ( right_speaker, dead ) .

Objects : Name of an element of certain type. Represents an entity or property of an entity in the real world. There six different object type. This is symbol object type.

Interior-Overlay.png 30 Contd is ( right_speaker, dead ) .

PREDICATES : Function with the value of true or false. It express a property or a relationship. The word before the parentheses is the name of relation and elements within the parentheses are the arguments of the predicate , which may be object or variables.

Interior-Overlay.png 31 Contd is ( right_speaker, dead ) .

PREDICATE + PERIOD = CLAUSE

Interior-Overlay.png 0The relations used in the clauses of the clauses section are defined in the predicates section. 0Each relation in each clause must have a corresponding predicate definition in the predicate section. 0For example :In the clause section is(right_speaker,defective). In the predicate section is(component,status) 32 Contd

Interior-Overlay.png 0The domain section also there , it defines the type of each object Domains Type 1.char single character 2.integer Integer form (32,786 to 32,785) 3.real Floating-point no. 4.string character sequence 5.symbol character sequence of letter 6.file symbolic file name 33 Contd

Interior-Overlay.png 34 RELATIONSHIP OF CLAUSES, PREDICATES, RELATION AND OBJECTS Clauses Facts Rules Predicates Periods(.) Relations Arguments Objects Variables

Interior-Overlay.png 0The Variable can be used in Turbo PROLOG clause or goal to specify an unknown quantity. 0A variable name must be begin with a capital letter. 0For example, symptom(Disease,runny_nose) 0Variable is Disease. 0It always start from upper case letter. 35 THE PROLOG VARIABLE

Interior-Overlay.png 36 Contd C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png 37 Contd C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png 38 Symptom(Diesease,runny_nose)

Clause 1 Clause 4 Clause 5 Clause 3 Clause 2 Symptom(cold,runny_nose)

Goal Succeeds (Display Bindings) Symptom(flu , runny_nose)

Goal Succeeds (Display Bindings)

Interior-Overlay.png 0Suppose patient has several symptoms to express all of these symptoms in a to find the single dieses that all of 0E.g. :- the patient has a runny nose ache.

and we want compound goal them relate to. and a mild body

Goal:symptom(Diseas, mild_body_ache) and symptom(Diseas, runny_nose) 0Lets implement it on PROLOG 39 COMPOUND GOALS ..

Interior-Overlay.png C:\DOCUME~1\Harshit\Desktop\TPROLOG\PROLOG.EXE 40 Contd

Interior-Overlay.png 0The solution of the compound goal proceeds :--

41 BACKTRACKING Execution

Top to bottom

Left to right

Interior-Overlay.png 0If any condition in the chain fails, . Prolog backtracks to previous condition, . moves relentlessly forward and backward through the conditions, . trying every available binding in an attempt to get the goal to succeed as many ways as possible. . It find its own way.

42 BACKTRACKING

Interior-Overlay.png 43 Contd

Interior-Overlay.png 44 Contd

Interior-Overlay.png 0A rule is an expression that indicates the truth of a particular fact depending upon one or more facts . X is sister of Y If X is female And parents of X are M and F And parents of Y are M and F 0The process of using rules to solve problems is called formal reasoning 0It gives PROLOG the ability of decision making. 45 USING RULES

Interior-Overlay.png 0A rule could be expressed as the following Turbo PROLOG clause. hypothesis(vitc_deficiency) if symptom(arthritis) and symptom(infection_sensitivity). 0Here, we can see that conclusion is stated first and is followed by the word if. 0The condition upon which the conclusion depends are stated next, each connected by the word and. 0The rule, like a fact, is terminated with a period. 0Conclusion is viewed as a PROLOG goal. 46 Contd

Interior-Overlay.png 0This goal is true if all the conditions for the goal are true. 0Every rule has a conclusion (or Head) and antecedent ( or body). 0The Body may be consists one or more premises. 0If all the premises are true, the conclusion is true, if any premises fails, the conclusion fails. hypothesis(vitc_deficiency) :symptom(arthritis), symptom(infection_sensitivity). 0The :- operator is called a break, a comma express an and relationship, and semicolon expresses an or relationship. 47 Contd

Interior-Overlay.png 0The process by which prolog tries to match a term against the facts or the heads of other rules in an effort to prove goal is called unification. 0Predicates unify each other if : . They have the same relation name. . They have the same number of

arguments. . All argument pairs unify with each other.

48 UNIFICATION

Interior-Overlay.png 0It classified into nine groups.. i.Control predicates ii.Reading predicates iii.Writing predicates iv.File system predicates v.Screen-handling predicates vi.String-handling predicates vii.Type-conversion predicates viii.System-level predicates ix.Not- predicate

49 BUILT-IN PREDICATES

Interior-Overlay.png OUTPUT PREDICATES 0Three output predicates: 1. write 2. writedevice 3. writef

50

Interior-Overlay.png The write Predicate 0For an example: go :hypothesis(Patient,Disease), write(Patient, probably has ,Disease, . ) ,nl.

0If we have program like . 0Now when we start turbo PROLOG and it prompts you for a goal, we only need enter the word go. 0Go will unify the head of you new rule and PROLOG will begin trying to prove hypothesis(Patient, Diseas).

51

Interior-Overlay.png 0If this goal will succeed , the write predicate displays the value of these variables in sentence: Charlie probably has german_measles. 0If there is no nl (new line) then It could be test:write ( This is an example ), write( of multiple write statements. ). Displays: This is an example of multiple write statements.

52 Contd

Interior-Overlay.png write ( This is an example ),nl. write( of multiple write statements. ). 0Then the result would be . 0This is an example of multiple write statements.

53 Contd

Interior-Overlay.png 0Used to force alignment of numbers or text 0Format: writef(format,E1,E2, ,En) ex. writef( %-10#5.0$%3.2\n ,fan,23,3.1) displays fan #23$3.10 54 The writef Predicate

Interior-Overlay.png INPUT PREDICATES readln : string or symbol readchar : character readint : integer readreal : real 55

Interior-Overlay.png Contd 56 readchar Predicate 0Use to read only single character. write( Does the ,patient, have a fever(y/n)? ), readchar(Reply),nl Reply = y .

Readln Predicate 0Use to read any string or symbol into a variable. Symptom(patient,fever):write( Does the ,patient, have a fever(yes/no)? ), readln(Reply) Reply= yes .

Interior-Overlay.png 57 readint Predicate 0Can be used to read an integer value to a variable.

Write( what is ,patient, age? ). readint(Age), Age>=12, Write(Patient, cannot be evaluated with ),nl Write( this system. ). readreal Predicate 0Can be used to read floating-point numbers into a variable.

0Write( what is the real price of ,Item, ? ), readreal(Price).

Contd

Interior-Overlay.png + Addition - Subtraction * Multiplication / Real division // Integer division ** Power

0Goal : X is 3*4. X = 12 Yes 58 ARITHMETIC OPERATOR

Interior-Overlay.png a :- b. /* a if b */ a :- b,c. /* a if b and c.*/ a :- b;c. /* a if b or c.*/ a :- \++ b. /* a if b is not provable*/ a :- not b. /* a if b fails*/ a :- b -> c;d. /* a if (if b then c else d)*/ 59 LOGICAL OPERATOR

Interior-Overlay.png 0Prolog is used in applications that requires formal reasoning. 0Basic Applications: . Expert System . Natural Language Processing . Robotics . Gaming and Simulation 60 APPLICATION FOR PROLOG

Interior-Overlay.png EXPERT SYSTEM 0Expert system are programs that use inference techniques that involves formal reasoning normally performed by a human expert to solve problems in specific area of knowledge. 0Each expert system can advise, diagnose, analyze and categorize using a previously defined knowledge base. 0The knowledge base is a collection of rule and facts which can be written in PROLOG.

61 Contd

Interior-Overlay.png NATURAL LANGUAGE PROCESSING 0Using Prolog, knowledge about human language is expressed in formal rules and facts. 0The computer can then begin a dialog with the user, asking questions about the problem and interpreting the user s answer.

62 Contd

Interior-Overlay.png ROBOTICS 0Robotics is a branch of artificial intelligence concerned with enabling computers to see and manipulate objects in their environment. 0Prolog facilitates the development of robotic control programs that can use input data from sensors to control manipulators. 0A robot can then apply formal reasoning to decisions, much as a human being does.

63 Contd

Interior-Overlay.png GAMING AND SIMULATION 0Prolog is ideal for games and simulations (cognitive modeling) involving formal reasoning. 0Most games and simulation employ a set of logical rules that control the play or action which is very adaptable to Prolog programming. 0Classical game such as N Queen Problem is written in Prolog. 64 Contd

Interior-Overlay.png 65 THANK YOU THANK YOU Will be continue by Arun

Interior-Overlay.png THE fail predicate 0In prolog, forcing a rule to fail under certain conditions is a type of control and is essential to good programming. 0In prolog, the fail forces backtracking in an attempt to unify with another clause. 0This predicate when invoked, the goal being proved fails and Backtracking is initiated. 0The predicate has no arguments so failing at the fail predicate is not dependent on variable binding. 19 April 2012 66

Interior-Overlay.png C:\Users\Tejas\Desktop\TPROLOG\PROLOG.EXE 19 April 2012 67

Interior-Overlay.png THE fail PREDICATE 0When the goal go is specified, unifies with the head of the first rule, and the testing begins for that rule. 0The location(city,state) predicate forces city to bind with jackson and state to bind with MS . 0Bco z of formatting of writef predicate, the City is leftjustified in a field of 10 characters, newline character also executed. 0The testing of the rule fails, forcing backtracking. 0Prolog backtracks, due to writef predicate which is always true. 19 April 2012 68

Interior-Overlay.png 19 April 2012 69 THE fail PREDICATE Several key points about the use of the fail predicate: 0The order of go clauses is very important. Their order defines an algorithms or procedure. 0second go clause is an important part of the definition. It terminates the backtracking and is called the terminating condition. 0The variable in the clause lose their binding every time the rule fails. The backtracking forces a new binding.

Interior-Overlay.png 19 April 2012 70 0Prolog remembers the bindings it has already tried. It marks the place of each binding, so it can return & unify with the next clause in sequence.

0Prolog proceeds from left to right, going as far as it can on one path before backtracking & trying another. In eg., it exhausts all possibilities of proving the 1st go clause, before moving on to the 2nd one. THE fail PREDICATE

Interior-Overlay.png 0The compilation and execution will give following output: Goal: go Jackson MS Washington DC Raleigh NC The goal succeeds 19 April 2012 71 RESULT

Interior-Overlay.png EXAMPLE 0In prolog, two or more rules may end with fail predicate may have same head.

0The second rule with same head executes and continues until it exhausts after first rule gets exhausted 19 April 2012 72

Interior-Overlay.png EXCLUSION USING THE fail PREDICATE 0To exclude from database all objects that meet specified criteria. 0The fail predicate is used to skip particular items from database . Exa, we can list all city/state combinations in the database except DC. 0When location(city,state) has state bound to DC, chkstate(state) will fail, forcing backtracking. 0Prolog backtracks when chkstate( DC ) fails, which tests the second clause, which succeeds and Prolog writes Washington, DC but that is required to be skipped. 0So to make this sructure work, we need to use CUT predicate. 19 April 2012 73

Interior-Overlay.png 19 April 2012 74 31 January 2007 74 C:\Users\Tejas\Desktop\TPROLOG\PROLOG.EXE

Interior-Overlay.png 19 April 2012 75 C:\Users\Tejas\Desktop\ARUN\TPROLOG\PROLOG.EXE Exclusion Example

Interior-Overlay.png EXCLUSION USING THE fail PREDICATE 0The cut helps to remove this disadvantage. 0Thus fail and cut is very powerful control structure. 19 April 2012 76

Interior-Overlay.png 19 April 2012 77 THE CONCEPT OF RECURSION 0Recursion is technique in which something is defined in terms of itself.

0In prolog, recursion is the technique of using a clause to invoke a copy of itself.

0Consider simple recursion example.

Interior-Overlay.png 19 April 2012 78 31 January 2007 78 C:\Users\Tejas\Desktop\ARUN\TPROLOG\PROLOG.EXE

Interior-Overlay.png Explanation 0When the goal count(N) is specified, it unifies with the second clause. 0The number is displayed, and NN is bound to 1+1, or 2. 0The rule now tries to match count(2), which unifies with a copy of second clause and displays this number. 0Cycle continues and when count reaches 9, count(9) unifies with the first clause terminating the recursion. 19 April 2012 79

Interior-Overlay.png 19 April 2012 80 THE CONCEPT OF RECURSION .THE repeat PREDICATE 0repeat Predicate uses recursion. 0Its format is repeat. repeat:repeat. 0It is useful for forcing program to generate alternate solutions through backtracking.

Interior-Overlay.png 19 April 2012 81 THE CONCEPT OF RECURSION 0When repeat predicate is used in rule, the predicate always succeeds.

0If a later premise cause failure of the rule, Prolog will backtrack to the repeat predicate.

0The repeat predicate always succeeds and terminates the backtracking, causing Prolog to move forward again on the same path. 31 January 2007

Interior-Overlay.png 19 April 2012 82 31 January 2007 82

Interior-Overlay.png 19 April 2012 83 31 January 2007 83

Interior-Overlay.png Explanation 0The logon routine compares name and password entered by each user to a pair stored in a table, if matching, logon predicates succeed otherwise fails 0First logon predicate will clear window 0Asking for input as name and password 0If it matches desired data, first logon rule will make logon successful, but if not matching, then second logon rule will be executed and will display Sorry, you are not permitted access. 19 April 2012 84

Interior-Overlay.png 19 April 2012 85 31 January 2007 85

Interior-Overlay.png 19 April 2012 86 31 January 2007 86

Interior-Overlay.png 19 April 2012 87 31 January 2007 87

Interior-Overlay.png explanation 0When the wrong input is used prolog falls through the second logon rule and begins to try to prove it. 0The repeat predicate will succeed first time bco z of the first repeat clause(a fact), which is always true. 0Prolog reaches the getinput(Name, Password) premise, asking for other user inputs. 0If the input is correct this time, the second logon rule succeeds 0If fails, backtracking is invoked, returning prolog to the first repeat predicate. 0Prolog invokes second repeat predicate, which is a rule: 19 April 2012 88

Interior-Overlay.png Cont 0So the repeat clause will repeatedly ask for a new inputs untill one of the logon rule succeeds. 0So prolog is reversing and moving forward for asking another pair. 0So actually creating a loop. 0It moves forward and backward repeatedly and ntill succeeds and backtracking is initiated. 19 April 2012 89

Interior-Overlay.png RULES OF RECURSION 0A program must include some method of terminating the recursion.

0Variable binding in a rule or fact applies only to the current layer. when the copy of rule is invoked, the variable in the copy are bound through the process of unification, just as in any other invocation. 19 April 2012 90

Interior-Overlay.png 19 April 2012 91 THE CUT 0The primary purpose of the cut is to prevent or block backtracking based on a specified condition.

0The cut predicate is specified as an exclamation point (!). It has no arguments.

0The cut predicate always succeeds, & once it succeeds, it act as fence, effectively blocking any backtracking beyond the cut

Interior-Overlay.png 19 April 2012 92 THE CUT 0If any premise beyond the cut fails, Prolog can only backtracks as far as the cut to try another path.

0If the rule itself fails & the cut is the last premise, no other rules with the same head can be tried.

Interior-Overlay.png 19 April 2012 93 31 January 2007 93

Interior-Overlay.png explanation 0In the original example without cut, the chkstate( DC ) predicate unified with the first chkstate( DC ) clause, which then failed. 0The prolog yhen backtracked to the chkstate(_) clause. 0This always succeeded, all items were displayed whether they were DC addresses or not. 0In the modified program. The cut prevents prolog from backtracking to the chkstate(_) premise and try to prove it. 0When the chkstate( DC ) conclusion fails, Prolog gives up on proving chkstate with the DC binding, so it backtracks to location(City,State) and next variable binding is tried. 19 April 2012 94

Interior-Overlay.png 19 April 2012 95 THE CUT 0The basic purpose of the cut is to eliminate certain search paths in the problem space.

0The cut prevents backtracking.

0In some cases, it serves a procedural function: The program will not work without it.

Interior-Overlay.png 19 April 2012 96 THE CUT 0In some cases, it serves a heuristics function: The program will work without it but cut eliminates the need to test irrelevant paths & speed up execution

0Assume rule of the form go:-premise1 and premise2 and ! And premise 3 and premise4.

Interior-Overlay.png THE CUT 0The cut can be used for any or all three purposes:-

.To terminate the search for any further solutions to a goal once a particular rule has been tested.

.To terminate the search for any further solutions to a goal once a particular rule has been forced to fail with the fail predicate.

.To eliminate paths in the database to speed up execution.

19 April 2012 97

Interior-Overlay.png TYPES OF CUT 0Two types of cut:- red cut and green cut. 0The green cut is use for force binding to be retained, once the fail clause is reached. 0Used to express determinism. 0The red cut is used to omit explicit conditions. 19 April 2012 98

Interior-Overlay.png 0EXAMPLE-1 predicates go clauses go:X=4+3, write(X),nl. 0Goal: go 7 True Goal: 0EXAMPLE-2 go:X=4+3, write(X),nl. X=4-3, write(X),nl.

0Goal: go 7 False Goal: 19 April 2012 99 ARITHMETIC OPERATIONS

Interior-Overlay.png ARITHMETIC OPERATIONS Five basic rules govern the equal sign in Turbo Prolog 0If one operand is a free variable & other is object, the variable will become bound to the object value, and the goal will succeed. Eg. If X=4+3, X will be bound to 7 0If one operand is bound variable & other is an object, the goal will succeed only if the variable is already bound to the value of the object. 0If X is bound to 7 & X=5+2 is assessed, the pgm display True 19 April 2012 100

Interior-Overlay.png 0If one variable is free variable & other is bound variable, the free variable will be bound to same value as the bound variable, and the goal will succeed. 0 If Y has been bound to 7, X=Y will bind to 7 0If both variable are bound variables, the goal will succeed only if both are bound to same value. 0If X is bound to 7 & Y is also, then X=Y will be true; otherwise it will be false. 19 April 2012 101 ARITHMETIC OPERATIONS

Interior-Overlay.png ARITHMETIC OPERATIONS 0If both operands are objects, the goal will succeed only if they are the same. eg., apple=apple will succeed. 19 April 2012 102

Interior-Overlay.png COMPARISON OPERATORS 0Permit a program to compare bound variables or objects in test. 0When they used, all variables must be bound.

.< Less than, > Greater than .= Equal to, <= less than or equal to .>= Greater than or equal to .<> Not equal to 19 April 2012 103

Interior-Overlay.png 0Example: predicates go clauses go:X=2, X<= 4+3, write(X), nl. 0Goal: go 2 True Goal: 19 April 2012 104 ARITHMETIC OPERATIONS

Interior-Overlay.png Operators & their Positions Infix . 4 + 7 Prefix. +(4,7) Postfix.4 7 + Infix notation Operator is between operands. X=2 0Compound expression. X=3+4 , are really multiple statements using infix notation. 0Symbol: +,-,*,/ Prefix notation 0Predicate: abs(x), cos(x), sin(x), tan(x), exp(x), ln(x), log(x), sqrt(x), round(x) 19 April 2012 105

Interior-Overlay.png ARITHMETIC OPERATIONS 0TYPE CONVERSIONS Predicates: char_ascii :- converts character to integer or integer to character if either is bound.

str_char:- converts string to character or character to string or tests

str_int:-converts string to integer or integer to string or tests

str_real:- converts string to real or real to string or tests 19 April 2012 106

Interior-Overlay.png COMPOUND OBJECTS 0In Prolog, it is possible to create object that contains other objects. The resulting structure is called a compound object. eg.: address(name,street,city,state,zip) Here, Entire address treated as single object in predicate. First part of compound object is the object s name is called functor. Eg. Address 19 April 2012 107

Interior-Overlay.png COMPOUND OBJECTS 0Each object that is a part of the arguments list is called a component. Eg. Name, street, city, state, zip. 19 April 2012 108

Interior-Overlay.png C:\Users\Tejas\Desktop\ARUN\TPROLOG\PROLOG.EXE 19 April 2012 109

Interior-Overlay.png EXPERT SYSTEM 19 April 2012 110

Interior-Overlay.png EXPERT SYSTEM 0An expert system is a computer program that uses knowledge and inference techniques to solve problems that are usually solved with human expertise. 0Stores large body of facts with rules, used to solve the problem. 19 April 2012 111

Interior-Overlay.png EXPERT SYSTEM 0Knowledge is stored for only single subject area called domain. 0Knowledge engineer:-observes, talk, and work with human expert to determine how to express the reasoning process of human expert in objective form. 19 April 2012 112

Interior-Overlay.png PRODUCTION SYSTEM 0PRODUCTION SYSTEMS:19 April 2012 113 INFERENCE ENGINE WORKING MEMORY (DYNAMIC DATABASE) RULE BASE (STATIC DATABASE) KNOWLEDGE BASE USER

Interior-Overlay.png FRAME-BASED SYSTEM 0Object is represented by frame. 0Relate hierarchical relationships, expressing a classification system. 0One or more filler slots representing attribute. 0Applicable to biological classification systems and similar systems. 19 April 2012 114

Interior-Overlay.png Reference 0Prolog software 0Introduction to turbo prolog, By: carl townsend 19 April 2012 115

Interior-Overlay.png THANK YOU 19 April 2012 116

Вам также может понравиться