Prolog 02
Prolog 02
Prolog 02
16-Feb-17
Ahmed Sallam
Slides based on original lecture slides Dr. Temur Kutsia
Prolog as Language
2Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Syntax
3Lecture 2: Prolog as Language 16-Feb-17
Terms:
constant
Variable
structure
Constants
4Lecture 2: Prolog as Language 16-Feb-17
Non-Constants
5Lecture 2: Prolog as Language 16-Feb-17
Variables
6Lecture 2: Prolog as Language 16-Feb-17
Structures
7Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Equality
12Lecture 2: Prolog as Language 16-Feb-17
Example: Instantiated
13Lecture 2: Prolog as Language 16-Feb-17
Example: Symbols
14Lecture 2: Prolog as Language 16-Feb-17
Arguments Instantiated
15Lecture 2: Prolog as Language 16-Feb-17
Arguments Instantiated
16Lecture 2: Prolog as Language 16-Feb-17
Equality
17Lecture 2: Prolog as Language 16-Feb-17
Prolog as Language
18Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Arithmetic Comparisons
19Lecture 2: Prolog as Language 16-Feb-17
Arithmetic
20Lecture 2: Prolog as Language 16-Feb-17
Example
21Lecture 2: Prolog as Language 16-Feb-17
Runs
22Lecture 2: Prolog as Language 16-Feb-17
Who was a Prince When
23Lecture 2: Prolog as Language 16-Feb-17
Invalid Question
24Lecture 2: Prolog as Language 16-Feb-17
Arithmetic Operations
25Lecture 2: Prolog as Language 16-Feb-17
Calculating
26Lecture 2: Prolog as Language 16-Feb-17
Questions
27Lecture 2: Prolog as Language 16-Feb-17
Questions
28Lecture 2: Prolog as Language 16-Feb-17
Prolog as Language
29Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
How Prolog Answers Questions
30Lecture 2: Prolog as Language 16-Feb-17
Matching
31Lecture 2: Prolog as Language 16-Feb-17
How Is this Matched
32Lecture 2: Prolog as Language 16-Feb-17
Prolog as Language
33Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Representing Structures as Trees
34Lecture 2: Prolog as Language 16-Feb-17
Representing Structures as Trees
35Lecture 2: Prolog as Language 16-Feb-17
Parsing
36Lecture 2: Prolog as Language 16-Feb-17
Parsing
37Lecture 2: Prolog as Language 16-Feb-17
Parsing
38Lecture 2: Prolog as Language 16-Feb-17
Prolog as Language
39Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Lists
40Lecture 2: Prolog as Language 16-Feb-17
Lists
41Lecture 2: Prolog as Language 16-Feb-17
Lists as Trees
42Lecture 2: Prolog as Language 16-Feb-17
List Manipulation
43Lecture 2: Prolog as Language 16-Feb-17
Head and Tail
44
a. member(X,[X|_]).
b. member(X,[_|Y]):-member(X,Y).
------------
? member(4, [1,2,4,-5,6,8]). T
1.a member(4, [1|[2,4,-5,6,8]]). F
1.b member(4,[_|[2,4,-5,6,8]]):- 2. member(4,[2,4,-
5,6,8]). T
2.a member(4,[2|[4,-5,6,8]]. F
2.b member(4,[_|4,-5,6,8]):- 3. member(4,[4,-5,6,8]). T
3.a member(4,[4|[-5,6,8]]). T
3.b member ().
Prolog as Language
49Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Recursion
50Lecture 2: Prolog as Language 16-Feb-17
Member Success
51Lecture 2: Prolog as Language 16-Feb-17
Member Failure
52Lecture 2: Prolog as Language 16-Feb-17
Member. Questions
53Lecture 2: Prolog as Language 16-Feb-17
Recursion. Termination Problems
54Lecture 2: Prolog as Language 16-Feb-17
Recursion. Termination Problems
55Lecture 2: Prolog as Language 16-Feb-17
Prolog as Language
56Lecture 2: Prolog as Language 16-Feb-17
Syntax
Equality
Arithmetic
Satisfying Goals
Structures and Trees
Lists
Recursive Search
Mapping
Mapping?
57Lecture 2: Prolog as Language 16-Feb-17
Mapping a Sentence to Another
58Lecture 2: Prolog as Language 16-Feb-17
Mapping a Sentence. P ROLOG Program
59Lecture 2: Prolog as Language 16-Feb-17
Boundary Conditions
60Lecture 2: Prolog as Language 16-Feb-17