Work with complex drilling cycles

I use Prolog to code some fairly complex rules in my project. There are many recursions, including mutual recursion. Part of the rules looks something like this:

pred1(X) :- ...
pred1(X) :- someguard(X), pred2(X).

pred2(X) :- ...
pred2(X) :- othercondition(X), pred1(X).

There is a fairly obvious endless cycle between pred1and pred2. Unfortunately, the interaction between these predicates is very difficult and difficult to distinguish. I was able to eliminate an infinite loop in this instance by passing a list of objects that were passed in pred1, but it is extremely cumbersome! In fact, this greatly downplays the purpose of using Prolog in this application.

How to make Prolog avoid endless loops? For example, if during the test pred1(foo)he tries to prove pred1(foo)how sub-goal, failure and return.

Can this be done using meta-interpreters ?

+4
source share
2 answers

One feature that is available on some Prolog systems and that can help you solve such problems is called a table. See for example the question and .

If tabbing is not available, then yes, meta-translators can definitely help a lot with this. For example, you can change the execution strategy, etc. Using the meta-interpreter.

In SWI-Prolog, also check call_with_inference_limit/3to strictly limit execution, regardless of processor type or system load.

Terminators such as cTI are related and useful : they allow you to statically obtain termination conditions.

+3

, - , . , .

, . : SWI , . make., check.

closure0/3 path/4, " ".

+4

Source: https://habr.com/ru/post/1614768/


All Articles