Cybercrimes in the Darknet and Their Detections: A Comprehensive Analysis and...
Prolog ppt
1. ADITYA ENGINEERING COLLEGE (A)
Logic Programming
By
R S S RAJU BATTULA
Asst.Prof
Dept of Computer Science and Engineering
Aditya Engineering College(A)
Surampalem.
2. Aditya Engineering College (A)
Principles of Programming Languages
• Predicate calculus
• Predicate calculus for proving Theorems
• Origins of Prolog
• Basic Elements of Prolog
• Deficiencies of Prolog
• Programming with Prolog
• Applications of Logic Programming
• Multi Paradigm Programming
Thursday, May 21, 2020R S S RAJU BATTULA
Logic Programming Contents
3. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Introduction: (Logic Programming)
Programming uses the symbolic form is called as Logic Programming. It is
also called as declarative language.
The syntax of logic programming is different from imperative and functional
languages.
The semantics of logic Programming also bears from imperative languages.
4. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Introduction to Predicate calculus:
Particular form of symbolic logic used for logic programming is predicate calculus.
Symbolic logic provides basis for logic programming. predicate calculus contains
Propositions.
Symbolic logic can be used for 3 basic needs
1. To express prepositions.
2. To express relationship between prepositions.
3. Describe how prepositions can create from others.
Particular form of symbolic logic used for logic programming is called “First order
Predicate calculus”.
5. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Prepositions:
Proposition is logical statement that may or may not be true. It consists of objects and
relationships of objects to each other.
Objects:
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 objects at different times
Different from variables in imperative languages
The simplest form of proposition is called atomic proposition consist of compound
terms. A compound term is one element of a mathematical relation, written in a form
that has the appearance of mathematical function
Compound term composed of two parts
Functor: function symbol that names the relationship
Ordered list of parameters (tuple)
6. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Eg: man(Jake) 1-tuple
like ( bob, playing) 2-tuple
Propositions are connected by operators
Name Symbol Example Meaning
Negation a not a
Conjunction a b a and b
Disjunction a b a or b
Equivalence a b a is equivalent to b
Implication
a b
a b
a implies b
b implies a
7. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Quantifiers:
Name Example Meaning
universal x.p For all x, p is true.
Existential x.p There exists value of x, p is
true
Clausal Form:
It is a simple form of preposition.
Format:
B1 U B2 U B3 U……..U Bn A1 n A2 n A3 n…..n An
8. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Origins of PROLOG: (Programming with Logic)
Invented by : Alain Colmerauer with Philippe Roussel
Year:1972
Associated with: Artificial Intelligence and Computational Linguistics.
Developed and Implemented in: Marseille, France
9. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Basic Elements of PROLOG:
1. FACT
2. OBJECTS
3. RELATION
4. PREDICATES
5. STRUCTURE OF PROLOG
10. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU B ATTULA
Facts ,objects and Relations:
Fact: A FACT can be described as symbolic relationship.
Eg: Samyra likes John.
likes(Samyra , John).
Relation Objects
Objects: An object is the name of the element of certain type.
6 types of objects:
1. Char 2. Integer 3. Real 4. String 5. Symbol 6. File
Relation: A relation is a name that defines the way in which a collection of
objects or variables belong together.
11. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Predicate:
Eg:
car is blue.
is( car, blue).
1. With out a period to a clause is called a predicate.
2. Predicate express relationship.
3. The elements with in the parenthesis are the arguments of predicate, which may
be objects or variables.
4. The word before the parenthesis is the name of the relation.
12. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Structure of PROLOG:
Domains
//defining objects ,variables
Predicates
//defining a Relationship, Function
Clauses
// defining Facts, Rules
Eg:
Domains
Person1,person2= symbol
Predicates
Likes(person1,person2)
Clauses
Likes(aditya, naina).
Likes(bob, hezal).
Output:
Goal: likes(bob, hezal).
TRUE
Goal: likes(bob, mary).
False
13. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Variables, Rules and Unification Process:
Variables: unknown quantity.
3 types of variables:
1. Bound (value is initiated to variable )
2. Free (which are not initiated or not defined at a
particular time )
3. Anonymous ( no variable no value)
Eg:
Domains
Disease, Indication =symbol
Predicate
Symptom(Disease, Indication)
Clauses
Symptom (flu, chills).
Symptom (cold, headache).
Symptom (flu, cough).
Goal:
Symptom( cold, indication)
Indication=headache
1 solution
Goal:
Symptom( ----, chill).
14. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Unification: (Pattern Matching)
The process by which a prolog tries to
match a term against the facts in an
effort to prove a goal is called
unification process.
In short, The process of matching the
items with variables is known as
Unification.
Predicates unify with each other if:
1. They have the same relation name.
2. They have the same number of
arguments.
3. All argument pairs unify with each
other.
Eg:
Domains
City, State=string
Predicate
Address(City, State)
Clauses
Address(“Lass Vegas”, “California”).
Address(“London”, ”Ontario”).
Address (“Egg Harbor”, ”New Jersey”).
Goal:
Address(“London”, ”Ontario”).
TRUE
15. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Rule:
A Rule is an expression that shows that the
truth of a particular fact is depends upon
one or more facts.
:- operator is called BREAK
Comma: an AND relationship.
Semicolon : an OR relationship.
Eg:
Jenny likes X if X likes Badminton.
Likes(Jenny, X) :- likes(X, Badminton).
Eg:
Domains
City, State=string
Predicate
Address(string , string)
go
Clauses
go:-
Address(City, State).
go.
Address (“Las Vegas”, ”California”).
Address(“London”, ”Ontario”).
Address (“Egg Harbor”, ”New Jersey”).
Goal:
Address(“London”, ”Ontario”).
TRUE
16. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Deficiencies of PROLOG:
1. Resolution order control:
Prolog always matches dame order, from beginning to end of given goal.
2. The closed world Assumption:
Prolog can prove the given goal is true but can’t prove given goal is false.
3. The Negation Problem:
The logical NOT is not an integral part of Prolog because
A:- B1n B2 n B3 n …. n Bn
if all B’s are true there only A’s will true, vice versa is difficult.
4. Intrinsic Limitations:
it specify the program to do but not to specify how to do.
17. Aditya Engineering College (A)
Principles of Programming Languages Thursday, May 21, 2020R S S RAJU BATTULA
Applications of logic Programming:
1.RDBMS
Tables can be described using structures and relationships given by using RULE.
2. Expert Systems
Most widely used logical Programming in expert systems is APES.
3.Natural Language Processing
Natural Language interface to computer s/w systems such as intelligent databases
and other Knowledge based.