Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
LOGIC PROGRAMMING LANGUAGE:
Prolog (Programming in Logic, 1972) is the most well-known representative of the
programming language paradigm.
Prolog is based on Horn clauses (Special kind of logic formula) and SLD(Selective
Linear Definite) resolution
Mostly developed in fifth generation computer systems project
Specially designed for theorem proof artificial intelligence but allows general
purpose computation
Logic programming sometimes called declarative programming language
Express programs in a form of symbolic logic
Use a logical inferencing process to produce results
Introduction to Predicate Calculus
Propositions: a logical statement that may or may not be true. Consists of
objects and relationships of objects to each other
Symbolic Logic: logic which can be used for the basic needs of formal
logic, express propositions, express relationships between propositions,
describe how new propositions can be inferred from other propositions.
Particular form of symbolic logic used for logic programming called
predicate calculus.
Object representation: objects in propositions are represented by simple
terms either constants or variables
Constant: a symbol that represents an object
Variable: a symbol that can represent different object at different times.
It is different from variable in imperative language
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Compound: Atomic proposition consist of compound terms, compound
terms one element of a mathematical relations, written like a
mathematical functions mapping
Clausal Form : propositions can be stated in two forms
Fact – proposition is assumed to be true
Query – truth of proposition is to be determined
Compound propositions : have two or more atomic propositions,
propositions are connected by operators or symbols
too many ways to state the same thing
Use a standard form for propositons
Clausal form : B1 U B2 U B3 ⸦ A1
Here Antecedent : right side
Consequent : left side
Proving theorems
A use of propositions is to discover new theorems that can be inferred
from known axioms and thermos. Resolutions an inference principle that
allows inferred propositions to be computed from given propositions
Resolution: unification finding values for variables in propositions that
allows matching process to succeed. Instantiation assigning temporary
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
values for variables in propositions that allows unification to succeed.
After instantiation variable with a value, if matching fails may need to
backtrack and instantiate with a different value.
Basis for logic programming to theorem proving
When propositions used for resolutions, only restricted form can be used
Horn clause – can have only two forms
Headed single atomic proposition on left side
Headless empty left side (used to state facts)
Most propositions can be stated as Horn Clauses
Logic programming
Declarative semantics
Introduction to PROLOG
Basic elements of Prolog
Term
Constant
Atom
Terms:
A Prolog term is a constant, a variable, or a structure.
A constant is either an atom or an integer. Atoms are the symbolic values
of Prolog and are similar to their counterparts in LISP.
A variable is any strings of letters, digits and underscores that begins with
an uppercase letter or underscore (_). Variables are not bound to types by
declarations. The binding of a value, and thus a type to a variable is called
an instantiation. The last kind of term is called a structure.
Structures represent the atomic propositions of predicate calculus and
their general form is the same: functor(parameter list). The functor is any
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
atom is used to identify the structure the parameter list can be any list of
atoms, variables or other structures.
Fact statements:
Used for the hypotheses
Headless Horn clauses
Prolog has two basic statement forms; these correspond to the headless
and headed Horn Clauses of predicate calculus. The simplest form of
headless Horn clause in Prolog is a single structure, which is interpreted as
an unconditional assertion, or fact. Logically, facts are simply propositions
that are assumed to be true.
Female (Shelley),
male (bill),
female (mary)
male (jake)
father(bill, jake)
father(bill, Shelley)
mother(mary, jake) mother(mary, Shelley)
These simple structures state certain facts about jake, Shelley, bill and
mary
For example the first states that Shelley is a female
The last four connect their two parameters with a relationship that is
named in the functor atom
For example the fifth proposition might be interpreted to mean that bill is
the father of jake
Rule statements:
Used for the hypotheses
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Headed Horn clauses
Right side: antecedent (if part) - may be single term or conjunction
Left side: consequent (then part) – Must be single term
Conjunction: multiple terms separated by logical AND operations (implied)
The other basic form of Prolog statement for constructing the database
corresponds to a headed Horn clause. This form can be related to a known
theorem in mathematics from which a conclusion can be brawn if the set
of given conditions is satisfied. The right side is the antecedent, or if part
and the left side is the consequent or then part. If the antecedent of a
Prolog statement is true, the the consequent of the statement must also
be true. Conjunctions contain multiple terms that are separated by logic
AND operations. In Prolog the AND operation is implied.
Female(shelley), child(shelley)
The general form of the Prolog headed Horn clause statement is
consequence:- antecedent_expression.
It is read as follows: “consequence can be concluded if the antecedent
expression is true or can be made to be true by some instantiation of its
variable
For example ancerstor (mary, shelley):-mother (mary, shelley)
States that if mary is the mother of shelley, then mary is an ancestor of
shelly. Headed Horn clauses are called rules, because they state rules of
implication between propositions.
Goal statements:
For theorem proving, theorem is in form of proposition that we want
system to prove or disprove – goal statement
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Some format as headless Horn
Conjunctive propositions and propositions with variables also legal goals
The syntactic form of Prolog goal statement is identical to that of headless
Horn clauses.
For example, we could have man(fred) to which the system will respond
either yes or no. The answer yes means that the system has proved the
goal was true under the given database of facts and relationships
Inferencing Process of Prolog:
Queries are called goals
If goal is a compound proposition, each of the facts is a subgoal
To prove a goal is true, must find a chain of inference rules and or facts
For example goal Q
B :- A
C:- B
…
Q:-P
Process of proving a subgoal called matching, satisfying or resolution.
Approaches
Bottom-up resolution, forward chaining –
Begin with facts and rules of database and attempt to find sequence that
leads and goals.
Works well with a large set of possibly correct answers.
Top-down resolution, backward chaining –
Begin with goal and attempt to find sequence that leads to set of facts in
database
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Works well with a small set of possibly correct answers
Prolog implementation use backward chaining.
Subgoal strategies: When goal has more than one subgoal, can use either
Depth-first search: find a complete proof for the first subgoal before
working on others.
Breadth-first search: work on all subgoals in parallel
Prolog uses depth-first search
Backtracking
With a goal with multiple subgoals if fail to show truth of one of subgoals,
reconsider previous subgoal to find an alternative solution is backtracking
Begin search where previous search left off
Can take lots of time and space because may find all possible proofs to
every subgoal.
Simple Arithmetic: Prolog supports integer variables and integer
arithmetic. Originally, the arithmetic operators were functors, so that the
sum of 7 and the variable X was formed with + (7, X)
Prolog now allows a more abbreviated syntax for arithmetic with the “is”
operator. This operator takes an arithmetic expression as its right operand
and a variable as its left operand. All variables in the expression must
already be instantiated, but the left-side variable cannot be previously
instantiated
For example in A is B / 17 + C
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Prolog does not have assignment statement in the same sense as
imperative languages
Trace:
Built-in structure that displays instantiations at each step
Tracing model of execution – four events
1. Call (beginning of attempt to satisfy goal)
2. Exit (when a goal has been satisfied)
3. Redo (when backtrack occurs)
4. Fail(when goal fails)
Example:
Likes(jake, chocolate)
Likes(jake,apricots)
Likes(darkle, licorice)
Likes(darkle, apricoats)
Trace
Likes(jake, X)
Likes(darcie,X)
List Structures
Other basic data structure (besides atomic propositions we have already
seen) list
List is a sequence of any number of elements
Elements can be atoms, atomic propositions, or other terms
[apple, grape, banana]
[ ] empty list
[X | Y] (head X and tail Y)
Department of Computer Science and Engineering
(Artificial Intelligence & Machine Learning)
Append example
Append([], list, list)
Append([Head| list1], list2, [Head | list3]:-
Append(list1,list2,list3)
Reverse example
Reverse([])
Reverse([Head | Tail, list):-
Reserve(Tail, Result),
Append(Result, [Head],List)
Deficiencies of Prolog
Resolution Order Control
The closed-world assumption
The negation problem
Intrinsic limitations
Applications of Logic Programming
Relational Database Management Systems
Expert Systems
Natural-language processing