In article <1pq4ieINNncv@dns1.NMSU.Edu> enpontel@dante.nmsu.edu (PONTELLI) writes:
> Furthermore I am not so convinced that Prolog's unification is more
> efficient than a properly implemented Martelli-Montanari (which, again is
> a quasi-linear algorithm) or Paterson-Wegman algorithm.
In the general case, it is not as efficient as a linear algorithm. However,
it is faster in simple cases, and these make up the bulk of the unifications
done in `typical' Prolog programs.
Two examples:
X = SomeVeryLargeDataStructure
Prolog's unification procedure just binds X in time O(1).
An algorithm with occurs check has to check if X occurs *somewhere*
in the large data structure, taking O(n) time at best.
X1 = p(X2, X2), X2 = p(X3, X3), ..., Xn = p(Xn-1, Xn-1),
Y1 = p(Y2, Y2), Y2 = p(Y3, Y3), ..., Yn = p(Yn-1, Yn-1),
X1 = Y1
A linear algorithm will perform the unification X1=Y1 in time O(n).
Prolog's procedure will need O(2^n).
The first case tends to be more common.
Jens.
--
Internet: jensk@hpbeo82.bbn.hp.com HPDESK : JENS_KILIAN%XU@HP1200
MausNet: Jens Kilian @ BB KILIAN_JENS/HP1200_XU@hpbbi4
-------------------------------------------------------------------------------
As the air to a bird, or the sea to a fish, so is contempt to the contemptible.
|