Prolog Flashcards
The aim of prolog is to
- represent knowledge efficiently through facts and rules
- retrieve and infer knowledge from this representation,
given a query
Logical principles are needed to enable such inference
Truth conditions, connectives, variables, predicates,
formula’s
Prolog: general framework
1: Knowledge base
* Facts
* Rules
* Stored in .pl files
* 2: Queries
* Posted from shell / script
* ?-
Prolog - not
- not(:Goal) - True if Goal cannot be proven
- not is deprecated due to its strong link to logical negation but still
provided - Use + instead
implication
:- defines an implication (A → B corresponds to B :- A).
conjunction
, defines a conjunction (in right-hand side of rule)
disjunction
; defines a disjunction (but can also be multiple rules)
atom
- A sequence of letters, digits, or underscores that starts with a lower-case letter, e.g. car, hOUSE_2, father
- A sequence of letters, digits or underscores that are enclosed in single quotes, e.g. ‘car’, ‘House’, ‘HOUSE 2’
- A string of special characters, e.g. :- or ,
number
A number is any sequence of numbers, possibly containing a dot.
Both atoms and numbers are called constants.
variable
A variable is a sequence of letters, digits or underscores that starts with an uppercase letter or an underscore, e.g. X, Car, HOUSE_2, _father, House.
o The variable _ is called the anonymous variable.
term
- Each constant and variable is a term.
- f(t1,…,tk) is a term if each ti is a term and f is an atom.
* This is called a compound term with functor f and arity k, which is often referred to in
the notation f/k (signature), e.g. has_wheels/1 or has_embodiment/2.
* A term is ground when it contains no variables
predicate
Any constant or compound term is known as a predicate
fact
predicate If immediately followed by a dot (.), it is called a fact (knowledge).
clause
A clause is any fact or rule.
* p(X) :- f(X),r(X) (Prolog)
* f(X)∧ r(X) → p(X) (FOL)
Clauses are always universal, i.e. here p(X) holds for all X