Suppose I have a set of Literals (represented as a list for instance) and a predicate specified dynamically, what I want is to produce a set of literals that contains all the previous ones in addition to the ones that can be deducted by applying the predicate to the set.
An example, having defined the predicate
pred(A, B) :- base(A, B).
pred(A, C) :- base(A, B), pred(B, C).
and supposing such a signature for the predicate
deduce_set(+Set, +Pred, ?DeducedSet)
the following statement holds (is true):
deduce_set([base(a,b), base(a,c), base(b,d), base(d, e)],
pred/2,
[base(a,b), base(a,c), base(b,d), base(d,e), pred(a,d), pred(a,e), pred(b,e)]
).
What is the most efficient and general way to do so? I've been thinking about something like:
- asserting all literals in Set
- call Pred
- if it succeeds assert its head
- collect all the asserted facts in the resulting set and put into a list
isn't there a better way?
UPDATE This solution, better defined by CapelliC, by using metaprogramming can't cope with vars in the set under Object Identity. Any workaround for this?
DeducedSetwith a completed list (closure) ofSetunder (dynamically defined) rules of inference for predicatePred? In this caseDeducedSetwill always consist of the (initial) listSet(which perhaps consists of terms with various functors) followed by a tail consisting of new terms for functorPred. Finding the closure under such rules of inference would probably be facilitated by introducing an accumulator argument. - hardmathDeducedSetuntil no further inferences are possible, and then "return" the already assembled list. Primarily I was asking if you want "closure" or simply a single pass revision to yourDeducedSet. - hardmath