3 ms·
FWIW in the limited time I've been using Prolog that pattern has worked fine for me. A factor to consider: Prolog is old. It's very unlikely to encounter some
by carapace 8y ago
FWIW in the limited time I've been using Prolog that pattern has worked fine for me.
A factor to consider: Prolog is old. It's very unlikely to encounter some problem or issue that ahs not already been addressed, often by a team of researchers.
For example, when I was exploring Prolog I tried a simple transformation on syllogisms.
I found some code online that had them in this form:
syll(all(M,P), all(S,M), all(S,P)).
% This is barbara in the 1st figure.
syll(no(M,P), all(S,M), no(S,P)).
% This is celarent in the 1st figure.
Etc... I transformed them using term_expansion/2 [1] with this rule:
term_expansion(syll(A, B, C), (C :- B, A)).
To generate rules like these:
all(A, C) :- all(A, B), all(B, C).
no(A, B) :- all(A, C), no(B, C).
Etc... However, these rules (plus a few facts:
all(dogs, canines).
all(canines, mammals).
) led to huge open-ended search.
?- all(A, B).
ERROR: Out of local stack
It turns out I can just use call_with_depth_limit/3 [2] to bound the search depth:
?- call_with_depth_limit(all(A, B), 10, R).
A = dogs,
B = mammals,
R = 11 ;
A = dogs,
B = canines,
R = 11 ;
A = canines,
B = mammals,
R = 1.
It finds some solutions. Not all Prologs have call_with_depth_limit/3 built-in but it's easy to write a meta-interpreter that does the same thing.[3]
From the POV of security, the trick I want to explore is writing Prolog code to generate provably-correct machine code.
[1] http://www.swi-prolog.org/pldoc/doc_for?object=term_expansion/2 http://www.swi-prolog.org/pldoc/doc_for?object=term_expansio...
[2] http://www.swi-prolog.org/pldoc/doc_for?object=call_with_depth_limit/3 http://www.swi-prolog.org/pldoc/doc_for?object=call_with_dep...
[3] https://en.wikipedia.org/wiki/Iterative_deepening_depth-first_search https://en.wikipedia.org/wiki/Iterative_deepening_depth-firs...
- sgt101 8y agoDid you try using answer sets?