Logic Programming + Finite State Machines Flashcards
What are the 5 data objects/terms
-Numbers
-Atoms
-Variables
-Compound terms
-Lists
What is a number
A number may be either an integer or a floating point
quantity (e.g 42 or -816.22)
What is an atom
An atom is a constant that does not have a numerical value. It
begins with a lowercase letter, or is quoted (e.g buffalo or ‘The X Files’)
What is a variable
A variable stands for a term that is to be determined. It begins
with an uppercase letter or ‘_’ (e.g X or Person_A)
What is a compound term
A compound term consists of a functor followed by a
sequence argument terms in brackets (e.g dog(rover))
What is a list
A list is a structured data type made up of a sequence of terms
enclosed in square brackets and separated by commas (e.g [dog, X, 220, 500])
What could a clause be
A clause may be
-a fact
-a rule
What is a fact
A fact is taken to be true. It must be an atom or a compound term and end in a full stop (e.g christmas. or dog(fido).)
What is a rule
A rule may be either true or false — only computation will
show. It must be an atom or a compound term, followed by a
“:-” followed by further atoms or a compound terms,
separated by commas (e.g grandfather(X, Y) :- father(X, Z), parent(Z, Y).)
What is the declarative reading of h :- t1, t2, … tk
h is true if t1, t2, … tk are all true
What is the procedural reading of h :- t1, t2, … tk
To compute h, compute t1, t2, … tk
What is a predicate
A predicate is defined by several clauses
What is a list
A list is made up of elements (possibly of different type)
enclosed in square brackets and separated by commas
What is the Cons Notation
The “cons” (or “|”) notation allows one to represent a list as
being constructed from some leading elements and a list (e.g [1, 2, 3 | [4, 5]] = [1, 2, 3, 4, 5])
sum_list( [], 0 ).
sum_list( [H|T], R )
:- sum_list( T, W ),
R is H + W.
In this predicate, what does H and T stand for
H is the head of the list, and T is the Tail
What is the member predicate
The member predicate is true when an element is a member of a list
member_list( E, [E|] ).
member_list( E, [|T] )
:- member_list( E, T ).
What is the append predicate
An append predicate appends two lists
append_list( [], Y, Y ).
append_list( [H|T], Y, [H|W] )
:- append_list( T, Y, W ).
What is the reverse predicate
A reverse predicate reverses a list
reverse_list( [], [] ).
reverse_list( [H|T], R )
:- reverse_list( T, W ),
append( W, [H], R ).
How can an atom be viewed as a list of ASCII codes
The “name” predicate allows one to convert from an atom to a list of integers
name( ace, X ).
X = [ 97, 99, 101 ]
Not really anything but just an example of making characters uppercase idk it might be useful
make_upper( [], [] ).
make_upper( [H|T], [V|W] )
:- to_upper( H, V ),
make_upper( T, W ).
to_upper( A, B )
:- B is A - 32.
What is the infix operator to carry out arithmetic
The operator ‘is’
What happens if the left argument of the arithmetic is an unbound variable
Bind it to the result of evaluating evaluating the right argument, and succeed
What happens if the left argument is a number, or a bound variable with a numerical values
Succeed if the right argument has the same numerical value
What are the arithmetic operators
X + Y: sum of X and Y
X - Y: difference of X and Y
X * Y: product of X and Y
X / Y: quotient of X and Y
X // Y: integer quotient of X and Y
X mod Y: remainder when X is divided by Y
X ^ Y: value of X to the power Y
What are the arithmetic functions
abs( N, X ): absolute value of N
sin( N, X ): sine of N (in radians)
cos( N, X ): cosine of N (in radians)
log( N, X ): natural logarithm of N
sqrt( N, X ): square root of X
What are the relational operators
X =:= Y: X and Y are same value
X == Y: X and Y are not same value
X > Y: X greater than Y
X >= Y: X greater than or equal to Y
X < Y: X less than Y
X =< Y: X less than or equal to Y
What are the unification operators
X = Y: X and Y can be unified
X = Y: X and Y cannot be unified
(ok so its supposed to be a backslash for the bottom one but its not appearing)
What is the only logical negation operator
+ X not X
(backslash isnt working here either)
What is the closed-word assumption
What is stated is true; what is not stated is false
What does ‘negation as failure’ mean
Anything that cannot be
proved true is false.
How do you construct ‘if-then-else’
By using -> ; (e.g maxof( X, Y, Z )
:- ( X =< Y
-> Z = Y
; Z = X
). )
How does Prolog attempt to satisfy a sequence of goals
It system attempts to
satisfy each goal in turn, working from left to right. If all the goals succeed in turn, the sequence of goals succeeds
as a whole.
A goal must be a call term, what is a call term
Either an atom, a compound
term, or an “is”, but not a number.
How does the Prolog system work to satisfy a single goal
It works through the
clauses in the database from top to bottom, examining those
clauses that have a functor and arity that unify with the goal.
(A functor is the atom part of a compound term and arity is the number of arguments)
What is unification
The matching algorithm used to choose a particular clause
How do two numbers unify
Two numbers unify if and only if they are the same
How do two atoms unify
Two atoms unify if and only if they are the same
How do variables unify
Two unbound variables, say A and T, always unify, with the
two variables bound to each other.
An unbound variable and a term that is not a variable always
unify, with the variable bound to the term.
How do two compound terms unify
Two compound terms unify if and only if they have the same
functor and the same arity, and their arguments can be unified
pairwise, working from left to right.
How do two lists unify
Two lists unify if and only if they have the same number of
elements and their elements can be unified pairwise, working
from left to right.
How do substitutions work
In general, the result of unification is a substitution
σ = X1/t1, X2/t2, . . . Xn/tn
where ti is a term to be substituted for variable Xi.
This substitution is carried forward to further unifications
What is backtracking
If any goal fails, the Prolog system tries to find another way of satisfying the most recently satisfied previous goal.
h :- t1, t2, … tk.
How does a logic program generate permutations
It will generate one permutation at a time, on demand from the tester, backtracking to consider
further permutations.
Why do purists not like the modification of the database
They see as being against the spirit of logic programming. Like other advanced features, they need to be used with care
What is a classical expert system
-A database of elementary facts about the domain;
-Some domain rules for knowledge acquisition;
-Some inference rules for reasoning from data;
-A facility for generating explanations.
What are the 4 examples of classical expert systems
-Dendral;
-MYCIN;
-PROSPECTOR;
-SHRDLU.
What is Dendral
The 1965 Dendral system (a contraction of DENDRitic ALgorithm) generates all possible arrangements of a set of atoms, and searches through it for likely ones, consistent with
the rules of chemical valence.
The heuristics employed are based on judgment and chemical knowledge — experience and intuition.
What is MYCIN
The 1972 MYCIN system (many antibiotics have the suffix “-mycin”) is designed to assist physicians in the diagnosis of bacterial infections.
Knowledge is encoded as 350 decision rules which embody the clinical decision criteria of infectious disease experts.
What is PROSPECTOR
The 1976 PROSPECTOR system was designed for decision-making problems in mineral exploration. It aids geologists in evaluating exploration sites or regions for occurrences of ore deposits of particular types.
What is SHRDLU
The 1968 SHRDLU system allowed the user to communicate with the computer in natural language, moving objects and querying the state of a simplified “blocks world.”
What is blackboard architecture
In expert systems, a blackboard architecture is one where a shared “blackboard” is iteratively updated by a diverse group of knowledge sources, starting with a problem specification and ending with a solution.
The Prolog database readily supports this architecture.
What is the difference between static and dynamic predicates
A static predicate cannot be modified as the program runs — by default, predicates are static ones.
A dynamic predicate can be modified as the program runs — predicates may be declared as dynamic ones.