LOGIC PROGRAMMING Lecture 2: Prolog as a languageUnifying Lists Lecture 2: Prolog as Language...
Transcript of LOGIC PROGRAMMING Lecture 2: Prolog as a languageUnifying Lists Lecture 2: Prolog as Language...
Ahmed SallamSlides based on original lecture slides Dr. Temur Kutsia
LOG
IC PRO
GRA
MM
ING Lecture 2: Prolog as a language
2/27/2015
Lecture 2: Prolog as Language 1
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language2
Syntax
Terms : constant Variable structure
2/27/2015Lecture 2: Prolog as Language3
Constants
2/27/2015Lecture 2: Prolog as Language4
Non-Constants
2/27/2015Lecture 2: Prolog as Language5
Variables
2/27/2015Lecture 2: Prolog as Language6
Structures
Collection of Objects, Components, grouped together in oneobject .
Help Organize . Make code more readable .
2/27/2015Lecture 2: Prolog as Language7
Structures
Example: Index Card for Library Author’s Name Title Date Publisher Name could be split also first, last, etc .
2/27/2015Lecture 2: Prolog as Language8
Examples
2/27/2015Lecture 2: Prolog as Language9
Questions
2/27/2015Lecture 2: Prolog as Language10
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language11
Equality
2/27/2015Lecture 2: Prolog as Language12
Example: Instantiated
2/27/2015Lecture 2: Prolog as Language13
Example: Symbols
2/27/2015Lecture 2: Prolog as Language14
Arguments Instantiated
2/27/2015Lecture 2: Prolog as Language15
Arguments Instantiated
2/27/2015Lecture 2: Prolog as Language16
Equality
2/27/2015Lecture 2: Prolog as Language17
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language18
Arithmetic Comparisons
2/27/2015Lecture 2: Prolog as Language19
Arithmetic
2/27/2015Lecture 2: Prolog as Language20
Example
2/27/2015Lecture 2: Prolog as Language21
Runs
2/27/2015Lecture 2: Prolog as Language22
Who was a Prince When
2/27/2015Lecture 2: Prolog as Language23
Invalid Question
2/27/2015Lecture 2: Prolog as Language24
Arithmetic Operations
2/27/2015Lecture 2: Prolog as Language25
Calculating
2/27/2015Lecture 2: Prolog as Language26
Questions
2/27/2015Lecture 2: Prolog as Language27
Questions
2/27/2015Lecture 2: Prolog as Language28
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language29
How Prolog Answers Questions
2/27/2015Lecture 2: Prolog as Language30
Matching
2/27/2015Lecture 2: Prolog as Language31
How Is this Matched
2/27/2015Lecture 2: Prolog as Language32
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language33
Representing Structures as Trees
2/27/2015Lecture 2: Prolog as Language34
Representing Structures as Trees
2/27/2015Lecture 2: Prolog as Language35
Parsing
2/27/2015Lecture 2: Prolog as Language36
Parsing
2/27/2015Lecture 2: Prolog as Language37
Parsing
2/27/2015Lecture 2: Prolog as Language38
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language39
Lists
2/27/2015Lecture 2: Prolog as Language40
Lists
2/27/2015Lecture 2: Prolog as Language41
Lists as Trees
2/27/2015Lecture 2: Prolog as Language42
List Manipulation
2/27/2015Lecture 2: Prolog as Language43
Head and Tail
2/27/2015Lecture 2: Prolog as Language
44
Unifying Lists
2/27/2015Lecture 2: Prolog as Language
45
Strings are Lists
2/27/2015Lecture 2: Prolog as Language46
Membership in a List
2/27/2015Lecture 2: Prolog as Language47
Membership in a List (Example)2/27/2015Lecture 2: Prolog as Language48
a. member(X,[X|_]). b. member(X,[_|Y]):-member(X,Y).------------? member(4, [1,2,4,-5,6,8]). T1.a member(4, [1|[2,4,-5,6,8]]). F1.b member(4,[_|[2,4,-5,6,8]]):- 2. member(4,[2,4,-5,6,8]). T2.a member(4,[2|[4,-5,6,8]]. F2.b member(4,[_|4,-5,6,8]):- 3. member(4,[4,-5,6,8]). T3.a member(4,[4|[-5,6,8]]). T3.b member ().
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language49
Recursion
2/27/2015Lecture 2: Prolog as Language50
Member Success
2/27/2015Lecture 2: Prolog as Language51
Member Failure
2/27/2015Lecture 2: Prolog as Language52
Member. Questions
2/27/2015Lecture 2: Prolog as Language53
Recursion. Termination Problems
2/27/2015Lecture 2: Prolog as Language54
Recursion. Termination Problems
2/27/2015Lecture 2: Prolog as Language55
Prolog as Language
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
2/27/2015Lecture 2: Prolog as Language56
Mapping ?
2/27/2015Lecture 2: Prolog as Language57
Mapping a Sentence to Another
2/27/2015Lecture 2: Prolog as Language58
Mapping a Sentence. PROLOG Program
2/27/2015Lecture 2: Prolog as Language59
Boundary Conditions
2/27/2015Lecture 2: Prolog as Language60