0
votes

Is it possible to partially match rule in prolog ?

a( b ) :- k(c),k( d ).
a( e ) :- k(g),k( d ).

So knowing that k(d):-true. is it somehow possible to obtain b & e ?

1
Not very clear what you are asking. - user1812457
If you're asking to derive, for example, a(b) given that k(d) is true, but k(c) is false, you can't with the rules you're showing. You might be able to create a meta-interpreter of the rules to determine that, however. - lurker
@lurker That is exactly what i want ;| ok then i guess prolog isn't the best choice - molok
I didn't say Prolog's not the best choice. ;) You can write a rule verifier in Prolog. - lurker
hmm , what about the other way around - is it possible to get all a( ) rules and all their right side elements , and check if one is true ? - molok

1 Answers

0
votes

I finally did what i wanted to and it goes like this (swi_prolog) where rule is the name of rules to check

true_check([_,H,B]):-
    call(H)->true;B=..L,true_check(L).
true_check([B]) :-
    call(B)->true;false.

possible(Rule):-
   current_predicate(rule,Head),
   clause(Head,B),
   B=..I,
   true_check(I),
   Head=..[_,Rule].