Download presentation
Presentation is loading. Please wait.
Published byColleen Washington Modified over 9 years ago
1
Logic Programming Tarik Booker
2
What will we cover? Introduction Definitions Predicate Calculus Prolog Applications
3
What is Logic Programming? Simply programming that uses a form of symbolic logic (predicate calculus) as a programming language Languages based on this type of programming are called Logic Programming Languages (Also known as declarative languages)
4
Definitions (1) Predicate Calculus: Proposition – a logical statement that may or may not be true Atomic – consist of compound terms Compound Terms – element of a mathematical relation Functor – function symbol that names the relation Ordered list – parameters man(bob) like(bob, steak)
5
Definitions (2) Clausal Form: B 1 B 2 B 3 A 1 A 2 A 3 Antecedent – right side of a clausal form Consequent – left side of a clausal form Declarative Semantics – there is a simple way to determine the meaning of each statement
6
Prolog Logic Programming Language Definitions: Term – a constant, variable or structure Constant – only an atom (synbolic value) or an integer Variable – any string of letters, digits, or underscores that begins with an uppercase letter Structure – atomic propositions of predicate calculus Ex: mystruct(parameter list) Instantiation – a binding of a value to a variable
7
Sample Prolog (Fact Statements) Fact Statements: male(bill). male(jack). father(bill, jack). Which is Correct? Bill is Jack’s father? Jack is Bill’s father?
8
(Answer) Either way! There are no intrinsic semantics in Prolog (just like Predicate Calculus) Can be interpreted by the programmer in any way he/she likes.
9
Sample Prolog (Rule Statements) Consequence_1 :- Antecedent_expression Examples: female(shelley), child(shelley). ancestor(mary, shelley) :- mother(mary, shelley). (If Mary is the mother of Shelley, then Mary is the ancestor of Shelley)
10
Goal Statements Queries are known as goals in Prolog. Example: father(jason, freddy). father(X, freddy).
11
Inferencing You want a goal. When the goal is a compound proposition, each of the facts (structures) is called a subgoal To prove a goal is true, the inferencing process muse connect the goal to one or more facts in the database Proving a subgoal is known as satisfying the subgoal
12
Inferencing Example Database contains: father(bob). man(X) :- father(X). Your goal (query): man(bob). Forward Chaining – bottom-up resolution (start with facts, find goal) Backward Chaining – top-down resolution(start with goal, find facts)
13
Inferencing (2) Forward Chaining: better when the number of possible correct answers is large Backward Chaining: better when there is a reasonable small set of candidate answers When goal has more than one structure, we must search: Depth-first – finds a proof for the first subgoal beforw working on the others Breadth-first – works on all subgoals in parallel Prolog uses depth-first, because it utilizes fewer resources Backing up in a goal to a previously proven subgoal is known as backtracking
14
Applications of Logic Programming Relational Database Management Systems Expert Systems – emulate human expertise in some particular domain Natural Language Processing
15
Resources Used Sebesta, Robert W. Concepts of Programming Languages (4 th Edition)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.