Address 27: Prolog s Resolution and Programming Techniques .


76 views
Uploaded on:
Description
The College of North Carolina at House of prayer Slope. Address 27: Prolog's Determination and Programming Methods. COMP 144 Programming Dialect Ideas Spring 2002. Felix Hernandez-Campos Walk 27. SWI-Prolog. We will utilize SWI-Prolog for the Prolog programming assignments
Transcripts
Slide 1

The University of North Carolina at Chapel Hill Lecture 27: Prolog\'s Resolution and Programming Techniques COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos March 27 COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 2

SWI-Prolog We will utilize SWI-Prolog for the Prolog programming assignments http://www.swi-prolog.org/After the establishment, attempt the case program ?- [likes]. % likes incorporated 0.00 sec, 2,148 bytes Yes ?- likes(sam, curry). No ?- likes(sam, X). X = dahl ; X = baked ; X = kurma ; Load illustration likes.pl This objective can\'t be turned out to be, false (This is the purported Close World Assumption ) Asks the mediator to discover more arrangements COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 3

SWI-Prolog The supervisor dispatched as a major aspect of SWI-Prolog underpins shading and setting delicate space Try "Alter" under "Document" COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 4

Prolog Programming Model A program is a database of (Horn) statements Each provisions is made out of terms : Constants (particles, that are identifier beginning with a lowercase letter, or numbers) E.g. curry, 4.5 Variables (identifiers beginning with a capitalized letter) E.g. Sustenance Structures (predicates or information structures) E.g. indian(Food) , date(Year,Month,Day) COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 5

Data Structures Data structures comprise of an iota called the functor and a rundown of contentions E.g. date(Year,Month,Day) E.g. T = tree(3, tree(2,nil,nil), tree(5,nil,nil)) Functors 3 2 5 COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 6

Principle of Resolution Prolog execution depends on the rule of determination If C 1 and C 2 are Horn provisos and the head of C 1 matches one of the terms in the assemblage of C 2 , then we can supplant the term in C 2 with the group of C 1 For instance, C 1 : likes(sam,Food) :- indian(Food), mild(Food). C 2 : indian(dahl). C 3 : mild(dahl). We can supplant the first and the second terms in C 1 by C 2 and C 3 utilizing the rule of determination (in the wake of instantiating variable Food to dahl ) Therefore, likes(sam, dahl) can be demonstrated COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 7

Unification Prolog partners factors and values utilizing a procedure known as unification Variable that get an esteem are said to be instantiated Unification manages A consistent brings together just with itself Two structures bring together if and just in the event that they have the same functor and a similar number of contentions, and the comparing contentions bring together recursively A variable binds together to with anything COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 8

Equality is characterized as unifiability A correspondence objective is utilizing an infix predicate = For example, ?- dahl = dahl. Yes ?- dahl = curry. No ?- likes(Person, dahl) = likes(sam, Food). Individual = sam Food = dahl ; No ?- likes(Person, curry) = likes(sam, Food). Individual = sam Food = curry ; No COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 9

Internal Representation for a uninstantiated variable Any instantiation demonstrates the equity Equality What is the aftereffects of ?- likes(Person, Food) = likes(sam, Food). Individual = sam Food = _G158 ; No COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 10

Execution Order Prolog scans for a determination succession that fulfills the objective so as to fulfill the consistent predicate, we can envision two pursuit methodologies: Forward binding , got the objective from the aphorisms Backward affixing , begin with the objective and endeavor to determine them working in reverse Backward fastening is typically more proficient, so it is the component basic the execution of Prolog projects Forward tying is more productive when the quantity of truths is little and the quantity of standards is vast COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 11

Backward Chaining in Prolog Backward tying takes after a great profundity first backtracking calculation Example Goal: Snowy(C) COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 12

Depth-first backtracking The look for a determination is requested and profundity first The conduct of the translator is unsurprising Ordering is major in Recursion is again the fundamental computational strategy, as it was in practical dialects Inappropriate requesting of the terms may bring about non-ending resolutions (unbounded relapse) For instance: Graph edge(a,b). edge(b, c). edge(c, d). edge(d,e). edge(b, e). edge(d, f). path(X, X). path(X, Y) :- edge(Z, Y), path(X, Z). Redress COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 13

Depth-first backtracking The scan for a determination is requested and profundity first The conduct of the mediator is unsurprising Ordering is central in Recursion is again the essential computational system, as it was in useful dialects Inappropriate requesting of the terms may bring about non-ending resolutions (endless relapse) For instance: Graph edge(a,b). edge(b, c). edge(c, d). edge(d,e). edge(b, e). edge(d, f). path(X, Y) :- path(X, Z), edge(Z, Y). path(X, X). Wrong COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 14

Infinite Regression Goal COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 15

Examples Genealogy http://ktiml.mff.cuni.cz/~bartak/prolog/genealogy.html Data structures and number juggling Prolog has a number-crunching functor is that binds together number-crunching values E.g. is (X, 1+2), X is 1+2 Dates case http://ktiml.mff.cuni.cz/~bartak/prolog/genealogy.html COMP 144 Programming Language Concepts Felix Hernandez-Campos

Slide 16

Reading Assignment Read Scott Sect. 11.3.1 Guide to Prolog Example , Roman Barták Go through the initial two illustrations http://ktiml.mff.cuni.cz/~bartak/prolog/learning.html COMP 144 Programming Language Concepts Felix Hernandez-Campos

Recommended
View more...