Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does HiLog add anything that can not be done with "call" in Prolog? [duplicate]

The Wikipedia article for Prolog states:

Higher-order programming style in Prolog was pioneered in HiLog and λProlog.

The motivation for HiLog includes its ability to implement higher-order predicates like maplist:

maplist(F)([],[]).
maplist(F)([X|Xs],[Y|Ys]) <- F(X,Y), maplist(F)(Xs,Ys).

The paper that describes HiLog assumes that Prolog only has call/1, not call/3.

However, since Prolog (now) has call/3, maplist can be easily implemented in it:

maplist(_, [], []).
maplist(P, [X|Xs], [Y|Ys]) :- call(P, X, Y), maplist(P, Xs, Ys).

Is HiLog mostly of historical interest, or is its "higher-order" logic more general that what's available in Prolog now?

like image 942
MWB Avatar asked Nov 14 '20 03:11

MWB


3 Answers

From wiki

Although syntactically HiLog strictly extends first order logic, HiLog can be embedded into this logic.

Any HiLog term can be translated into a Prolog term (HiLog: A foundation for higher-order logic programming - Weidong Chen, Michael Kifer, David S.Warren - 1993). So in a sense yes, it is not more general than Prolog.

Let me quote a few conclusions from the paper

Firstly, programming in HiLog makes more logic programs logical. We all admonish Prolog programmers to make their programs as pure as possible and to eschew the evils of Prolog’s nonlogical constructs. In Prolog, the intermixing of predicate and function symbols, in particular in the predicate, call/ 1, is nonlogical, whereas in HiLog, it is completely logical and is a first-class citizen. So in HiLog, programmers need not avoid using call/l, and thus have more flexibility in their task of writing pure logic programs.

Secondly, even though one might say that HiLog is simply a syntactic variant of Prolog, syntax is important when one is doing meta-programming. Since in meta-programming the syntax determines the data structures to be manipulated, a simpler syntax means that meta-programs can be much simpler.

like image 116
rajashekar Avatar answered Oct 20 '22 18:10

rajashekar


A bit vaguely:

HiLog is not in Prolog (Prolog stays Prolog) but is used in Flora, which is basically an logic-based object-oriented database. It has its own syntax and runs on XSB Prolog.

If I understand correctly, the idea of HiLog is to have a defined practical syntax for "higher-order" predicates, by allowing variables in predicate name positions. This is the difference between the two maplist examples.

This looks as if this was 2-nd order logic (which becomes uncomputable/untractable as there is no way to find out whether a predicate F is related to a predicate G in general as you may be forced to compare their extent, all the points where they succeed) but is flattened down to 1-st order (computable) by restriction to syntactic equality (F and G are the same if the name the same predicate, foo/2) at which point one can deploy call/N to generate Prolog code.

So, yes, currently you have to jump through hoops to express statements in Prolog that may be a one-liner in HiLog (I have no examples though, not having though too deeply about this). It's the difference between C and ... uh ... Prolog!

Similar to a host of other ideas for extensions/modifications to Prolog into various X-logs, not all of which were implemented (I once tried to make a an overview image here), "HiLog syntax" (or something similar to it) may be found in a specialized X-log of the future that breaks out of its niche.

like image 28
David Tonhofer Avatar answered Oct 20 '22 18:10

David Tonhofer


Since I answered my own question in the comments, I'll post it here:

There are things you can do in HiLog, that can not be done with call in Prolog, for example:

Queries like:

?- X(dog, 55, Y).

Assertions like:

foo(X, Y) :- Z(X), Z(Y(X)).

As stated in the aforementioned HiLog paper and the HiLog Wikipedia page, Prolog can emulate HiLog. However, this requires converting the whole program and all queries into a single predicate.

like image 1
MWB Avatar answered Oct 20 '22 18:10

MWB