0% found this document useful (0 votes)
10 views

Logic Programming-1

Ppt of logic programming

Uploaded by

SHARK GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Logic Programming-1

Ppt of logic programming

Uploaded by

SHARK GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

LOGIC

PROGRAMMING
-GROUP H
 INTRODUCTION :-
Logic programming is a programming paradigm that is based on formal
logic.

In this paradigm, you write programs by specifying a set of facts and
rules, and then query the system to infer new information or solve
problems.

Prolog is the most widely used logic programming language.

Prolog is a computer programming language that is used for solving


• problems that involve objects and the relationships between objects.
 BACKGROUND FOR LOGIC:-
A proposition is a logical statement that is only made if it is true
• Today is Tuesday
• The Earth is round

Symbolic logic uses propositions to express ideas, relationships between


ideas and to generate new ideas based on the given propositions.

Two forms of propositions are


• Atomic propositions
• Compound terms (multiple propositions connected through the logical
operators of and, or, not, and implies)

Propositions will either be true (if stated) or something to prove or disprove


(determine if it is true) – we do not include statements which are false
 LOGIC FORMULAS:-
 Declarative statement contains:
- Persons (individual)
• "Mary, Tom".
• - Relation between individuals like:
• ". . . is a mother "
• ". . . is a child of . . . "
• ". . . loves . . . "
• - Relation may not hold between individuals like:
• “…being a mother"
• - Relations with more than two objects like:
• “ . . . is the sum of . . . and . . . "
 PROLOG:-
PROLOG is a programming language that allows the programmer to specify
declarative statements only
• declarative statements (things you are declaring) fall into 2 categories
• predicates/propositions that are true
• clauses (truth preserving rules in clausal form)
• once specified, the programmer then introduces questions to be
answered
• PROLOG uses resolution (backward chaining) and unification to
perform the problem solving automatically
PROLOG was developed in France and England in the late 70s
• the intent was to provide a language that could accommodate logic
statements and has largely been used in AI but also to a lesser extent as
a database language or to solve database related problems
 ELEMENTS OF PROLOG:-
Terms – constant, variable, structure
• constants are atoms or integers (atoms are like those symbols found in Lisp)
• variables are not bound to types, but are bound to values when instantiated
(via unification)
• an instantiation will last as long as it takes to complete a goal
• proving something is true, or reaching a dead end with the current instantiation
• structures are predicates and are represented as
• functor(parameter list) where functor is the name of the predicate
All statements in Prolog consist of clauses
• headed clauses are rules
• headless clauses are statements that are always true
• in reality, a headless clause is a rule whose condition is always true
• all clauses must end with a period
 ADVANTAGES OF PROLOG:-
 There are several advantages to using Prolog
• ability to create automated problem solvers merely by listing knowledge
• a shortcut way to build and query a database
• solving significantly difficult problems with minimal code:
• Deriving the permutations of a list List:
perm(List,[H|Perm]):-delete(H,List,Rest),perm(Rest,Perm).
perm([ ],[ ]).
delete(X,[X|T],T).
delete(X,[H|T],[H|NT]):-delete(X,T,NT).
• Sorting a list of values stored in List:
insert_sort(List,Sorted):-i_sort(List,[],Sorted).
i_sort([ ],Acc,Acc).
i_sort([H|T],Acc,Sorted):-insert(H,Acc,NAcc),i_sort(T,NAcc,Sorted).
insert(X,[Y|T],[Y|NT]):-X>Y,insert(X,T,NT).
insert(X,[Y|T],[X,Y|T]):-X=<Y.
insert(X,[],[X]).
A naïve sort (inefficient, but simple):
naive_sort(List,Sorted):-perm(List,Sorted),is_sorted(Sorted).
is_sorted([ ]).
is_sorted([ _ ]).
 DEFICIENCIES OF PROLOG:-
Lack of control structures
• Prolog offers built-in control of resolution and unification
• you often have to force a problem into the resolution mold to solve it with Prolog (most problems cannot or
should not be solved in this way)
Inefficiencies of resolution
• resolution, as a process, is intractable (O(2n) for n clauses)
• useful heuristics could be applied to reduce the complexity, but there is no way to apply heuristics in Prolog
• they would just be additional rules that increases the size of n!
Closed world assumption
• in any form of logic reasoning, if something is not known, it is assumed to be false and everything
is either true or false
Negation is difficult to represent
• since there is no NOT in Prolog, how do we represent NOT?
• recall that anything explicitly stated must be true so we cannot specify NOT something as something would then
be false
• we can represent A != B, but we cannot represent ~dog(X).
THANK YOU
1.SANDEEP GUPTA-123
2.ABHISHEK SHARMA-
130
3.SINESH PRAJAPATI-126
4.SHAIKH SHARIK-128
5.GANESH NISHAD-125
6.MANIKANDAN-124
7.ROHIT SINGH-140

You might also like