How is the 'is/2' Prolog predicate implemented? I know that
X is 3*4
is equivalent with
is(X, 3*4)
But is the predicate implemented using imperative programming? In other words, is the implementation equivalent with the following C code?
if(uninstantiated(x))
{
X = 3*4;
}
else
{
//signal an error
}
Or is it implemented using declarative programming and other predicates?
Depends on your Prolog, obviously, but any practical implementation will do its dirty work in C or another imperative language. Part of
is/2
can be simulated in pure Prolog:Where
evaluate
is a huge predicate that knows about arithmetic expressions. There are ways to implement large parts of it in pure Prolog too, but that will be both slow and painful. E.g. if you have a predicate that adds integers, then you can multiply them as well using the following (stupid) algorithm:None of this is guaranteed to be either practical or correct; I'm just showing how arithmetic could be implemented in Prolog.