Chapter Five
Chapter Five
Logic Programming:
Outlines
Relational databases
Mathematical logic
Artificial intelligence
Prolog
• Prolog is very useful in some problem areas, such as artificial
intelligence, natural language processing, databases, . . . , but
pretty useless in others, such as graphics or numerical algorithms.
• Prolog is a programming language for symbolic, non-numeric
computation.
• Suitable for solving problems that involve objects and relations b/n
objects. The arguments of relations can be concrete
Example:
• date(day, month,year).
con…
• The set of compound terms and atoms together form set of
prolog predicates.
• A term that doesn't contain any variables is called a ground
term.
Clauses, Programs & Queries
• Prolog program consists of clauses.
• These are three types:
• Facts
• Rules and
• Questions.
Facts
A Fact is a predicate followed by a dot.
Meaning of fact is that certain instance of relation as being
true.
Fact declares things that are always, unconditionally true.
The built–in predicate fail always fails; you can use it to force
other predicates to backtrack through all solutions.
true
Con…
• Prolog generally prints true when it has
successfully completed a command, and false if it
fails to.
Conjoining commands
• ?- see('mydata'),
read(X),
read(Y),
read(Z),
seen.
• The predicate tell opens a file for output and switches
output to that file; told closes output files and
switches output back to the console.
CHARACTER INPUT AND OUTPUT: get, get0, put
rules about some domain and then use the database to draw conclusions.
or rule-based systems.
both the facts known to the expert and the expert’s reasoning path in
reaching conclusions from those facts. The completed expert system not
only simulates the human expert’s actions but can be questioned to reveal
Static predicates cannot, because their clauses have been compiled into a
form that runs faster but is no longer modifiable at run time.
Dynamic declarations have another effect, too: they tell the Prolog system
not to worry if you try to query a predicate that doesn’t exist yet.
• Assertz, asserta: permanent way of storing information.
predicate.
• If there are no clauses for that predicate, the predicate is created and
declared to be dynamic.
If the predicate already has some clauses and is static, an error condition is
raised.
assertz(Clause): Like asserta, but adds the clause at the end of the other