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