Week 9 Intro to Prolog Flashcards
(18 cards)
Logic programming
Logic is used to express knowlege (describe program)
Inference is used to compute and obtain solutions to programs
Advantages of logic programming
Advantages:
. declarative style of programming
. program can be used in different ways
. PRECISE AND SIMPLE SEMANTICS
. same formalism to write programs , manipulate them , prove properties
Disadvantage of logic programming
The capability to handle arithmetic and IO operations comes at the expense of declarative semantics
. Only a fragment of classical first order logic
What is domain of computation in prolog
Terms
What are terms
Variable (X,Y,Z)
function symbols ie f with arity n that takes t1 … tn as arguments where t1…tn are terms
function with arity 0 is a constant ie a (lowecase)
function with arity n>=1 f(t1…tn)
Predicate symbols
if p is a predicate with arity n and has arguments t1 …tn where t1..tn are terms then p(t1…tn) is an Atomic formula A
What is a literal
Atomic formula or its negation
IMPORTANT
PREDICATES TAKE TERMS AS ARGUMENTS NOT OTHER PREDICATES
horn clause
disjunction of literals of which at most one is positive
definite horn clause
disjunction of literals where there is exactly one positive literal
Horn clause 3 cases
One positive (fact)
one positive some negfative (rule)
only negatives (goal)
What is a program in prolog
set of definite horn clauses ie a set of facts and rules
IMPORTANT NOTE ABOUT VARIABLES
ALL VARIABLES IN PROLOG INDIVIDUALLY UNIVERSALLY QUANTIFIED
What is a value
term associated to variables by means of a substitutiobn
Substitiution
partial mapping of Variables to terms
NOT TERMS TO VARIABLES AS NOT ALL TERMS CAN BE REPLACED (IE CONSTANTS …
IMPORTANT FACT ABOUT SUBSTITUTION
simultaneously replace each variable
ie t = loves ( X, Y) σ = {X -> Y , Y -> a }
tσ = loves( Y , a)
NOT loves(a,a) since we simultaneously replace not one after the other
JUST READ
Order of clauses significant as resolution applied in program order
selection function picks leftmost goal
Just READ - Language limitationbs
Negation:
Prolog programs are composed of definite clauses which contain one +ve literal. Therefore it is impossible to state facts involving negative statements or rules with negative literals in their head
General Resolution:
If there was no restrictions then 1) clauses can be resolved in multiple ways, 2) we need to arbitrarily chose the next pair of clauses
Consequences: resolution of a program with a goal can be made unique and deterministic, Resolvent of 2 clauses will either be empty(success) or generate a new goal